3. (40 Points) Structures Program Suppose you have a portable weather station th
ID: 3710630 • Letter: 3
Question
3. (40 Points) Structures Program
Suppose you have a portable weather station that can measure the following:
Temperature (degrees Celsius)Wind Speed (miles per hour)Barometric Pressure (mm of mercury e.g. 30.5)Precipitation (hundredths of an inch e.g. 0.05)
The weather station has a GPS unit that can be used to provide location data in the form of latitude, longitude and altitude (meters). It also records the date (MM DD YYYY) and time (HH MM SS) of each measurement.
Measurements are recorded hourly and combined into a daily file (24 measurements per day)
Design a hierarchical structure to record measurements from the weather station. Store the data into an array of 24 measurements (One day of data) using this Data File.
Using the data write functions that will compute and print to the screen the following information:
Location of the weather station (latitude, longitude and altitude)High Temperature for the day with date and timeLow temperature for the day with date and timeMaximum wind speed for the 24-hour period with date and timeTotal precipitation for the 24-hour period with data
You may pass the entire array of records to the functions or pass just one record at a time.
Here is the data file. Download it from here.
http://uahcs.org/CS121/data/Weather_Station_Data_Problem_Six.txt
PORTABLE WEATHER STATION DAILY RECORD
DATE: 11 21 2017
LOCATION: LAT 34.7191438 LON -86.6463600 ALT 650 FT
TIME TEMP WIND_SPEED PRESSURE PRECIP
00:00:20 65.9 4.9 30.05 0.11
01:00:20 65.2 4.0 30.07 0.02
02:00:05 64.3 3.5 30.05 0.00
03:00:10 63.9 4.1 30.06 0.00
04:00:15 63.2 2.0 29.99 0.15
05:00:03 62.1 2.5 29.98 0.22
06:00:11 60.7 1.5 29.97 0.00
07:00:21 62.2 3.3 29.96 0.07
08:00:08 64.8 4.3 29.96 0.09
09:00:51 66.0 6.2 29.96 0.15
10:00:12 68.0 7.1 29.95 0.10
11:00:21 71.0 8.2 29.96 0.00
12:00:09 75.0 7.5 29.99 0.00
13:00:11 77.0 9.2 29.97 0.21
14:00:12 78.6 9.3 29.98 0.03
15:00:07 81.4 8.7 30.00 0.00
16:00:03 83.6 6.0 30.01 0.00
17:00:10 85.8 5.9 30.01 0.00
18:00:22 82.7 4.6 30.01 0.00
19:00:16 80.2 5.9 30.01 0.00
20:00:22 77.2 3.8 30.02 0.00
21:00:08 72.1 5.2 30.02 0.00
22:00:22 70.8 3.1 30.04 0.00
23:00:22 67.2 2.2 30.03 0.13
Explanation / Answer
ANS:-
PROGRAM:-
#include<iostream>
#include<fstream>
#include<sstream>
using namespace std;
void getHighTemperature(string date, string time[], double temp[], int count){
double max = temp[0];
int index = 0;
for (int i = 0; i<count; i++){
if (temp[i] > max){
max = temp[i];
index = i;
}
}
cout << date << endl;
cout << "Time:" << time[index] << endl;
cout << "High Temperature : " << max << " degree celsius" << endl;
}
void getLowTemperature(string date, string time[], double temp[], int count){
double min = temp[0];
int index = 0;
for (int i = 0; i<count; i++){
if (temp[i] < min){
min = temp[i];
index = i;
}
}
cout << date << endl;
cout << "Time:" << time[index] << endl;
cout << "Low Temperature : " << min << " degree celsius" << endl;
}
void getMaxWindSpeed(string date, string time[], double windSpeed[], int count){
double max = windSpeed[0];
int index = 0;
for (int i = 0; i<count; i++){
if (windSpeed[i] > max){
max = windSpeed[i];
index = i;
}
}
cout << date << endl;
cout << "Time:" << time[index] << endl;
cout << "Maximum Wind Speed : " << max << endl;
}
void getTotalPercip(string date, double percip[], int count){
double sum = 0;
for (int i = 0; i<count; i++){
sum = sum + percip[i];
}
cout << date << endl;
cout << "Total Percipitation : " << sum << endl;
}
int main(){
string date;
string line;
string location;
string time[100];
double temp[100];
double windSpeed[100];
double presure[100];
double percip[100];
ifstream fin("datafile.txt");
if (!fin){
cout << "Error opening file ";
return 0;
}
getline(fin, line);
getline(fin, date);
getline(fin,location);
getline(fin,line);
int count = 0;
cout << location << endl;
while (getline(fin,line)){
stringstream ss(line);
ss >> time[count] >> temp[count] >> windSpeed[count] >> presure[count] >> percip[100];
count++;
}
getHighTemperature(date, time, temp,count);
getLowTemperature(date, time, temp,count);
getMaxWindSpeed(date,time,windSpeed,count);
getTotalPercip(date,percip,count);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.