In: Computer Science
Question 2. Write a complete C++ program that uses a 2-dimensional array with 4 rows and 30 columns. Row represents sections of a course and column represents the students, value inside each position of the array is the final exam grade for each students. Fill the array with random numbers between 40 and 100. Calculate the total, average, maximum, minimum for each section. Please do it simple. code
/* Here is your required code*/
#include <iostream>
#include <stdlib.h>
#include<time.h>
using namespace std;
int main()
{srand(time(0));
int a[4][30];
for(int i=0;i<4;i++)
for(int j=0;j<30;j++)
a[i][j]=(rand() %
(100 - 40 + 1)) + 40;
float total,avg,min,max;
for(int i=0;i<4;i++){
min=a[i][0];max=a[i][0];
total=0;
for(int j=0;j<30;j++){
if(a[i][j]>max)
max=a[i][j];
if(a[i][j]<min)
min=a[i][j];
total+=a[i][j];
}
cout<<"\nTotal of "<<i+1<<"th section:
"<<total;
cout<<"\nAverage of "<<i+1<<"th section:
"<<total/30;
cout<<"\nMinimum of "<<i+1<<"th section:
"<<min;
cout<<"\nMaximum of "<<i+1<<"th section:
"<<max;
}
return 0;
}