Question

C++ Grades . Write a program that uses enum types to assign letter grades that can...

C++ 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;

enum Grade {
    F, D, C, B, A
};

Grade assignCourseGrade(double grade) {
    if(grade >= 90) {
        return A;
    } else if(grade >= 80) {
        return B;
    } else if(grade >= 70) {
        return C;
    } else if(grade >= 60) {
        return D;
    } else {
        return F;
    }
}

int main() {
    double grade;
    cout << "Enter grade[0-100]: ";
    cin >> grade;
    while (grade < 0 || grade > 100) {
        cout << "Error. Enter grade[0-100]: ";
        cin >> grade;
    }
    Grade letterGrade = assignCourseGrade(grade);
    switch (letterGrade) {
        case A:
            cout << "letter grade is A" << endl;
            break;
        case B:
            cout << "letter grade is B" << endl;
            break;
        case C:
            cout << "letter grade is C" << endl;
            break;
        case D:
            cout << "letter grade is D" << endl;
            break;
        case F:
            cout << "letter grade is F" << endl;
            break;
    }
    return 0;
}

Enter grade[0-100]: Error. Enter grade [0-100]: Error. Enter grade [0-100] letter grade is B 1,4 :.i.ix:»: <ly:aack: :..:: 〕多

Add a comment
Know the answer?
Add Answer to:
C++ Grades . Write a program that uses enum types to assign letter grades that can...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Java, write a program that teachers can use to enter and calculate grades of individual...

    Using Java, write a program that teachers can use to enter and calculate grades of individual students by utilizing an array, Scanner object, casting, and the print method. First, let the user choose the size for the integer array by using a Scanner object. The integer array will hold individual assignment grades of a fictional student. Next, use a loop to populate the integer array with individual grades. Make sure each individual grade entered by the user fills just one...

  • This C# program prints out a corresponding letter grade for a given mark. It uses a...

    This C# program prints out a corresponding letter grade for a given mark. It uses a method (called MarktoGrade) to determine the letter grade. MarktoGrade takes one integer call by value formal parameter (called mark) and returns a char value that is the letter grade. All of the input and output (except an error message) is done in Main. There is one syntax error in this program that you will need to fix before it will compile (the error is...

  • Write a program that computes the average of a set of grades. The user is prompted...

    Write a program that computes the average of a set of grades. The user is prompted the following: 1-Number of grades to be entered. 2-The value of the minimum grade. 3-The value of the maximum grade. Make sure to write input validation for the following: 1-The number of grades cannot be negative! In case it is 0, it means that user has no grades to enter. 2-Each entered grade should be a valid grade between the minimum and maximum values...

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • Write a JAVA program that prompts the user for student grades and displays the highest and...

    Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{   public static void main(String[] args){     Scanner input = new Scanner(System.in);     System.out.println("Enter as many student grades as you like. Enter a character to stop.");     double grade = input.nextDouble();     double minGrade = Double.MAX_VALUE;     double maxGrade = Double.MIN_VALUE;     while (Character.isDigit(grade)) {       if (grade == 0)...

  • C++ Write a program to calculate final grade in this class, for the scores given below...

    C++ Write a program to calculate final grade in this class, for the scores given below . Remember to exclude one lowest quiz score out of the 4 while initializing the array. Display final numeric score and letter grade. Use standard include <iostream> Implementation: Use arrays for quizzes, labs, projects and exams. Follow Sample Output for formatting. May use initialization lists for arrays. Weight distribution is as follows: Labs: 15% Projects: 20% Quizzes: 20% Exams: 25% Final Project: 20% Display...

  • In C Langage Write a grading program for a class with the following grading policies:- a. There are two quizzes, each gr...

    In C Langage Write a grading program for a class with the following grading policies:- a. There are two quizzes, each graded on the basis of 10 points. b. There is one midterm exam and one final exam, each graded on the basis of 100 points. c. The final exam counts for 50 percent of the grade, the midterm counts for 25 percent and the two quizzes together count for a total of 25 percent. Grading system is as follows:-...

  • Java Description You are given the task of reading a student’s name, semester letter grades, and...

    Java Description You are given the task of reading a student’s name, semester letter grades, and semester hours attempted from one file; calculating the semester GPA; and writing the student’s name and semester GPA to another file. GPA Calculation GPA = Total Quality Points / Hours Attempted Quality Points for each class = Grade Conversion Points * Hours Attempted The letter grades with corresponding point conversions is based upon the following table: Letter Grade Conversion Points A 4 points B...

  • Write a program to calculate your final grade in this class. Three(8) assignments have yet to...

    Write a program to calculate your final grade in this class. Three(8) assignments have yet to be graded: Quiz 7, Lab 7 and Final Project. Assume ungraded items receive a grade of 100 points. Remember to drop the lowest two quiz scores. Display final numeric score and letter grade. Implementation: Weight distribution is listed in canvas. Use arrays for quizzes, labs, projects and exams. You are allowed to use initialization lists for arrays. Use at least three (3) programmer defined...

  • Write a C++ program that computes student grades for an assignment as a percentage given each...

    Write a C++ program that computes student grades for an assignment as a percentage given each student's score and the total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath header file and displayed as a percentage. You must also display the floating-point result up to 5 decimal places. You must use at least 2 functions: one to print the last name of the student and another function to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT