Question

In: Computer Science

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 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.

Sample output:

Please enter the name of the temperature data file: tempAugData.txt Please enter the boundary temperature: 68.0

Climate Data statistics: Average temperature: 66.2

Years that averaged at least 68.0 degrees: 7 1936 1995 2003 2007 2010 2011 2016

Maximum average temperature: 68.9 occurred in 2007

Minimum average temperature: 63.9 occurred in 1927

Additional Requirements:

• Your program must compile and run, otherwise you will receive a 0.

• Your program should test for file open errors.

• I recommend temporarily echoing the input from the file to the screen (using cout) to be sure you are reading the input correctly into your array.

• You should have many separate loops in your program. Do not try to compute everything in one single loop.

• For partial credit, implement some subset of the features completely. This will probably lead to a better score than implementing every feature poorly

USING ARRAYS.

Solutions

Expert Solution

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++;
}
//output
printf("Average monthly average temperature: %.1f\n",(total/temps.size()));
printf("Number of years with monthly average temperature above %.1f: %d,",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;
if(temps[i]>=x)
printf("%d ",1901+i);
}
//output
printf("\n");
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:

'


Related Solutions

Part 1 Lottery Statistics Create a program that will compute some statistics on winning lottery numbers....
Part 1 Lottery Statistics Create a program that will compute some statistics on winning lottery numbers. Download a .csv file from Winning Powerball Numbers containing a record of past winning numbers. Examine the formatting of this file. Create a dictionary that contains each winning number and the number of times that number was drawn. Print the 10 most frequently drawn numbers, and the 10 least frequently drawn numbers. HINT: You can’t sort a dictionary. Build a list that is ordered...
Write a C++ program that takes in a set of daily average temperatures (up to a...
Write a C++ program that takes in a set of daily average temperatures (up to a maximum of 30): 1.Ask the user for a temperature 2.If the user enters a -1 then stop asking for temperatures. 3. After the user is done entering temperatures: a. Print out the temperatures entered. b. print out the average, high and low temperatures. To get average, use: average = (sum of temps) divided by (count of temps) to get max or min, either keep...
The data below are the average monthly temperatures, in °F, and the monthly natural gas consumption,...
The data below are the average monthly temperatures, in °F, and the monthly natural gas consumption, in ccf, for a household in northwestern Pennsylvania. a.)Test the significance of the correlation coefficient using α = 0.05 and the claim ρ < 0. Identify the claim, state the null and alternative hypotheses, find the critical value, find the standardized test statistic, make a decision on the null hypothesis (you may use a P-Value instead of the standardized test statistic), write an interpretation...
For this C++ program, Write and modify the code to compute and display the class average...
For this C++ program, Write and modify the code to compute and display the class average as well as the standard deviation. Your code changes are as follows: 1. The variable “double grade” should be replaced by a two-dimensional array variable “double grade[NUMSTUDENTS][NUMGRADES].” Also replace the variable “double average” by “double average[NUMSTUDENTS].” This is necessary since you need to save the entered grades specially to compute the standard deviations. 2. After completing the display of the average grade of all...
Write a program to compute the total time and average speed it will take a runner...
Write a program to compute the total time and average speed it will take a runner to run 10 miles with the following pace segments: they run the first mile at a pace of 7 minutes per mile, the following 4 miles at a pace of 8.5 minutes per mile, the next 4 miles at a pace of 9 minutes per mile and the last mile at a pace of 3.5 minutes per mile. Performs the computations and prints the...
Write a program to compute answers to some basic geometry formulas. The program prompts the user...
Write a program to compute answers to some basic geometry formulas. The program prompts the user to input a length (in centimeters) specified as a floating point value. The program then echoes the input and computes areas of squares and circles and the volume of a cube. For the squares, you will assume that the input length value is the length of a side. For the circles, this same value becomes the diameter. Use the meter value input to calculate...
Write a Java program to compute the income after tax of an employee based on the...
Write a Java program to compute the income after tax of an employee based on the following rule of tax rate. Assuming the salary is $22000, display the tax and the income after tax. 12% if salary ≥ 25,000 5% if salary < 10,000 Otherwise 8% will be applied Write a Java program to compute and display the sum of the numbers that can be both divisible by 6 and 8 from 1 to 500. Suppose there is a list...
Suppose you are writing a program to compute the semester GPA for a person based on...
Suppose you are writing a program to compute the semester GPA for a person based on knowing the grades earned and the number of credit hours for each course taken. What type of tests would you need to create to check that your program was working correctly? Be specific, and remember to keep in mind tests that might contain unexpected input. How would your program react to those? After you have made your post, you need to provide thoughtful comments...
You are required to write a program to provide the statistics of a file (Number of...
You are required to write a program to provide the statistics of a file (Number of letters, number of words, number of vowels, number of special characters and number of digits. You should implement this problem as a class and call it FileContentStats which provides statistics about the number of letters, number of words, number of vowels, number of special characters, number of lines and number of digits. All of these should be private data members. (Should be in C++...
Q#3 Write a C++ program to read 10 temperatures in Celsius and to store the temperatures...
Q#3 Write a C++ program to read 10 temperatures in Celsius and to store the temperatures in an array of integers, then it should convert the temperatures to Fahrenheit and store the new values rounded to the nearest integer in another array . The program should display both temperatures in a table form.    F = 9/5 x C + 32 where F is temp in Fahrenheit and C temperature in Celsius
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT