CECS 282
LAB ASSIGNMENT #2
Assigned date: 2/2
Due date: 2/9
20 points
Before doing this lab assignment, you need to do the following activities:
Problem 1 - [10 points]
The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (rainfall 20% higher than average) dry (rainfall 25% lower than average). or average. The data file for monthly rain fall is called rainfall.txt.
Output
The year's average monthly rainfall was 139 mm.
September has the highest rainfall (190 mm).
January has the lowes rainfall (95 mm)
Month Rainfall(mm) Classification
------- --------------- --------------
1 95 Dry
2 100 Dry
3 120 Average
4 130 Average
5 135 Average
6 145 Average
7 155 Average
8 185 Rainy
9 190 Rainy
10 160 Average
11 130 Average
12 120 Average
Program Requirements:
Implement the following functions in the program:
Hint:
Read data from a file.
GRADING
Problem 2 - [10 points]
Write a program that create a two-dimensional array initialized with test data. The program should have the following functions:
Use the main method below to test the program.
int main()
{
// Array with test data
int testArray[ROWS][COLS] =
{ { 1, 2, 3, 4, 5 },
{ 6, 7, 8, 9, 10 },
{ 11, 12, 13, 14, 15 },
{ 16, 17, 18, 19, 20 }
};
// Display the total of the array elements.
cout << "The total of the array elements is "
<< getTotal(testArray, ROWS, COLS)
<< endl;
// Display the average of the array elements.
cout << "The average value of an element is "
<< getAverage(testArray, ROWS, COLS)
<< endl;
// Display the total of row 0.
cout << "The total of row 0 is "
<< getRowTotal(testArray, 0, COLS)
<< endl;
// Display the total of column 2.
cout << "The total of col 2 is "
<< getColumnTotal(testArray, 2, ROWS)
<< endl;
// Display the highest value in row 2.
cout << "The highest value in row 2 is "
<< getHighestInRow(testArray, 2, COLS)
<< endl;
// Display the lowest value in row 2.
cout << "The lowest value in row 2 is "
<< getLowestInRow(testArray, 2, COLS)
<< endl;
return 0;
}
Output sample
The total of the array elements is 210
The average value of an element is 10.5
The total of row 0 is 15
The total of col 2 is 42
The highest value in row 2 is 15
The lowest value in row 2 is 11
GRADING