Write a class to represent a dynamically sized array of


CPSC Program

This is the program

Write a class to represent a dynamically sized array of integers. Name it DynArray.

submit: a file named dynarray.h that contains all of your class code

Class specifications:

Private data members:

data arraysize datasize

- a pointer to integer array data

- an integer representing the array size (allocated space) - an integer representing the amount of data stored in the array Public member functions:

default constructor: Sets the array size to be 10 elements, the data size to be 0, and dynamically allocates the 10 element array space.

constructor receiving size: Checks the size parameter value to make sure that it is a positive (>0) value. If the value is positive, it
becomes the array size.

If the value is not legal, the array size should be set to 10. After setting the array size, the data size is set to 0, and the dynamic allocation is performed.

copy constructor: Receive one DynArray object as a parameter and make the new object a copy of that object with its own separately allocated memory space, but with the same sizes and same data.

destructor: Dynamically de-allocate the array space and set the pointer value to NULL.

setArraySize: This function receives a size value. If the parameter value is

greater than the existing array size, change the array size, allocate a new array space, copy all of the data values to the new space, and deallocate the old array space.

If the size value is invalid (smaller than current size), do nothing.

getArraySize: Return a copy of the array size field.

getDataSize: Return a copy of the data size field.

addValue: Receives an integer value. If there is currently room in the

allocated array space, then store the value into the array. If there is not space, then relocate the array to another location with twice as much space as before, and then store the parameter value into the array.

= operator: Receives one DynArray object as a parameter and makes the current object a copy of that parameter object with its own separately allocated array space. Make sure to de-allocate the current array space before dynamically allocating a new one.

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Write a class to represent a dynamically sized array of
Reference No:- TGS01722997

Now Priced at $40 (50% Discount)

Recommended (95%)

Rated (4.7/5)