Question
Consider a class Array that manages a C++ array of integers. It has enough storage for an array of up to 1024 integers. It starts
Consider a class Array that manages a C++ array of integers. It has enough storage for an array of up to 1024 integers. It starts with zero elements using the storage. It provides a method bool addElement(int e) that adds elements to the array. In case the number of elements in the array is less that the full capacity (1024), then the method places the new element e at the first unused index of the storage starting from index 0 and returns true. In case the number of elements in the array is equal to the full capacity, the method prints an error and returns false.
Declare class Array that has an array of integers storage and a number n book-keeping the number of elements in storage.
Provide a default constructor for the array that initializes n to zero.
Provide method addElement(int e) that adds elements e to the array.
Provide a copy constructor Array(Array & a) that takes a reference to an existing array a and copies its content a.storage and a.n to the constructed object.
Provide an assignment operator Array & operator = (Array & oa) that takes a reference to an existing array oa and copies its content oa.storage and oa.n to the object. Once done it returns a reference to the this object. (return *this;).
Provide a helper function ostream & operator << (ostream & ostr, Array & arr) that helps print the content of an instance arr of class Array.
Test your code by declaring two instances of type Array in main, adding elements to them using addElement, copying one to the other using the copy constructor and the assignment operator and printing them to cout using the << operator.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started