working quiz program

hey guys I recently made a quiz program to make a quiz(duh) for school and I figured I would share the code with you guys. Its an class so read this first:
http://www.cplusplus.com/doc/tutorial/classes/
Some basic instructions for how to use it are at the end. If you need any more help just post.
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <string>
using namespace std;

//dont bother with how it works ill tell you at the end
//todo: make input a string, make constructor usefull for something, add more error handling
class quiz
{
private:
	//how many questions
	int hmq;
	char answer [50];
	string question [50];
	//plus or minus
	// prints diferenrnt mesages if its positive than if its minus
	int pom;
	string plus;
	string minus;

public:
	quiz()
	{
		pom = 0;
	}
	void set_pom_answers(string pluss, string minuss)
{
	 plus = pluss;
	 minus = minuss;
}
	void set_hmq(int hmqq)
{
		hmq = hmqq;
}
//qn = question number ca = correct answer q = question
	void set_q_a(int qn, string q, char ca)
{
	question[qn - 1] = q;
	answer[qn - 1] = ca;
}
void run_quiz()
{
	char ans;
	for(int i = 0; i < hmq; i++)
	{
		cout << question[i] << ": ";
		cin >> ans;
		if(ans == answer[i])
		{
			cout << "Correct! good for you!" << endl;
			pom = pom + 1;
		}
		else
		{
			cout << "Wrong. :(" << endl;
			pom = pom - 1;
		}
		system("pause");
		system("cls");
	}
	if(pom >= 0)
	{
		cout << plus << endl;
		cout << "your score was " << pom << endl;
	}
	else if(pom < 0)
	{
		cout << minus << endl;
		cout << "your score was " << pom << endl;
	}
	else
	{
		cout << "input not recognised" << endl;
	}
	system("pause");
		}

};
/*
how to use the above class:
to set how many questions you want type: set_hmq(#) where # = the amount of questions
to set the questions and right answers type: void set_q_a(#1, #2, #3) where #1 is the question number(remember 1 is question 1 not 0) 
#2 is the question itself(a string) 
#3 is the right answer(its a char)
to set the end-quiz message type: set_pom_answers(#1, #2) where #1 is the message you get if you get the most questions right
#2 is the one you get if you get the most wrong
to start the quiz type: run_quiz()
there you go your own easy to set up quiz! :)
50 questions max
*/

remember I threw this together really quick so it's not completely finished. I did not even bother commenting correctly.
my 10 question quiz on healthy living looked like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "class.h"

int main()
{
	quiz healthy_eating;
	healthy_eating.set_hmq(10);
	healthy_eating.set_pom_answers("You are foodsmart.", "You are not foodsmart.");
	healthy_eating.set_q_a(1, "Almonds are a protein alternative? [t]rue, [f]alse", 't');
	healthy_eating.set_q_a(2, "Spinach is a good source of iron? [t]rue, [f]alse", 't');
	healthy_eating.set_q_a(3, "Soy is a healthy choice for baby's? [t]rue, [f]alse", 'f');
	healthy_eating.set_q_a(4, "Chicken nuggets are healthier than sawdust? [t]rue, [f]alse", 'f');
	healthy_eating.set_q_a(5, "Normal salad dressing is healthier than fat free? [t]rue, [f]alse", 't');
	healthy_eating.set_q_a(6, "Feta cheese is non-fatty? [t]rue, [f]alse", 'f');
	healthy_eating.set_q_a(7, "Skipping breakfast is a good way to lose weight? [t]rue, [f]alse", 'f');
	healthy_eating.set_q_a(8, "Orange juice is a huge source of vitamin E? [t]rue, [f]alse", 'f');
	healthy_eating.set_q_a(9, "Milk is a good source of vitamin D? [t]rue, [f]alse", 't');
	healthy_eating.set_q_a(10, "A good breakfast is important for your daily routine? [t]rue, [f]alse", 't');
	healthy_eating.run_quiz();
	return 0;
}

Forgot to say: ideas on how to improve upon this are welcome.

yay 50'th post!!
Your indention is a bit messy at some points - at least IMO putting two tabs in front of a function declaration and then having the opening and closing braces at the original indention level makes it harder to read. Some vertical whitespace between function definitions inside you class also wouldn't hurt.

Your constructor should initialize variables in the initialization list, not in the body.

Non inline method definitions should be done outside the class body, preferably in a seperate cpp.

You should remove all your system calls.

Your set_q_a function does not check if the question index is valid

Instead of a function to set a question to a specific index, you should just have a function that adds questions, and one that removes questions.

You could use vectors instead of arrays for arbitrary amounts of questions - this would also remove your responsibility to keep track of the amount of questions yourself

You could put the Question/Answer data into a struct, because that'd make it easier accessible.

You should make your parameter names more meaningful, at least not something like "pluss".

Also, right now you are not really using any of the advantages of OOP here, so was it really necessary to write a class for your quiz?
I considered doing a few of those things but when i made it I just needed it to work. no time to optimize. however I will optimize it soon.
Topic archived. No new replies allowed.