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:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education