in c++: Implement the Array class that is defined below and test it in the main program. The main program must test all the member functions including the overloaded operators that are defined in the class:
in c++: Implement the Array class that is defined below and test it in the main program. The main program must test all the member functions including the overloaded operators that are defined in the class:
#ifndef array_h
#define array_h
#include <iostream>
using namespace std;
class Array { // Class declaration
friend const Array operator+(const Array & a1, const Array &a2);
friend bool operator==(const Array & a, const Array &b);//Equality test
public:
Array(int = 10); //Initialize the array with 0 values, default size =10
Array(const Array & a); // copy constructor
~Array();//Destructor
int getSize();// return the size of the array.
const Array & operator=(const Array & a);//assignement operator
Array operator+(int x);//+ operator
bool operator!=(const Array & a) const;//Not equal test
void read();
void print();
Array operator-();//Negate (unary operation)
Array & operator++();//pre increment
Array & operator+= (const Array & a);
private:
int size; // size of created array
int * arr;
};
#endif
.
.
.
Test your class with the following main (your class should work with this main without any modifications):
void main()
{
Array a(5), b(5);
cout << "Please Enter the array A : ";
a.read();
cout << "Please Enter the array B : ";
b.read();
cout << "A = ";
a.print();
cout << " B = ";
b.print();
cout<< endl;
Array c = (++a + b);
cout << "C = ++A + B = ";
c.print();
cout<< endl;
cout << "A after the ++ = ";
a.print();
cout<< endl;
cout << "-C = ";
(-c).print();
cout<< endl;
cout << "C = ";
c.print();
cout<< endl;
c = a;
cout << "C = A = ";
c.print();
cout<< endl;
cout << "C == A = " << (c == a) << endl;
cout << "C != A = " << (c != a) << endl;
c += a;
cout << "C += A = ";
c.print();
cout<< endl;
Array d = (c + 5);
cout << "D = C + 5 = ";
d.print();
cout<< endl;
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images