Home > Back-end >  The great spirit to solve
The great spirit to solve

Time:10-09

The following is an integer array class intArray statement, please give all data members of the class definition, requirements:
(1) can be based on "& gt; & gt;" , "& lt; & lt;" Overloaded implementation direct input and output of array elements, the input, the input values for the array length for the first time, the continuous input some number as an array of content, output, the first suggest the number of array elements, then each element in the array output;
(2) the overloaded "=", "+", "-" operator to direct assignment was carried out on the two array class object, addition and subtraction,
(3) write a main function to test the class requirements:
1) structure contains the first ten array element of an array of objects, a call flow extracting again initialization operator overloading function to realize a element (the element value of 1 to 10) respectively, output a array;
2) and used to construct the array b, the output array b, and invoke the get function for b subscript for each element of an odd number of values and output, and then call the set function to the element value multiplied by 2, the output array b;
3) to construct a contains five elements of the array c, the total value of 1 the array output, then call the ReSize function will be reset to its size 10, calls the "=" overloaded function copies the value of a to c, c output array;
4) respectively b + c, b and c value to arrays d and e, and the output,
The class intArray
{public:
IntArray (int size);//the constructor
IntArray (const intArray & amp; X);//copy constructor
~ intArray ();//destructors
Bool Set (int I, int elem);//set the value of the ith an array element, set up the returns true on success, or false on failure
Bool Get (int I, int & amp; Elem);//get the ith array element values, returns true on success, or false on failure
Const int Length ();//get the length of the array
Void the ReSize (int size);//reset array
IntArray & amp; Operator=(const intArray & amp; Other);//the assignment operator "=" overloaded function
IntArray & amp; The operator + (const intArray & amp; Other);//add operators overloaded functions
"="IntArray & amp; Operator - (const intArray & amp; Other);//subtraction operator "=" overloaded function
Friend ostream & amp; Operator> (ostream & amp; , intArray & amp;);//an array of whole input
Friend ostream & amp; Operator<(ostream & amp; , intArray & amp;);//an array of overall output
Private:
Int * element;//a pointer to the dynamic array
Int arraysize;//the current length of the array
};
  • Related