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

Program assignment: Write a program that uses a two-dimensional array to store t

ID: 3614844 • Letter: P

Question

Program assignment:

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 temp for the year. Program must consist of the following functions:

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

b.       Function averageHigh: This function calculates and returns the average high temp for the year.

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

d.       Function indexHighTemp: This function returns the index of the highest high temp in the array.

e.       Function indexLowTemp: This function returns the index of the lowest low temp in the array.

(These functions must all have the appropriate parameters)

Program:

#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 array [12][2];

    int high;

    int low;

   

    ifstream infile;

    ofstream outfile;

   

    infile.open("E:\program6input.txt");

    outfile.open("E:\program6ouput.txt");

    outfile << "Daniel" <<endl;

    outfile<<endl;

    outfile<<fixed<<showpoint<<setprecision(2);

   

    getData(array, infile);

   

    averageHigh(array);

   

    outfile << setw(18) << left << "Average High Temp:" << averageHigh (array)<<endl;

   

    averageLow (array);

   

    outfile << setw(18) << left << "Average Low Temp:"<<averageLow (array)<<endl;

   

    high = indexHighTemp (array, outfile);

    low = indexLowTemp (array, outfile);

   

    outfile << setw(18) << left << "Highest Temp:";

    outfile << high << endl;

   

    outfile << setw(18) << left << "Lowest Temp:";

    outfile << low << endl;

   

infile.close();

outfile.close();

system("pause");

}

void getData (int array[12][2], ifstream& infile)

{

             int x;

             int y;

             for(x=0; x<12; x++)

    {

            for(y=0; y<12; y++)

      {

            infile >> array[x][y];

      }

    }

}

double averageHigh (int array [12][2])

{

       double avg;

       double sum;

       int x;

       int y;

       avg = 0;

       sum = 0;

      

       for (x = 0; x<12; x++)

   {

        for (y = 0; y<12; y++)

   {

        sum = sum + array[x][y];

   }

   }

        avg = sum / x;

        return avg;

}

double averageLow (int array[12][2])

{

       double avg2;

       double sum2;

       int x;

       int y;

       avg2=0;

       sum2=0;

      

       for (x=0; x<12; x++)

    {

 

Explanation / Answer



v oid getData (intarray[12][2], ifstream& infile)
{
   int x;
   int y;
   for(x=0;x<12; x++)
   {
   for(y=0;y<2; y++)
   {
   infile >>array[x][y];
   }
   }
}
double averageHigh (int array [12][2])
{
   double avg;
   double sum;
   int x;
   int y;
   avg = 0;
   sum = 0;
     
   for (x = 0; x<12; x++)
   {
  
   {
   sum = sum +array[x][0];
   }
   }
   avg = sum / x;
   return avg;
}
double averageLow (int array[12][2])
{
   double avg2;
   double sum2;
   int x;
   int y;
   avg2=0;
   sum2=0;
     
   for (x=0; x<12; x++)
   {

   {
   sum2 = sum2 + array[x][1];
   }
}
   avg2 = sum2 /x;
   return avg2;
}
int indexHighTemp (int array[12][2], ofstream&outfile) {
   int highest;    int x;    int y;    int xx;    int yy;    highest = array[0][0];
  
   for (x=0; x<12; x++)
{
   for (y=0; y<2; y++)
{
   if (highest < array[x][y])
   {
   highest =array[x][y];    xx=x;    yy=y;
   }    }
}
outfile << setw(18) << left << "HighTemp Index:"<< "[" << xx << ","<<yy<< "]" << endl;
return highest;
}
int indexLowTemp (int array[12][2], ofstream& outfile)
{
   int lowest;
   int x;
   int y;
   int xx;
   int yy;
   lowest = array[0][0];
  
   for (x=0; x<12; x++)
{
   for (y=0; y<2; y++)
   {
   if (lowest > array[x][y])
   {
   lowest = array[x][y];
   xx = x;
   yy = y;
   }
   }
}
v oid getData (intarray[12][2], ifstream& infile) oid getData (intarray[12][2], ifstream& infile) oid getData (intarray[12][2], ifstream& infile)
{
   int x;
   int y;
   for(x=0;x<12; x++)
   {
   for(y=0;y<2; y++)
   {
   infile >>array[x][y];
   }
   }
}
double averageHigh (int array [12][2])
{
   double avg;
   double sum;
   int x;
   int y;
   avg = 0;
   sum = 0;
     
   for (x = 0; x<12; x++)
   {
  
   {
   sum = sum +array[x][0];
   }
   }
   avg = sum / x;
   return avg;
}
double averageLow (int array[12][2])
{
   double avg2;
   double sum2;
   int x;
   int y;
   avg2=0;
   sum2=0;
     
   for (x=0; x<12; x++)
   {

   {
   sum2 = sum2 + array[x][1];
   }
}
   avg2 = sum2 /x;
   return avg2;
}
int indexHighTemp (int array[12][2], ofstream&outfile) {
   int highest;    int x;    int y;    int xx;    int yy;    highest = array[0][0];
  
   for (x=0; x<12; x++)
{
   for (y=0; y<2; y++)
{
   if (highest < array[x][y])
   {
   highest =array[x][y];    xx=x;    yy=y;
   }    }
}
outfile << setw(18) << left << "HighTemp Index:"<< "[" << xx << ","<<yy<< "]" << endl;
return highest;
}
int indexLowTemp (int array[12][2], ofstream& outfile)
{
   int lowest;
   int x;
   int y;
   int xx;
   int yy;
   lowest = array[0][0];
  
   for (x=0; x<12; x++)
{
   for (y=0; y<2; y++)
   {
   if (lowest > array[x][y])
   {
   lowest = array[x][y];
   xx = x;
   yy = y;
   }
   }
}
{
   int x;
   int y;
   for(x=0;x<12; x++)
   {
   for(y=0;y<2; y++)
   {
   infile >>array[x][y];
   }
   }
}
double averageHigh (int array [12][2])
{
   double avg;
   double sum;
   int x;
   int y;
   avg = 0;
   sum = 0;
     
   for (x = 0; x<12; x++)
   {
  
   {
   sum = sum +array[x][0];
   }
   }
   avg = sum / x;
   return avg;
}
double averageLow (int array[12][2])
{
   double avg2;
   double sum2;
   int x;
   int y;
   avg2=0;
   sum2=0;
     
   for (x=0; x<12; x++)
   {

   {
   sum2 = sum2 + array[x][1];
   }
}
   avg2 = sum2 /x;
   return avg2;
}
int indexHighTemp (int array[12][2], ofstream&outfile) {
   int highest;    int x;    int y;    int xx;    int yy;    highest = array[0][0];
  
   for (x=0; x<12; x++)
{
   for (y=0; y<2; y++)
{
   if (highest < array[x][y])
   {
   highest =array[x][y];    xx=x;    yy=y;
   }    }
}
outfile << setw(18) << left << "HighTemp Index:"<< "[" << xx << ","<<yy<< "]" << endl;
return highest;
}
int indexLowTemp (int array[12][2], ofstream& outfile)
{
   int lowest;
   int x;
   int y;
   int xx;
   int yy;
   lowest = array[0][0];
  
   for (x=0; x<12; x++)
{
   for (y=0; y<2; y++)
   {
   if (lowest > array[x][y])
   {
   lowest = array[x][y];
   xx = x;
   yy = y;
   }
   }
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote