This exercise is designed to introduce you to arrays and strings (i.e., arrays o
ID: 3815686 • Letter: T
Question
This exercise is designed to introduce you to arrays and strings (i.e., arrays of characters) in C++. Suppose a class of students takes a 20-question multiple-choice exam; each question has five choices (A, B, C, D, E), only one of which is correct. For simplicity, we assume that every student attempts to answer every question, i.e., there are no "blank" responses. The students' responses are put in a data file "tests.dat", each record of which consists of a student id (a string eleven characters long), followed by a blank, followed by that student's 20 responses (a string twenty characters long). Thus a typical record might look like: There is a second file called "answers.dat" which consists of a single record, namely the correct answers to the exam (a string twenty characters long). Thus, this record might look like: in which case the above student has answered question 1 correctly, but blown question 2, etc. Your job, as teaching assistant for the course, is to write a C++ program to read in the correct answers from the "answers.dat" file and then loop through the "tests.dat" file and produce the following GRADE SUMMARY REPORT. (The example below illustrates a class of size 23? of course, you should count as .you read the student response file.)Explanation / Answer
Take in the name of student file from the user and answer file name from the user, then read each file character by character while storing characters in an array. Then compare both arrays to find the number of correct answers.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
cout<<"Answer File Name: ";
string answerFile;
cin>>answerFile;
cout<<"Student File Name";
string studentFile;
cin>>studentFile;
char ch, ch1;
char studentResponse[50];
char answers[20];
fstream ans(answerFile, fstream::in);
fstream stu(studentFile, fstream::in);
int i=0;
while(stu >> noskips >> ch)
{
studentResponse[i] = ch;
i++;
}
i=0;
while(ans >> noskips >> ch1)
{
answers[i] = ch1;
i++;
}
i=0;
int j = 11;
int count = 0;
while(j <= 31)
{
if(answers[i] == studentResponse[j])
{
count++;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.