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

I forgot to add the additional requirements to my question for the last expert t

ID: 674852 • Letter: I

Question

I forgot to add the additional requirements to my question for the last expert that helped me. Here they are:

using three arrays to store the temperatures, one for June, one for July, and one for August. 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(s). Don’t forget to skip the first line in the file.

/**C++ program that reads a text file called "tempdata.txt" . The text file contains the date and maximum temperture recorded for three months june=6,july=7 and august=8
The program outputs the average daily high temperture, number of days over 100 degree recored in each month,
the maximum temperature recored in every month.
*/
#include<iostream>
#include<iomanip>
#include<string>
#include<climits>
#include<fstream>
using namespace std;
int main()
{
double totalTemp = 0;
int dailyTemp;
int maxTemp = INT_MIN;
  


int juneHighTemp = INT_MIN;
int maxdayOfJune = 0;
int julyHighTemp = INT_MIN;
int maxdayOfJuly = 0;
int augustHighTemp = INT_MIN;
int maxdayOfAugust = 0;
int daysInJuneOver100 = 0;
int dayofMaxInJune = 0;
int daysInJulyOver100 = 0;
int dayofMaxInJuly = 0;
int daysInAugustOver100 = 0;
int dayofMaxInAugust = 0;

int countOf100days=0;

string line;
ifstream inFile;
inFile.open("tempdata.txt");


//check if file exist
if(!inFile)
{
cout<<"File does not exist . "<<endl;
system("pause");
exit(0);
}


getline(inFile,line);

char slash;
int month;
int day;
int year;

int maxTempDayInMonth=0;

  

//Read date and temperture for 3 months
for(int m = 6; m <=8; m++)
{

//read month,day and month and daily high temperature for 30 days in each month
for(int dayCount = 1; inFile >> month >> slash >> day >> slash >> year >> dailyTemp && dayCount <= 30; dayCount++)
{
if(dailyTemp > maxTemp)
{
maxTemp = dailyTemp;
maxTempDayInMonth = day;
}
if(dailyTemp >= 100)
countOf100days++;

totalTemp += dailyTemp;

}

//set hightemp, days over 100 degree temperature, max temperture in the month
//reset the countOf100days, maxTemp and maxTempDayInMonth
//for june month
if(m==6)
{
juneHighTemp = maxTemp;
daysInJuneOver100 = countOf100days;
maxdayOfJune = maxTempDayInMonth;
countOf100days = 0;
maxTemp = INT_MIN;
maxTempDayInMonth = INT_MIN;
}
//set hightemp, days over 100 degree temperature, max temperture in the month
//reset the countOf100days, maxTemp and maxTempDayInMonth
//for july month=7
if(m==7)
{
julyHighTemp = maxTemp;
daysInJulyOver100 = countOf100days;
maxdayOfJuly = maxTempDayInMonth;
countOf100days = 0;
maxTemp = INT_MIN;
maxTempDayInMonth = INT_MIN;
}
//set hightemp, days over 100 degree temperature, max temperture in the month
//reset the countOf100days, maxTemp and maxTempDayInMonth
//for august=8
if(m==8)
{
augustHighTemp = maxTemp;
daysInAugustOver100 = countOf100days;
maxdayOfAugust = maxTempDayInMonth;
countOf100days = 0;
maxTemp = INT_MIN;
maxTempDayInMonth = INT_MIN;
}
}

cout << "High temperature statistics for the summer:" << endl << endl;
  

cout << "Average daily high temperature: " << setprecision(1) << fixed << totalTemp/90 << endl << endl;


cout << "Number of days over 100 in June: " << daysInJuneOver100 << endl << endl;
cout << "Number of days over 100 in July: " << daysInJulyOver100 << endl<< endl;
cout << "Number of days over 100 in August: " << daysInAugustOver100 << endl << endl;


cout << "Maximum temperature for June :" << juneHighTemp << " occurred on June " << maxdayOfJune << endl << endl;
cout << "Maximum temperature for July :" << julyHighTemp << " occurred on July " << maxdayOfJuly << endl << endl;
cout << "Maximum temperature for August:" << augustHighTemp << " occurred on August " << maxdayOfAugust << endl << endl;


//close the input file object
inFile.close();
system("pause");
return 0;

}

