Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************
- Author: Dr. Daniel Spiegel, Updated by: Trisha Badlu
- Creation Date: 21 March 2017
- Due Date: 31 March 2017
- Assignment: #3
- Filename: Array.h
- Course: CSC136 - 020
- Professor Name: Dr. Spiegel
- Purpose: Define prototype for Array class.
- ***************************************************************/
- // File: Array.h
- // Simple class Array prototype (for integers)
- #ifndef ARRAY_H
- #define ARRAY_H
- #include <iostream>
- using namespace std;
- class Array {
- public:
- Array(int arraySize= 10); // default constructor
- Array(const Array &init); // copy constructor
- ~Array(); // destructor
- // Functions updated to use term 'capacity' to better describe use
- /***************************************************************
- Function name: setCapacity (mutator)
- Description: Sets the capacity to the specified number
- Parameters: int - capacity (import)
- Return Value: none
- ***************************************************************/
- void setCapacity(int); // set the capacity
- /***************************************************************
- Function name: getCapacity (inspector)
- Description: Returns the capacity of the specified object
- Parameters: none
- Return Value: int - capacity
- ***************************************************************/
- int getCapacity() const; // return capacity
- /***************************************************************
- Function name: getEltsInUse (inspector)
- Description: Returns the number of elements in use of the
- specified object
- Parameters: none
- Return Value: int - numElts
- ***************************************************************/
- int getEltsInUse() const; //Added
- /***************************************************************
- Function name: setEltsInUse (mutator)
- Description: Sets the number of elements in use to the
- specified number
- Parameters: int - eltsInUse (import)
- Return Value: none
- ***************************************************************/
- void setEltsInUse(int); //Added
- /***************************************************************
- Function name: &sort (facilitator)
- Description: Sorts the values stored in the object
- Parameters: none
- Return Value: none
- ***************************************************************/
- Array &sort(); //Added
- /***************************************************************
- Function name: &operator= (mutator)
- Description: Assigns arrays equal to each other
- Parameters: const Array& - right (import)
- Return Value: Array - *this
- ***************************************************************/
- const Array &operator=( const Array & ); // assign arrays
- /***************************************************************
- Function name: operator== (facilitator)
- Description: Checks if array is equal to another
- Parameters: const Array& - right (import)
- Return Value: bool - true/false
- ***************************************************************/
- bool operator==( const Array & ) const; // compare equal
- /***************************************************************
- Function name: operator!= (facilitator)
- Description: Checks if array is unequal to another
- Parameters: const Array& - right (import)
- Return Value: bool - true/false
- ***************************************************************/
- bool operator!=(const Array &right) const; // Determine if two arrays are not equal
- /***************************************************************
- Function name: operator+= (mutator)
- Description: Adds specified number to an array
- Parameters: const int - right (import)
- Return Value: Array - *this
- ***************************************************************/
- const Array &operator+=(const int right);
- /***************************************************************
- Function name: &operator[] (inspector)
- Description: Creates an lvalue for non-const arrays
- Parameters: int - subscript (import)
- Return Value: int - ptr[subscript]
- ***************************************************************/
- int &operator[](int); // l-value subscript operator
- /***************************************************************
- Function name: &operator[] (inspector)
- Description: Creates an rvalue for const arrays
- Parameters: int - subscript (import)
- Return Value: int - ptr[subscript]
- ***************************************************************/
- const int &operator[](int) const; // r-value subscript operator
- /***************************************************************
- Function name: getArrayCount (inspector)
- Description: Gets the amount of arrays created
- Parameters: none
- Return Value: int - arrayCount
- ***************************************************************/
- static int getArrayCount(); // Return count of arrays instantiated.
- private:
- int capacity, // capacity of the array
- numElts; // Elements in the array in use
- int *ptr; // pointer to first element of array
- static int arrayCount; // # of Arrays instantiated
- };
- /***************************************************************
- Function name: operator<< (facilitator)
- Description: Prints out the array with only in use elements
- Parameters: ostream& - output (import/export)
- const Array& - right (import)
- Return Value: ostream& - output
- ***************************************************************/
- ostream &operator<<(ostream &, const Array &);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement