Create a C++ program City Jan(avg_F) Apr(avg_F) Jul(avg_F) Oct(avg_F) Rain(avg_i
ID: 3785322 • Letter: C
Question
Create a C++ program
City Jan(avg_F) Apr(avg_F) Jul(avg_F) Oct(avg_F) Rain(avg_in) Rain(avg_days) Snow(avg_in) Obs(yrs)
Albany,_N.Y. 22.2 46.6 71.1 49.3 38.60 136 64.4 57
Albuquerque,_N.M. 35.7 55.6 78.5 57.3 9.47 60 11.0 64
Anchorage,_Alaska 15.8 36.3 58.4 34.1 16.08 115 70.8 39/60
Asheville,_N.C. 35.8 54.1 73.0 55.2 47.07 126 15.3 39
Atlanta,_Ga. 42.7 61.6 80.0 62.8 50.20 115 2.1 69/65
Atlantic_City,_N.J. 32.1 50.6 75.3 55.1 40.59 113 16.2 60/54
Austin,_Texas 50.2 68.3 84.2 70.6 33.65 85 0.9 62/58
Baltimore,_Md. 32.3 53.2 76.5 55.4 41.94 115 21.5 53
Baton_Rouge,_La. 50.1 66.6 81.7 68.1 63.08 110 0.2 52/46
Billings,_Mont. 24.0 46.1 72.0 48.1 14.77 96 56.9 69
Birmingham,_Ala. 42.6 61.3 80.2 62.9 53.99 117 1.5 60
Bismarck,_N.D. 10.2 43.3 70.4 45.2 16.84 96 44.3 64
Boise,_Idaho 30.2 50.6 74.7 52.8 12.19 89 20.6 64
Boston,_Mass. 29.3 48.3 73.9 54.1 42.53 127 42.8 52/66
Bridgeport,_Conn. 29.9 48.9 74.0 54.7 44.15 119 26.2 55/49
Buffalo,_N.Y. 24.5 45.3 70.8 50.7 40.54 169 93.6 60
Burlington,_Vt. 18.0 43.5 70.6 47.7 36.05 154 79.3 60
Caribou,_Maine 9.5 38.1 65.6 42.8 37.44 161 112.1 64/63
Casper,_Wyo. 22.3 42.7 70.0 45.7 13.03 94 77.8 53
Charleston,_S.C. 47.9 64.2 81.7 66.2 51.53 114 0.7 61/57
Charleston,_W.Va. 33.4 54.3 73.9 55.1 44.05 151 34.0 56/49
Charlotte,_N.C. 41.7 60.9 80.3 61.7 43.51 112 5.6 64
Cheyenne,_Wyo. 25.9 41.6 67.7 45.4 15.45 100 55.8 68
Chicago,_Ill. 22.0 47.8 73.3 52.1 36.27 125 38.0 45/44
C
leveland,_Ohio 25.7 47.6 71.9 52.2 38.71 155 57.6 62
Columbia,_S.C. 44.6 63.2 82.0 63.7 48.27 109 1.9 56/55
Columbus,_Ohio 28.3 52.0 75.1 54.7 38.52 137 28.2 64/56
Concord,_N.H. 20.1 44.6 70.0 47.8 37.60 127 64.5 62
Dallas-Ft._Worth,_Texas 44.1 65.0 85.0 67.2 34.73 79 2.6 50/45
Denver,_Colo. 29.2 47.6 73.4 51.0 15.81 89 60.3 61
Des_Moines,_Iowa 20.4 50.6 76.1 52.8 34.72 108 33.3 64/60
Detroit,_Mich. 24.5 48.1 73.5 51.9 32.89 135 41.3 45
Dodge_City,_Kan. 30.1 53.9 79.8 57.1 22.35 78 20.3 61
Duluth,_Minn. 8.4 39.0 65.5 43.5 31.00 134 80.6 62/60
El_Paso,_Texas 45.1 64.6 83.3 64.9 9.43 49 5.3 64/57
Fairbanks,_Alaska -9.7 31.7 62.4 23.5 10.34 106 67.7 52
Fargo,_N.D. 6.8 43.5 70.6 45.3 21.19 101 40.8 61
Grand_Junction,_Colo. 26.1 50.9 76.8 52.7 8.99 72 23.6 57
Grand_Rapids,_Mich. 22.4 46.3 71.4 49.9 37.13 144 73.3 40
Hartford,_Conn. 25.7 48.9 73.7 51.9 46.16 128 49.6 49/46
Helena,_Mont. 20.2 44.1 67.8 44.8 11.32 95 46.9 63/58
Honolulu,_Hawaii 73.0 75.6 80.8 80.2 18.29 96 0.0 54/52
Houston,_Texas 51.8 68.5 83.6 70.4 47.84 105 0.4 34/69
Indianapolis,_Ind. 26.5 52.0 75.4 54.6 40.95 126 23.9 64/72
Jackson,_Miss. 45.0 63.4 81.4 64.4 55.95 110 1.0 40/38
Jacksonville,_Fla. 53.1 66.6 81.6 69.4 52.34 116 0.01 62/60
Juneau,_Alaska 25.7 40.8 56.8 42.3 58.33 223 97.0 59
Kansas_City,_Mo. 26.9 54.4 78.5 56.8 37.98 104 19.9 31/69
Knoxville,_Tenn. 37.6 57.8 77.7 58.8 48.22 127 11.5 61/58
Las_Vegas,_Nev. 47.0 66.0 91.2 68.7 4.49 26 1.2 55/48
Lexington,_Ky. 32.0 54.6 76.1 56.6 45.91 130 16.1 59/53
Little_Rock,_Ark. 40.1 61.4 82.4 63.3 50.93 104 5.2 61/56
Long_Beach,_Calif. 57.0 63.0 73.8 68.6 12.94 31 0.01 59/52
Los_Angeles,_Calif. 57.1 60.8 69.3 66.9 13.15 35 0.01 68/62
Louisville,_Ky. 33.0 56.4 78.4 58.5 44.54 124 16.4 56
Madison,_Wisc. 17.3 45.9 71.6 49.3 32.95 120 43.8 55
Memphis,_Tenn. 39.9 62.1 82.5 63.8 54.65 107 5.1 53/49
Miami,_Fla. 68.1 75.7 83.7 78.8 58.53 131 0.01 61/59
Milwaukee,_Wisc. 20.7 45.2 72.0 51.4 34.81 125 47.0 63
Minneapolis-St._Paul,_Minn. 13.1 46.6 73.2 48.7 29.41 115 49.9 65/62
Mobile,_Ala. 50.1 66.1 81.5 67.7 66.29 121 0.4 62/61
Montgomery,_Ala. 46.6 64.3 81.8 65.4 54.77 108 0.4 59/52
Mt._Washington,_N.H. 5.2 22.9 48.7 30.2 101.91 209 259.9 71
Nashville,_Tenn. 36.8 58.5 79.1 59.9 48.11 119 10.1 62/58
Newark,_N.J. 31.3 52.3 77.2 56.4 46.25 122 28.3 62
New_Orleans,_La. 52.6 68.2 82.7 70.0 64.16 114 0.2 55/51
New_York,_N.Y. 32.1 52.5 76.5 56.6 49.69 121 28.6 134/135
Norfolk,_Va. 40.1 57.4 79.1 61.1 45.74 116 7.8 55/53
Oklahoma_City,_Okla. 36.7 59.7 82.0 62.0 35.85 83 9.5 64
Olympia,_Wash. 38.1 47.4 62.8 49.7 50.79 163 16.7 62/55
Omaha,_Neb. 21.7 51.4 76.7 53.2 30.22 99 30.1 67/68
Philadelphia,_Pa. 32.3 53.1 77.6 57.2 42.05 117 20.8 63/61
Phoenix,_Ariz. 54.2 70.2 92.8 74.6 8.29 36 0.01 64/62
Pittsburgh,_Pa. 27.5 49.9 72.6 52.5 37.85 152 43.6 51
Portland,_Maine 21.7 43.7 68.7 47.7 45.83 129 70.4 63
Portland,_Ore. 39.9 51.2 68.1 54.3 37.07 153 6.5 63/55
Providence,_R.I. 28.7 48.6 73.3 53.0 46.45 124 36.0 50
Raleigh,_N.C. 39.7 59.1 78.8 60.0 43.05 113 7.5 59
Reno,_Nev. 33.6 48.6 71.3 52.0 7.48 51 24.3 61/54
Richmond,_Va. 36.4 57.1 77.9 58.3 43.91 114 13.8 66/64
Roswell,_N.M. 40.0 60.5 80.8 61.4 13.34 54 11.7 31/51
Sacramento,_Calif. 46.3 58.9 75.4 64.4 17.93 58 0.01 64/50
Salt_Lake_City,_Utah 29.2 50.0 77.0 52.5 16.50 91 58.7 75
San_Antonio,_Texas 50.3 68.6 84.3 70.7 32.92 82 0.7 61/58
San_Diego,_Calif. 57.8 62.6 70.9 67.6 10.77 41 0.01 63/60
San_Francisco,_Calif. 49.4 56.2 62.8 61.0 20.11 63 0.01 76/69
Savannah,_Ga. 49.2 65.3 82.1 67.1 49.58 111 0.4 53/48
Seattle-Tacoma,_Wash. 40.9 50.2 65.3 52.7 37.07 155 11.4 59/52
Sioux_Falls,_S.D. 14.0 45.7 73.0 48.0 24.69 98 41.2 58
Spokane,_Wash. 27.3 46.5 68.6 47.2 16.67 112 48.6 56
Springfield,_Ill. 25.1 52.8 76.3 55.5 35.56 113 23.2 56
St._Louis,_Mo. 29.6 56.6 80.2 58.3 38.75 111 19.6 46/67
Tampa,_Fla. 61.3 71.5 82.5 75.8 44.77 106 0.01 57
Toledo,_Ohio 23.9 48.3 73.0 51.8 33.21 134 37.1 48/43
Tucson,_Ariz. 51.7 66.0 86.5 70.5 12.17 53 1.2 63
Tulsa,_Okla. 36.4 60.8 83.5 62.6 42.42 91 10.2 64
Vero_Beach,_Fla. 63.0 71.5 81.7 76.4 51.93 126 0.01 20/18
Washington,_D.C. 34.9 56.1 79.2 58.8 39.35 113 17.1 62/60
Wichita,_Kan. 30.2 55.3 81.0 58.6 30.38 85 15.9 50
Wilmington,_Del. 31.5 52.4 76.6 55.8 42.81 117 21.1 56/53
The attached file is a list of weather statistics for various US cities. Each line has 9 tab-separated fields that can be read using the stream-in operator. City name January average temperature in degrees Fahrenheit April average temperature July average temperature October average temperature Average annual precipitation in inches Average annual days of rain Average annual snowfall in inches Years of observations used to compile the statistics: rain [/snow] The first line in the file is the field names, which can be ignored. Cities with multiple words in their names, such as New York, have the words connected with underscores, New_York, so the city name can be read with a single stream-in request. The only whitespaces in the file are the tab field separators. Write a program to read the file and calculate the average annual temperature for the city by averaging the four seasonal temperatures. Display the names and temperatures of the cities with the highest and lowest average annual temperatures. The output should look like number of cities examined has the minimum average annual temperature of has the maximum average annual temperature ofExplanation / Answer
PROGRAM CODE:
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
using namespace std;
int numberOfCities = 0;
struct WeatherStatistics
{
string city_name;
double jan_avg;
double apr_avg;
double july_avg;
double oct_avg;
double avg_precip;
double avg_daysOfRain;
double avg_annualRainfall;
int yearsOfObservation;
}*statistics[100];
int main() {
string max_city = "";
double max_avg_temp = 0.0;
string min_city = "";
double min_avg_temp = 1000.0;
string fileName = "";
cout<<"Enter the file name: ";
cin>>fileName;
ifstream infile(fileName);
string line;
while(getline(infile, line))
{
istringstream iss(line);
vector<string> tokens;
statistics[numberOfCities] = new WeatherStatistics;
string token;
while(getline(iss, token, ' '))
tokens.push_back(token);
statistics[numberOfCities]->city_name = tokens.at(0);
statistics[numberOfCities]->jan_avg =stod(tokens.at(1));
statistics[numberOfCities]->apr_avg =stod(tokens.at(2));
statistics[numberOfCities]->july_avg = stod(tokens.at(3));
statistics[numberOfCities]->oct_avg = stod(tokens.at(4));
statistics[numberOfCities]->avg_precip = stod(tokens.at(5));
statistics[numberOfCities]->avg_daysOfRain = stod(tokens.at(6));
statistics[numberOfCities]->avg_annualRainfall = stod(tokens.at(7));
statistics[numberOfCities]->yearsOfObservation = stod(tokens.at(8));
double annualTemp = (statistics[numberOfCities]->jan_avg + statistics[numberOfCities]->apr_avg +
statistics[numberOfCities]->july_avg + statistics[numberOfCities]->oct_avg)/4;
if(max_avg_temp < annualTemp)
{
max_avg_temp = annualTemp;
max_city = statistics[numberOfCities]->city_name;
}
if(min_avg_temp > annualTemp)
{
min_avg_temp = annualTemp;
min_city = statistics[numberOfCities]->city_name;
}
numberOfCities++;
}
cout<<"Number of cities examined: "<<numberOfCities<<endl;
cout<<min_city<<" has the minimum average annual temperature of "<<min_avg_temp<<endl;
cout<<max_city<<" has the maximum average annual temperature of "<<max_avg_temp<<endl;
return 0;
}