Question

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 would like for you to compute in your program are:

The average daily high temperature for the entire month.

The number of days over 100 for the month.

The maximum temperature for the month and on what day it occurred.

Input: All of the input will come from a file named “summerTemps.txt”. The temperatures may have fractional parts, like 99.87. Your program should also test for file open errors.

Processing: The data must be stored in an array. Compute the statistics requested above. Use a function for each task as well as a function to read in the data (we will write that in class).


Output: Display the statistics to the screen, labelled, and with the temperatures formatted to 1 decimal place.

Sample output:

Average daily high temperature: 92.6
Number of days over 100 : 4
Maximum temperature: 102.2 (occurred on June 20)

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

You will have at least four functions and an array

use C++ coding

codeBlack program

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

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

double average(double arr[], int size){
   double total = 0;
   for(int i = 0; i < size; ++i){
       total += arr[i];
   }
   return total / size;
}

int numDaysOver(double arr[], int size, int val){
   int count = 0;
   for(int i = 0; i < size; ++i){
       if(arr[i] > val)
           ++count;
   }
   return count;
}

int getMaxInd(double arr[], int size){
   int maxInd = 0;
   for(int i = 1; i < size; ++i){
       if(arr[i] > arr[maxInd]){
           maxInd = i;
       }
   }
   return maxInd;
}

int readData(string fileName, double arr[]){
   ifstream in(fileName.c_str());
   if(in.is_open()){
       double val;
       int i = 0;
       while(in >> val){
           arr[i++] = val;
       }
       return i;
       in.close();
   }
   else{
       cout << "can not open " << fileName << " to read" << endl;
       return 0;
   }
}

int main(){
   double arr[1000];
   int size = 0;
   size = readData("summerTemps.txt", arr);
   cout << "Average daily high temperature: " << average(arr, size) << endl;
   cout << "Number of days over 100 : " << numDaysOver(arr, size, 100) << endl;
   int ind = getMaxInd(arr, size);
   cout << "Maximum temperature: " << arr[ind] << " (occurred on June " << (ind + 1) << ")" << endl;
   return 0;
}

\color{blue}\underline{summerTemps.txt\;I\;used:}

93.5
94.6
97.9
92.5
92.7
94.4
100.2
101.4
99.6
98.4

C:Windows system321cmd.exe Average daily high temperature: 96.52 Number of days over 100 : 2 Maximum temperature: 101.4 〈occu

Add a comment
Know the answer?
Add Answer to:
Problem: A local amateur meteorologist has been recording daily high temperatures throughout the month of June....
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...

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

  • Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month...

    Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month and stored in a file called temperature.txt. Write a complete C Language program that reads the stored temperatures, one at a time, from the file temperature.txt and converts the read temperature to its equivalent in Celsius. Your program should store each converted temperature in an output file called results.txt. Your program should find the average, the minimum, and the maximum temperatures in Celsius and...

  • Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month...

    Assume that, for a given town, mid-day daily temperature in Fahrenheit was measured for a month and stored in a file called temperature.txt. Write a complete C language program that reads the stored temperatures, one at a time, from the file temperature.txt and converts the read temperature to its equivalent in Celsius. Your program should store each converted temperature in an output file called results.txt. Your program should also find the average, the minimum, and the maximum temperatures in Celsius...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...

  • Arrays: City temperatures The maximum daily temperatures (in "C) for Istanbul and Ankara during August 2019...

    Arrays: City temperatures The maximum daily temperatures (in "C) for Istanbul and Ankara during August 2019 are given below. Ankara: [33 30 31 32 33 35 30 29 29 28 29 30 32 32 33 32 34 31 33 30 29 30 31 33 31 30 27 26 27 26 27] Istanbul: [35 32 32 31 34 30 29 32 34 35 36 35 34 32 33 33 34 35 35 34 32 30 30 29 28 31 32 30...

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

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

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