Calculate GPAs given the information below. Run your program with the given test
ID: 641054 • Letter: C
Question
Calculate GPAs given the information below. Run your program with the given test cases.
Notes: (1) use switch statements, (2) the program should prompt the user for the number of courses, (3) the program should ask for the letter grade (string variable) and the credit hours for that course, (4) GPA is based on a 4.0 grading scale, (5) your solution should use 1 or two loops (6) GPA is calculated by (total earned grade point hours/total credit hours).
Letter Grade
Grade Points
A
4.0
A-
3.7
B+
3.3
B
3.0
B-
2.7
C+
2.3
C
2.0
Letter Grade
Grade Points
C-
1.7
D+
1.3
D
1.0
D-
0.7
E
0.0
Test your program with the following two cases:
A, B- , B+ with credit hours [3 5 5]
B+, C-, D with credit hours [5 4 3]
Letter Grade
Grade Points
A
4.0
A-
3.7
B+
3.3
B
3.0
B-
2.7
C+
2.3
C
2.0
Explanation / Answer
#include <stdio.h>
main()
{
int i,j,n,hourssum=0;
float temp =0,gradesum=0,finalgrade = 0;
printf("enter the number of courses ");
scanf("%d",&n);
while(n--)
{
char grade[5];
int hours;
temp=0;
printf("enter the grade ");
scanf("%s",&grade);
printf("enter the grade hours ");
scanf("%d",&hours);
printf("%s %d ",grade,hours);
switch(grade[0])
{
case 'A': temp = 4;
break;
case 'B': temp = 3;
break;
case 'C': temp = 2;
break;
case 'D': temp = 1;
break;
case 'E': temp = 0;
break;
default: printf("Please enter the correct grade ");
break;
}
if(grade[1]=='-')
temp= temp-0.3;
if(grade[1]=='+')
temp = temp + 0.3;
gradesum = gradesum + (temp * hours);
hourssum = hourssum + hours;
}
finalgrade = gradesum/hourssum;
printf("grade sum = %f hourssum = %d final grade = %f ",gradesum,hourssum,finalgrade);
}
I/P:
3
A
3
B-
5
B+
5
OUTPUT:
INPUT:
3
B+
5
C-
4
D
3
OUTPUT:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.