Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

the Computer Science department needs help in grading a True/False test. The stu

ID: 3626571 • Letter: T

Question

the Computer Science department 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 the answers to the test in the form:

TFFTFFTTTTTTFFTFTFTT


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 -1 point and no answer gets 0 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.

Test your program with the following input file:(what is inside the file)

TTFTFTTTFTFTFFTTFTTF
ABC54102 T FTFTFTTTFTTFTTF TF
DEF56278 TTFTFTTTFTFTFFTTFTTF
ABC42366 TTFTFTTTFTFTFFTTF
ABC42586 TTTTFTTT TFTFFFTF
LKJ81672    TTTFTFFTFFTTFTFTF
STD24151 TFTFTTTFTFTFFTTF

MY ANSWER: (So you get the idea. I have got most of the program finished but it has a few bugs that I can't figure out,so please just fixed my code )


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

const int Answers = 20;

char getGrade(int percent);

int main()
{
    char answers[Answers];
    char studentAnswers[Answers + 1];
    string studentNum;
    int i;

    ifstream inFile;
    inFile.open("testdata.txt");
    ofstream outFile;
    outFile.open("Output.txt");

   
    for (i = 0; i < Answers; i++)
    {
        inFile.get(answers[i]);
    }

    while (!inFile.eof())
    {
    int score = 0;
    double possiblePoints = 40.0;
    double percent = 0.0;

   
    inFile >> studentNum;

   
    inFile.get();

   
    for (i = 0; i < Answers; i++)
    {
        inFile.get(studentAnswers[i]);
    }



    for (i = 0; i < Answers; i++)
    {
        outFile << "Correct answer: " << answers[i] << endl;
        outFile << "Student answer: " << studentAnswers[i] << endl;
        outFile << " " << endl;
        if (answers[i] == studentAnswers[i])
        {
            score = score + 2;
        }
        else if (answers[i] = ' ')
        {
            score = score;
        }
        else if (answers[i] != studentAnswers[i])
        {
            score = score - 1;
        }
    }

   
    outFile << "Student: " << studentNum << endl;
    outFile << "Answers: ";
    for (i = 0; i < Answers+1; i++)
    {
        outFile << studentAnswers[i];
    }
    outFile << "Test Score: " << score << "40" << endl;
    percent = (score / possiblePoints) * 100;
    outFile << "Percent: " << percent << "%" << endl;
    outFile << "Grade: " << getGrade(percent) << endl;
   
    }

    inFile.close();
    outFile.close();

    return 0;
}


char getGrade(int percent)
{   
    if (percent >= 90)
        return 'A';
    else if (percent >= 80)
        return 'B';
    else if (percent >= 70)
        return 'C';
    else if (percent >= 60)
        return 'D';
    else
        return 'F';
}


Explanation / Answer

please rate - thanks

#include <iostream>
#include <fstream>
#include <string>
#include<iomanip>
using namespace std;
char letter(int);
int main()
{char key[21],answer[21],id[9];
int score,i;
char space;
ifstream in;
in.open("input.txt");           //open file
if(in.fail())             //is it ok?
    { cout<<"file did not open please check it ";
     system("pause");
     return 1;
        }
ofstream outFile;
outFile.open("Output.txt");
in.get(key, 21);
in>>id;

while(in)
    {in.get(space);
    for(i=0;i<20;i++)
       answer[i]=' ';
     answer[20]='';
    in.get(answer,21);
       
   
   score = 0;       
     for(i=0;i<20; i++)
       {if(answer[i]==' ')
           score+=0;
       else if(answer[i]==key[i])
          score+=2;
        else
          score--;
          }
       outFile<<id<<" "<<setw(21)<<left<<answer<<" "<<score<<" "<<letter((int)((double)score/40.*10.))<<endl;
      in>>id;
      }
in.close();
outFile.close();

    return 0;
}

char letter(int score)
{switch(score)
    {case 10:
     case 9: return 'A';
     case 8: return 'B';
     case 7: return 'C';
     case 6: return 'D';
     default: return 'F';
    }
}