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

I need help cleaning up my program. Myinstructor says I am on the right track bu

ID: 3614856 • Letter: I

Question

I need help cleaning up my program. Myinstructor says I am on the right track but need to clean theprogram up a little…I’m not too sure what that meansbut if anyone can help me I will rate lifesaver.

Program assignment:

Write a program that uses a two-dimensional arrayto store the highest and lowest temperatures for each month of theyear. The program should output the average high, average low andthe highest and lowest temp for the year. Program must consist ofthe following functions:

a.       Function getData: This function reads and stores data in thetwo-dimensional array.

b.       FunctionaverageHigh: This function calculates and returns the average hightemp for the year.

c.       Function average low: This function calculates and returns theaverage low temp for the year.

d.       FunctionindexHighTemp: This function returns the index of the highest hightemp in the array.

e.       FunctionindexLowTemp: This function returns the index of the lowest lowtemp in the array.

//Program that uses atwo-dimesional arrayto store highest and lowest temp.
//for each month of the year. Program outputs avg high, avg low,highest and
// lowest temp for year.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;

void getData(int array[12][2], ifstream& infile);
double averageHigh (int array [12][2]);
double averageLow (int array [12][2]);
int indexHighTemp (int array [12][2], ofstream& outfile);
int indexLowTemp (int array [12][2], ofstream&outfile);

int main()
{
    int HighLowarray [12][2];
    int highTemperature;
    int lowTemperature;
   
    ifstream infile;
    ofstream outfile;
   
    infile.open("E:\Prog6inputTemp.txt");
    outfile.open("E:\Program6ouputTemp.txt");
    outfile << "Daniel" <<endl;
   outfile<<fixed<<showpoint<<setprecision(2);
   
    getData(HighLowarray, infile);
    averageHigh(HighLowarray);
   
    outfile << setw(30) << left <<"Average High Temperture is:" <<
    averageHigh (HighLowarray)<<endl;
    averageLow (HighLowarray);
   
    outfile << setw(30) << left <<"Average Low Temperture is:"<<
    averageLow (HighLowarray)<<endl;
   
    highTemperature = indexHighTemp (HighLowarray,outfile);
    lowTemperature = indexLowTemp (HighLowarray,outfile);
   
    outfile << setw(30) << left <<"Highest Temperature is:";
    outfile << highTemperature <<endl;
   
    outfile << setw(30) << left <<"Lowest Temperature is:";
    outfile << lowTemperature <<endl;
   
infile.close();
outfile.close();
system("pause");
}

void getData (intHighLowarray[12][2], ifstream& infile)
{
    int row, col;
    for(row=0; row<12; row++)
    {
    for(col=0; col<2; col++)
    {
    infile >> HighLowarray[row][col];
    }
    }
}
double averageHigh (int HighLowarray [12][2])
{
   double avg;
   double sum;
   int row, col;
   avg = 0;
   sum = 0;
      
   for (row = 0; row<12; row++)
   {
   for (col = 1; col<2; col++)
   {
   sum = sum + HighLowarray[row][col];
   }
   }
   avg = sum / row;
   return avg;
}
double averageLow (int HighLowarray[12][2])
{
   double avgerage;
   double sum1;
   int row, col;
   avgerage=0;
   sum1=0;
      
   for (row=0; row<12; row++)
   {
   for (col=0; col<1; col++)
   {
   sum1 = sum1 + HighLowarray[row][col];
   }
   }
   avgerage = sum1 /row;
return avgerage;
}
int indexHighTemp (int HighLowarray[12][2], ofstream&outfile)
{
    int highest;
    int row,col;
    int rowindex;
    int colindex;
    highest = HighLowarray[0][1];
   
    for (row=1; row<12; row++)
   {
    for (col=1; col<2; col++)
   {
    if (highest < HighLowarray[row][col])
   {
    highest =HighLowarray[row][col];
    rowindex=row;
    colindex=col;
   }
    else
    highest=highest;
   }
}

outfile << setw(30) << left << "High Temp Indexis:"<< "[" << rowindex << ","<<
colindex<< "]" << endl;
return highest;
}
int indexLowTemp (int HighLowarray[12][2], ofstream&outfile)         
{
    int lowest, row, col;
    int rowindex;
    int colindex;
    lowest = HighLowarray[0][0];
   
    for (row=1; row<12; row++)
{
    for (col=0; col<1; col++)
{
    if (lowest > HighLowarray[row][col])
{
    lowest = HighLowarray[row][col];
    rowindex = row;
    colindex = col;
    }
    else
    lowest = lowest;
    }   
}
outfile << setw(30) << left << "Low TemperatureIndex is:" <<
    "[" << rowindex << "," <<colindex<< "]"<< endl;
return lowest;
}

Explanation / Answer

please rate - thanks add comments //Program that uses a two-dimesional arrayto store highest andlowest temp. //for each month of the year. Program outputs avg high, avg low,highest and // lowest temp for year. #include #include #include #include using namespace std; void getData(int array [][2], ifstream& infile,int &n); double averageHigh (int array [][2],int n); double averageLow (int array [][2],int n); int indexHighTemp (int array [][2], int n, ofstream&outfile); int indexLowTemp (int array [][2], int n, ofstream&outfile); int main() {     int HighLowarray [20][2];     int highTemperature;     int lowTemperature;     int n;     ifstream infile;     ofstream outfile;      infile.open("E:\Prog6inputTemp.txt"); outfile.open("E:\Program6ouputTemp.txt");     outfile
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote