Question

IN C++ FORMAT it will have a txt file with January 0 -10 -20 -12 February...

IN C++ FORMAT

it will have a txt file with

January  0 -10 -20 -12
February 0  20 -30 -10
March    5  45  20  32
April   25  65  45  55
May     12  75  32  66
June    18  85  65  72
July     6  98  88  90
August  18  102 82  91
September 16 85 65  73
October 12  72  45  59
November 5  62  30  45
December 0  46 -15  33

Write a program using structures to store the following weather information:

Total Rainfall

High Temperature

Low Temperature

Average Temperature

Use an the input.txt file to load the data to your array of 12 weather structures.

Once the data for all the months is entered, the program should calculate and display the:

Total rainfall for the year

Average of all of the months average temperatures.

Highest temp for the year and its months

Lowest temp for the year and its month


Validatation Input temps should be between -100 and +140 and and total rainfall must not be less than 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM

#include<iostream>

#include<math.h>

#include<fstream>

#include<string>

#include<sstream>

using namespace std;

typedef struct

{

int rain;

int hightemp;

int lowtemp;

int avgtemp;

}record;

int main()

{

int i,num[50],ctr;

record weather[12];

string line;

ifstream ifile;

i=-1;

ifile.open("input.txt");

if (ifile.is_open())

{

while(getline(ifile,line,' '))

{

stringstream geek(line);

geek>>num[++i];

//cout<<num[i];

}

}

ifile.close();

  

ctr=0;

for(int j=1;j<i;j=j+4)

{

if (num[j]>=0)

weather[ctr].rain=num[j];

else

weather[ctr].rain=0;

if num[j+1]>=-100 && num[j+1]<=140

{

weather[ctr].hightemp=num[j+1];

}

else

weather[ctr].hightemp=0;

  if num[j+2]>=-100 && num[j+2]<=140

{

weather[ctr].lowtemp=num[j+2];

}

else

weather[ctr].lowtemp=0;

weather[ctr].avgtemp=num[j+3];

ctr=ctr+1;

}

  

int totrain=0,totavgtemp=0,high,low,highmonth,lowmonth;

high=weather[0].hightemp;

low=weather[0].lowtemp;

for(i=0;i<12;i++)

{

//cout<<endl<<weather[i].rain;

totrain=totrain+weather[i].rain;

//cout<<endl<<weather[i].hightemp;

if(high<weather[i].hightemp)

{

high=weather[i].hightemp;

highmonth=i;

}

//cout<<endl<<weather[i].lowtemp;

if(low>weather[i].lowtemp)

{

low=weather[i].lowtemp;

lowmonth=i;

}

//cout<<endl<<weather[i].avgtemp;

totavgtemp=totavgtemp+weather[i].avgtemp;

}

totavgtemp=totavgtemp/12;

cout<<endl<<"Total rainfall of the year:"<<totrain;

cout<<endl<<"Average of the average temperature of every month:"<<totavgtemp;

cout<<endl<<"Highest temperature:"<<high;

cout<<endl<<"Month with the highest temperature:";

switch(highmonth)

{

case 0:cout<<"January";break;

case 1:cout<<"February";break;

case 2:cout<<"March";break;

case 3:cout<<"April";break;

case 4:cout<<"May";break;

case 5:cout<<"June";break;

case 6:cout<<"July";break;

case 7:cout<<"August";break;

case 8:cout<<"September";break;

case 9:cout<<"October";break;

case 10:cout<<"November";break;

case 11:cout<<"December";break;

default:break;

}

cout<<endl<<"Lowest temperature:"<<low;

cout<<endl<<"Month with the lowest temperature:";

switch(lowmonth)

{

case 0:cout<<"January";break;

case 1:cout<<"February";break;

case 2:cout<<"March";break;

case 3:cout<<"April";break;

case 4:cout<<"May";break;

case 5:cout<<"June";break;

case 6:cout<<"July";break;

case 7:cout<<"August";break;

case 8:cout<<"September";break;

case 9:cout<<"October";break;

case 10:cout<<"November";break;

case 11:cout<<"December";break;

default:break;

}

  

return 0;

}

INPUT FILE

*Special Note: The Input File must have single spacing between each word. If not the spaces need to be truncated.

OUTPUT

