Write a Program to Calculate grade points GPA in C++
Program:
#include<iostream>
using namespace std;
// Code By HI
class marks
{
private :
float QP[20], marks[20];
float sgpa=0, GP, gpa;
float total_QP=0;
int credit_hrs[20];
int total_cdr_hrs=0;
public :
void getdata(int x)
{
for (int i=1; i<=x; i++)
{
cout<<"Enter Marks: ";
cin>>marks[i];
cout<<"Enter Credit Hours: ";
cin>>credit_hrs[i];
total_cdr_hrs+=credit_hrs[i];
// Condition For 50 Marks Subjects //
if (credit_hrs[i]<=2)
{
marks[i]=marks[i]*2;
}
// --------------------------------- //
if (marks[i]>=85)
{
GP=4.0;
}
else if (marks[i]==83 || marks[i]==84)
{
GP=3.9;
}
else if (marks[i]==82)
{
GP=3.8;
}
else if (marks[i]==80 || marks[i]==81)
{
GP=3.7;
}
else if (marks[i]==80 || marks[i]==81)
{
GP=3.7;
}
else if (marks[i]==79)
{
GP=3.6;
}
else if (marks[i]==77 || marks[i]==78)
{
GP=3.5;
}
else if (marks[i]==76 )
{
GP=3.4;
}
else if (marks[i]==75 || marks[i]==74 )
{
GP=3.3;
}
else if (marks[i]==73)
{
GP=3.2;
}
else if (marks[i]==72 || marks[i]==71)
{
GP=3.1;
}
else if (marks[i]==70 )
{
GP=3.0;
}
else if (marks[i]==69 )
{
GP=2.9;
}
else if (marks[i]==68 )
{
GP=2.8;
}
else if (marks[i]==67 )
{
GP=2.7;
}
else if (marks[i]==66 )
{
GP=2.6;
}
else if (marks[i]==65 )
{
GP=2.5;
}
else if (marks[i]==64 )
{
GP=2.4;
}
else if (marks[i]==63 )
{
GP=2.3;
}
else if (marks[i]==62 )
{
GP=2.2;
}
else if (marks[i]==61 )
{
GP=2.1;
}
else if (marks[i]==60 )
{
GP=2.0;
}
else if (marks[i]==59 )
{
GP=1.9;
}
else if (marks[i]==58 )
{
GP=1.8;
}
else if (marks[i]==57 )
{
GP=1.7;
}
else if (marks[i]==56 )
{
GP=1.6;
}
else if (marks[i]==55 )
{
GP=1.5;
}
else if (marks[i]==54 )
{
GP=1.4;
}
else if (marks[i]==53 )
{
GP=1.3;
}
else if (marks[i]==52 )
{
GP=1.2;
}
else if (marks[i]==51 )
{
GP=1.1;
}
else if (marks[i]==50 )
{
GP=1.0;
}
else if (marks[i]<50)
{
GP=0.0;
}
// GP Of A Subject = Credit Hours * Quality Point //
QP[i]=GP*credit_hrs[i];
}
}
void showdata(int x)
{
for (int i=1; i<=x; i++)
{
total_QP+=QP[i];
}
cout<<"Total Quality Points of All Subjects: "<<total_QP<<endl;
cout<<"Total Credit Hours of All Subjects: "<<total_cdr_hrs<<endl;
gpa=total_QP/total_cdr_hrs;
cout<<"Your SGPA is: "<<gpa<<endl;
}
};
int main()
{
cout<<"\n\nENTER MARKS OF THEORy AND PRACTICAL SUBJECTS AND CREDIT HOURS FOR EACH SUBJECT "<<endl;
cout<<endl;
int n;
cout<<"Enter Number Of Subjects (Theory + Practical): ";
cin>>n;
marks m1;
m1.getdata (n);
cout<<"\n ------------ Your SGPA ----------------- "<<endl;
cout<<endl;
m1.showdata (n);
return 0;
}