Write a C program to calculate class average for the following 10 students and 5
ID: 3760870 • Letter: W
Question
Write a C program to calculate class average for the following 10 students and 5 courses. M1 to M5 are marks in course1 to course5 respectively. Marks are out of 50. Marks of the students are shown in the table below. Total is initialized to zero (It is compute and populated in the array later.)
Divide the problem into sub problems. Write function for each sub-problem and call all the functions in main function. Write the following functions:
(i) populateMarksArray(): Write a function to read values in two dimensional array of marks from the above table. Populate id no in first column, marks in other columns and initialize last column with zeros. Identify input arguments and return type of the function. [Note: Ignore first row from above table].
Id No
M1
M2
M3
M4
M5
Total
1
32.5
43
23
12
44
0
2
23
23.5
45.5
25
19
0
3
34
13.5
32.5
21.5
26
0
4
41
21
31
14
12
0
5
22
42
45
12
14
0
6
33
44
21
11
29
0
7
39
47
28
17
48
0
8
38
27
36
19
39
0
9
49.5
28.5
46
20.5
50
0
10
29
54
33.5
22.5
10
0
(ii) computeTotal(): Write a function to compute total marks of each student and update the marks array.
(iii) computeClassAverage(): Write a function to calculate average of all the students in the class and return it to main function.
(iv) computeMaxTotal(): Write a function to find a student with maximum total marks. Function returns id no of the student with maximum total.
Id No
M1
M2
M3
M4
M5
Total
1
32.5
43
23
12
44
0
2
23
23.5
45.5
25
19
0
3
34
13.5
32.5
21.5
26
0
4
41
21
31
14
12
0
5
22
42
45
12
14
0
6
33
44
21
11
29
0
7
39
47
28
17
48
0
8
38
27
36
19
39
0
9
49.5
28.5
46
20.5
50
0
10
29
54
33.5
22.5
10
0
Explanation / Answer
#include <stdio.h>
void populateMarksArray(float Array[10][7])
{
int i, j;
float A[10][7] = {{1,32.5,43,23,12,44,0},
{2,23,23.5,45.5,25,19,0},
{3,34,13.5,32.5,21.5,26,0},
{4,41,21,31,14,12,0},
{5,22,42,45,12,14,0},
{6,33,44,21,11,29,0},
{7,39,47,28,17,48,0},
{8,38,27,36,19,39,0},
{9,49.5,28.5,46,20.5,50,0},
{10,29,54,33.5,22.5,10,0}};
for(i = 0; i < 10; i++)
for(j = 0; j < 7 ; j++)
Array[i][j] = A[i][j];
}
void computeTotal(float Array[10][7])
{
int i, j;
for(i = 0; i < 10; i++)
{
for(j = 1; j < 6; j++)
Array[i][6] += Array[i][j];
}
}
float computeClassAverage(float Array[10][7])
{
int i;
float sum = 0;
for(i = 0; i < 10; i++)
sum += Array[i][6];
return sum/10;
}
int computeMaxTotal(float Array[10][7])
{
int i;
int max;
max = 0;
for(i = 1; i < 10; i++)
if(Array[i][6] > Array[max][6])
max = i;
return Array[max][0];
}
int main()
{
float Array[10][7];
int i, j;
populateMarksArray(Array);
computeTotal(Array);
;
printf("Students marks: ");
for(i = 0; i < 10; i++)
{
for(j = 0; j < 7; j++)
printf("%.2f ", Array[i][j]);
printf(" ");
}
printf("The average marks of the class is: %.2f ", computeClassAverage(Array));
printf("The topper of the class is: %i ", computeMaxTotal(Array));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.