C++ ASSIGNMENT: Grades Write a program that uses enum types to assign letter gra
ID: 3711074 • Letter: C
Question
C++ ASSIGNMENT: Grades
Write a program that uses enum types to assign letter grades that can be automatically converted to numerical grades. For this assignment, you'll create an enum type with the values F, D, C, B, and A, so the letter grades are associated with ordinal values 0, 1, 2, 3, and 4, respectively (which coincide with the quality points for that grade). Write a method assignCourseGrade(double grade) which takes a real number representing the grade for the class, converts it to an enumeration and returns the enum value. Use the converted enumeration to display the student's letter grade and quality points for the class.
INPUT VALIDATION: Ensure the user input is between 0 and 100.
Explanation / Answer
Hi buddy please find answer as below
#include <iostream>
using namespace std;
enum CourseGrade
{
F=0,
D=1,
C=2,
B=3,
A=4
} CourseGradeVal;
CourseGrade assignCourseGrade(double grade);
char* CourseGradeToString(CourseGrade enumVal);
int main()
{
CourseGradeVal= assignCourseGrade(1);
string strVal= CourseGradeToString(CourseGradeVal);
std::cout <<"Letter Grade is " <<strVal << " and Letter point is " << CourseGradeVal;
return 0;
}
char* CourseGradeToString(CourseGrade enumVal)
{
char* enumValString[5] = {"F","D","C","B","A"};
return enumValString[enumVal];
}
CourseGrade assignCourseGrade(double grade)
{
if(grade==0)
{
CourseGradeVal = F;
}
else if(grade==1)
{
CourseGradeVal = D;
}
else if(grade==2)
{
CourseGradeVal = C;
}
else if(grade==3)
{
CourseGradeVal = B;
}
else if(grade==4)
{
CourseGradeVal = A;
}
else
{
CourseGradeVal = F;
}
return CourseGradeVal;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.