Calculate your GPA in 1st Semester
C++ Code:
# include <iostream>
# include <iomanip>
using namespace std;
char subGrades[6][3];
void calGPA(char subGrades[][3])
{
double gradePoints = 0;
double gpa;
for (int i = 0; i < 6; i++)
{
if (i!=1)
{
if (strcmp(subGrades[i], "A") == 0)
{
gradePoints = gradePoints + (3.0*4.0);
}
else if (strcmp(subGrades[i], "A-") == 0)
{
gradePoints = gradePoints + (3.0*3.7);
}
else if (strcmp(subGrades[i], "B+") == 0)
{
gradePoints = gradePoints + (3.0*3.3);
}
else if (strcmp(subGrades[i], "B") == 0)
{
gradePoints = gradePoints + (3.0*3.0);
}
else if (strcmp(subGrades[i], "B-") == 0)
{
gradePoints = gradePoints + (3.0*2.7);
}
else if (strcmp(subGrades[i], "C+") == 0)
{
gradePoints = gradePoints + (3.0*2.3);
}
else if (strcmp(subGrades[i], "C") == 0)
{
gradePoints = gradePoints + (3.0*2.0);
}
else if (strcmp(subGrades[i], "C-") == 0)
{
gradePoints = gradePoints + (3.0*1.7);
}
else if (strcmp(subGrades[i], "D") == 0)
{
gradePoints = gradePoints + (3.0*1.0);
}
else if (strcmp(subGrades[i], "F") == 0)
{
gradePoints = gradePoints + (3.0*0.0);
}
}
if (i==1)
{
if (strcmp(subGrades[i], "A") == 0)
{
gradePoints = gradePoints + (1.0*4.0);
}
else if (strcmp(subGrades[i], "A-") == 0)
{
gradePoints = gradePoints + (1.0*3.7);
}
else if (strcmp(subGrades[i], "B+") == 0)
{
gradePoints = gradePoints + (1.0*3.3);
}
else if (strcmp(subGrades[i], "B") == 0)
{
gradePoints = gradePoints + (1.0*3.0);
}
else if (strcmp(subGrades[i], "B-") == 0)
{
gradePoints = gradePoints + (1.0*2.7);
}
else if (strcmp(subGrades[i], "C+") == 0)
{
gradePoints = gradePoints + (1.0*2.3);
}
else if (strcmp(subGrades[i], "C") == 0)
{
gradePoints = gradePoints + (1.0*2.0);
}
else if (strcmp(subGrades[i], "C-") == 0)
{
gradePoints = gradePoints + (1.0*1.7);
}
else if (strcmp(subGrades[i], "D") == 0)
{
gradePoints = gradePoints + (1.0*1.0);
}
else if (strcmp(subGrades[i], "F") == 0)
{
gradePoints = gradePoints + (1.0*0.0);
}
}
}
cout << setprecision(3) << showpoint << endl;
gpa = gradePoints / 16.00;
cout << "Your GPA in 1st Semester is : " << gpa << endl;
}
void calGradePoint(double subNumbers[])
{
for (int i = 0; i < 6; i++)
{
if (subNumbers[i] >= 80 && subNumbers[i] <= 100)
{
subGrades[i][0] = 'A';
if (subNumbers[i] >= 80 && subNumbers[i]<85)
{
subGrades[i][1] = '-';
subGrades[i][2] = '\0';
}
else
{
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
}
else if (subNumbers[i] >= 65)
{
subGrades[i][0] = 'B';
if (subNumbers[i] >= 75)
{
subGrades[i][1] = '+';
subGrades[i][2] = '\0';
}
else if (subNumbers[i] >= 70)
{
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
else
{
subGrades[i][1] = '-';
subGrades[i][2] = '\0';
}
}
else if (subNumbers[i] >= 55)
{
subGrades[i][0] = 'C';
if (subNumbers[i] >= 61)
{
subGrades[i][1] = '+';
subGrades[i][2] = '\0';
}
else if (subNumbers[i] >= 58)
{
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
else
{
subGrades[i][1] = '-';
subGrades[i][2] = '\0';
}
}
else if (subNumbers[i] >= 50)
{
subGrades[i][0] = 'D';
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
else
{
subGrades[i][0] = 'F';
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
}
calGPA(subGrades);
}
int main()
{
int choice;
double subNumbers[6];
cout << "Welcome to Your GPA Calculator in 1st Semester" << endl;
cout << endl;
cout << "Please select the way you want to proceed : " << endl;
cout << "Enter '1' to calculate GPA by Grades (A-F)" << endl;
cout << "Enter '2' to calculate GPA by Numbers in each Subject" << endl;
cin >> choice;
while (choice<1 ||choice>2)
{
cout << "Wrong choice" << endl;
cout << "Enter '1' to calculate GPA by Grades (A-F)" << endl;
cout << "Enter '2' to calculate GPA by Numbers in each Subject" << endl;
cin >> choice;
}
cin.ignore();
if (choice == 1)
{
cout << "Please follow the Following table to enter your Grade : " << endl;
cout << "Enter 'A' for 85 marks or above" << endl;
cout << "Enter 'A-' for (80-84) marks" << endl;
cout << "Enter 'B+' for (75-79) marks" << endl;
cout << "Enter 'B' for (70-74) marks" << endl;
cout << "Enter 'B-' for (65-69) marks" << endl;
cout << "Enter 'C+' for (61-64) marks" << endl;
cout << "Enter 'C' for (58-60) marks" << endl;
cout << "Enter 'C-' for (55-57) marks" << endl;
cout << "Enter 'D' for (50-54) marks" << endl;
cout << "Enter 'F' for 50 below marks" << endl;
cout << endl;
cout << "Please enter the grade of Programming Fundamentals : ";
cin.getline(subGrades[0], 3);
cout << "Please enter the grade of Programming Fundamentals Lab : ";
cin.getline(subGrades[1], 3);
cout << "Please enter the grade of Introduction to Computing : ";
cin.getline(subGrades[2], 3);
cout << "Please enter the grade of Calculus-I : ";
cin.getline(subGrades[3], 3);
cout << "Please enter the grade of ElectroMagnetic Theory : ";
cin.getline(subGrades[4], 3);
cout << "Please enter the grade of Islamiat+Pak.Studies : ";
cin.getline(subGrades[5], 3);
calGPA(subGrades);
}
else
{
cout << "Please enter numbers of Programming Fundamentals : ";
cin >> subNumbers[0];
cout << "Please enter numbers of Programming Fundamentals Lab : ";
cin >> subNumbers[1];
cout << "Please enter numbers of Introduction to Computing : ";
cin >> subNumbers[2];
cout << "Please enter numbers of Calculus-I : ";
cin >> subNumbers[3];
cout << "Please enter numbers of ElectroMagnetic Theory : ";
cin >> subNumbers[4];
cout << "Please enter numbers of Islamiat+Pak.Studies : ";
cin >> subNumbers[5];
calGradePoint(subNumbers);
}
getchar();
system("pause");
}
# include <iostream>
# include <iomanip>
using namespace std;
char subGrades[6][3];
void calGPA(char subGrades[][3])
{
double gradePoints = 0;
double gpa;
for (int i = 0; i < 6; i++)
{
if (i!=1)
{
if (strcmp(subGrades[i], "A") == 0)
{
gradePoints = gradePoints + (3.0*4.0);
}
else if (strcmp(subGrades[i], "A-") == 0)
{
gradePoints = gradePoints + (3.0*3.7);
}
else if (strcmp(subGrades[i], "B+") == 0)
{
gradePoints = gradePoints + (3.0*3.3);
}
else if (strcmp(subGrades[i], "B") == 0)
{
gradePoints = gradePoints + (3.0*3.0);
}
else if (strcmp(subGrades[i], "B-") == 0)
{
gradePoints = gradePoints + (3.0*2.7);
}
else if (strcmp(subGrades[i], "C+") == 0)
{
gradePoints = gradePoints + (3.0*2.3);
}
else if (strcmp(subGrades[i], "C") == 0)
{
gradePoints = gradePoints + (3.0*2.0);
}
else if (strcmp(subGrades[i], "C-") == 0)
{
gradePoints = gradePoints + (3.0*1.7);
}
else if (strcmp(subGrades[i], "D") == 0)
{
gradePoints = gradePoints + (3.0*1.0);
}
else if (strcmp(subGrades[i], "F") == 0)
{
gradePoints = gradePoints + (3.0*0.0);
}
}
if (i==1)
{
if (strcmp(subGrades[i], "A") == 0)
{
gradePoints = gradePoints + (1.0*4.0);
}
else if (strcmp(subGrades[i], "A-") == 0)
{
gradePoints = gradePoints + (1.0*3.7);
}
else if (strcmp(subGrades[i], "B+") == 0)
{
gradePoints = gradePoints + (1.0*3.3);
}
else if (strcmp(subGrades[i], "B") == 0)
{
gradePoints = gradePoints + (1.0*3.0);
}
else if (strcmp(subGrades[i], "B-") == 0)
{
gradePoints = gradePoints + (1.0*2.7);
}
else if (strcmp(subGrades[i], "C+") == 0)
{
gradePoints = gradePoints + (1.0*2.3);
}
else if (strcmp(subGrades[i], "C") == 0)
{
gradePoints = gradePoints + (1.0*2.0);
}
else if (strcmp(subGrades[i], "C-") == 0)
{
gradePoints = gradePoints + (1.0*1.7);
}
else if (strcmp(subGrades[i], "D") == 0)
{
gradePoints = gradePoints + (1.0*1.0);
}
else if (strcmp(subGrades[i], "F") == 0)
{
gradePoints = gradePoints + (1.0*0.0);
}
}
}
cout << setprecision(3) << showpoint << endl;
gpa = gradePoints / 16.00;
cout << "Your GPA in 1st Semester is : " << gpa << endl;
}
void calGradePoint(double subNumbers[])
{
for (int i = 0; i < 6; i++)
{
if (subNumbers[i] >= 80 && subNumbers[i] <= 100)
{
subGrades[i][0] = 'A';
if (subNumbers[i] >= 80 && subNumbers[i]<85)
{
subGrades[i][1] = '-';
subGrades[i][2] = '\0';
}
else
{
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
}
else if (subNumbers[i] >= 65)
{
subGrades[i][0] = 'B';
if (subNumbers[i] >= 75)
{
subGrades[i][1] = '+';
subGrades[i][2] = '\0';
}
else if (subNumbers[i] >= 70)
{
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
else
{
subGrades[i][1] = '-';
subGrades[i][2] = '\0';
}
}
else if (subNumbers[i] >= 55)
{
subGrades[i][0] = 'C';
if (subNumbers[i] >= 61)
{
subGrades[i][1] = '+';
subGrades[i][2] = '\0';
}
else if (subNumbers[i] >= 58)
{
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
else
{
subGrades[i][1] = '-';
subGrades[i][2] = '\0';
}
}
else if (subNumbers[i] >= 50)
{
subGrades[i][0] = 'D';
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
else
{
subGrades[i][0] = 'F';
subGrades[i][1] = '\0';
subGrades[i][2] = '\0';
}
}
calGPA(subGrades);
}
int main()
{
int choice;
double subNumbers[6];
cout << "Welcome to Your GPA Calculator in 1st Semester" << endl;
cout << endl;
cout << "Please select the way you want to proceed : " << endl;
cout << "Enter '1' to calculate GPA by Grades (A-F)" << endl;
cout << "Enter '2' to calculate GPA by Numbers in each Subject" << endl;
cin >> choice;
while (choice<1 ||choice>2)
{
cout << "Wrong choice" << endl;
cout << "Enter '1' to calculate GPA by Grades (A-F)" << endl;
cout << "Enter '2' to calculate GPA by Numbers in each Subject" << endl;
cin >> choice;
}
cin.ignore();
if (choice == 1)
{
cout << "Please follow the Following table to enter your Grade : " << endl;
cout << "Enter 'A' for 85 marks or above" << endl;
cout << "Enter 'A-' for (80-84) marks" << endl;
cout << "Enter 'B+' for (75-79) marks" << endl;
cout << "Enter 'B' for (70-74) marks" << endl;
cout << "Enter 'B-' for (65-69) marks" << endl;
cout << "Enter 'C+' for (61-64) marks" << endl;
cout << "Enter 'C' for (58-60) marks" << endl;
cout << "Enter 'C-' for (55-57) marks" << endl;
cout << "Enter 'D' for (50-54) marks" << endl;
cout << "Enter 'F' for 50 below marks" << endl;
cout << endl;
cout << "Please enter the grade of Programming Fundamentals : ";
cin.getline(subGrades[0], 3);
cout << "Please enter the grade of Programming Fundamentals Lab : ";
cin.getline(subGrades[1], 3);
cout << "Please enter the grade of Introduction to Computing : ";
cin.getline(subGrades[2], 3);
cout << "Please enter the grade of Calculus-I : ";
cin.getline(subGrades[3], 3);
cout << "Please enter the grade of ElectroMagnetic Theory : ";
cin.getline(subGrades[4], 3);
cout << "Please enter the grade of Islamiat+Pak.Studies : ";
cin.getline(subGrades[5], 3);
calGPA(subGrades);
}
else
{
cout << "Please enter numbers of Programming Fundamentals : ";
cin >> subNumbers[0];
cout << "Please enter numbers of Programming Fundamentals Lab : ";
cin >> subNumbers[1];
cout << "Please enter numbers of Introduction to Computing : ";
cin >> subNumbers[2];
cout << "Please enter numbers of Calculus-I : ";
cin >> subNumbers[3];
cout << "Please enter numbers of ElectroMagnetic Theory : ";
cin >> subNumbers[4];
cout << "Please enter numbers of Islamiat+Pak.Studies : ";
cin >> subNumbers[5];
calGradePoint(subNumbers);
}
getchar();
system("pause");
}