main() function is given below. Based on this function, your task is to write complete code required to run the main() function successfully.   class MyArray { private: float* array; int size; Declare a static variable to count the number of objects public: Implement a static function to re

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section: Chapter Questions
Problem 1PP
icon
Related questions
Question

A main() function is given below. Based on this function, your task is to write complete code
required to run the main() function successfully.

 

class MyArray
{
private:
float* array;
int size;
Declare a static variable to count the number of objects
public:
Implement a static function to return total count of objects
};
int main()
{
int size;
float* ptr;
cout << "Enter the size of your array" << endl;
cin >> size;
ptr = new float[size];
cout << "Enter elements of array" << endl;
for (int i = 0; i < size; i++)
{
cin >> ptr[i];
}
MyArray a1(ptr, size);
MyArray a2 = a1;
int len = a1.getSize();
float* res;
res = new float[len];

res = a1.getArray();
for (int i = 0; i < len; i++)
{
cout << res[i];
}
// incase of array, compare or add or perform any operation index wise
if (a1 == a2) // overload == operator to compare two objects
{
cout << "Both arrays are equal" << endl;
}
else
{
cout << "Both arrays are not equal" << endl;
}
MyArray a3;
a3 = a1 + a2; // overload the + operator to add two objects
a3.display();
MyArray a4;
a4 = a1 - a2; // overload the - operator to subtract two objects
a4.display();
MyArray a5;
a5 = a4; // overload the = operator to assign a4 to a5
a5.display();
// overload > and < operator to check which object is greater
if (a3 > a4)
{
cout << "Array3 is greater than array4" << endl;

else if (a3 < a4)
{
cout << "Array4 is greater than array3" << endl;
}
cout << "Final Count: " << MyArray::getCount() << endl;
return 0;
}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
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