Drivers License Program Help.

I got assigned to write a program based off this description:
"The local Driver's License Office has asked you to write a program that grades the written
portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the
correct answers:
1. B 6. A 11. B 16. C
2. D 7. B 12. C 17. C
3. A 8. A 13. D 18. D
4. A 9. C 14. A 19. D
5. C 10. D 15. D 20. A"

The book describes that I need to create a class called "TestGrader". The class will have an answers array, which holds the 20 correct answers. I need two public member functions that enable the user to interact with the class: setKey and grade. The setKey function receives a 20-char string holding the correct answers and copies the information into its answers array. The grade function recieves a 20-char array holding the test takers answers and compares each of their answers to the correct one. The test taker must correctly answer 15 or more to pass the exam. After 'grading' the exam, the grade function should create and return the user a string that includes the following information:

-a message indicating whether the applicant passed or failed the exam
-the number of right answers and the number of wrong answers
-a list of the question numbers for all incorrectly answered questions

I believe then it is describing main. The book says the client program that creates and uses a TestGrader object should first make a single call to setKey, passing it a string containing the 20 correct answers. Once this is done it should allow the test takers 20 answers to be entered, making sure only A-D are accepted, and store them in a 20-char array. Then it should call the grade function to grade the exam and should display the string the function returns. The program should loop to allow additional test to be entered and graded until the user indicates a desire to quit.

This is my second semester taking a programming class however I still feel like I'm a horrible programmer. I can't really wrap my head around array's, classes and loops in this situation. My program is incomplete but any help/revisions would be greatly appreciated.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>

using namespace std;

const int NUM_QUESTIONS = 20; 
//We need to create a class that will have an answers array of 20 
//characters, which holds the corrrect test answers.
//The class will have two public member functions, setKey and grade.
class TestGrader
{
private:
	char answerKey[NUM_QUESTIONS];
	char userAnswers[NUM_QUESTIONS];
public: 
	
	void setKey(char correctanswers[NUM_QUESTIONS])
	{
		for (int x = 0; x < NUM_QUESTIONS; x++)
		{
			correctanswers[x] == answerKey[x];
		}

	}
	bool grade(char answers)
	{
		if (toupper(answers) != 'A' && toupper(answers) != 'B' && toupper(answers) != 'C' &&
			toupper(answers) != 'D' &&)
		{
			cout << "Please enter a valid answer" << endl;
			return false;
		}
};

int main()
{

	TestGrader grader1;
	int correctAnswers;

	char answerKey[20] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C',
		'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A' };
	char userAnswers[NUM_QUESTIONS];


	for (int i = 0; i < NUM_QUESTIONS; i++)
	{
		do
		{
			cout << "Enter your answer for question #" << i + 1 << " ";
			cin >> userAnswers[i];
		} while (grader1.grade(userAnswers));

		grader1.setKey(answerKey)
		
	} 




	







	return;
}
Topic archived. No new replies allowed.