GPA Calculator
GPA Calculator
#include<string>
using namespace std;
struct CGPA
{
int crh[7], tcr = 0;
float gp = 0.0, gpa;
float c[7], gr[7];
double Grade[9] = { 4.0,3.70,3.4,3.00,2.5,2.00,1.50,1.00,0.00 };
string rade[9] = { "A+","A","B+","B","B-","C+","C","D","F" };
float AP = 4.0, A = 3.70, BP = 3.40, B = 3.00, BN = 2.5, CP = 2.00, C = 1.50, D =
1.00, F = 0.00;
int cr[8], t = 0;
float gpac[8], gpc = 0.0, cgpa;
};
float Number(CGPA *);
float Grade(CGPA *);
float CGP(CGPA *);
void Status(CGPA *);
void list();
void show();
void print();
void main()
{
CGPA c;
int u, i;
cout << "============================================" << endl;
cout << "\t\tWelcome To CGPA Calculator " << endl;
cout << "============================================" << endl;
main:
print();
cin >> u;
if (u == 1)
{
GPA:
show();
cin >> i;
if (i == 1)
{
cout << "Your GPA is : " << Number(&c);
cout << "\n";
Status(&c);
goto GPA;
}
else if (i == 2)
{
Grade(&c);
cout << "\n";
Status(&c);
goto GPA;
}
else if (i == 3)
{
goto main;
}
else
{
cout << "You Entered Inavalid." << endl;
goto GPA;
}
}
else if (u == 2)
{
cout << "Your CGPA is : " << CGP(&c);
cout << "\n";
Status(&c);
goto main;
}
else if (u == 3)
{
list();
cout << "\n\n";
goto main;
}
else if (u == 4)
{
exit(0);
}
system("pause");
}
void show()
{
cout << "1. By Using Number" << endl;
cout << "2. By Using Grades" << endl;
cout << "3. Main Menu" << endl;
cout << " Select" << endl;
}
void print()
{
cout << "\n>>>>Main Menu<<<<\n" << endl;
cout << "1. GPA Calculator " << endl;
cout << "2. CGPA Calculator " << endl;
cout << "3. Grades List " << endl;
cout << "4. Exit" << endl;
cout << " Select" << endl;
}
float Number(CGPA *c)
{
int i;
cout << "Enter a Total Number of Subjects in Current Semester : " << endl;
cin >> i;
c->gp = 0;
c->tcr = 0;
for (int j = 0; j < i; j++)
{
cout << "Enter Obtained Marks in " << j + 1 << " Subject : " << endl;
cin >> c->c[j];
cout << "Enter Credit Hour : " << endl;
cin >> c->crh[j];
if (c->c[j] >= 84.50 && c->c[j] <= 100)
{
c->gr[j] = c->AP;
}
else if (c->c[j] < 84.49 && c->c[j] >= 79.50)
{
c->gr[j] = c->A;
}
else if (c->c[j] < 79.49 && c->c[j] >= 74.50)
{
c->gr[j] = c->BP;
}
else if (c->c[j] < 74.49 && c->c[j] >= 69.50)
{
c->gr[j] = c->B;
}
else if (c->c[j] < 69.49 && c->c[j] >= 64.50)
{
c->gr[j] = c->BN;
}
else if (c->c[j] < 64.49 && c->c[j] >= 59.50)
{
c->gr[j] = c->CP;
}
else if (c->c[j] < 59.49 && c->c[j] >= 54.50)
{
c->gr[j] = c->C;
}
else if (c->c[j] < 54.49 && c->c[j] >= 49.50)
{
c->gr[j] = c->D;
}
else
{
c->gr[j] = c->F;
}
c->gp = c->crh[j] * c->gr[j] + c->gp;
c->tcr = c->crh[j] + c->tcr;
}
c->gpa = c->gp / c->tcr;
return c->gpa;
}
float Grade(CGPA *c)
{
string a;
int y, i;
cout << "Enter a Total Number of Subjects in Current Semester : " << endl;
cin >> i;
c->gp = 0;
c->tcr = 0;
for (int j = 0; j < i; j++)
{
cout << "Enter Obtained Grades in " << j + 1 << " Subject : " << endl;
cin >> a;
cout << "Enter a Credit Hour : " << endl;
cin >> c->crh[j];
for (int b = 0; b < 9; b++)
{
if (c->rade[b] == a)
{
y = b;
}
}
c->gr[j] = c->Grade[y];
c->gp = c->crh[j] * c->gr[j] + c->gp;
c->tcr = c->crh[j] + c->tcr;
}
c->gpa = c->gp / c->tcr;
cout << "Your GPA is : ";
cout << c->gpa;
return c->gpa;
}
float CGP(CGPA *c)
{
int m;
cout << "Enter Number of Semester : " << endl;
cin >> m;
c->gpc = 0;
c->t = 0;
for (int l = 0; l < m; l++)
{
cout << "Enter a GPA of " << l + 1 << " Semester : " << endl;
cin >> c->gpac[l];
cout << "Enter a Total Credit Hours of " << l + 1 << " Semester : " <<
endl;
cin >> c->cr[l];
c->gpc = c->gpc + c->gpac[l] * c->cr[l];
c->t = c->t + c->cr[l];
}
c->cgpa = c->gpc / c->t;
return c->cgpa;
}
void Status(CGPA *c)
{
if (c->gpa == 4.00 || c->cgpa == 4.00)
{
cout << "Your Status is >>>> Exceptional" << endl;
}
else if (c->gpa<4.00&&c->gpa >= 3.70 || c->cgpa<4.00&&c->cgpa >= 3.70)
{
cout << "Your Status is >>>> Outstanding" << endl;
}
else if (c->gpa<3.70&&c->gpa >= 3.40 || c->cgpa<3.70&&c->cgpa >= 3.40)
{
cout << "Your Status is >>>> Excellent" << endl;
}
else if (c->gpa<3.40&&c->gpa >= 3.00 || c->cgpa<3.40&&c->cgpa >= 3.00)
{
cout << "Your Status is >>>> Very Good" << endl;
}
else if (c->gpa<3.00&&c->gpa >= 2.50 || c->cgpa<3.00&&c->cgpa >= 2.50)
{
cout << "Your Status is >>>> Good" << endl;
}
else if (c->gpa<2.50&&c->gpa >= 2.00 || c->cgpa<2.50&&c->cgpa >= 2.00)
{
cout << "Your Status is >>>> Average" << endl;
}
else if (c->gpa<2.00&&c->gpa >= 1.50 || c->cgpa<2.00&&c->cgpa >= 1.50)
{
cout << "Your Status is >>>> Satisfactory" << endl;
}
else if (c->gpa<1.50&&c->gpa >= 1.00 || c->cgpa<1.50&&c->cgpa >= 1.00)
{
cout << "Your Status is >>>> Pass" << endl;
}
else if (c->gpa<1.00&&c->gpa >= 0.00 || c->cgpa<1.00&&c->cgpa >= 0.00)
{
cout << "Your Status is >>>> Fail" << endl;
}
cout << "\n\n";
}
void list()
{
cout << "Marks Percentage\tGrade\tPoints\tStatus" << endl;
cout << "84.50 and Above\t\tA+\t4.00\tExceptional" << endl;
cout << "79.50-84.49\t\tA\t3.70\tOutstanding" << endl;
cout << "74.50-79.49\t\tB+\t3.40\tExcellent" << endl;
cout << "69.50-74.49\t\tB\t3.00\tVery Good" << endl;
cout << "64.50-69.49\t\tB-\t2.50\tGood" << endl;
cout << "59.50-64.49\t\tC+\t2.00\tAverage" << endl;
cout << "54.50-59.49\t\tC\t1.50\tSatisfactory" << endl;
cout << "49.50-54.49\t\tD\t1.00\tPass" << endl;
cout << "Below 49.50\t\tF\t0.00\tFail" << endl;
}