Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that will construct an Array class that solves the array ind

ID: 662778 • Letter: W

Question

Write a C++ program that will construct an Array class that solves the array index out of bound problem, and also allows the user to begin the array index starting at any integer, positive or negative. Every object of type Array 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 that will declare an array (Note: *This is only an example. Only use the input data at the bottom to test the code.*:

Array   list(5);                . Declares a normal array 0 to 4 subscripts
Array   myList(2, 13);   .   An array starting at subscript 2 to subscript 13.
Array   yourList(-5,9);   . An array starting at subscript -5 to subscript 9.

The statement in line 1 declares a list to be an array of 5 elements, the element type is int, and the elements start from list[0] .... list [4]. Line 2 declares a list of 11 elements, starting at myList[2] ... myList[12]. Line 3 declares a list of 14 elements, starting at myList[-5] ... myList[8].

The above would be done (declared) in your constructor function(s). Use the new int[ value ] to declare an array.   Example   for the above myAry yourList(-5,9) has 14 elements to the array, in your constructor function you would have myAry = new int [14].

You are to overload the == and !== and << operators for the Array class. Arrays are equal if all elements in one array are equal to each corresponding element in the second array. << just prints out all elements of the array. (It would be nice to see the subscripts:

example   (2) 5 (3) 15 Where (2) is the subscript and 5 is the value.

The last method to implement is the [ ] operator. You have to have a method to make sure the subscripts are in range of the definition when defined.

Use the following below to test the data:

Array test(10);

Array Ary1(10,15);

Array Ary2(-5, 10);

for ( i=0; i<10; i++)

   test[i] = i+1;

cout << Test array output << endl;

for ( i=0; i<10; i++)

   cout << test[i] << ;

cout << endl;

i = -5;

while ( i < 10 )

{    Ary2[ i ] = i*2;

     i++;

};

cout << Ary2 array output << endl;

for ( i= -5; i<10; i++)

   cout << Ary2[i] << ;

cout << endl;

i = 10;

while ( i < 15 )

{    Ary1[ i ] = i*100;

     i++;

};

cout << Ary1 array output << endl;

for ( i= 10; i<15; i++)

   cout << Ary1[i] << ;

cout << endl;

cout << Test boundary conditions << endl;

Ary1[8] = 100;

Ary1[16] = 200;

i = 100;

cout << ary1[i] << endl;

Explanation / Answer

01 class myArray 02 { 03 public: 04     int *list; 05     int listSize; 06     int index; 07     myArray(int _listSize); 08     myArray(int _listSize, int index); 09        10 }; 11 myArray::myArray(int _listSize) 12 { 13     if(_listSize
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote