C   Programming: From Problem Analysis to Program Design
C Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9780357238547
Author: D. S. Malik
Publisher: Cengage Limited
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
The Apgar Medical group keeps a patient file for each doctor in the office. Each record contains the patient's first and last name, home address, and birth year. The records are sorted in ascending birth year order. Write a program so that display a count of the number of patients born each year John Hanson, 23 Elm, 1927Mary Locust, 476 Maple, 1950Susan Monroe, 512 Peachtree, 1957Carol Fortune, 2819 Locust, 1960James Fortune, 2819 Locust, 1963Lawrence Fish, 12 Elm, 1968Janice Weiss, 234 Birch, 1971Henry Garza, 199 Second, 1973Kimberly Swanson, 310 Appletree, 1980Louis Claude, 2716 Third, 1981Jill Fox, 12 Oak, 1985Opal Reynolds, 78 County Line, 1987Francis Dumas, 67 Fourth, 1992Madison Conroy, 23 Fifth, 1996Daniel Moy, 100 Sunset, 1987
Java Problem The teacher at a school needs help grading an exam with a number of True/False questions. The students’ IDs and test answers are stored in a file. The first entry of the file contains the answer to the test in the form: TTFTFTTTFTFTFFTTFTTF Every other entry in the file is the student’s ID, followed by a blank, followed by the students’ response. For instance, the entry: ABC54102 T FTFTFTTTFTTFTTF TF The student’s ID is ABC54102, answer to question 1 is True, the answer to question 3 is False. Also, the student did not answer question 2 and question 18. The exam has 20 questions. Here is the grading policy: each correct answer is awarded two points, each wrong answer get -1 point, and no answer gets 0 point. Write a program that processes the test data. The output should be the student’s ID, followed by the answers, followed by the test score (total points), followed by the test grade. Assume the following grade scale will be used: 90%-100%, A; 80%-89.99%, B; 70%-79.99%,…
Finish this program from the code posted below! Note: There should be two files Main.py and Contact.py You will implement the edit_contact function. In the function, do the following: Ask the user to enter the name of the contact they want to edit. If the contact exists, in a loop, give them the following choices  Remove one of the phone numbers from that Contact. Add a phone number to that Contact. Change that Contact's email address. Change that Contact's name (if they do this, you will have to remove the key/value pair from the dictionary and re-add it, since the key is the contact’s name. Use the dictionary's pop method for this!) Stop editing the Contact Once the user is finished making changes to the Contact, the function should return. Code:from Contact import Contactimport pickledef load_contacts():""" Unpickle the data on mydata.dat and save it to a dictionaryReturn an empty dictionary if the file doesn't exist """try:with open("mydata.dat", 'rb') as file:return…
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 Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
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
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