#include #include //for the i/o manipulator setw #include #include using namespace std; class weather { public: int todaysDate; //index into the array a int tempHi; int tempLo; string day; string weather; void print() const; void nextDay(); void change(); }; const string weekday[] { "Tuesday", //0 "Wednesday", //1 "Thursday", //2 "Friday", //3 "Saturday", //4 "Sunday", //5 "Monday" //6 }; const size_t weekSize {size(weekday)}; void weather::print() const { cout << "Day " << todaysDate+1 << " " //Humans count starting at 1. << setw(10) << left << day + "," << " " << "High of " << setw(2) << tempHi << "F, " << "Low of " << setw(2) << tempLo << "F, " << "Forecast of " << weather << "\n"; } void weather::nextDay() { ++todaysDate; i //Update the five data members. day = weekday[todaysDate % weekSize]; //subscript in range 0 to 6 tempHi = a[todaysDate].tempHi; tempLo = a[todaysDate].tempLo; weather = a[todaysDate].weather; } void weather::change() { //The main function has already output the first weather report. //Now we print the remaining weather reports. while (todaysDate < n - 1) { nextDay(); print(); } } struct stats { int tempHi; //Fahrenheit int tempLo; string weather; }; const stats a[] { {74, 61, "Sunny"}, //0 {84, 67, "Sunny"}, //1 {90, 72, "Partly Cloudy"}, //2 {85, 68, "Partly Cloudy"}, //3 {75, 65, "Showers"}, //4 {79, 63, "Partly Cloudy"}, //5 {74, 63, "Partly Cloudy"}, //6 {74, 65, "Mostly Cloudy"} //7 }; const size_t n {size(a)}; int main() { weather today; //Create an object. const int d {0}; today.todaysDate = d; //Load information into the five data members. today.day = weekday[d % weekSize]; //subscript in range 0 to 6 today.tempHi = a[d].tempHi; today.tempLo = a[d].tempLo; today.weather = a[d].weather; today.print(); today.change(); return EXIT_SUCCESS; }