Grading papers

Hello I have a new question: I just started a 2nd level C++ class and we have an assignment. Grading quizzes:Write a program helps your instructor grade quizzes. The program will read a file containing a single student’s answers to a recently given quiz. It will compute the student’sgrade on the test as a percentage, and then print a report.answers.datYour program should read the file answers.dat. This file contains the name of the student who took the quiz, and his answers for each question. The answers file has the following format:

The student name is always the first line.A student name may or may not have last names. For example, both Elvis Presley and Cher took this class.

A quiz always has 11 questions. There is one answer per line. Each answer is one word and all lowercase.

The correct answers to the quiz questions were:1.C++2.for3.if4.variable5.function6.return7.array8.void9.reference10.main11.prototype


I'm not necessarily asking for the code, just some structure on what I need to do??????
You're going to input data from the file, so knowing the structure is important. First line is their name, so take in the whole line and save it as a string if needed.

Next, you'll take in every line after that and check them one at a time, like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
std::string input;
std::string answers[11] = { "C++", "for", "if", //etc...
for (int i = 1; i < 12; i++) //"i" represents the problem#
{
     std::getline(std::cin, input);
     if (input == answers[i])
     {
          //They have the Correct Answer
     }
     else
     {
          //They don't have the right answer
     }
}
that code unfortunately did not produce anything.... he wants us to do something like what this last student posted....

I did use an array to store the answer file. And created another array to store the correct answers. Then called to 3 functions. The first inputed the answer file into the first array. The second compared both arrays and created a message displaying each element and if it was incorrect. The third, compared the arrays and counted incorrect statements in the array and output a score.

You need to finish the code, this was just a skeleton. You need to make an ifstream and then replace "std::cin" with the name of the new stream.


I did use an array to store the answer file. And created another array to store the correct answers. Then called to 3 functions. The first inputed the answer file into the first array. The second compared both arrays and created a message displaying each element and if it was incorrect. The third, compared the arrays and counted incorrect statements in the array and output a score.

Is this what you did, or what the other student did? If you did this, what else do you need? What are you stuck on?
the paragraph attached was what the other student did. new stream?????

so when it runs it looks like this \/ \/ \/ \/

report for Elvis Presley
CORRECT ANS STUDENT ANS
C++ C++
for for
if if
variable variable
function function
return cheesy INCORRECT
array array
void robots INCORRECT
reference reference
main main
prototype prototype

QUIZ SCORE
81.82%
Press any key to continue...
Last edited on
1
2
3
4
5
6
7
8
9
#include <fstream> //For ifstream/ofstream

int main()
{
     std::string input;
     std::ifstream inFile;
     inFile.open("data.dat");
     inFile >> input;
}
so the professor wants us to put the code that you put in before this one ^^^ or something similar into the namespace section instead of the main function. so would I need to set up a function protype such as:

void gradeStudent(input, answers){

place code you first gave me (not word for word, but similar)

}

then create some function to actually calculate the grade ??????


then just call them in the main function?
I did use an array to store the answer file. And created another array to store the correct answers. Then called to 3 functions. The first inputed the answer file into the first array. The second compared both arrays and created a message displaying each element and if it was incorrect. The third, compared the arrays and counted incorrect statements in the array and output a score.

You'll make the string array as I showed at first, which will hold the answers. There will be another string you can use as an array to check at the end, or a regular string that you can grade while taking input from the file (take in a line, then check if it's the right answer, then take in the next line).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <fstream> //For ifstream/ofstream

bool checkAnswer(std::string input, std::string answers[], int i)
{
     //Check
     input == answers[i];

     return true or false;
}

void gradeStudent(std::string answers[])
{
     std::string input;
     std::ifstream inFile;
     inFile.open("data.dat");
     //Do inputs and loop
     for(int i = 0; i < answers.size(); i++)
     {
           inFile >> input;
           checkAnswer(input, answers, i); //Check
     }
}

int main()
{
     std::string answers[11] = { "C++", "for", "if", //etc...
     gradeStudent(answers);
}



Just some skeleton code that may needs to be altered, see what you can do with it.
Last edited on
ok I sorta get what you are going for the first box was creating the array with the correct answers....the second box was creating the read file, and the third one is comparing the input answer with the correct answer.

does it calculate and present the quiz grade?
does it calculate and present the quiz grade?

The code doesn't do much right now, you need add stuff to it. It seems you might be further behind than you should be.

I recommend using this website to get into C++ coding:
LearnCpp.com
Topic archived. No new replies allowed.