SHARE
TWEET

Untitled

a guest Apr 18th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***************************************************************
  2. Author:     Dr. Daniel Spiegel, Updated by: Trisha Badlu
  3. Creation Date:  21 March 2017                            
  4. Due Date:   31 March 2017
  5. Assignment:     #3
  6. Filename:       Array.h                                  
  7. Course:     CSC136 - 020                                    
  8. Professor Name: Dr. Spiegel    
  9. Purpose:    Define prototype for Array class.
  10. ***************************************************************/
  11. // File: Array.h
  12. // Simple class Array prototype (for integers)
  13. #ifndef ARRAY_H
  14. #define ARRAY_H
  15.  
  16. #include <iostream>
  17.  
  18.  using namespace std;
  19.  
  20. class Array {
  21.  
  22. public:
  23.    Array(int arraySize= 10);              // default constructor
  24.    Array(const Array &init);              // copy constructor
  25.    ~Array();                              // destructor
  26.    
  27.    // Functions updated to use term 'capacity' to better describe use
  28.  
  29. /***************************************************************
  30. Function name: setCapacity (mutator)                                          
  31. Description: Sets the capacity to the specified number          
  32. Parameters: int - capacity (import)          
  33. Return Value: none      
  34. ***************************************************************/
  35.    void setCapacity(int);           // set the capacity
  36. /***************************************************************
  37. Function name: getCapacity (inspector)          
  38. Description: Returns the capacity of the specified object        
  39. Parameters: none                                              
  40. Return Value: int - capacity      
  41. ***************************************************************/
  42.    int getCapacity() const;                 // return capacity
  43. /***************************************************************
  44. Function name: getEltsInUse (inspector)      
  45. Description: Returns the number of elements in use of the
  46.          specified object        
  47. Parameters: none                                              
  48. Return Value: int - numElts      
  49. ***************************************************************/
  50.    int getEltsInUse() const; //Added
  51. /***************************************************************
  52. Function name: setEltsInUse (mutator)    
  53. Description: Sets the number of elements in use to the
  54.          specified number          
  55. Parameters: int - eltsInUse (import)    
  56. Return Value: none      
  57. ***************************************************************/
  58.    void setEltsInUse(int); //Added
  59. /***************************************************************
  60. Function name: &sort (facilitator)                                          
  61. Description: Sorts the values stored in the object          
  62. Parameters: none                                              
  63. Return Value: none      
  64. ***************************************************************/
  65.    Array &sort(); //Added
  66. /***************************************************************
  67. Function name: &operator= (mutator)                                          
  68. Description: Assigns arrays equal to each other          
  69. Parameters: const Array& - right (import)      
  70. Return Value: Array - *this      
  71. ***************************************************************/
  72.    const Array &operator=( const Array & ); // assign arrays
  73. /***************************************************************
  74. Function name: operator== (facilitator)                  
  75. Description: Checks if array is equal to another        
  76. Parameters: const Array& - right (import)    
  77. Return Value: bool - true/false    
  78. ***************************************************************/
  79.    bool operator==( const Array & ) const;  // compare equal
  80. /***************************************************************
  81. Function name: operator!= (facilitator)  
  82. Description: Checks if array is unequal to another        
  83. Parameters: const Array& - right (import)    
  84. Return Value: bool - true/false    
  85. ***************************************************************/
  86.    bool operator!=(const Array &right) const;   // Determine if two arrays are not equal
  87. /***************************************************************
  88. Function name: operator+= (mutator)                                          
  89. Description: Adds specified number to an array          
  90. Parameters: const int - right (import)  
  91. Return Value: Array - *this      
  92. ***************************************************************/
  93.    const Array &operator+=(const int right);
  94. /***************************************************************
  95. Function name: &operator[] (inspector)  
  96. Description: Creates an lvalue for non-const arrays          
  97. Parameters: int - subscript (import)        
  98. Return Value: int - ptr[subscript]    
  99. ***************************************************************/
  100.    int &operator[](int);              // l-value subscript operator
  101. /***************************************************************
  102. Function name: &operator[] (inspector)    
  103. Description: Creates an rvalue for const arrays          
  104. Parameters: int - subscript (import)  
  105. Return Value: int - ptr[subscript]    
  106. ***************************************************************/
  107.    const int &operator[](int) const;  // r-value subscript operator
  108. /***************************************************************
  109. Function name: getArrayCount (inspector)  
  110. Description: Gets the amount of arrays created        
  111. Parameters: none                                              
  112. Return Value: int - arrayCount    
  113. ***************************************************************/  
  114.    static int getArrayCount();          // Return count of arrays instantiated.
  115.  
  116. private:
  117.    int capacity,        // capacity of the array
  118.        numElts;         // Elements in the array in use
  119.    int *ptr;            // pointer to first element of array
  120.    static int arrayCount;   // # of Arrays instantiated
  121.  
  122. };
  123. /***************************************************************
  124. Function name: operator<< (facilitator)  
  125. Description: Prints out the array with only in use elements        
  126. Parameters: ostream& - output (import/export)
  127.         const Array& - right (import)
  128. Return Value: ostream& - output    
  129. ***************************************************************/
  130.    ostream &operator<<(ostream &, const Array &);
  131.  
  132. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top