C++question Write a program that uses enum types to assign letter grades that ca
ID: 3717429 • Letter: C
Question
C++question
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
#include <iostream>
using namespace std;
enum classGrades{
F,D,C,B,A
}grades;
int main()
{
char firstname[25];
char lastname[25];
enum grades {F,D,C,B,A};
int age, grade;
char finalGrade;
cout << "What is students first name? ";
cin.getline(firstname, 26);
cout << "What is students last name? ";
cin.getline(lastname, 26);
cout << "Marks of the student ";
cin >> grade;
finalGrade = assignCourseGrade(double grade);
cout << "Name: " << lastname << ", " << firstname << endl;
cout << "Grade: " << finalGrade << endl;
return 0;
}
public char assignCourseGrade(double grade){
char result;
if(grade >= 90){
result = grades(4);
}
else if(grade >=80 || grade<90){
result = grades(3);
}
else if(grade >=65 || grade<80){
result = grades(2);
}
else if(grade >=45 || grade<65){
result = grades(1);
}
else
{
result = grades(0);
}
return result;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.