Write a program that asks the user to type in the grades for 20 students in 4 different courses. All students are taking the same 4 courses. Use a two dimensional array to display the names of the students, the name of each course and the marks. Have the program calculate each student's average and the average for each course.Can someone shed some light on this C++ coding assignment?

Hm....

Must 2 dim?

How to record?

struct room{

string name;

int corse[4];

int sum;

float average;}

And generate struct to 20 element of array:

room student[20];

1. Input

for(i=0;i%26lt;20;i++){

cin%26gt;%26gt;student[i].name; //input name

for(j=0;j%26lt;4;j++) cin%26gt;%26gt;student[i].corse[j]; //input corse

}

2. Calculate

for(i=0;i%26lt;20;i++){

sudent[i].sum=0;

for(j=0;j%26lt;4;j++){

student[i].sum+=student[i].corse[j];

student[i].average=sudent[i].sum/4.0;}

}

3. And list of student:

for(i=0;i%26lt;20;i++){

cout%26lt;%26lt;sudent[i].name;

cout%26lt;%26lt;sudent[i].sum;

cout%26lt;%26lt;sudent[i].average;

}Can someone shed some light on this C++ coding assignment?

in java:

bufferedReader reader = new bufferedReader(System.readln());

int[] course = new int[4];

int[] student = new int[20];

// ask and assign values

for(int j = 0; j %26lt; 4; j++){

course[ j ] = student[];

for(int i = 0; i %26lt; 20; i++){

System.out.println(';Student';+i';: Enter grade for course';+j);

student[ i ] = reader.ReadLine();

}}

to find the average add up and divide by total.

Subscribe to:
Post Comments (Atom)

## No comments:

## Post a Comment