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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.

 

I have it running correctly up until the last 2 student scores. Its not reading that they did not answer the last two questions and its giving the students credit for those answers.

CODE:

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

 

 

CENGAGE MINDTAP
Q Search this course
Programming Exercise 12-2
Tasks
>_ Terminal
Input
sandbox $ rm -f a.out
sandbox $
sandbox $
20
sandbox $ g++ -Wall -std=c++0x_main.
cpp
Output
sandbox $ ./a.out
Key TTFTFTTTETETFFTTETTE
ABC54102 T FTETETTTETTFITE TË 27 D
Key TTFTFTTTETETEFITETTE
DEF56278 TTETEIITETETFFITETTE 40 A
ABC54102 T ETETETTTEITETTE TE 27 D
ABC42366 TTETETTTETETFFITE 37 A
DEF56278 TTETFITTETETEFITEITE 40 A
ABC42366 TTETETITETETEEITE 37 A
ABC42586 TTTTEIII TETEFETE. 29 C
ABC42586 TIITEIII TETFFFTE. 29 C
sandbox $ |
20
Results e
Key TTFTFTTTFTETFFTTETTE
ABC54102 T FTETETTTETTETTE TE 27 D
DEF56278 TTFTFTTTFTFTFFTTETTE 40 A
ABC42366 TTFTFTTTFTFTFFTTF 34 B
ABC42586 TTTTETTT TETFFFTF 26 D
Expected Output O
Key TTFTFTTTFTFTFFTTFTTE
ABC54102 T FTETETTTETTETTE TË 27 D
DEF56278 TTFTFTTTFTFTFFTTETTE 40 A
ABC42366 TTFTFTTTFTFTFFTTF 34 B
ABC42586 TTTTFTTT TETFFFTF 26 D
(?
Run checks
A Submit 80%
!!
Transcribed Image Text:CENGAGE MINDTAP Q Search this course Programming Exercise 12-2 Tasks >_ Terminal Input sandbox $ rm -f a.out sandbox $ sandbox $ 20 sandbox $ g++ -Wall -std=c++0x_main. cpp Output sandbox $ ./a.out Key TTFTFTTTETETFFTTETTE ABC54102 T FTETETTTETTFITE TË 27 D Key TTFTFTTTETETEFITETTE DEF56278 TTETEIITETETFFITETTE 40 A ABC54102 T ETETETTTEITETTE TE 27 D ABC42366 TTETETTTETETFFITE 37 A DEF56278 TTETFITTETETEFITEITE 40 A ABC42366 TTETETITETETEEITE 37 A ABC42586 TTTTEIII TETEFETE. 29 C ABC42586 TIITEIII TETFFFTE. 29 C sandbox $ | 20 Results e Key TTFTFTTTFTETFFTTETTE ABC54102 T FTETETTTETTETTE TE 27 D DEF56278 TTFTFTTTFTFTFFTTETTE 40 A ABC42366 TTFTFTTTFTFTFFTTF 34 B ABC42586 TTTTETTT TETFFFTF 26 D Expected Output O Key TTFTFTTTFTFTFFTTFTTE ABC54102 T FTETETTTETTETTE TË 27 D DEF56278 TTFTFTTTFTFTFFTTETTE 40 A ABC42366 TTFTFTTTFTFTFFTTF 34 B ABC42586 TTTTFTTT TETFFFTF 26 D (? Run checks A Submit 80% !!
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education