Write a program to calculate the SPI(semester performance index) and CPI(Cumulative Performance Index) of a student taking N courses in a semester. Each course has a specified weight, termed as credit and a student secures a letter grade in that course as per the Grading System.
The Grading System is as follows:
Letter Grade Numerical Grade
A 10
B 9
. .
. .
K 0
Note that the numerical grade can be obtained from the letter grade using arithmetic operations on char type data.
#include <iostream>
using namespace std;
int toInt(char c)
{
int result;
switch(c)
{
case 'A': return 10;
case 'B' : return 9;
case 'C' : return 8;
case 'D' : return 7;
case 'E' : return 6;
case 'F' : return 5;
case 'G' : return 4;
case 'H' : return 3;
case 'I' : return 2;
case 'J' : return 1;
case 'K' : return 0;
default: return -1;
}
}
int main()
{
cout << "Enter number of course for Student: ";
int courses;
char mark;
int CPI = 0;
cin >> courses;
for(int i = 0; i < courses; i++)
{
cout << i << " course Grade(A..K): ";
cin >> mark;
CPI += toInt(mark);
}
double SPI = (double)CPI/courses;
cout << "SPI is: " << SPI << endl;
cout << "CPI is: " << CPI << endl;
return 0;
}
Comments
Leave a comment