Question: Assignment 5 : overloading member functions. Overview: Your goal is to create an 'Array' class that is able to hold multiple integer values. The 'Array'
Assignment : overloading member functions.
Overview:
Your goal is to create an 'Array' class that is able to hold multiple integer values. The 'Array' class will be given functionality through the use of various overloaded operators You will be given the main function for your program and must add code in order to achieve the desired result. Do not change any code in main. If something is not working, you must change your own code, not the code in main
main
int main
Array arr arr;
for int i ; i arrgetSize; i
arri
for int i ; i arrgetSize; i
arri
cout "arr contains: arr; cout "arr contains: arr;
Array arrarr;
cout "arr contains: arr endl;
arr arr;
cout "arr contains: arr;
arr arr;
cout "arr contains: arr endl;
cout boolalpha; Display booleans as 'true' or 'false' instead of or cout "arr arr: arr arr endl; cout "arr arr: arr arr endi; cout "arr arr: arr arr endl endl;
arr;
cout "New arr: arr;
cout "arr arr: arr arr endl;
cout "arr arr: arr arr endl;
cout "arr arr:arr arr endl endl;
arr arr;
cout "arr arr: arr endl;
cout arr: arr;
cout arr: arr endl endl; cout "arr: arr;
cout "arr is: arr endl; cout arr: arr; cout "arr is: arr endi;
cout "Total number of elements in all arrays: Array::getNumberOfElements endl endl; return ;
Below is your desired output:
arr contains:
arr contains: arr contains:
arr contains: arr contains:
arr arr: true arr arr: true arr arr: false
New arr:
arr arr: false arr arr: false arr arr: true
arr arr:
arr:
arr:
arr:
arr is:
ar:
arr is:
Total number of elements in all arrays:
Specifications
The 'Array' class should have an overloaded constructor that accepts an integer argument which represents the size of the array. Use this size to create a dynamicallyallocated array of integers.
This means you will need at least two member variables for your class: a pointer to a dynamicallyallocated array of integers and the size of the array
The equality operator should return true if one Array object is an inorder subset of another Array object.
For example, if a and a a a should return true because a is contained in a
if a and a a a should return false. Even though a has all the elements of a they are not in the correct order
Notice that you are able to compare two Array objects with differentlysized arrays. Your code should not assume that one array will always be larger than the other.
The lessthan operator should compare two Array objects elementbyelement, starting from the beginning. To illustrate...
If a and a a a would return true because the first element in a is less than the first element in a
If a and a a a would return false because the first element
in a is greater than the first element in a
If a and a a a would return true. The first elements of a and a are the same, so move onto the next element. The second element of a is less than the second element of a so true is returned. If all elements in a and a are the same, return false.
The not operator should randomly shuffle the elements in the array
Randomly shuffling elements in an array is a logic problem that may take some time to work out. Create a sample cpp file where you can test your ideas. Once you have the algorithm figured out, transfer it into your 'Array' class.
f you can't think of a way to shuffle the elements, the FishYates Shuffle is a simple and efficient way to shuffle. See this link for help.
Because you need to randomly shuffle the elements, you will need to use rand in your code. Remember that when using rand you need to call srand only once in your code. Because you can't change main, you will need to think about how to implement this
The indirection operator should return the smallest value inside the Array object
The compound sum assignment operator should extend the lefthand object to include the elements of the righthand object
For example, assume a and a The following statement:
a a
Should result in a and a Notice that the right
hand object does not change
Because your 'Array' class stores the elements in a dynamicallyallocated array, you will need to allocate more room
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
