Question: 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

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 temperatures for the year. Your program must consist of the following functions:

  • Part a: Function getData: This function reads and stores data in the two- dimensional array.
  • Part b: Function averageHigh: This function calculates and returns the aver- age high temperature for the year.
  • Part c: Function averageLow: This function calculates and returns the average low temperature for the year.
  • Part d: Function indexHighTemp: This function returns the index of the highest high temperature in the array.
  • Part e: Function indexLowTemp: This function returns the index of the lowest low temperature in the array.

(These functions must all have the appropriate parameters.)

 

And this is the structure I have to follow

#include

 

using namespace std;

 

const int NO_OF_MONTHS = 12;

 

void getData(int twoDim[][2], int rows);

int averageHigh(int twoDim[][2], int rows);

int averageLow(int twoDim[][2], int rows);

int indexHighTemp(int twoDim[][2], int rows);

int indexLowTemp(int twoDim[][2], int rows);

 

int main()

{

   // declare 2D array hiLowArray

 

    int indexHigh;

    int indexLow;

 

   getData(hiLowArray, NO_OF_MONTHS);

 

   cout << "Average high temperature: "

        << averageHigh(hiLowArray, NO_OF_MONTHS) << endl;

   cout << "Average low temperature: "

        << averageLow(hiLowArray, NO_OF_MONTHS) << endl;

 

   indexHigh = indexHighTemp(hiLowArray, NO_OF_MONTHS);

   cout << "Highest temperature: " << hiLowArray[indexHigh][0] << endl;

 

   indexLow = indexLowTemp(hiLowArray, NO_OF_MONTHS);

   cout << "Lowest temperature: " << hiLowArray[indexLow][1] << endl;

 

    return 0;

}

 

// part a

void getData(int twoDim[][2], int rows)

{

    // function code

}

 

// part b

int averageHigh(int twoDim[][2], int rows)

{

    // function code

}

 

// part c

int averageLow(int twoDim[][2], int rows)

{

    // function code

}

 

// part d

int indexHighTemp(int twoDim[][2], int rows)

{

    // function code

}

 

// part e

int indexLowTemp(int twoDim[][2], int rows)

{

    // function code

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!