I have a text file with 50 multiple choice answers of 10 students which I need t
ID: 3546382 • Letter: I
Question
I have a text file with 50 multiple choice answers of 10 students which I need to compare to an answer key in the same text file..
The format goes like this
<answer key>
<student name>
<his answers>
<student name>
<his answers>
and so forth...
how can I input the information in a text file into a data array in the program which will allow me to manipulate data and compare answers to give a grade to each student??
So far I am only able to add the answer key into a data array which is the first line of the text file.. I need to add strings for the name and add their respective answers into the program so I am able to compare them with the answer key..
NEED HELP PLEASE!!! with a code.
Explanation / Answer
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char input[100];
char name[5][100];
char answerkey[100];
char hisresponse[5][100];
int anscount[5]={0};
cout<<"Enter the name of the input file"<<endl;
cin>>input;
ifstream inputfile(input);
inputfile>>answerkey;
for(int i=0;i<5;i++)
{
inputfile>>name[i];
inputfile>>hisresponse[i];
}
for(int i=0;i<5;i++)
{
for(int j=0;j<50;j++)
{
if(hisresponse[i][j]==answerkey[j])
anscount[i]++;
}
cout<<name[i]<<" answered "<<anscount<<" answers correctly"<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.