Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each
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 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
}
Microsoft Visual C# An Introduction to Object-Oriented Programming
ISBN: 978-1337102100
7th edition
Authors: Joyce Farrell