// filename: TemperatureArray.cpp /************************************ This program uses the TemperatureList class that contain an array of temperature values to demonstrate inserting items into arrays and outputing the values. *************************************/ #include // for cout #include // for the exit function using namespace std; const int MAX_LIST_SIZE = 5; class TemperatureList { public: TemperatureList( ); // 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. Note this // function does NOT change the values. 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. private: double list[MAX_LIST_SIZE]; // of temperatures in Fahrenheit int size; // number of array positions filled }; int main() { TemperatureList myTemperatures; myTemperatures.add_temperature(90); myTemperatures.add_temperature(88); myTemperatures.add_temperature(70); myTemperatures.add_temperature(56); myTemperatures.add_temperature(77); // The following statement will have the object return an // error message. myTemperatures.add_temperature(69); cout << myTemperatures; int temp; cin >> temp; return 0; } TemperatureList::TemperatureList( ) : size(0) { //Body intentionally empty. } void TemperatureList::add_temperature(double temperature) { if ( full() ) { int temp; cout << "Error: adding "<> temp; exit(1); } else { cout << "Added "<