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:

New Perspectives on HTML5, CSS3, and JavaScript
6th Edition
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Patrick M. Carey
Chapter12: Working With Document Nodes And Style Sheets: Creating A Dynamic Document Outline
Section12.1: Visual Overview: Exploring The Node Tree
Problem 7QC
icon
Related questions
Question
100%

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;

}

Example Run:
C. C:\WINDOWS\system32\cmd.e.
-
Please Enter the array A : 1 2 3 4 5
Please Enter the array B: 9 8 7 6 5
A = 1 2 3 4 5
C = ++A + B
A after the ++ =
-C
B = 9 8 7 6 5
11 11 11 11 11
%3D
2 3 4 5 6
-11 -11 -11 -11 -11
= 11 11 11 11 11
C = A = 2 3 4 5 6
А
1
==
C != A
C += A
%3D
4 6 8 10 12
D = C + 5
Press any key to continue .
9 11 13 15 17
Transcribed Image Text:Example Run: C. C:\WINDOWS\system32\cmd.e. - Please Enter the array A : 1 2 3 4 5 Please Enter the array B: 9 8 7 6 5 A = 1 2 3 4 5 C = ++A + B A after the ++ = -C B = 9 8 7 6 5 11 11 11 11 11 %3D 2 3 4 5 6 -11 -11 -11 -11 -11 = 11 11 11 11 11 C = A = 2 3 4 5 6 А 1 == C != A C += A %3D 4 6 8 10 12 D = C + 5 Press any key to continue . 9 11 13 15 17
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning