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

Language: C++ exam.txt : Thank you in advance for the help!! :) For this lab you

ID: 3739881 • Letter: L

Question

Language: C++

exam.txt :

Thank you in advance for the help!! :)

For this lab you need to write a program to read in the data and store them into a 2-dimentional array, and use 1 function print the answers given by each student and use another function to analyze the answers. (If you don't remember how to read data from a file, see Lab #7 instruction.) The data file is in the file called exam.txt. It is provided to you and you need to copy it to wormulon. You should begin by opening the file with nano or another text editor and examining the format note that it contains the students' ids and answers to 10 questions for each of the students. In the main) function: *Read in the data from exam.txt and store the data to a 2-dimentional array *Ask user to enter the correct answers (For example: A B D CDACDB B), store the correct answers into another array *Pass the 2-dimentional array to a function to print the student ids and their 10 answers. Pass the 2-dimentional array, and the array holding correct answers to a function. In the function for printing students' ids and answers Print each student ID, and followed by 10 answers. For example Studentl A B D C DA C D B B Student2 A B C C DA CA B B Studen t3 A B D C D A C D C B In the function for grading the answers: Grade each student's answers by using the correct answers enter by the user, and print the score for each student. Keep track of the highest score, print it at the end. Keep track of the lowest score, print it at the end. *Calculate the average score, print it at the end. Sample output: Studentl score is 10 Student2 score is 8 Student3 score is9 the average score is 7.8 highest score is 10 lowest score is 3

Explanation / Answer

Solution:

Please save the .txt file where the code is saved, thanks :)

code:

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

# define SIZE 5 // number of students

// function declaration

void displayStudent(string student_score[][11]);

void gradeAnswer(string student_score[][11],string correct_ans[]);

int main() {

               ifstream fin("exam.txt"); // input file

               // if file can be opened

               if(fin.is_open())

               {

                              string students_ans[SIZE][11];

                              string correct_ans[10];

                              int st_no =0,ans_no=0;

                              // loop to read till the end of file

                              while(!fin.eof())

                              {

                                             fin>>students_ans[st_no][ans_no];

                                             if(ans_no == 10)

                                             {

                                                            ans_no=0;

                                                            st_no++;

                                             }else

                                                            ans_no++;

                              }

                              // input of correct answers

                              cout<<" Enter correct answers for the 10 questions : ";

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

                                             cin>>correct_ans[i];

                              displayStudent(students_ans);

                              gradeAnswer(students_ans,correct_ans);

               }else

                              cout<<" Unable to open file";

               fin.close(); // close the file

               return 0;

}

// function to display the details of students

void displayStudent(string student_score[][11])

{

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

               {

                              for(int j=0;j<11;j++)

                              {

                                             cout<<student_score[i][j]<<" ";

                              }

                              cout<<endl;

               }

}

//function to compute the grade of students and find and display the highest, lowest and average score

void gradeAnswer(string student_score[][11],string correct_ans[])

{

               int highest_score =0;

               int lowest_score =10;

               float avg_score;

               int total_score=0;

               int score;

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

               {

                              score =0;

                              for(int j=0;j<10;j++)

                              {

                                             if(student_score[i][j+1].compare(correct_ans[j]) == 0)

                                                            score++;

                              }

                              cout<<" "<<student_score[i][0]<<" score is "<<score;

                              if(score > highest_score)

                                             highest_score = score;

                              if(score < lowest_score)

                                             lowest_score = score;

                              total_score += score;

               }

               avg_score = (float)total_score/SIZE;

               cout<<" The average score is "<<fixed<<setprecision(2)<<avg_score;

               cout<<" Highest score is "<<highest_score;

               cout<<" Lowest score is "<<lowest_score;

}


I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)