Question: Please C++ programming 6. The following CH main driver, along with function myFunc, uses a CH class DynArray that models a dynamic integer array that



6. The following CH main driver, along with function myFunc, uses a CH class DynArray that models a dynamic integer array that is, the class uses dynamic memory allocation to create a contiguous block of memory for storing a specified number of integers. The indexing for a DynArray object is the same as for a regular array. But, a DynArray can be initialized to size zero. Write the CH DynArray class. Here is a brief description of all of the class functions that your class should include: No-argument constructor - initializes a DynArray object to being empty. One-argument constructor - uses dynamic memory allocation to obtain a contiguous block of memory for storing n int values, where n is its argument. show - displays the nth element in the DynArray. If the DynArray is empty or ifn is an invalid index, this function should generate an error message. set - will set the nth element in the DynArray to x, where n is the value of its first argument and x is value of its second argument. If the DynArray is empty or if n is an invalid index, this function should generate an error message. expand - will take an existing DynArray and expand its size by its argument, s. Hint: To expand a DynArray, allocate a new larger block of dynamic memory, copy the values from the old DynArray to the new memory, and deallocate the old memory. A destructor to deallocate dynamic memory when a DynArray object passes out of scope. Requirement: When accessing the dynamic array elements in the set, show and expand member +, along with pointer arithmetic instead of the Requirement: When accessing the dynamic array elements in the set, show and expand member fmetions, you must use the dereferencing operator, -, along with pointer arithmetic instead of the array indexing operator, 1 Next, combine your DynArray class with the following main and my Func code and run the resulting CH program. The output generated from a run of your program should be similar to that shown in the output of a sample run given after the code. void my Eunc(); int main() + int size, more, i; DynArray y: cout > size: DynArray x(size); for(i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
