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

This exercise is designed to introduce you to arrays and atringa (., arrays of c

ID: 3699847 • Letter: T

Question

This exercise is designed to introduce you to arrays and atringa (., arrays of characters) in+ Suppose a class of students takes a 20-question ultiple-choice exam: each question has five choices (A,B,C.D,E), only one of which is correct. For siaplicity, e assune that every student attempts to answer every question, i.e., there are no "Dank" are put in a data file "tests.dat", each record of which consists of a student id (a string eleven characters long), folloved by a blank, folloved by The students that student's 20 responses (a string twenty characters long) Thus a typical record ight look like: There is a second file called"ansvers.dat" which consists of a singla record, nanely the correct ansvera to the exan (a string twenty characters long).Thus,this record Bight look likes in which case the above student has ansvered question 1 correctly, but blom question 2, eto Your Job, as teaching assistant for the course, is to vrite s C++ progran to read in the correct ansvers from the "answers.dat file and then loop through the "cests.dat file and tollowing GRADE SUMMARY REPORT. (The exanple below class of size 23 of course, you should count as you read the student response tile scudent-4 aumber correct page 2 430-52-6192 12-82-5225 20-49-5322 456-65-3211 990-45-0978 24-98-5445 12-34-3443 35-56-8790 52-23-5675 76-45-5454 67-71-930 45-54-7034 55-12-2341 19 sane order as in the "tests.dat" file, i.e., no rearranging

Explanation / Answer

/* C++ program to read student response and correct answers from 2 data files and display a

summary report of the number of correct answers by each student and frequency of options for each quuestions

*/

#include <iostream>

#include <iomanip>

#include <stdlib.h>

#include <fstream>

using namespace std;

int main() {

               ifstream studIn("tests.dat");

               ifstream answers("answers.dat");

               int questions = 20,students =0,correct =0;

               int choiceA[20], choiceB[20],choiceC[20],choiceD[20],choiceE[20];

               string correctAnswers; // string containing the correct answers for all questions

               string studentID,studentResponse; // string containing studentID and student response for all questions

               // array containing the frequency of options selected for each questions

               for(int i=0;i<questions;i++)

               {

                              choiceA[i]=0;

                              choiceB[i]=0;

                              choiceC[i]=0;

                              choiceD[i]=0;

                              choiceE[i]=0;

               }

               // check if both file can be read

               if(studIn.is_open() && answers.is_open())

               {

                              //read the correct answers file and store it in correctAnswers;

                              while(!answers.eof())

                              {

                                             answers>>correctAnswers;

                              }

                              //read the tests.dat file , for the response of each student

                              cout<<" "<<setw(20)<<"student-id"<<setw(20)<<"number correct "<<endl;

                              while(!studIn.eof())

                              {

                                             correct=0;

                                             studIn>>studentID>>studentResponse;

                                             students++;

                                             // loop over the student response and update the parameters

                                             for(int i=0;i<studentResponse.length();i++)

                                             {

                                                            if(toupper(studentResponse.at(i)) == toupper(correctAnswers.at(i)))

                                                                           correct++;

                                                            if(toupper(studentResponse.at(i))== 'A')

                                                                           choiceA[i]++;

                                                            else if(toupper(studentResponse.at(i))== 'B')

                                                                           choiceB[i]++;

                                                            else if(toupper(studentResponse.at(i))== 'C')

                                                                           choiceC[i]++;

                                                            else if(toupper(studentResponse.at(i))== 'D')

                                                                           choiceD[i]++;

                                                            else

                                                                           choiceE[i]++;

                                             }

                                             // display the student id and number of correct answers

                                             cout<<" "<<setw(20)<<studentID<<setw(18)<<correct<<endl;

                              }

                              cout<<" Number of students taking exam : "<<students<<endl;

                              // loop to display the question number and frequency of responses for each option

                              cout<<" "<<setw(20)<<"question"<<setw(10)<<"A"<<setw(10)<<"B"<<setw(10)<<"C"<<setw(10)<<"D"<<setw(10)<<"E"<<endl;

                              for(int i=0;i<questions;i++)

                              {

                                             cout<<" "<<setw(20)<<(i+1);

                                             if(correctAnswers.at(i) =='A')

                                                            cout<<setw(10)<<choiceA[i]<<"*";

                                             else

                                                            cout<<setw(10)<<choiceA[i]<<" ";

                                             if(correctAnswers.at(i) =='B')

                                                            cout<<setw(10)<<choiceB[i]<<"*";

                                             else

                                                            cout<<setw(10)<<choiceB[i]<<" ";

                                             if(correctAnswers.at(i) =='C')

                                                            cout<<setw(10)<<choiceC[i]<<"*";

                                             else

                                                            cout<<setw(10)<<choiceC[i]<<" ";

                                             if(correctAnswers.at(i) =='D')

                                                            cout<<setw(10)<<choiceD[i]<<"*";

                                             else

                                                            cout<<setw(10)<<choiceD[i]<<" ";

                                             if(correctAnswers.at(i) =='E')

                                                            cout<<setw(10)<<choiceE[i]<<"*";

                                             else

                                                            cout<<setw(10)<<choiceE[i]<<" ";

                              }

               }else

                              cout<<" Unable to open one/both input files";

               // close the files

               studIn.close();

               answers.close();

               return 0;

}

// end of program

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote