1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#include<iostream>
using namespace std;
void Introduction(string, long);
float CalcGPA(float, float);
float totalGPA(float[], int);
float CalTotCredit(float[], int);
int main()
{
char choice;
float totalcredit=0, G=0, TC=0;
string name;
long MatrixNo;
int j, noSemester;
float GPA[j], totcredit[j], TGPA=0, TotalCredit=0,CGPA=0, Tcredit=0, totalCredit;
cout<<"Do you want to calculate CGPA? Yes='Y'/No='N'";
cin>>choice;
if(choice=='Y'||choice=='y')
{
cout<<"How many semesters did student take for his/her course?";
cin>>noSemester;
for(j=0; j<=noSemester; j++)
{
Introduction(name, MatrixNo);
cout<<"Semester: "<<j+1;
CalcGPA(GPA, totalCredit);
GPA[j]=G;
totcredit[j]=TC;
}
totalGPA(GPA, noSemester);
TGPA+=totalGPA(GPA, noSemester);
Tcredit+=CalTotCredit(TC[], noSemester);
CGPA=TGPA/TC;
cout<<name<<", "<<MatrixNo<<" have CGPA of "<<CGPA;
cout<<"Do you want to calculate CGPA? Yes='Y'/No='N'";
cin>>choice;
}
else
if(choice=='N'||choice=='n')
cout<<"Thank you for using this program. Have a nice day!!!"<<endl;
else
{
cout<<"Sorry wrong input!!! Please try again...";
cout<<"Do you want to calculate CGPA? Yes='Y'/No='N'";
cin>>choice;
}
system("PAUSE");
return 0;
}
void Introduction(string name, long MatrixNo)
{
cout<<"Student's name: ";
cin>>name;
cout<<"Enter "<<name<< "matrix number: ";
cin>>MatrixNo;
}
float CalcGPA(float &GPA,float &totalCredit)
{
int j=0, NoOfSubject=0;
float credit, point, total;
cout<<"Number: "<<j+1;
cout<<"How many subjects did you take in a semester?";
cin>>NoOfSubject;
for(int i=0; i<NoOfSubject; i++)
{
cout<<"Credit: ";
cin>>credit;
cout<<"Point: ";
cin>>point;
totalCredit+=credit;
total=credit*point;
}
GPA=total/totalCredit;
}
float totalGPA(float GPA[], int noSemester)
{
float Total_GPA=0;
int i=0;
while(i<noSemester)
{
Total_GPA+=GPA[i];
i+=1;
}
return Total_GPA;
}
float CalTotCredit(float tc[],int ts)
{
float Tcredit=0, CGPA=0;
int i=0;
while(i<ts)
{
Tcredit+=tc[i];
}
return Tcredit;
}
|