Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help with computer science in C++ . please give me detailed solution so that i c

ID: 3807639 • Letter: H

Question

help with computer science in C++ . please give me detailed solution so that i can study for this. thank you so much

Problem: A local amateur meteorologist has been recording daily high temperatures throughout a typical summer month. He would like you to write a program to compute some statistics based on the data he has collected. He has placed the name of the month and 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 the first of the month, the second is for the second day, 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 “summer_temps.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 in June: 92.6
Number of days over 100 in June: 4
Maximum temperature: 102.2 (occurred on June 20)

Notes:

The program should work for any month, not just June. (So how big does the array need to be?)

You will have at least four functions and an array. Do not do the calculations as you are reading in the data. We will write the function to read in the data in class.Note that in the function that determines the number of days over 100, that temperature should be a parameter so you could determine the number of days over any temperature (such as 90, etc.). An example call might be:

getNumDaysOver(array, numElements,90); //returns an integer with the number of days over 90

Your source program file must be named  temps_xxxxxx.cpp

where xxxxxx is your netID.

don't forget the underscore in the filename!

Appropriate values should be stored in constant variables.

Be sure to follow the documentation standards for the course.Each variable must be declared on a separate line

Use meaningful variable names

Explanation / Answer

// C++ code
#include <iostream>
#include <cmath>
#include <fstream>

using namespace std;

int MAXDAYS = 31;

string readFIle(string filename, double temperature[])
{
   string month;
   int size = 0;
   ifstream inFile (filename.c_str());
   if (inFile.is_open())
   {
       inFile >> month;
   while (true)
   {
       inFile >> temperature[size];
       size++;
       if(inFile.eof())
           break;
   }
   inFile.close();
   }

   else cout << "Unable to open file";

   MAXDAYS = size;

   return month;
}

void calculateaverage(double temperature[], string month)
{
   double average = 0;
   for (int i = 0; i < MAXDAYS; ++i)
   {
       average = average + temperature[i];
   }
   average = average/MAXDAYS;
   cout << "Average daily high temperature in "<< month << ": " << average << endl;
}

void calculatehighest(double temperature[], string month)
{
   double highest = temperature[0];
   int idx = 0;
   for (int i = 0; i < MAXDAYS; ++i)
   {
       if(temperature[i] > highest)
       {
           highest = temperature[i];
           idx = i;
       }
   }
   cout << "Maximum temperature: " << highest << " (occurred on " << month << " " << (idx+1) << " )" << endl;
}

void calculateover100(double temperature[], string month)
{
   int over100 = 0;
   for (int i = 0; i < MAXDAYS; ++i)
   {
       if(temperature[i] > 100)
           over100++;
   }
   cout << "Number of days over 100 in " << month << ": " << over100 << endl;
}

int main()
{
   double temperature[MAXDAYS];
   string month;
   string filename;
   cout <<"Enter filename: ";
   cin >> filename;

   month = readFIle(filename,temperature);
   calculateaverage(temperature, month);
   calculateover100(temperature, month);
   calculatehighest(temperature, month);

   return 0;
}

/*
summer_temps.txt
June
88.9
90.6
94.3
77.7
80.5
88.9
90.2
92.3
94.5
96.7
99.8
100.3
101.7
88.9
92.7
94.6
99.8
98.3
101.3
102.2
94.3
77.7
80.5
88.9
90.2
92.3
94.5
96.7
99.8
89.7

output:
Enter filename: summer_temps.txt
Average daily high temperature in June: 92.6267
Number of days over 100 in June: 4
Maximum temperature: 102.2 (occurred on June 20 )

*/