Question

In: Computer Science

To store the information about a city and its weather forecast, create a struct that holds...

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:

in c++

Solutions

Expert Solution

#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;
}

Related Solutions

C++ programming To store the information about a city and its weather forecast, create a struct...
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...
Create a typedef fruitType using the struct fruitType_struct to store the following data about a fruit:...
Create a typedef fruitType using the struct fruitType_struct to store the following data about a fruit: name (string, up to 50 characters long) color (string, up to 10 characters long) fat (integer) sugar (integer) carbohydrate (integer) Write a void function called printFruit that takes a fruitType parameter and prints the data (as shown in the example below). Declare a variable of type fruitType to store the following data: name: banana color: yellow fat: 1 sugar: 15 carbohydrate: 22 then use...
Write in C++: create a Doubly Linked List class that holds a struct with an integer...
Write in C++: create a Doubly Linked List class that holds a struct with an integer and a string. It must have append, insert, remove, find, and clear.
Code in python: Write a class that implements a struct. In your struct store Student information...
Code in python: Write a class that implements a struct. In your struct store Student information such as name, netid, and gpa. Write a function that can access a student in a list of 5 structs by netid and print their name and gpa. Show that your function works by calling it.
The goal is to Create an array of struct “employee” Fill the array with information read...
The goal is to Create an array of struct “employee” Fill the array with information read from standard input using C++ style I/O Shuffle the array Select 5 employees from the shuffled array Sort the shuffled array of employees by the alphabetical order of their last Name Print this array using C++ style I/O Random Number Seeding We will make use of the random_shuffle() function from the standard algorithm library. You can use srand() function provided in with a seed...
Define a struct computerType to store the following data about a computer: Manufacturer (50 character string),...
Define a struct computerType to store the following data about a computer: Manufacturer (50 character string), model type (50 character string), processor type (10 character string), ram (int) in GB, hard drive size (int) in GB, year when the computer was built (int), and the price (double). Write a program that declares a variable of type computerType, prompts the user to the input data for the struct, and then outputs all the computer's data from the struct. For Example: Enter...
Write a class named RetailItem that holds data about an item in retail store.
Python 3Your program will have 2 classes:A) RetailItem ClassWrite a class named RetailItem that holds data about an item in retail store.Attributes: The class should store following data in attributes:>item_Name> PriceMethods:> RetailItem class’s __init__ method should accept an argument for each attribute.> RetailItem class should also have accessor and mutator methods for each attributeB) MainMenu ClassAttributes: The class should store following data in attributes:> List of RetailItem Objects: InventoryMethods:> createInventory(): method to create three RetailItem Objects store in list Inventory...
i want to create a weather api. which is pullling out information of all the cities(for...
i want to create a weather api. which is pullling out information of all the cities(for the whole world)  using their names or by their zipcode. and it should change the background image as the temperature is, cold, or hot, or mild etc. i need in help in making this weather api and also it can be in any language. please help me out
Create a Weather API.(ANY LANUGUAGE). " that pulls out information from web and stores the data...
Create a Weather API.(ANY LANUGUAGE). " that pulls out information from web and stores the data in back end. in which users can enter location: city or zip code to get the weather of that city or state. weather info should be in degree farenhit and centigrade. it should show the images as you see in you phone for weather and speed, etc. and it should change picture according to weather. for example, rain, cloudy, sunny, night, thunder. SHOW THE...
Family Supermarkets has decided to increase the size of its Lansing store. It wants information about...
Family Supermarkets has decided to increase the size of its Lansing store. It wants information about the profitability of its individual product lines: meats, fresh produce, and packaged food. The following data is for the year 2017 for each product line: Meats Fresh Produce Packaged Foods Revenue $790,000 $840,000 $460,000 Cost of goods sold $590,000 $600,000 $340,000 purchase orders 276 315 126 hours of stocking shelves 204 2,021 1,067 items sold 311,000 443,000 131,000 The Company also provides the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT