header

Homework 26

Modify the temperatureList class you wrote for homework 22 to take advantage of dynamic allocation.

Modify the Default Constructor

The default constructor must be modified to dynamically allocate memory for the newly constructed temperatureList object. The default capacity will be 10 as it was before.

Modify the Copy Constructor

The copy constructor must be modified to dynamically allocate memory for the newly constructed temperatureList object. The capacity of the copy should be the same as the capacity of the original temperatureList object.

Add an Initialization Constructor

Add an initialization constructor. This constructor has an integer parameter which represents the initial capacity of the newly constructed temperatureList object. If this parameter is less than the default capacity use the default capacity instead.

You will need to modify the test program so that it also tests the initialization constructor since we didn't have an initialization constructor before.

Add a Destructor Function

Add a destructor function that de-allocates the memory used by a temperatureList object whenever the object goes out of scope.

Modify the Append Function (Optional)

In homework 22, the append function did nothing if the list was full. Modify the append function so that when the list is full, the append function will automatically increase the capacity of the list by 10 and then append a new temperatureRecord object containing the append function parameter values. Here is the basic logic:

if (list is full)
{
    allocate memory for new, longer list
    copy contents of the full list into the new list
    de-allocate the memory for the old list
}
append record containing parameter values to list

The append logic following the if statement is the same as before.

You will need to reinterpret the results of the test program since the append function works differently than it did before.