Lab 6 Operator, Copy, and Stream overloading


Design an Array class to operate on and store any number of floating-point values. Write a constructor to accept the amount of floating-point values to dynamically create and a destructor that performs the necessary cleanup and de-allocation. Write an overloaded operator function to perform addition on 2 objects with the same number of floating-point values. Overload the operator to simply add the corresponding floating-point values between two Array objects. In addition, write an overloaded operator function to perform addition between an Array object and a single floating-point value (add the float to each of the array values). Override the default copy constructor and assignment operator to perform a deep-copy. Lastly, overload the output stream operator to print the state of an Array object. Write a small application, similar to the one shown below, to test your class. As before write your Array class in separate source and header files (.C and .h) and the application in a separate file (lab6.C).


using namespace std;


#include <iostream>

#include Array.h




Array a1( 3 );

a1.setValue( 0, 1.0 );

a1.setValue( 1, 22.0 );

a1.setValue( 2, 12.2 );


Array a2( 3 );

a2.setValue( 0, 3.3 );

a2.setValue( 1, 44.5 );

a2.setValue( 2, 21.7 );


Array tmp;

tmp = a1 + a2;

cout << tmp;