TemperatureList Class with Dynamic Array.
I need help with a C Programming question. All explanations and answers will be used to help me learn.
In your textbook’s display 11-10, TemperatureList class was discussed. You will implement that same class using dynamic array in this lab. The original TemperatureList class implementation is given to you for reference.
This is the interface of the original class:
//Initializes the object to an empty list.
void add_temperature(double temperature);
//Precondition: The list is not full.
//Postcondition: The temperature has been added to the list.
bool full( ) const;
//Returns true if the list is full; false otherwise.
friend ostream& operator <<(ostream& outs, const TemperatureList& the_object);
//Overloads the << operator so it can be used to output values of
//type TemperatureList. Temperatures are output one per line.
//Precondition: If outs is a file output stream, then outs
//has already been connected to a file.
double list[MAX_LIST_SIZE]; //of temperatures in Fahrenheit
int size; //number of array positions filled
Your job is to:
- Replace the array list[MAX_LIST_SIZE] with a dynamic array
- Add a max_size member variable that sets the max number of elements allowed in the array
- Add a constructor that accepts an integer parameter that specifies max_size
- Add the big three
- Change the implementation of the class to make sure no memory leak happens and the class functions as expected
- Separate the class into templist.h and templist.cpp files
- Follow the ADT (Abstract Data Type) guideline to implement the required class
- Comment well in your program and any functions you use
- In summary, you will have 8 member functions in your class:
- Default constructor
- Constructor that accepts an integer parameter to set the max_size
- Copy constructor
- Overload = operator
- full (no change in its implementation)
- Overloading operator << (nothing shall need to change in its implementation)
- You will have 3 member variables in your class
- size – current size of your array
- max_size – max size the array will hold
- list – dynamic array/pointer to
- Starting from scratch might be easier for you than editing the original TemperatureList class.
- Watch video 12-2 for a discussion of TemperatureList implemented with a normal array.
- Watch the demos (videos 12-3 to 12-6) on List class in your lecture videos for how to implement the big three.
- Your TemperatureList class will be tested against other programs that use your class.
- Download the main.cpp as a starter test program. Feel free to edit it.
- Download the original TemperatureList class for reference.
Running your class with the given main.cpp will produce the following output:
Now there's no temperatures in a.
How about temperatures in b?
How to Run the Project
Create a new project in your IDE. Copy the content of the downloaded main.cpp to your new project. Add two files in your project (note you will need to tell your IDE the type of file you are adding).
Run the project as usual.