Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:31:49+00:00 2026-06-07T03:31:49+00:00

The following is the problem description: The history teacher at your school needs help

  • 0

The following is the problem description:

The history teacher at your school needs help in grading a True/False test.
The students’ IDs and test answers are stored in a file. The first entry in the
file contains answers to the test in the form:

TFFTFFTTTTFFTFTFTFTT

Every other entry in the file is the student ID, followed by a blank, followed
by the student’s responses. For example, the entry:

ABC54301 TFTFTFTT TFTFTFFTTFT

indicates that the student ID is ABC54301 and the answer to question 1 is
True, the answer to question 2 is False, and so on. This student did not
answer question 9. The exam has 20 questions, and the class has more than
150 students. Each correct answer is awarded two points, each wrong answer
gets one point deducted, and no answer gets zero points. 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, followed by the test grade.
Assume the following grade scale: 90%–100%, A; 80%–89.99%, B;
70%–79.99%, C; 60%–69.99%, D; and 0%–59.99%, F.

This is the program I have made:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
//declaring variables
ifstream file("grading.txt");
char key[21];
char id[9];
char student[21];
int score = 0, i;

//initializing arrays
for(i=0; i<21; i++)
{
    key[i]=0;
    student[i]=0;
}
for(i=0; i<9; i++)
    id[i]=0;

//processing the key
file >> key;
file.ignore(100, "\n");

//processing student grades
while(file.good())
{

    file >> id;
    file.ignore();
    getline(file, student);
    file.ignore(100, "\n");

    //comparing key and student answer
    for(i=0; i<21; i++)
    {
        if(strcmp(student[i], key[i])
            score += 2;
        else
            score -= 1;
    }

    //outputing student id, score and grade
    cout << "Student ID: " << id;
    cout << "Score: " << score;
    score = (score/(40))*100;
    if(score >= 90 && score <= 100)
        cout << "Grade: A" << endl << endl;
    else if(score >= 80 && score <= 89.99)
        cout << "Grade: B" << endl << endl;
    else if(score >= 70 && score <= 79.99)
        cout << "Grade: C" << endl << endl;
    else if(score >= 60 && score <= 69.99)
        cout << "Grade: D" << endl << endl;
    else if(score >= 0 && score <= 59.99)
        cout << "Grade: F" << endl << endl;
    else
        cout << "Invalid percentage" << endl;
}

//closing file
file.close();

return 0;
}

I seem to be getting the following compilation errors: http://pastebin.com/r0Y1xX8M (couldn’t edit the errors properly on here, sorry)

Help would be appreciated with the compile errors, and any other suggestions as to how to solve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:31:51+00:00Added an answer on June 7, 2026 at 3:31 am

    Your first problem is in

    file.ignore(100, "\n");
    

    I believe that you want to use '\n' with single quotes rather than double quotes. single quotes represents a character. double quotes represents an array or characters(a string)

    secondly, I believe that iostream contains a string class, which encapsulates the character array. I believe that getline uses that string class. For using character arrays, my personal preference is fscanf, but most of your code seems to be based around iostream, so changing your character arrays to strings might be the simplest change to make.

    also, your if(strcmp(student[i], key[i]) line is passing in characters instead of the character arrays. I believe that if(student[i] == key[i]) is what you want to do.

    your compilation errors tell you what line of code the error is on, so for the rest of them you can look at your code and think about the problem yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following is the problem description: let c[n] be the catalan number for n
Problem Description: Occassionally when debugging, I get the following error. I'm using visual studio
Given the following xml fragment: <Problems> <Problem> <File>file1</File> <Description>desc1</Description> </Problem> <Problem> <File>file1</File> <Description>desc2</Description> </Problem>
Following is my problem description A B C D 1 H1 H2 H3 H4
Problem description: I need to implement 2 classes like following: class A1 { common_method1();
Problem Description In my yacc parser grammar, I have the following rules and corresponding
Following class structure is given: class Job { String description; Collection<JobHistory> history; } class
Following problem: I want to render a news stream of short messages based on
The following problem happens on both Safari and Chrome, so probably a WebKit issue.
I have the following problem. I have embedded a map using Google Maps' API.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.