Create class city which have data for average temperature. Accept data from the user for 5 different cities and display the information on screen.
Answers
Explanation:
#include <iostream> using namespace std; const int CITY = 2; const int WEEK = 7; int main() { int temperature[CITY][WEEK]; cout << "Enter all temperature for a week of first city and then second city. \n"; // Inserting the values into the temperature array for (int i = 0; i < CITY; ++i) { for(int j = 0; j < WEEK; ++j) { cout << "City " << i + 1 << ", Day " << j + 1 << " : "; cin >> temperature[i][j]; } } cout << "\n\nDisplaying Values:\n"; // Accessing the values from the temperature array for (int i = 0; i < CITY; ++i) { for(int j = 0; j < WEEK; ++j) { cout << "City " << i + 1 << ", Day " << j + 1 << " = " << temperature[i][j] << endl; } } return 0; }
Output
Enter all temperature for a week of first city and then second city. City 1, Day 1 : 32 City 1, Day 2 : 33 City 1, Day 3 : 32 City 1, Day 4 : 34 City 1, Day 5 : 35 City 1, Day 6 : 36 City 1, Day 7 : 38 City 2, Day 1 : 23 City 2, Day 2 : 24 City 2, Day 3 : 26 City 2, Day 4 : 22 City 2, Day 5 : 29 City 2, Day 6 : 27 City 2, Day 7 : 23 Displaying Values: City 1, Day 1 = 32 City 1, Day 2 = 33 City 1, Day 3 = 32 City 1, Day 4 = 34 City 1, Day 5 = 35 City 1, Day 6 = 36 City 1, Day 7 = 38 City 2, Day 1 = 23 City 2, Day 2 = 24 City 2, Day 3 = 26 City 2, Day 4 = 22 City 2, Day 5 = 29 City 2, Day 6 = 27 City 2, Day 7 = 23