In: Computer Science
C++ programming
To store the information about a city and its weather forecast, create a struct that holds the city's name (string), population (int), and a forecast array storing 7 string elements representing the city's weather in the next 7 days.
The program will then accept user input to enter the name and population of the city, then it accepts 7 string inputs to store into the forecast array.
Then the program will output the city's name, population, and forecast data.
Ex: If the inputs are:
Houston 2313000 sunny sunny sunny rainy thunderstorm sunny sunny
the function outputs:
Houston Population: 2313000 7 Day Forecast: Day 0: sunny Day 1: sunny Day 2: sunny Day 3: rainy Day 4: thunderstorm Day 5: sunny Day 6: sunny
Your program must name the struct "city" with name, population, and forecast as the corresponding member names!
Your program must define and call this function to output the city information:
void city_info(city c)
#include <iostream>
using namespace std;
/* Define your struct here */
/* Define your printing function here */
int main() {
/* Type your code here */
return 0;
}
#include <iostream> #include <string> using namespace std; struct city { string city; int population; string day0; string day1; string day2; string day3; string day4; string day5; string day6; }; void city_info(city c) { cout << c.city << endl; cout << "Population: " << c.population << endl; cout << "7 Day Forecast: " << endl; cout << "Day 0: " << c.day0 << endl; cout << "Day 1: " << c.day1 << endl; cout << "Day 2: " << c.day2 << endl; cout << "Day 3: " << c.day3 << endl; cout << "Day 4: " << c.day4 << endl; cout << "Day 5: " << c.day5 << endl; cout << "Day 6: " << c.day6 << endl; } int main() { city c; cin >> c.city >> c.population >> c.day0 >> c.day1 >> c.day2 >> c.day3 >> c.day4 >> c.day5 >> c.day6; city_info(c); return 0; }