#include <ArrayInt.h>
Public Methods | |
Array (int=10) | |
Array (const Array &) | |
~Array () | |
int | getSize () const |
const Array & | operator= (const Array &) |
bool | operator== (const Array &) const |
bool | operator!= (const Array &right) const |
int & | operator[] (int) |
const int & | operator[] (int) const |
Static Public Methods | |
int | getArrayCount () |
Private Attributes | |
int | size |
int * | ptr |
Static Private Attributes | |
int | arrayCount = 0 |
Friends | |
ostream & | operator<< (ostream &, const Array &) |
istream & | operator>> (istream &, Array &) |
|
Definition at line 12 of file ArrayInt.cpp. 00013 { 00014 size = ( arraySize > 0 ? arraySize : 10 ); 00015 ptr = new int[ size ]; // create space for array 00016 assert( ptr != 0 ); // terminate if memory not allocated 00017 ++arrayCount; // count one more object 00018 00019 for ( int i = 0; i < size; i++ ) 00020 ptr[ i ] = 0; // initialize array 00021 } |
|
Definition at line 25 of file ArrayInt.cpp. 00025 : size( init.size ) 00026 { 00027 ptr = new int[ size ]; // create space for array 00028 assert( ptr != 0 ); // terminate if memory not allocated 00029 ++arrayCount; // count one more object 00030 00031 for ( int i = 0; i < size; i++ ) 00032 ptr[ i ] = init.ptr[ i ]; // copy init into object 00033 } |
|
Definition at line 36 of file ArrayInt.cpp. 00037 { 00038 delete [] ptr; // reclaim space for array 00039 --arrayCount; // one fewer objects 00040 } |
|
Definition at line 103 of file ArrayInt.cpp. Referenced by main().
00103 { return arrayCount; } |
|
Definition at line 43 of file ArrayInt.cpp. Referenced by main().
00043 { return size; } |
|
Definition at line 23 of file ArrayInt.h. 00024 { return ! ( *this == right ); } |
|
Definition at line 47 of file ArrayInt.cpp. 00048 { 00049 if ( &right != this ) { // check for self-assignment 00050 00051 // for arrays of different sizes, deallocate original 00052 // left side array, then allocate new left side array. 00053 if ( size != right.size ) { 00054 delete [] ptr; // reclaim space 00055 size = right.size; // resize this object 00056 ptr = new int[ size ]; // create space for array copy 00057 assert( ptr != 0 ); // terminate if not allocated 00058 } 00059 00060 for ( int i = 0; i < size; i++ ) 00061 ptr[ i ] = right.ptr[ i ]; // copy array into object 00062 } 00063 00064 return *this; // enables x = y = z; 00065 } |
|
Definition at line 69 of file ArrayInt.cpp. |
|
Definition at line 93 of file ArrayInt.cpp. 00094 { 00095 // check for subscript out of range error 00096 assert( 0 <= subscript && subscript < size ); 00097 00098 return ptr[ subscript ]; // const reference return 00099 } |
|
Definition at line 83 of file ArrayInt.cpp. 00084 { 00085 // check for subscript out of range error 00086 assert( 0 <= subscript && subscript < size ); 00087 00088 return ptr[ subscript ]; // reference return 00089 } |
|
Definition at line 116 of file ArrayInt.cpp. 00117 { 00118 int i; 00119 00120 for ( i = 0; i < a.size; i++ ) { 00121 output << setw( 12 ) << a.ptr[ i ]; 00122 00123 if ( ( i + 1 ) % 4 == 0 ) // 4 numbers per row of output 00124 output << endl; 00125 } 00126 00127 if ( i % 4 != 0 ) 00128 output << endl; 00129 00130 return output; // enables cout << x << y; 00131 } |
|
Definition at line 107 of file ArrayInt.cpp. |
|
Definition at line 9 of file ArrayInt.cpp. |
|
Definition at line 32 of file ArrayInt.h. Referenced by operator<<(), operator=(), operator==(), and operator>>().
|
|
Definition at line 31 of file ArrayInt.h. Referenced by operator<<(), operator=(), operator==(), and operator>>().
|