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

<p>Write a C++ program to grade multiple-choice, including True/False, questions

ID: 3641514 • Letter: #

Question

<p>Write a C++ program to grade multiple-choice, including True/False, questions for an exam given in a class. A class may have one or more sections. The answer keys are the same for all sections of a class for one exam, but the number of students is normally different for different sections. Your program will be used for different classes and/or different exams, and the number of questions will be different. But any exam can have at most 30 questions. The answer key and a student's answer to a question could be a digit, between 1 and 5 (inclusive), or a character among A, B, C, D, E, F and T, or lower case equivalent.<br /><br />Input Data<br />The first value in the input file is the number of questions of the exam.<br />The second line is the answer keys without spaces between any two answers.<br />The next line is the number of sections, followed by data for all sections.<br />The data for a section begins with the number of students, followed by students' data.<br />The data for each student is on a separate line, beginning with the answers from the student followed by the student's last name.<br />As the key answers, there is no space between any two answers.<br />The student's last name comes after his/her last answer without any spaces between.<br />Any student's last name has at most 15 characters.<br />Sample input is given later.<br />You can assume the input data are correct and do not check for invalid values.<br /><br /><br /><br />Output Data<br />For each student, last name, number of correct answers, and Pass or Fail. A student passes an exam if the number of correct answers is 60% or better of total number of questions, and fails otherwise.<br />For each section, the total number of students and the number of students who passed the exam.<br />For the entire class, the number of sections, the total number of students and the number of students who passed the exam.<br />See sample output later for the exact output format.<br /><br /><span><strong>The following requirements must be followed:</strong></span><br /><span><strong>You must NOT use structs or 2D array.&#160;</strong></span><br /><span><strong>You must use the following functions in your program.&#160;</strong></span><br /><span><strong> // The function reads in numQuestions answers into array answers.</strong></span><br /><span><strong> // Parameters: (out, in)</strong></span><br /><span><strong> void ReadAnswers(char answers[], int numQuestions);</strong></span><br /><br /><span><strong> // The function compares a student's answers against the answer </strong></span><br /><span><strong> // keys and passes back the number of correct answers and </strong></span><br /><span><strong> // whether the student passed the exam.</strong></span><br /><span><strong> // Parameters: (in, in, in, out, out)</strong></span><br /><span><strong> void ProcessAnswer(const char keys[], const char answers[], int numQuestion, int&amp; correct, bool&amp; pass);</strong></span><br /><span><strong>You must use the same function ReadAnswers() to read the answer keys and the answers for each student. You will lose 2 points if different functions are used.</strong></span><br /><span><strong>You must use for loops to process all sections of the class, all students of a section, and all answers of a student. No while loops are allowed on this assignment. You will lose 2 points for each while loop used in your program.</strong></span><br /><br /><br />Your main() function could be like the following:<br /> Read number of questions<br /> Read and store the answer keys<br /> Read number of sections <br /> For each section<br /> Process all students' answers <br /> Update class results<br /> Display results for the section<br /> Display results for the entire class <br />You can also use function toupper(x) to convert a character to upper case. You need to include header file to use the function.</p>
<p><strong>Sample Input&#160;</strong></p>
<p>10<br />t2ft5Ttfft<br />2<br />4<br />T2Ft4ttftTHockney<br />t1fF5ffttfHill<br />f3ft5fTTftLongwood<br />t4Tf5TFTFTSharp<br />5<br />T2Ft5ttffTHockney<br />t2ft4ttfFtHill<br />f2ft4tTTftLongwood<br />t2Tf5FFTFTSharp<br />t2fT5FFTtTQuick</p>
<p><strong>Sample Output&#160;</strong></p>
<p>Name Correct Answers PASS/FAIL<br />--------------- --------------- ---------<br /> Hockney 8 PASS<br /> Hill 3 FAIL<br /> Longwood 6 PASS<br /> Sharp 5 FAIL<br /><br />2 out of 4 students of section 1 passed the exam.<br /><br /> Name Correct Answers PASS/FAIL<br />--------------- --------------- ---------<br /> Hockney 10 PASS<br /> Hill 9 PASS<br /> Longwood 7 PASS<br /> Sharp 5 FAIL<br /> Quick 6 PASS<br /><br />4 out of 5 students of section 2 passed the exam.<br />There are 2 sections, and 6 out of 9 students passed the exam.</p>

