//--------------------------------------------------------- // Implement and test a class that models a list of // temperature records. // // D. Searls // Asbury College // Nov 2007 //--------------------------------------------------------- #include #include using namespace std; class temperatureRecord { /***** Paste your class temperatureRecord implementation here *****/ }; class temperatureList { private: static const int CAPACITY = 10; temperatureRecord list[CAPACITY]; int n; public: //----------------------------------------------------- // Construct a new temperature list. //----------------------------------------------------- temperatureList() { } //----------------------------------------------------- // Construct a new temperature list with the same // state as the specified list. // // In parameter: tList //----------------------------------------------------- temperatureList(const temperatureList& tList) { } // Member functions //----------------------------------------------------- // Append a new set of temperature values to the end // of the list. If the list is full, this function does // nothing. // // In parameters: lowTemp, highTemp //----------------------------------------------------- void append(double lowTemp, double highTemp) { } //----------------------------------------------------- // Set the low temperature at the specified position // to the specified value. // // Preconditions: 0 <= pos < length // // If pos is invalid (pos < 0 or pos >= length) then no // changes of any kind are made to the list. // // In Parameters: newLow, pos //----------------------------------------------------- void setLowAt(double newLow, int pos) { } //----------------------------------------------------- // Set high temperature at the specified position // to the specified value. // // Preconditions: 0 <= pos < length // // If pos is invalid (pos < 0 or pos >= length) then no // changes of any kind are made to the list. // // In Parameters: newHigh, pos //----------------------------------------------------- void setHighAt(double newHigh, int pos) { } //----------------------------------------------------- // Return the low temperature at the specified // position. // // Precondition: 0 <= pos < length // // If pos is invalid (pos < 0 or pos >= length) a value // of 0.0 is returned. // // In Parameter: pos //----------------------------------------------------- double getLowAt(int pos) const { } //----------------------------------------------------- // Return the high temperature at the specified // position. // // Precondition: 0 <= pos < length // // If pos is invalid (pos < 0 or pos >= length) a value // of 0.0 is returned. // // In Parameter: pos //----------------------------------------------------- double getHighAt(int pos) const { } //----------------------------------------------------- // Return the length of this list. The length is the // number of records stored in the list. //----------------------------------------------------- int length() { } //----------------------------------------------------- // Return the capacity of this list. The capacity is // the number of records that could be stored in the // list. //----------------------------------------------------- int capacity() { } //----------------------------------------------------- // Return the minimum low temperature in the list. If // the list is empty, 0.0 is returned. //----------------------------------------------------- double getMinLow() { } //----------------------------------------------------- // Return the minimum high temperature in the list. If // the list is empty, 0.0 is returned. //----------------------------------------------------- double getMinHigh() { } //----------------------------------------------------- // Return the maximum low temperature in the list. If // the list is empty, 0.0 is returned. //----------------------------------------------------- double getMaxLow() { } //----------------------------------------------------- // Return the maximum high temperature in the list. If // the list is empty, 0.0 is returned. //----------------------------------------------------- double getMaxHigh() { } //----------------------------------------------------- // Return the average low temperature in the list. If // the list is empty, 0.0 is returned. //----------------------------------------------------- double getAvgLow() { } //----------------------------------------------------- // Return the average high temperature in the list. If // the list is empty, 0.0 is returned. //----------------------------------------------------- double getAvgHigh() { } //----------------------------------------------------- // Clear the entire list of all its contents. //----------------------------------------------------- void clearAll() { } }; // End class temperatureList //********************************************************* // T E S T P R O G R A M //********************************************************* int main() { temperatureList data; // Display the length and capacity of the default list. cout << "Default List" << endl; cout << " Length = " << data.length() << endl; cout << " Capacity = " << data.capacity() << endl << endl; // Populate the list. for (int i = 0; i < 12; i++) { data.append(-10*i, 10*i); } // Display the length and capacity of the populated list. cout << "Populated List" << endl; cout << " Length = " << data.length() << endl; cout << " Capacity = " << data.capacity() << endl << endl; // Display the list. Invalid positions are included // to test the getters. cout << "List Contents" << endl; for (int i = -2; i < 12; i++) { cout << setw(6) << i; cout << setw(6) << data.getLowAt(i); cout << setw(6) << data.getHighAt(i); cout << endl; } cout << endl; // Modify the list values using the setters. Invalid // positions are included to test the setters. for (int i = -2; i < 12; i++) { data.setLowAt(-100*i, i); data.setHighAt(100*i, i); } // Display the list. cout << "List Contents" << endl; for (int i = 0; i < data.length(); i++) { cout << setw(6) << i; cout << setw(6) << data.getLowAt(i); cout << setw(6) << data.getHighAt(i); cout << endl; } cout << endl; // Verify that the copy constructor works properly temperatureList copy(data); cout << "Copy Contents" << endl; for (int i = 0; i < copy.length(); i++) { cout << setw(6) << i; cout << setw(6) << data.getLowAt(i); cout << setw(6) << data.getHighAt(i); cout << endl; } cout << endl; // Display the temperature statistics cout << "Temperature Statistics" << endl; cout << " Minimum Low: " << data.getMinLow() << endl; cout << " Maximum Low: " << data.getMaxLow() << endl; cout << endl; cout << " Minimum High: " << data.getMinHigh() << endl; cout << " Maximum High: " << data.getMaxHigh() << endl; cout << endl; cout << " Average Low: " << data.getAvgLow() << endl; cout << " Average High: " << data.getAvgHigh() << endl; cout << endl; // Clear the list and display the length and capacity // of the cleared list data.clearAll(); cout << "Cleared List" << endl; cout << " Length = " << data.length() << endl; cout << " Capacity = " << data.capacity() << endl << endl; // Display the temperature statistics cout << "Temperature Statistics" << endl; cout << " Minimum Low: " << data.getMinLow() << endl; cout << " Maximum Low: " << data.getMaxLow() << endl; cout << endl; cout << " Minimum High: " << data.getMinHigh() << endl; cout << " Maximum High: " << data.getMaxHigh() << endl; cout << endl; cout << " Average Low: " << data.getAvgLow() << endl; cout << " Average High: " << data.getAvgHigh() << endl; cout << endl; return 0; }