Question

In: Computer Science

Question 2. Write a complete C++ program that uses a 2-dimensional array with 4 rows and...

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

Solutions

Expert Solution

/* 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;
}


Related Solutions

JAVA LANGUAGE Write a program that declares a 2-Dimensional Array with 4 rows and 4 columns...
JAVA LANGUAGE Write a program that declares a 2-Dimensional Array with 4 rows and 4 columns to store integer values, and then: fill elements with values as the sum of its column index and row index, e.g., the element at row index 0 and column index 0 is (0+0=0), the element at row index 0 and column index 1 is (0+1=1). compute the sum of elements at the second row. compute the sum of elements at the third column. compute...
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write Matrix Addition 2 D (dimensional) Array program in c++.
In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number of rows r aand number of columns c - Create a two-dimensional array of integers int numbers[r][c] -input data for each element of numbers Your program must compute and display the largest number is each row and column of the number array
Complete the "dumb" 8 queens program that Use the 1 dimensional array representation. C++ This is...
Complete the "dumb" 8 queens program that Use the 1 dimensional array representation. C++ This is the solution to the  question. i want this program to written in different WAY. nothing fancy. #include<cmath> #include<fstream> #include<iostream> using namespace std; bool ok(int b[][8]){ int rQueens=0, dQueens=0; for(int row=0; row<8; row++){ for(int column=0; column<8; column++){ //Rows test if(b[row][column]==1) rQueens++; if(rQueens>1) return false; //Diagonals test    for(int j=1; ((column-j)>=0)&&((row-j)>=0); j++){ if(b[row-j][column-j]==1&&b[row][column]==1) return false; } for(int k=1; ((column-k)>=0)&&((row+k)<8); k++){ if(b[row+k][column-k]==1&&b[row][column]==1) return false; } } rQueens=0; }...
Complete the 8 queens 1 dimensional array program with backtracking in c+++. (don't use go to...
Complete the 8 queens 1 dimensional array program with backtracking in c+++. (don't use go to statement ) and please describe all the code statement and show the code in complier and also which can be copied. thank you very much
In C++, write a program that uses array to calculate the factorial of a reasonable large...
In C++, write a program that uses array to calculate the factorial of a reasonable large number (say, up to 2,000).
In C++. Write a program that uses array to calculate the factorial of a reasonable large...
In C++. Write a program that uses array to calculate the factorial of a reasonable large number (say, up to 2,000).  
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT