In: Computer Science
As a part-time student, you took three courses last semester. Write, run, and test a C++ program that calculates and displays the numerical grades, the equivalent letter grades and your grade point average (GPA) for the semester. Your program should prompt the user to enter the numerical grade and credit hours for each course. This information should then be displayed in a tabular format. A warning message should be printed if the GPA is less than 2.0 and a congratulatory message if the GPA is 3.5 or above. Recall: A >= 90; 80 <= B < 90; 70 <= C < 80; 60 <= D < 70; F < 60 qualityPoints: A = 4; B = 3; C = 2, D = 1; F =0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
float marks[3],credits[3];
for(int i=0;i<3;i++) {
cout<<"Enter your Marks and Credit hours of Subject "<<i<<": ";
cin>>marks[i]>>credits[i];
}
char grades[3];
float GPA = 0;
int total_credit = 0;
for(int i=0;i<3;i++) {
if(marks[i] >= 90) {
grades[i] = 'A';
GPA = GPA+(4*credits[i]);
}
else if(marks[i] >= 80) {
grades[i] = 'B';
GPA = GPA+(3*credits[i]);
}
else if(marks[i] >= 70) {
grades[i] = 'C';
GPA = GPA+(2*credits[i]);
}
else if(marks[i] >= 60) {
grades[i] = 'B';
GPA = GPA+(1*credits[i]);
}
else {
grades[i] = 'F';
GPA = GPA+(0*credits[i]);
}
total_credit = total_credit+credits[i];
}
GPA = GPA/total_credit;
cout<<"Subject\tMarks\tLetter Grade\n";
for(int i=0;i<3;i++)
cout<<"Subject"<<(i+1)<<"\t"<<marks[i]<<"\t"<<grades[i]<<"\n";
cout<<setprecision(2)<<fixed;
cout<<"The GPA is "<<GPA<<"\n";
if(GPA < 2.0)
cout<<"Warning! Your GPA is less than 2.0\n";
if(GPA >= 3.5)
cout<<"Congralutions! Your GPA is above 3.5\n";
return 0;
}
Output
Enter your Marks and Credit hours of Subject 0: 90 5
Enter your Marks and Credit hours of Subject 1: 80 4
Enter your Marks and Credit hours of Subject 2: 95 5
Subject Marks Letter Grade
Subject1 90 A
Subject2 80 B
Subject3 95 A
The GPA is 3.71
Congralutions! Your GPA is above 3.5
Output screenshot