Absolute C++
Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
bartleby

Videos

Textbook Question
Book Icon
Chapter 6, Problem 1PP

Write a grading program for a class with the following grading policies:

  1. There are two quizzes, each graded on the basis of 10 points.
  2. There is one midterm exam and one final exam, each graded on the basis of 100 points.
  3. The final exam counts for 50 % of the grade, the midterm counts for 25 % , and the two quizzes together count for a total of 25 % . (Do not forget to normalize the quiz scores. They should be converted to a percentage before they are aver-aged in.)

Any grade of 90 or more is an A, any grade of 80 or more (but less than 90) is a B, any grade of 70 or more (but less than 80) is a C, any grade of 60 or more (but less than 70) is a D, and any grade below 60 is an F. The program will read in the student’s scores and output the student’s record, which consists of two quiz and two exam scores as well as the student’s average numeric score for the entire course and final letter grade. Define and use a structure for the student record.

Expert Solution & Answer
Check Mark
Program Plan Intro

Program Plan:

1. The following variables are used in the program.

  • quiz1 variable of integer data type is used to store the score of quiz 1.
  • quiz2variable of integer data type is used to store the score of quiz 2.
  • midtermvariable of integer data type is used to store the score of midterm exam.
  • final variable of integer data type is used to store the score of final exam.
  • grade variable to character data type is used to store the final grade.
  • Student struct to store all the scores of the student.

2. The following method is used in the program:

calculate() method to calculate the final score of the student.

Program Description:

In this program, user input is taken for all the 4 scores. These scores are used to calculate the final score. The final grade is decided based on the final score. The scores of a student are stored in a struct.

Explanation of Solution

#include <iostream>

using namespace std;

// structure to hold scores of a student 
struct Student
{
    int quiz1, quiz2;
    int midterm, final;
};

// method to calculate the final score of a student 
// takes the structure as a parameter
float calculate(Student& s)
{
    int quiz;
    float total;

    quiz = s.quiz1 + s.quiz2;

    total = (s.final/2) + (s.midterm/4) + (quiz/4)*5;

    return total;
}


// main method for testing of the code 
int main()
{
    // variable of type struct created
    Student s;

    // user input taken for all 4 scores 
    std::cout << "Enter the score of quiz 1: ";
    std::cin >> s.quiz1;

    std::cout << "Enter the score of quiz 2: ";
    std::cin >> s.quiz2;

    std::cout << "Enter the score of midterm exam: ";
    std::cin >> s.midterm;

    std::cout << "Enter the score of final exam: ";
    std::cin >> s.final;

    // final score collected from calculate() method
    float a = calculate(s);
    char grade;

    // calculating grade based on final score 
    if(a>=90)
        grade = 'A';
    if(a<90 && a>=80)
        grade = 'B';
    if(a<80 && a>=70)
        grade = 'C';
    if(a<70 && a>=60)
        grade = 'D';
    if(a<60)
        grade = 'F';

    // displaying student result  
    std::cout << "\n=== STUDENT RECORD ===" << std::endl;
    std::cout << "Quiz 1: " << s.quiz1 << std::endl;
    std::cout << "Quiz 2: " << s.quiz2 << std::endl;
    std::cout << "Midterm exam: " << s.midterm << std::endl;
    std::cout << "Final exam: " << s.final << std::endl;
    std::cout << "Average score: " << a << std::endl;
    std::cout << "Final grade: " <<grade << std::endl;

    return 0;
}

Sample output:

Enter the score of quiz 1: 6
Enter the score of quiz 2: 5
Enter the score of midterm exam: 60
Enter the score of final exam: 75

=== STUDENT RECORD ===
Quiz 1: 6
Quiz 2: 5
Midterm exam: 60
Final exam: 75
Average score: 62
Final grade: D

Explanation:

In the above program, a struct is created having 4 integer data members to store all the 4 scores. In the main() function, user input is taken for all the 4 scores. These scores are stored in the struct data members. The struct is passed as a parameter to the calculate() function. The calculate() function calculates the final score and returns the final score. The final score is collected from the calculate() function inside main() function. Using multiple if statements, the final grade is decided based on the final score. The 4 scores along with the final score and the final grade of the student are displayed.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Do not use regular expressions in your solution for this exercise. Write a program that checks to see if an input password is valid or not. In this exercise, a valid password has the following characteristics:  It contains at least eight characters.  It contains at most 12 characters.  It contains only alphabetic characters, digits and the underscore (‘_’) character. It does not start with a digit.  It has a mix of upper-case and lower-case characters.    Your class must contain the following method: public static String checkPassword(String input) This method receives a possible password as input and returns only the String“OK” if the password is valid. If the password is not valid then you can return the reason(s) for that as the return value. This is not a part of the requirements, however, and you don’t need to do that. You can simply return null for an invalid password.
Please written by computer source Python asignment For this assignment you are to implement a program that computes the salaries for a set of employees. The program should begin by asking the user if there is an employee for which a salary is to be computed. If the user responds in the affirmative by inputting “yes” (in lowercase) the program should prompt the user to input the employee’s hourly pay rate and the number of hours worked by that employee. There should be a separate prompt for each of these two values. Once this data has been input, the program should compute the employee’s salary as the product of the hourly pay rate and the number of hours worked for the first 40 hours worked (i.e., straight time), plus time-and-a-half for those hours exceeding 40, and then output the result in a user-friendly format. Once the salary for the employee has been computed and output, the program should then ask the user if a salary should be computed for another employee. If again the user…
Code and output
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License