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
Description: In a hypothetical class, students take two midterms and an optional final. If a student takes the final and gets in it a better score than the lowest of the two midterm scores, then the lowest midterm score would be replaced by the comprehensive final score. The overall score will then be calculated by averaging the three test scores. If the student does not take the optional final, the overall score is calculated using only the two midterm scores. Students' exam scores are included in the "Question1" tab in the attached worksheet. Empty data entries for the optional comprehensive final means that the student did not take the optional final. Tasks: Task 1: In Question1 _Module, code a function that requires midterm1 score, midterm2 score, and comprehensive final as inputs and calculate the overall score per the description above. Task 2: In Question1_Module, code a Sub that uses the function coded in task 1 to fill column 'I' of the worksheet and link this sub to the…
PROGRAMMING LANGUAGE: C++ ALSO PUT SCREENSHOTS WITH EVERY TASK. TASK 1 : A class of ten students took a quiz .The grades (integers are in range 0-100) for this quiz are available to you .Determine class average on quiz . TASK 2: Write c++ code that print summery of exam result and decide either student should have makeup class or not .If more then 30% of class fails in exam it’s mean they need a makeup class otherwise they don’t need any makeup class. For class strength take input from user  (Hint: take two variables pass and fail) TASK 3: write a c++  that will determine whether a department-store customer has exceeded the credit limit on the charge account .For each customer , following facts are available : Account number (an integer) Balance at beginning of month Total of all items charged by this customer this month Total of all credit applied to this customer’s account this month. Allowed credit limit You are required to use a while structure to input each of these facts ,…
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.
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