Question
The purpose of this challenge is to use an array of an abstract data type (struct) and save the data to a file. This challenge
The purpose of this challenge is to use an array of an abstract data type (struct) and save the data to a file. This challenge implements data entry for collection of weather data.
Requirements
Declare a struct called Weather as below:
struct Weather { string city; double temperature; double humidity; };
In main(), create an array using the struct variable called weather_data. This array can contain 10 elements.
Create a function int collect_data(Weather data[], int size). This function prompts the user to input data for each of the properties of the Weather struct (city, temperature and humidity). During the collection process, if the user enters a city name of stop, do not store this is as the city name and do not ask the user for temperature and humidity. stop is an indicator to stop user input. Using stop as the city name will stop the user input process, even if the array is not yet full. This user will return the number of actual records entered. A record is equivalent to one complete struct data element.
In main(), declare an integer called count. This represents the count of records actually entered by the user.
Create a function void save_data(Weather data[], int count). This function will save the struct data to a file called weather.txt. In this file, each record will be stored as city, temperature, humidity each record taking up one line in the file. The count parameter indicates how many elements in the data array actually contain user input.
Your main() function will simply call collect_data() and save_data() to get the user input and to save the data to the file respectively.
DO NOT USE
Classes.
Sample Interaction / Output
City? Seattle Temperature? 87 Humidity? 100 City? Tampa Temperature? 100 Humidity? 100 City? stop 2 records entered. Open weather.txt file to see info.
Contents of weather.txt
Seattle, 87, 100 Tampa, 100, 100
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started