Question: 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

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

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

friend ostream & operator

friend istream & operator >>(istream & is, const Array & a);

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

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):

#include

#include "Array.h"

#include

using namespace std;

void main()

{

Array a(5), b(5);

cout

cin >> a;

cout

cin >> b;

cout

Array c = (++a + b);

cout

cout

cout

cout

c = a;

cout

cout

cout

c += a;

cout

Array d = (c + 5);

cout

}

Sample Output:

Implement the Array class that is defined below and test it in

EL CAWindowslsystem32Mcmd.exe lease Enter the array A lease Enter the array B 2 2 2 2 2 2 2 2 2 1 1 1 1 ++A 4 4 4 4 4 after the 2 2 2 2 4 -4 4 4 4 4 4 A 4 4 4 4 4 11 0 Then C 4 0 4 4 4 2 Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!