#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
// Function to calculate grade and GPA points
pair<string, double> calculateGrade(double percentage) {
if (percentage >= 90) return {"A+", 4.0};
if (percentage >= 80) return {"A", 3.7};
if (percentage >= 70) return {"B+", 3.3};
if (percentage >= 60) return {"B", 3.0};
if (percentage >= 55) return {"C+", 2.7};
if (percentage >= 50) return {"C", 2.0};
return {"F", 0.0};
}
int main() {
// Welcome Note
cout << "=========================================\n";
cout << "Welcome to GCUF Sahiwal Campus CGPA Calculator\n";
cout << "=========================================\n\n";
// Input number of courses
int numCourses;
cout << "Enter the number of courses for this semester: ";
cin >> numCourses;
vector<string> courseNames(numCourses);
vector<int> creditHours(numCourses);
vector<string> grades(numCourses);
vector<double> GPAs(numCourses);
double totalQualityPoints = 0;
int totalCreditHours = 0;
// Input course details
for (int i = 0; i < numCourses; i++) {
cout << "\nEnter details for course " << i + 1 << ":\n";
cout << "Course name: ";
cin.ignore();
getline(cin, courseNames[i]);
cout << "Select credit hour policy:\n";
cout << "1. Policy 1 (3-0 credits)\n";
cout << "2. Policy 2 (2-1 credits)\n";
cout << "3. Policy 3 (3-1 credits)\n";
int policy;
cin >> policy;
double midTerm, sessional, finalExam, practical, totalMarks = 0;
switch (policy) {
case 1:
creditHours[i] = 3;
cout << "Enter marks (out of 18) for Mid-term: ";
cin >> midTerm;
cout << "Enter marks (out of 12) for Sessional: ";
cin >> sessional;
cout << "Enter marks (out of 30) for Final Exam: ";
cin >> finalExam;
cout << "Enter marks (out of 40) for Practical: ";
cin >> practical;
totalMarks = midTerm + sessional + finalExam + practical;
break;
case 2:
creditHours[i] = 3; // 2-1 credits = 3 credit hours total
cout << "Enter marks (out of 12) for Mid-term: ";
cin >> midTerm;
cout << "Enter marks (out of 8) for Sessional: ";
cin >> sessional;
cout << "Enter marks (out of 20) for Final Exam: ";
cin >> finalExam;
cout << "Enter marks (out of 60) for Practical: ";
cin >> practical;
totalMarks = midTerm + sessional + finalExam + practical;
break;
case 3:
creditHours[i] = 4;
cout << "Enter marks (out of 18) for Mid-term: ";
cin >> midTerm;
cout << "Enter marks (out of 12) for Sessional: ";
cin >> sessional;
cout << "Enter marks (out of 30) for Final Exam: ";
cin >> finalExam;
cout << "Enter marks (out of 40) for Practical: ";
cin >> practical;
totalMarks = midTerm + sessional + finalExam + practical;
break;
default:
cout << "Invalid policy selected. Exiting...\n";
return 1;
}
double percentage = (totalMarks / 100) * 100;
auto [grade, GPA] = calculateGrade(percentage);
grades[i] = grade;
GPAs[i] = GPA;
totalQualityPoints += GPA * creditHours[i];
totalCreditHours += creditHours[i];
}
// Semester GPA Calculation
double semesterGPA = totalQualityPoints / totalCreditHours;
// Input previous CGPA
double previousCGPA;
int totalPreviousSemesters;
cout << "\nEnter your previous CGPA: ";
cin >> previousCGPA;
cout << "Enter the number of semesters completed before this semester: ";
cin >> totalPreviousSemesters;
// Overall CGPA Calculation
double overallCGPA = ((previousCGPA * totalPreviousSemesters) + semesterGPA) / (totalPreviousSemesters + 1);
// Display Results
cout << "\n========== Results ==========\n";
cout << left << setw(15) << "Course" << setw(10) << "Grade" << setw(10) << "GPA\n";
for (int i = 0; i < numCourses; i++) {
cout << left << setw(15) << courseNames[i] << setw(10) << grades[i] << setw(10) << GPAs[i] << "\n";
}
cout << "\nSemester GPA: " << fixed << setprecision(2) << semesterGPA;
cout << "\nOverall CGPA: " << fixed << setprecision(2) << overallCGPA;
// Goodbye Note
cout << "\n\n=========================================\n";
cout << "Thank you for using GCUF Sahiwal Campus CGPA Calculator!\n";
cout << "=========================================\n";
return 0;
}
Comments
Post a Comment