Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this is the test.dat this is the answer .dat I need help please with source code

ID: 3812318 • Letter: T

Question







this is the test.dat


this is the answer .dat
I need help please with source code and output

This exercise is designed to introduce you to arrays and atrings (i..., arrays of characters in C++ Suppose a students takes a 20 question examI each question five choices A,B,C, D,E), only one of which is correct. attempts For simplicity assume that every student responses to answer question i there are no blank students are "tests -dat", The responses put in a data file string eleven each of of followed by that characters long), followed by a blank long a typical responsaa string twenty characters record night 1ook 120-49-5322 EBADDE There is a second file called "answers. dat" which consists ot a single record, namely the corregt ansvers to the exam (a string twenty character long Thus this record might loak s CBEDBEBAECDDAEEBDEDE in which case the above student has answered question 1 correctly but blown question etc your job, as teaching assistant for the course, is to write a c++ program to read in the answers from the answers dat file and then loop through the tests dat" file and produce the following GRADE SUMMARY REPOR The example below ilmustrates class of size 23 of course you should gount as you read the response file

Explanation / Answer


#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
using namespace std;

int main(int argc, char* argv[])
{
  
ifstream file("answer.dat");
string ans;
while (file && getline(file, ans)){
if (ans.length() == 0)continue;
}
  
for (auto const& c : ans)
std::cout << c << endl;

int totalStudents = 0;   
  
cout << " Student-ID " << "Marks" << endl;
   ifstream file1("test.dat"); // pass file name as argment
   string linebuffer;

int options[20][5] = {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
  
   while (file1 && getline(file1, linebuffer)){
       if (linebuffer.length() == 0)continue;
string buf; // Have a buffer string
stringstream ss(linebuffer); // Insert the string into a stream

vector<string> tokens; // Create vector to hold our words
int marks = 0;
while (ss >> buf)
tokens.push_back(buf);
  
string sans = tokens.at(1);
for (int i=0;i<ans.length();i++){
if('A'==ans[i]){
options[i][0]++;
}
else if(ans[i]=='B'){
options[i][1]++;
}
else if(ans[i]=='C'){
options[i][2]++;
}
else if(ans[i]=='D'){
options[i][3]++;
}
else {
options[i][4]++;
}
  
if(ans[i]==sans[i]){
marks++;
// cout << "true"<<endl;
}
   }
  
   totalStudents++;
   // tokens.push_back(marks+"");
cout << " "<<tokens.at(0) <<" "<<marks<<endl;   
   }
  
   cout <<"Total number of students who took test:" << totalStudents <<endl;
   cout << " question Number " << " A " << " B " << " C " << " D " << " E " <<endl;
  
   // output each array element's value
for ( int i = 0; i < 20; i++ ){
int a = ans[i] - 65;
// cout << ans[i] << " "<< a;
cout <<" "<< i+1 << " ";
for ( int j = 0; j < 5; j++ ) {
if(j==a){
cout << options[i][j]<<"*"<<" ";
}
else{
cout << options[i][j]<<" ";
}
}
  
cout <<endl;
}

   return 0;
}