Explanation / Answer

#include<iostream>
#include<iomanip>
#include<string>
#include<climits>
#include<fstream>
using namespace std;
int main()
{
double totalTemp = 0;
int dailyTemp;
int maxTemp = INT_MIN;
  


int juneHighTemp = INT_MIN;
int maxdayOfJune = 0;
int julyHighTemp = INT_MIN;
int maxdayOfJuly = 0;
int augustHighTemp = INT_MIN;
int maxdayOfAugust = 0;
int daysInJuneOver100 = 0;
int dayofMaxInJune = 0;
int daysInJulyOver100 = 0;
int dayofMaxInJuly = 0;
int daysInAugustOver100 = 0;
int dayofMaxInAugust = 0;

int countOf100days=0;

string line;
ifstream inFile;
inFile.open("tempdata.txt");


//check if file exist
if(!inFile)
{
cout<<"File does not exist . "<<endl;
system("pause");
exit(0);
}


getline(inFile,line);

char slash;
int month;
int day;
int year;

int maxTempDayInMonth=0;

  

//Read date and temperture for 3 months
for(int m = 6; m <=8; m++)
{

//read month,day and month and daily high temperature for 30 days in each month
for(int dayCount = 1; inFile >> month >> slash >> day >> slash >> year >> dailyTemp && dayCount <= 30; dayCount++)
{
if(dailyTemp > maxTemp)
{
maxTemp = dailyTemp;
maxTempDayInMonth = day;
}
if(dailyTemp >= 100)
countOf100days++;

totalTemp += dailyTemp;

}

//set hightemp, days over 100 degree temperature, max temperture in the month
//reset the countOf100days, maxTemp and maxTempDayInMonth
//for june month
if(m==6)
{
juneHighTemp = maxTemp;
daysInJuneOver100 = countOf100days;
maxdayOfJune = maxTempDayInMonth;
countOf100days = 0;
maxTemp = INT_MIN;
maxTempDayInMonth = INT_MIN;
}
//set hightemp, days over 100 degree temperature, max temperture in the month
//reset the countOf100days, maxTemp and maxTempDayInMonth
//for july month=7
if(m==7)
{
julyHighTemp = maxTemp;
daysInJulyOver100 = countOf100days;
maxdayOfJuly = maxTempDayInMonth;
countOf100days = 0;
maxTemp = INT_MIN;
maxTempDayInMonth = INT_MIN;
}
//set hightemp, days over 100 degree temperature, max temperture in the month
//reset the countOf100days, maxTemp and maxTempDayInMonth
//for august=8
if(m==8)
{
augustHighTemp = maxTemp;
daysInAugustOver100 = countOf100days;
maxdayOfAugust = maxTempDayInMonth;
countOf100days = 0;
maxTemp = INT_MIN;
maxTempDayInMonth = INT_MIN;
}
}

cout << "High temperature statistics for the summer:" << endl << endl;
  

cout << "Average daily high temperature: " << setprecision(1) << fixed << totalTemp/90 << endl << endl;


cout << "Number of days over 100 in June: " << daysInJuneOver100 << endl << endl;
cout << "Number of days over 100 in July: " << daysInJulyOver100 << endl<< endl;
cout << "Number of days over 100 in August: " << daysInAugustOver100 << endl << endl;


cout << "Maximum temperature for June :" << juneHighTemp << " occurred on June " << maxdayOfJune << endl << endl;
cout << "Maximum temperature for July :" << julyHighTemp << " occurred on July " << maxdayOfJuly << endl << endl;
cout << "Maximum temperature for August:" << augustHighTemp << " occurred on August " << maxdayOfAugust << endl << endl;


//close the input file object
inFile.close();
system("pause");
return 0;

}

This code is absolutely correct