Add a comment
Know the answer?
Add Answer to:
IN C++ FORMAT it will have a txt file with January 0 -10 -20 -12 February...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertain...

    The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertaining to the lines: cin>>month[i].lowTemp; and months[i].avgTemp = (months[i].highTemp + month[i].lowTemp)/2; The error messages read as follows: error C2039: 'lowTemp': is not a member of 'std::basic_string<_Elem,_Traits,_Ax>' and it continues. The second error message is identical. The program is as follows: Ch. 11, Assignment #3. pg. 646. Program #4. //Weather Statistics. //Write a program that uses a structure to store the...

  • 1. Write a C++ program that reads daily weather observation data from a file and writes...

    1. Write a C++ program that reads daily weather observation data from a file and writes monthly and annual summaries of the daily data to a file. a. The daily weather data will be contained in a file named wx_data.txt, with each line of the file representing the weather data for a single day. b. For each day, the date, precipitation amount, maximum temperature, and minimum temperature will be provided as tab-separated data with the following format: 20180101 0.02 37...

  • Therefore, for this program you will read the data in the file named weatherdata_2.txt into arrays...

    Therefore, for this program you will read the data in the file named weatherdata_2.txt into arrays for the wind speed and for the temperature. You will then use the stored data to calculate and output the average wind speed and the average temperature. Create a constant with a value of 30 and use that to declare and loop through your arrays and as a divisor to produce your averages. Here is the data file (below). 1. 14 25 2. 12...

  • [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a...

    [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. For example, the output might look like this: During the months of March–June the total rainfall was 7.32 inches and the average monthly rainfall...

  • Hi im having trouble with this homework question. Can someone show me how to do this in C++ with all the steps? Weather Analysis WeatherAnalyzer - New Day Data 2- Good Days 3- Summary 0- Exit Step 0:...

    Hi im having trouble with this homework question. Can someone show me how to do this in C++ with all the steps? Weather Analysis WeatherAnalyzer - New Day Data 2- Good Days 3- Summary 0- Exit Step 0: You can get the sample file from this link: Each row in the text file represent weather measurement of a day. For each day, the file contains the temperature (first column), humidity (second column) and the wind (third column) values emp 70...

  • Write a program that scores the total rainfall for each of 12 months into an array...

    Write a program that scores the total rainfall for each of 12 months into an array double. A sample array definition is shown below double thisYear[] = {1.6, 2.1, 1.7, 3.5, 2.6, 3.7, 3.9, 2.6, 2.9, 4.3, 2.4, 3.7}; The program should have the four functions to calculate the following 1. The total rainfall for the year 2. The average monthly rainfall 3. The month with most rain 4. The month with least rain Output: What to deliver? Your .cpp...

  • Need help writing a program that meets pseudocode and criteria . Txt File below input.txt file...

    Need help writing a program that meets pseudocode and criteria . Txt File below input.txt file data 05 11/30/16 03 12/07/16 05 12/07/16 05 12/08/16 01 12/10/16 07 12/11/16 07 12/14/16 06 12/15/16 02 12/21/16 05 12/21/16 06 12/22/16 07 12/22/16 08 12/23/16 07 12/23/16 07 12/23/16 07 12/23/16 08 12/24/16 08 12/24/16 07 12/24/16 03 12/26/16 05 12/26/16 07 12/28/16 04 12/29/16 07 01/01/17 06 01/03/17 07 01/03/17 08 01/05/17 05 01/10/17 04 01/17/17 08 01/17/17 07 01/18/17 07...

  • In Java language: Write a rainfall class that stores the total rainfall for each of 12...

    In Java language: Write a rainfall class that stores the total rainfall for each of 12 months of years 2015 -2017 into an 2D array of doubles. Use the text file at Actividades/Tareas link as input of rainfall data. The program should read the input data from a text file. The program should have methods that at least return the following: • Total rainfall for the years 2015 – 2017 - return a 1D array • The average monthly rainfall...

  • 'Student Pair' 'Standard Teaching Method' 'New Teaching Method' 1 51 67 2 72 90 3 85...

    'Student Pair' 'Standard Teaching Method' 'New Teaching Method' 1 51 67 2 72 90 3 85 82 4 51 63 5 73 76 6 72 73 7 65 78 8 72 94 9 72 85 10 95 100 11 70 80 12 60 72 13 57 100 14 48 58 15 74 89 16 63 97 17 82 88 18 57 45 19 87 81 20 65 99 21 48 69 22 97 70 23 61 47 24 83 73...

  • Using FLA arrays For this exercise, I want you to read 20 integer numbers from a...

    Using FLA arrays For this exercise, I want you to read 20 integer numbers from a given data file and average them. You must use an array and 2 functions. The first function will load an array with the data from the input file. The second function will average the data in the file. FILE* and the naming and location (path) of the text file for input. The mode of the user defined file stream. The function declaration. Ensure you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT