write a C ++ program to Create a 2-dimensional array with 4 rows and 30 columns.
ID: 3534255 • Letter: W
Question
write a C ++ program to Create 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.
1.5. Generate a histogram for all the grades. Each score represents one dot on the histogram. To do
that, first create an array of size 61 and then stores the count of each scores in the array . Once you have all the count, output the number of dots for each score based on the count.
plz compile before posting it , if u got correct answer then post the answer otherwise i do need the wrong code b/c somebody already post the wrong code and that's why i resubmit this question.
Explanation / Answer
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int cls[4][30];
int sectionMax[4],sectionMin[4],sectionTotal[4],sectionHistogram[4][61];
float sectionAvg[4];
for(int i=0;i<4;i++)
for(int j=0;j<30;j++)
cls[i][j] = rand()a + 40;
for(int i=0;i<4;i++)
for(int j=0;j<61;j++)
sectionHistogram[i][j] = 0;
for(int i=0;i<4;i++)
{
int max=0,min=101,total=0;
for(int j=0;j<30;j++)
{
total += cls[i][j];
if(cls[i][j]>max)
max = cls[i][j];
if(cls[i][j]<min)
min = cls[i][j];
sectionHistogram[i][cls[i][j]-40]++;
}
sectionTotal[i] = total;
sectionMin[i] = min;
sectionMax[i] = max;
sectionAvg[i] = total*1.0/30;
}
for(int i=0;i<4;i++)
{
cout<<"Performance of section :"<<i+1<<endl;
cout<<"Total marks = "<<sectionTotal[i]<<endl;
cout<<"Highest marks = "<<sectionMax[i]<<endl;
cout<<"Lowest marks = "<<sectionMin[i]<<endl;
cout<<"Average marks = "<<sectionAvg[i]<<endl;
cout<<endl<<endl;
}
for(int i=0;i<4;i++)
{
cout<<"Histogram for section :"<<i+1<<endl;
cout<<"Marks Students"<<endl;
for (int j = 0; j < 61; j++)
{
cout<<j+40<<' '<<sectionHistogram[i][j]<<endl;
}
cout<<endl<<endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.