Question

Problem: You will write a program a C++ to compute some statistics based on monthly average...

Problem: You will write a program a C++ to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website.

The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for 1901, the second is for 1902, and so on through 2016.

The statistics you should compute in your program are:

• The average of the monthly average temperatures for the entire time period.

• The number of years that the monthly average reached at least X degrees where X is a value input from the user. These years should also be displayed to the screen.

• The maximum monthly average temperature for the time period and in what year it occurred.

• The minimum monthly average temperature for the time period and in what year it occurred.

Input: Your program should ask the user for the name of the file, and then open that file for input. It should then ask the user for a boundary temperature (the X in the second bullet above) that is used to calculate some of the statistics.

Processing: Compute the statistics requested above.

Output: Display the statistics, labeled, and with the temperatures formatted to 1 decimal place. Also output the count of the years above X before outputting the list of the years.

Here are the values of all the temperatures : https://userweb.cs.txstate.edu/~js236/cs1428/tempaugdata.tx

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

SOURCE CODE IN C++:

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int main()
{
string fileName;
cout << "Enter name of the file: "; //input prompt
cin >> fileName; //input
ifstream in(fileName); //opening file
if(in.is_open()==false)
{
cout << "File not found!" << endl;
return 1;
}
vector<double> temps; //to store the temperatures
double temp,total=0,x; //to input temperature, store sum of temperatures and store user input temperature
int count=0; //to store number of years with temperature above x
cout << "Enter the value of x: "; //input prompt
cin >> x; //input
while(in >> temp) //while there is still value in the file, we read it into temp
{
temps.push_back(temp);
total+=temp;
if(temp>=x)
count++;
}
//finding maximum and minimum temperature years
int minY=0,maxY=0;
for(int i=1;i<temps.size();i++)
{
if(temps[i]>temps[maxY])
maxY=i;
if(temps[i]<temps[minY])
minY=i;
}
//output
printf("Average monthly average temperature: %.1f\n",(total/temps.size()));
printf("Number of years with monthly average temperature above %.1f: %d\n",x,count);
printf("Maximum temperature was %.1f in the year %d\n",temps[maxY],1901+maxY);
printf("Minimum temperature was %.1f in the year %d\n",temps[minY],1901+minY);
return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Problem: You will write a program a C++ to compute some statistics based on monthly average...
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
  • Problem: You will write a program to compute some statistics based on monthly average temperatures for...

    Problem: You will write a program to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for 1901, the...

  • Write the program in C The following statistics for cities of the Vege country are stored...

    Write the program in C The following statistics for cities of the Vege country are stored in a file: Name: a string of characters less than 15 characters long. Population: an integer value. Area: square miles of type double Write a program that: asks and gets the name of the input file from the user. Read the contents of the file into an array length 10 of structures -ask the user for the name of a city (less than 15...

  • Problem: A local amateur meteorologist has been recording daily high temperatures throughout the month of June....

    Problem: A local amateur meteorologist has been recording daily high temperatures throughout the month of June. He would like you to write a program to compute some statistics based on the data he has collected. He has placed each daily high temperature on a separate line in a file named “summer_temps.txt”. The high temperatures are in order so that the first one is for June 1, the second is for June 2, and so on. The statistics that the meteorologist...

  • Write a program that would ask the user to enter an input file name, and an...

    Write a program that would ask the user to enter an input file name, and an output file name. Then the program reads the content of the input file, and read the data in each line as a number (double). These numbers represent the temperatures degrees in Fahrenheit for each day. The program should convert the temperature degrees to Celsius and then writes the numbers to the output file, with the number of day added to the beginning of the...

  • Write a program called problem4.cpp that creates a histogram of the temperature values over the past...

    Write a program called problem4.cpp that creates a histogram of the temperature values over the past year. The temperature values ranges from 0 to 25 degrees, and the program should ask the use to input the number of days in the past year where the temperature was of each of these values. After the user inputs this data, the program should draw a histogram of these temperatures using the char ‘*’ and output the mode temperature (the temperature that occurred...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • INTRODUCTION You are working on development of a new power plant for Centerville, USA. Average monthly...

    INTRODUCTION You are working on development of a new power plant for Centerville, USA. Average monthly temperature data has been collected as part of designing the new power plant, and you are required to develop a computer program that will perform averaging analysis. The input data file is called temp. As you examine the input file, you notice that the first record line is the name of the city and type of data, the second record line contains the control...

  • Write a C program to compute average grades for a course. The course records are in...

    Write a C program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student’s first name, then one space, then the student’s last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program...

  • Due: in class Tuesday, 3/27/2018 (upload electronic copy by 9:00am) Problem: You will write a program...

    Due: in class Tuesday, 3/27/2018 (upload electronic copy by 9:00am) Problem: You will write a program to compute some statistics about boxes of a popular breakfast cereal called "Chocolate Frosted Sugar Bombs" manufactured by the General Junkfoods Corporation. Automated machinery is used at the company's factory to fill individual boxes with cereal. No machine is perfect, so the amount of cereal actually in a box will vary slightly from box to box. The data file CFSB.txt on the class website...

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