Question: Solve problem 11 on page 983 using the following modifications: A. Add an overloaded operator!=() and operator==() functions. B. Add the overloaded stream extraction and
Solve problem 11 on page 983 using the following modifications:
A. Add an overloaded operator!=() and operator==() functions.
B. Add the overloaded stream extraction and stream insertion operators: Operator>> and operator<< respectively.
C. Use the attached project zip file to create your solution program:
Here is the information from the book:
Recall that in C++, there is no check on an array index out of bounds. However, during program execution, an array index out of bounds can cause serious problems. Also, in C++, the array index starts at 0.
Design and implement the class myArray that solves the array index out of bounds problem and also allows the user to begin the array index starting at any integer, positive or negative. Every object of type myArray is an array of type int . During execution, when accessing an array component, if the index is out of bounds, the program must terminate with an appropriate error message. Consider the following statements:x
The statement in Line 1 declares list to be an array of five components, the component type is int , and the components are: list[0], list[1], ..., list[4]; the statement in Line 2 declares myList to be an array of 11 components, the component type is int , and the components are: myList[2], myList[3], ..., myList[12]; the statement in Line 3 declares yourList to be an array of 14 components, the component type is int , and the components are: yourList[-5], yourList[-4], ..., yourList[0], ..., yourList[8]. Write a program to test the class myArray.
Here is the starter code that we were given:
#include
using namespace std;
int main() { myArray
cout << "list1 before initialization: "; cout << list1<< endl;
cout << "Enter integer values into list1: "; cin >> list1; cout << endl;
cout << "After filling list1: "; cout << list1 << endl;
list2 = list1; cout << "list2 after assigning list1 to list2: "; cout << list2 << endl;
cout << "Enter new elements into list1: "; cin >> list1;
cout << "List1 after assigning values: "; cout << list1 << endl;
myArray
cout << "Enter values into list3: "; cin >> list3; cout << endl; cout << "list3 values: " << endl; cout << list3<< endl; cout << endl;
list3[-2] = 7; list3[4] = 8; list3[0] = 54; list3[2] = list3[4] + list3[-2];
cout << "list3 after changing values: "; cout << list3 << endl;
if (list1 == list2) cout << " list 1 is equal to list2 " << endl; else cout << " list 1 is not equal to list2" << endl;
if (list1 != list2) cout << " list 1 is not equal to list2 " << endl; else cout << " list 1 is equal to list2" << endl;
system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
