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

***All arrays must be dynamic*** ***All interaction with the arrays must be done

ID: 3754428 • Letter: #

Question

***All arrays must be dynamic***

***All interaction with the arrays must be done via a pointer.***

***Use pointer arithmetic to traverse the arrays***

Create a program to grade a 20 question true/false test.

All input will come from a file

The first line of the file contains the answer key for the test

For example: TFFTFFTTTTFFTFTFTFTT

Every other entry in the file is the student ID, followed by a space, followed by the student’s responses.

Spaces in the student's answers indicate the student did not answer a question.

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 class has an unknown number of students.

Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points.

The output should be

the student’s ID,

the student's test score,

the student's letter grade.

Assume the following grade scale:

90%–100%, A;

80%– 89.99%, B;

70%–79.99%, C;

60%–69.99%, D;

< 59.99%, F.

All output should be written to a file and formatted properly.

Test scores should be rounded to two decimal places

Use a tab delimiter between student items (listed above)

Write each student's data on a separate line.

sample input file:

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

Explanation / Answer

#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';
    }
}