Question #26661

Write C++ Console Application to calculate and display the average CGPA of 10 students with the following requirements.
1.Your program must use Class for student which have the following variables/attributes
1.Name
2.MatrixNo
3.Cgpa.
2.Your program should get information of 10 students Name,MatrixNo,Cgpa) from User and store it in Arrayof object of type Student (from item 1).
3.Then, your program must calculate and display the average CGPA from the Array(from item 2

Expert's answer

/*Write C++ Console Application to calculate and display the average CGPA of
10 students with the following requirements.
1.Your program must use Class for student which have the following
variables/attributes
1.Name
2.MatrixNo
3.Cgpa.
2.Your program should get information of 10 students Name,MatrixNo,Cgpa)
from User and store it in Arrayof object of type Student (from item 1).
3.Then, your program must calculate and display the average CGPA from the
Array(from item 2*/
# include <iostream>
# include < string>
using namespace std;
class stud{
protected:
string name;
string mat;
double gpa;
public:
void get(){
cout<<"Name:";
getline(cin,name,'\n');

cout<<"matrix number:";
/*cin.ignore();*/
getline(cin,mat,'\n');

cout<<"GPA:";
cin>>gpa;
cout<<endl;
cin.ignore();
}
friend double average(stud a[], int len);
};
double average(stud a[], int len){
double av=0;
for (int i=0; i<len;i++){
av+=a[i].gpa;
}
return av/len;
}
int main(){
stud s[10];
for (int i=0; i<10;i++){
s[i].get();
}
cout<<"average GPA:"<<average(s,10);

system("PAUSE");
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS