Answer to Question #161845 in C++ for Rahul

Question #161845

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.


1
Expert's answer
2021-02-07T16:50:58-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog