Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

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

More Books

Students also viewed these Databases questions