Explanation / Answer

#include <iostream>
#include <cctype>
using namespace std;
void ReadAnswers(char answers[],int numQuestions)
{
for (int answer = 0; answer < numQuestions; answer++)
{
cin >> answers[answer];
if (!isdigit(answers[answer]) && !isupper(answers[answer]))
answers[answer] = toupper(answers[answer]);
}
}
void ProcessAnswers(const char key[], const char answers[], int numQuestions, int &correct, bool &pass)
{
for (int i = 0; i < numQuestions; i++)
{
if (key[i] == answers[i])
correct = correct + 1;
}
double score = 100 * (correct/numQuestions);
if(score >= 60.0)
pass = true;
else
pass = false;
}
void ReadLastName(char name[], int &length)
{
char c;
int i;
for(i = 0; i < 15; i++)
{
if((c = cin.peek()) == ' ')
{
name[i] = ' ';
break;
}
cin.get(c);
name[i] = c;
}
length = i;
}

void PrintName(char* name)
{
for (int i = 0; name[i] != ' '; i++)
cout << name[i];
cout << endl << endl;
}
int main()

{
//Input number of questions
//Input number of sections
//for each section
//Read in answer key
//For each student
//Read in student answers
//Read in student's last name
//Output last name, num correct, and pass or fail status of each student

int numQuestions, numSections, nameLength; //num of questions and sections, length of student's last name
char answerKey[30], numStudents[30]; // the answers for the exam; num of students in each section
char studentName[15], studentAnswers[30]; //name of student; student's answers for exam
char* student_Name[30];
int numCorrect[30]; //num of qestions correct for each stduent(up to 30)
bool passed[30]; //pass or fail status for each stduent(up to 30)
int numSectionPassed[30]; //the num of stduents passed for each section
cout << "Input number of questions: ";
cin >> numQuestions;
cout << "Input answer key: ";
ReadAnswers(answerKey,numQuestions);
cout << "Input number of sections: ";
cin >> numSections;
for(int i = 0; i < numSections; i++)
{
cout << "Input number of students for section " << i << ": ";
cin >> numStudents[i];
cout << "Num of Students: " << numStudents[i] << endl;
//Having trouble with this loop; not enough time to figure it out
for(int j = 0; j < numStudents[i]; j++)
{
cout << "Input data for student " << j << endl;
ReadAnswers(studentAnswers,numQuestions);
ReadLastName(studentName,nameLength);
// student_Name[j] = &studentName[0];
ProcessAnswers(answerKey,studentAnswers,numQuestions,numCorrect[j],passed[j]);
if(passed[j] = true)
numSectionPassed[i] = numSectionPassed[i] + 1;
cout << "J--" << j << endl;
}

}
int student = 0, section = 0;
for(section; section < numSections; section++)
{
cout << "--------------------------------- ";
cout << "Name Correct Answers Pass/Fail ";

for(student; student < numStudents[section]; student++)
{
PrintName(student_Name[student]);
cout << " " << numCorrect[student] << " ";
if(passed[student] == true)
cout << "Passed";
else
cout << "Falied";
}
cout << endl;
cout << numSectionPassed[section] << " out of " << numStudents[section]
<< " of section " << section << " passed the exam." << endl;
}




return 0;
}

This code does not fully work. I ran out of time.
Maybe you can modify this code to make it work. Or, you can just use it to give you an idea of what the program could look like.

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