C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 8, Problem 6PE
Program Plan Intro

Program Plan:

  1. Include necessary header files: iostream, fstream, string, and iomanip.
  2. Define the main() function.
  3. Declare the necessary variables:
    1. An ifstream object to read the input file.
    2. A string variable to hold the correct test answers.
    3. A string variable to hold each line of student data.
    4. A string variable to hold the student ID.
    5. A string variable to hold the student's answers to the test.
    6. An integer variable to hold the student's score.
    7. An integer variable to hold the number of questions the student didn't answer.
    8. An integer variable to hold the total number of questions.
    9. A double variable to hold the percentage score.
    10. A char variable to hold the student's grade.
  4. Open the input file using the ifstream object.
  5. Read the first line of the file, which contains the correct test answers, and store them in the testAnswers variable.
  6. Use a loop to read each subsequent line of the file:
    1. Extract the student ID and answers from the line using the substr() method.
    2. Initialize the score and notAnswered variables to 0.
    3. Loop through each answer and compare it to the corresponding correct answer:
    4. If the answer is correct, increase the score by 2.
    5. If the answer is incorrect, decrease the score by 1.
    6. If the question wasn't answered, increment the notAnswered variable.
    7. Calculate the percentage score and determine the student's grade based on the percentage score.
    8. Output the student's ID, their answers, their score, their percentage score, and their grade to the console.
  7. Close the input file.
  8. End the main() function and the program.

Program Description:

To read student answers from a text file compare them to the correct answers and calculate the students' scores and grades.

Blurred answer
Students have asked these similar questions
We are considering the RSA encryption scheme. The involved numbers are small, so the communication is insecure.  Alice's public key (n,public_key) is (247,7). A code breaker manages to factories  247 = 13 x 19  Determine Alice's secret key. To solve the problem, you need not use the extended Euclid algorithm, but you may assume that her private key is one of the following numbers 31,35,55,59,77,89.
Consider the following Turing Machine (TM). Does the TM halt if it begins on the empty tape? If it halts, after how many steps? Does the TM halt if it begins on a tape that contains a single letter A followed by blanks? Justify your answer.
Pllleasassseee ssiiirrrr soolveee thissssss questionnnnnnn
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY