Write a program that use a twodimensional array to store the


Write a program that use a two-dimensional array to store the highest and lowest temperatures for each month of the year (12 by 2). The program should output the average high, average low, and highest and lowest temperature of the year. Your program must contain of the following methods. Method gel Data This method reads and stores the duo in the two- array Method average High: This method calculates and returns the average high temperature of the year. Method averageLow This method calculates and returns the average low temperatures of the year. Method indexHighTemp: This method returns of index of the highest temperatures In the array. Method indexLowTemp: This method returns the index of the lowest temperature of the year.

Solution

#include <iostream>
using namespace std;

void getData(double temp[12][2]) //get mimimum and maximum temperature for 12 months
{
   int i,j;
   cout<<\"\ Enter the minimum and maximum temperature for 12 months\";
   for(i=0;i<12;i++)
   for(j=0;j<2;j++)
   cin>>temp[i][j];
  
}
void averageHigh(double temp[12][2]) // calculate avergae high for 12 months
{
   int i ,j;
   j=1;
   double avgHigh=0;
   for(i=0;i<12;i++)
   avgHigh =avgHigh + temp[i][j];
  
   cout<<\"\ Average High Temperature :\"<<avgHigh/10;
  
  
}
void averageLow(double temp[12][2]) // calculate average low for 12 months
{
   int i ,j;
   j=0;
   double avgLow=0;
   for(i=0;i<12;i++)
   avgLow =avgLow + temp[i][j];
  
   cout<<\"\ Average Low Temperature :\"<<avgLow/10;
  
}
void indexHighTemp(double temp[12][2]) //find the month for highestest temperature
{
   double highTemp=0;
   int month,i,j=1;
    for(i=0;i<12;i++)
{
   if(temp[i][j] > highTemp)
   {
   highTemp =temp[i][j];
   month =i;
   }
}
   cout<<\"\ The highest Temperature in the year is \"<<highTemp<< \" degrees celcius in month \"<<month+1;
}
void indexLowTemp(double temp[12][2]) //find the month for low temperature
{
   double lowTemp=99;
   int month,i,j=0;
    for(i=0;i<12;i++)
{
   if(temp[i][j] < lowTemp)
   {
   lowTemp =temp[i][j];
   month =i;
   }
}
   cout<<\"\ The lowest Temperature in the year is \"<<lowTemp<<\" degrees celcius in month \"<<month+1;
}
int main()
{
   double temp[12][2];
  
   getData(temp);
  
   averageHigh(temp);
  
   averageLow(temp);
  
   indexHighTemp(temp);
  
   indexLowTemp(temp);
   return 0;
}

output:

Success time: 0 memory: 3472 signal:0

 Write a program that use a two-dimensional array to store the highest and lowest temperatures for each month of the year (12 by 2). The program should output t
 Write a program that use a two-dimensional array to store the highest and lowest temperatures for each month of the year (12 by 2). The program should output t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site