Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ #, both myArray.h and myArrayimp.cpp. here is instruction. Please use the file names listed below since your file will have the following components: Ch13_Ex11_MainProgram.cpp

c++ #, both myArray.h and myArrayimp.cpp. here is instruction.

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

Semantics Of A Networked World Semantics For Grid Databases First International Ifip Conference Icsnw 2004 Paris France June 2004 Revised Selected Papers Lncs 3226

Authors: Mokrane Bouzeghoub ,Carole Goble ,Vipul Kashyap ,Stefano Spaccapietra

2004 Edition

3540236090, 978-3540236092

More Books

Students also viewed these Databases questions