Question

In: Computer Science

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

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

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:...
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...
In C Programming Create a payroll program to store and calculate the payroll for a small...
In C Programming Create a payroll program to store and calculate the payroll for a small company as follows: Ask the user for the number of employees and only accept the number if it is between 5 and 40 employees, otherwise prompt the user again and test the input, keep repeating until the user enters an acceptable number. Create an array of floats that is 4 rows and an number of columns equal to the number of employees in the...
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.
C++ programming Complete the code to input and store all the information in the structure Book:...
C++ programming Complete the code to input and store all the information in the structure Book: title, author, year and pages. Complete the function print() with arguments and code to print a Book variable in the following format: Book title: <title> Book author: <name> Published in <year> Number of pages: <pages> #include <iostream> using namespace std; struct Book { string title; string author; string year; int pages; }; void print(/*arguments*/) { //Complete function } int main() { //Declare structure variable...
C# Programming create a Hash Function
C# Programming create a Hash Function
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
This project requires the student to create a record (in C++ called a struct). The record...
This project requires the student to create a record (in C++ called a struct). The record should contain several fields of different data types and should allow the user to search the records to find the student with the highest grade. In this project the student should gain an understanding of the nature of records with multiple data types, how to save the records, search the records and retrieve them.  The special problems of maintaining records of multiple data types on...
c++ programming: Given: Struct myq { double a,b,c };      X1= -b + sqrt(b*b-4 * a*...
c++ programming: Given: Struct myq { double a,b,c };      X1= -b + sqrt(b*b-4 * a* c)/2 *a;       X2= -b- sqrt(b*b- 4 * a * c)/2 * a;       X0f v= (-b)/( 2*a);       a>0 if maximum otherwise it is minimum        b*b – 4*a*c >0    two unrepeated roots        b*b- 4 * a* c =0 two repeated roots        b*b- 4 * a* c <0 two complex roots Write a function with an argument to calculate x1, make...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT