Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do not change anything in the supplied Ch13_Ex11_MainProgram.cpp except to add documentation and your name . 1. Please use the file names listed below since

Do not change anything in the supplied Ch13_Ex11_MainProgram.cpp except to add documentation and your name.

1. Please use the file names listed below since your file will have the following components: Ch13_Ex11_MainProgram.cpp - given file

#include #include "myArray.h"

using namespace std;

int main() { myArray list1(5); myArray list2(5);

int i;

cout << "list1 : "; for (i = 0 ; i < 5; i++) cout << list1[i] <<" "; cout<< endl;

cout << "Enter 5 integers: "; for (i = 0 ; i < 5; i++) cin >> list1[i]; cout << endl;

cout << "After filling list1: ";

for (i = 0 ; i < 5; i++) cout << list1[i] <<" "; cout<< endl;

list2 = list1; cout << "list2 : "; for (i = 0 ; i < 5; i++) cout << list2[i] <<" "; cout<< endl;

cout << "Enter 3 elements: ";

for (i = 0; i < 3; i++) cin >> list1[i]; cout << endl;

cout << "First three elements of list1: "; for (i = 0; i < 3; i++) cout << list1[i] << " "; cout << endl;

myArray list3(-2, 6);

cout << "list3: "; for (i = -2 ; i < 6; i++) cout << list3[i] <<" "; cout<< endl;

list3[-2] = 7; list3[4] = 8; list3[0] = 54; list3[2] = list3[4] + list3[-2];

cout << "list3: "; for (i = -2 ; i < 6; i++) cout << list3[i] <<" "; cout<< endl; system("pause");

return 0; } myArray.h myArrayImp.cpp

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.

2. 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); //Line 1 myArray myList(2, 13); //Line 2 myArray yourList(-5, 9); //Line 3

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], list[1], ..., list[4]; the statement in Line 2 declares myList to be an array of 11 com- ponents, 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].

3. Write a program to test the class myArray.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

Students also viewed these Databases questions

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago