Question: A c++ program that incoperates both question 4 and 5. and consists of header and source files IntArray.h and IntArray.cpp which implement the class IntArray.

A c++ program that incoperates both question 4 and 5. and consists of header and source files IntArray.h and IntArray.cpp which implement the class IntArray. The program also has to have its own unit tests. I can't use the "error.h" functions instead throw an appropriate std::exception.

A c++ program that incoperates both question 4 and 5. and consists

4. Design and implement a class called IntArray that implements the following methods: .A constructor IntArray (n) that creates an IntArray object with n elements, each of which is initialized to 0. .A destructor that frees any heap storage allocated by the IntArray. A method size () that returns the number of elements in the Inthrray. A method get (k) that returns the element at position k. If k is outside the : vector bounds, get should call error with an appropriate message A method put (k, value) that assigns value to the element at position k. . As with get, the put method should call error if k is out of bounds. Your solution should be split into separate interface and implementation files in a manner similar to the charStack example from this chapter. In the initial version of the code, you should add the necessary definitions to the intarray.h file to prevent clients from copying IntArray objects. Design and implement a unit test to check the methods exported by the class. By keeping track of the array size and checking that index values are inside the array bounds, this simple IntArray class already fixes two of the most serious shortcomings of the built-in array type. You can make the Intarray class from the preceding exercise look a little more like traditional arrays by overriding the bracket-selection operator, which has the following prototype: 5. int & operatorI (int k) Like the get and put methods, your implementation of operator[] should check to make sure that the index k is valid. If it is, the operator [1 method should return the element by reference so that clients can assign a new value to a selection expression

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!