Pages

Wednesday, November 4, 2015

C++ Program To Calculate The Average For 10 Students In 5 Courses

Computer science program using C++ language to calculate the sum and average of 10 students in 5 different courses. Note that c++ is case sensitive. There are two loops in this program. The first loop to read in the names of 10 students and the second loop which is within the first loop is to read in the scores in each courses. The first loop is incremented when the second inner loop is completed.

Tracing through the program we have the predecessor directives, next is declarations. The identifer 'nos' specifies the number of students. Then 'noc' the number of courses. 'Score' is declared as an array, while 'sum' and 'ave' as integers.




#include <iostream.h>
#include <conio.h>
void main ()
{
const int nos=10;
const int noc=5;
char name [nos];
float scores [nos][noc];
float sum[nos], ave[nos];
int i,j;

for (i=1;i<nos; i++)
{
cout<<"Enter name of student: "<<i<<endl;
cin>>name;

for(j=1;j<=noc;j++)
{
cout<<" enter the score: "<<j<<endl;
cin>> score[i][j];
sum[i]=score[i][j];
}

ave[i]=sum[i]/5;

cout<<"Average Score For"<<" "name<<" "<<ave[i]<<endl;
}
}