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

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

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