Question: Indent code and insert comments to document your program. [10 pts] Program must be implemented and run as instructed. [80 pts] At a minimum, make

Indent code and insert comments to document your program. [10 pts] Program must be implemented and run as instructed. [80 pts] At a minimum, make sure that the Source and executable files are in the Microsoft Visual Studio Solution folder. The folder is zipped up into a file. The zipped file is submitted to Blackboard. [10 pts]

1. 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:

(problem 11)

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: myArray list(5); myArray myList(2, 13); myArray yourList(-5, 9); The statement in Line 1 declares list to be an array of 5 components, the component type is int, and the components are: list[0],

(the code for that)

/************************** myArray.h **********************/

#include class myArray{ int size, start, end; int *data; public: myArray(int sz); myArray(int lower, int upper); int &operator [](const int index); };

/************************** myArray.cpp **********************/

#include #include "myArray.h" myArray :: myArray(int sz)//constructor { size = sz; start = 0; end = sz-1; data = new int[size]; for(int i=start;i<=end;i++) *(data+i)=0; } myArray :: myArray(int lower, int upper) //constructor overloaded { size = upper-lower; start = lower; end = upper-1; data = new int[size]; for(int i=start;i<=end;i++) *(data+i)=0; } int& myArray :: operator [](const int index)//[] operator { if(index >= start && index <= end) { int &elem = *(data+index); return elem; } else { std::cout <<"Error: Array Index is out of range. "; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!