Redo this exercise in Programming assignment one using dynamic arrays/pointers:
ID: 3651718 • Letter: R
Question
Redo this exercise in Programming assignment one using dynamic arrays/pointers: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.
Here's my original file:
#include <iostream>
#include <fstream>
#include <string>
#include<iomanip>
using namespace std;
char grade(int);
int main()
{
char answers[21],response[21],sid[9];
int score,i;
char space;
double average;
ifstream infile;
//the input file
infile.open("input.txt");
//if no input file is found
if(infile.fail())
{ cout<<"file not found ";
system("pause");
return 1;
}
ofstream outFile;
outFile.open("output.txt");
infile.get(answers, 21);
infile>>sid;
while(infile)
{infile.get(space);
for(i=0;i<20;i++)
response[i]=' ';
response[20]='';
infile.get(response,21);
score = 0;
for(i=0;i<20; i++)
{
//if there is no answer
if(response[i]==' ')
score+=0;
//if it is a correct answer
else if(response[i]==answers[i])
score+=2;
//if it is a wrong answer
else
score--;
}
average = (score/40)*10;
//writing the output file
outFile<<sid<<" "<<setw(21)<<left<<response<<" "<<score<<" "<<grade((int)average)<<endl;
infile>>sid;
}
infile.close();
outFile.close();
cout<<"output file created successfully"<<endl;
system("pause");
return 0;
}
//function to find grade
char grade(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';
}
}
Again I need the same thing rewritten using dynamic arrays/pointers please. Thanks
Explanation / Answer
#include #include #include 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 key; file.ignore(100, " "); //processing student grades while(file.good()) { file >> id; file.ignore(); getline(file, student); file.ignore(100, " "); //comparing key and student answer for(i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.