0% found this document useful (0 votes)
2 views

outputCode

The document is a C++ program that calculates the Cumulative Grade Point Average (CGPA) based on user input for courses, credits, and grades. It defines a 'Course' structure and uses a function to compute the CGPA by weighing grades with their respective credits. The program prompts the user for the number of courses and details for each course before displaying the calculated CGPA.

Uploaded by

srcramchand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

outputCode

The document is a C++ program that calculates the Cumulative Grade Point Average (CGPA) based on user input for courses, credits, and grades. It defines a 'Course' structure and uses a function to compute the CGPA by weighing grades with their respective credits. The program prompts the user for the number of courses and details for each course before displaying the calculated CGPA.

Uploaded by

srcramchand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

#include <vector>
#include <iomanip>

using namespace std;

struct Course {
string name;
int credits;
float grade;
};

float calculateCGPA(const vector<Course>& courses) {


float totalGradePoints = 0.0;
int totalCredits = 0;

for (const auto& course : courses) {


totalGradePoints += course.grade * course.credits;
totalCredits += course.credits;
}

return totalCredits > 0 ? totalGradePoints / totalCredits : 0.0;


}

int main() {
int numCourses;
cout << "Enter the number of courses: ";
cin >> numCourses;

vector<Course> courses(numCourses);

for (int i = 0; i < numCourses; ++i) {


cout << "Enter the name of course " << (i + 1) << ": ";
cin >> courses[i].name;
cout << "Enter the credits for " << courses[i].name << ": ";
cin >> courses[i].credits;
cout << "Enter the grade for " << courses[i].name << ": ";
cin >> courses[i].grade;
}

float cgpa = calculateCGPA(courses);

cout << fixed << setprecision(2);


cout << "Cumulative Grade Point Average (CGPA): " << cgpa << endl;

return 0;
}

You might also like