I need to write the following program in C++ and I have no idea what to do. I have read my book and looked online and don’t really know what to do. I cannot use arrays either. I was really hoping that someone could help me because that would be great!!!! THANKS!!! Here is the program I need to do:
You’ve been asked to write a program to grade a multiple choice exam. The exam has 20 questions, each answered with a letter in the range of ‘a’ through ‘f’. The data are stored on a file (exams.dat) where the first line is the key, consisting of a string of 20 characters. The remaining lines on the file are exam answers, and consist of a student ID number, a space, and a string of 20 characters. The program should read the key, then read each exam and output the ID number and score to file scores.dat. Erroneous input should result in an error message.
After that, just iterate through the vector/array and compare the answers. If an answer is too high, then return Invalid answers. If you reach the end of the answers before the end of the test, return Too few, and vice versa, return Too many. Then you can just use fstream again to create/open scores and put the data in.
Otherwise, if you are not familiar with vector etc as suggested above, you can use a single string to read the answers stream and check the length() of it to determine if it has too few or too many characters, like < 20 or > 20 to say too few or too many.
It would look like:
fs >> id >> answerString ;
where id a long integer and answerString is 'string' type.
And for checking each character, you either can use [] or at() function of 'string' object.
Check it out. Good luck :)