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

Specifications: Write a C++ program that uses a two dimensional array to store t

ID: 3775472 • Letter: S

Question

Specifications: Write a C++ 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, highest and lowest temperatures of the year. Your program must consist of the following functions: Function getData: this function reads and stores data m the two-dimensional array. Function averageHigh: this function calculates and returns the average high temperature of the year. Function averageLow: this function calculates and returns the average low temperature of the year. Function HighTemp: this function returns the highest high temperature in the array. Function: lowTemp: this function returns the lowest low temperature in the array. These functions must all have the appropriate parameters (No global variables). Turn in a printout of your source code and upload a copy of your source code to Sakai (Assignments: Program-4). Name your source file prog4.cpp.

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;

void getData(int temp[2][12])
{
   int flg=0;
   cout<<"Enter 2D Array ";//Accept array
   for (int i = 0; i < 12; ++i)
   {

       for (int j = 0; j < 2; ++j)
       {
          
           cin>>temp[i][j];
          
          
       }
   }
}

int averageHigh(int temp[2][12])
{
   int sum=0;//find sum
  

       for (int j = 0; j < 12; ++j)
       {
      
           sum+=temp[j][0];
          
       }
       int avg=sum/12;

       return avg;
  
}


int HighTemp(int temp[2][12])
{
   int high=INT_MIN;//find high temp
  
  
       for (int j = 0; j < 12; ++j)
       {
      
           if(high<temp[j][0])//change current high
               high=temp[j][0];
          
       }
      

       return high;
  
}

int averageLow(int temp[2][12])//find average lw
{
   int sum=0;
  

       for (int j = 0; j < 12; ++j)
       {
      
           sum+=temp[j][1];//add all low temp
          
       }
       int avg=sum/12;//avearge of all low temp

       return avg;
  
}


int LowTemp(int temp[2][12])
{
   int low=INT_MAX;
  
  
       for (int j = 0; j < 12; ++j)
       {
      
           if(low>temp[j][1])//change current low
               low=temp[j][1];
          
       }

          

       return low;//return lowest temp
  
}
int main()
{
int temp[2][12];

getData(temp);

cout<<"Average High Temp is "<<averageHigh(temp)<<endl;
cout<<"Average Low Temp is "<<averageLow(temp)<<endl;
cout<<"High Temp is "<<HighTemp(temp)<<endl;
cout<<"Low Temp is "<<LowTemp(temp)<<endl;
}

==================================================================

akshay@akshay-Inspiron-3537:~/Chegg$ g++ month.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Enter 2D Array
1 2
2 4
3 6
4 8
5 10
6 12
7 14
8 16
9 18
10 20
11 22
12 24
Average High Temp is 6
Average Low Temp is 13
High Temp is 12
Low Temp is 2

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