ABSOLUTE C++ -TEXT
ABSOLUTE C++ -TEXT
6th Edition
ISBN: 2810017515514
Author: SAVITCH
Publisher: PEARSON
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
(1 point) By dragging statements from the left column to the right column below, give a proof by induction of the following statement: an = = 9" - 1 is a solution to the recurrence relation an = 9an-18 with ao = : 0. The correct proof will use 8 of the statements below. Statements to choose from: Note that a₁ = 9a0 + 8. Now assume that P(n) is true for all n ≥ 0. Your Proof: Put chosen statements in order in this column and press the Submit Answers button. Let P(n) be the predicate, "a = 9″ – 1". απ = 90 − 1 = Note that Let P(n) be the predicate, "an 9" - 1 is a solution to the recurrence relation an = 9an-1 +8 with ao = 0." - Now assume that P(k + 1) is true. Thus P(k) is true for all k. Thus P(k+1) is true. Then ak+1 = 9ak +8, so P(k + 1) is true. = 1 − 1 = 0, as required. Then = 9k — 1. ak Now assume that P(k) is true for an arbitrary integer k ≥ 1. By the recurrence relation, we have ak+1 = ak+1 = = 9ak + 8 = 9(9k − 1) + 8 This simplifies to 9k+19+8 = 9k+1 − 1 Then 9k+1 − 1 = 9(9*…
Given the following request to an AI chatbot, which response is more accurate? (You should use Google to verify that the factual claims in each response are accurate.)   Prompt Is this true? The first recorded use of the phrase "when pigs fly" in print is in a 1616 play by Ben Jonson called "The Devil is an Ass," in which a character says, "When pigs fly, good-night!!" Response   Response A Response B Yes, that's true! The phrase "when pigs fly" indeed appears in Ben Jonson's 1616 play The Devil is an Ass and was said during the second act in a conversation between Fitzdottrel and Pug. The phrase was first used to express skepticism or disbelief, suggesting that something is as unlikely to happen as the fanciful idea of pigs flying. This usage is often cited as one of the earliest instances of the phrase in print.   The claim that the phrase "when pigs fly" was first recorded in Ben Jonson's 1616 play "The Devil is an Ass" is not accurate. There is no evidence from the…
This is for my Computer Organization & Assembly Language Class
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
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License