Question: In C + + there is no check on array index out - of - bounds at compile time and it can cause serious error
In C there is no check on array index outofbounds at compile time and it can
cause serious error when program runs. And in C array index starts at
Your job here is to implement a class MyArray is to solve the outofbounds
problem and to start the array index at any integer positive integers. Every
object of type MyArray is an array of type int. During execution, when accessing
an array component, if the index is outofbounds, the program must terminate
with an appropriate message.
Consider the following
MyArray list;
MyArray myList;
You may use this for
The first line declares an array of int called list with five elements specified by
list list list list and list
The second line declares an array of int called list with eleven elements specified
by list list list up to list
Use this for the header file for the class MyArray
#include
#ifndef MyArrayH
#define MyArrayH
using namspace std;
class MyArray
public:
const MyArray& operatorconst MyArray& right;
overload assignment operator
MyArrayint uB;
MyArrayint B int uB;
MyArray;
MyArrayconst myArray ;
copy constructor
~MyArray;
destructor
int &operatorint;
const int &operatorint const;
overload relational operator
bool operatorconst myArray &right const;
bool operator!const myArray &right const;
private:
int aPtr;
int lowerBound;
int upperBound;
;
Then implement all the constructors shown, and all the methods and overloaded
operator shown above.
Test program with this
#include
#include "MyArray.h
using namespace std;
int main
MyArray list;
MyArray list;
int i;
cout "list: ;
for i ; i ; i
cout listi;
cout
Enter integers: ;
for i ; i ; i
cin listi;
cout
After input to list: ;
for i ; i ; i
cout listi;
list list;
cout
list :;
for i ; i ; i
cout listi;
cout
Enter elements: ;
for i ; i ; i
cin listi;
cout
First three elements of list: ;
for i ; i ; i
cout listi;
cout endl;
MyArray list;
cout
list: ;
for i ; i ; i
cout listi;
cou endl;
list;
list;
list;
list list list;
cout "list: ;
for i ; i ; i
cout listi;
cout endl;
return ;
Lastly, redesign the MyArray using templates so it can be used in any application that needs an array.
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
