Instructions Redo Programming Exercise 6 of Chapter 8 using dynamic arrays. The instructions have been posted for your convenience. 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 (note the empty space). 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. An example of the program is shown below: Processing Data Key: TTFTFTTTFTFTFFTTFTTF ABC54102 T FTFTFTTTFTTFTTF TF 27 D #include  #include  #include  #include #include using namespace std; char grade(double); int main(){ char *answer; char *response; char *sid; int score,i; double average; answer = new char[20]();

icon
Related questions
Question

Instructions

Redo Programming Exercise 6 of Chapter 8 using dynamic arrays. The instructions have been posted for your convenience.

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 (note the empty space). 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.

An example of the program is shown below:

Processing Data Key: TTFTFTTTFTFTFFTTFTTF ABC54102 T FTFTFTTTFTTFTTF TF 27 D

#include <iostream>
#include <fstream>
#include <string>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
char grade(double);


int main(){
char *answer;
char *response;
char *sid;
int score,i;
double average;

answer = new char[20]();
response = new char[20]();
sid = new char[8]();


ifstream infile;

infile.open("Ch12_Ex2Data.txt");
if(infile.fail())
{ cout<<"file not found \n";
return 1;
}

string ans;
getline(infile,ans);
for(int i=0;i<20;i++)answer[i]=ans[i];

string line;
cout<<"Key "<<answer<<endl;

while(getline(infile,line)){
   for(int i=0;i<8;i++)sid[i]=line[i];
     cout<<sid<<" ";
    for(int i=9;i<29;i++)response[i-9]=line[i];
    cout<<response<<" ";
    score = 0;
for(i=0;i<20; i++)
{
if(response[i]==' ')
score += 0;
else if(response[i]==answer[i])
score += 2;
else
score += -1;
}
cout<<score<<" ";
average = ((double)score/40.0)*100;
cout<<grade(average)<<endl;
}

delete[] answer;
delete[] response;
delete[] sid;
    return 0;
}

char grade(double average)
{

if(average>=90)return 'A';
else if(average>=80) return 'B';
else if(average>=70) return 'C';
else if(average>=60) return 'D';
else  return 'F';
}
 
Grading output
Input
20
Output
Key TTFTFTTTFTETEFTTETTE
ABC54102 T FTETETIIEIIEITE TF 27 D
DEF56278 TTFTETITETETEFTTETTE 40 A
ABC42366 TTFTETITETETFETTE 37 A
ABC42586 TTTTFTTT TETFFFTF 29 C
20
Results
Key TTFTFTTTFTFTFFTTETTE ABC54102 T FTETETTTETTETTE TF 27 D
DEF56278 TTETETTTETETFFTTFTTF 40 A ABC42366 TTFTFTTTFTFTFFTTF 34 B
ABC42586 TTTTFTTT TETFFFTF 26 D
Show Details
Transcribed Image Text:Grading output Input 20 Output Key TTFTFTTTFTETEFTTETTE ABC54102 T FTETETIIEIIEITE TF 27 D DEF56278 TTFTETITETETEFTTETTE 40 A ABC42366 TTFTETITETETFETTE 37 A ABC42586 TTTTFTTT TETFFFTF 29 C 20 Results Key TTFTFTTTFTFTFFTTETTE ABC54102 T FTETETTTETTETTE TF 27 D DEF56278 TTETETTTETETFFTTFTTF 40 A ABC42366 TTFTFTTTFTFTFFTTF 34 B ABC42586 TTTTFTTT TETFFFTF 26 D Show Details
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer