I need help with adding something

I have a project file about an election. I have typed below the output of the project file. Waht I need to do now is to add a function to ask for the number of votes and to determine the top six winner. I hope somoene can help me because I'm still not good when it comes to pointers.

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
  //implementation of member methods for Vote class
// include appropriate library files and Vote class
#include <iostream>
#include <string>
#include "Vote.h"

using namespace std;

// constructor file to initialize candidate
Vote::Vote()
{	
	cout << "Enter name of candidate: ";
	getline(cin, candidate,'\n');

}

//library file
#ifndef H_VOTE
#define H_VOTE
# include <string>

using namespace std;

class Vote
{
public:
	Vote();
private:
	string candidate;
};


#endif

//main program

#include <iostream>
#include "Vote.h"
using namespace std;

void setArray(Vote* &party, char p);

int main ()
{
	Vote *democrat, *independent, *libertarian, *republican, voter;

	setArray(democrat, 'd');
	setArray(independent, 'i');
	setArray(republican, 'r');
	

	return 0;
}

void setArray(Vote* &party, char p)
{
	int num;
	switch (p)
	{
	case 'd':	cout << "How many Democratic candidates are there? ";
				break;
	case 'i':	cout << "How many Independent candidates are there? ";
				break;
	case 'r':	cout << "How many Republican candidates are there? ";
				break;
	}

	cin >> num;
	cin.ignore();
	party = new Vote[num];
}

/*
How many Democratic candidates are there? 2
Enter name of candidate: Lawrence Liberal
Enter name of candidate: Lucille Left
How many Independent candidates are there? 1
Enter name of candidate: Gertrude Hopper
How many Libertarian candidates are there? 0
How many Republican candidates are there? 3
Enter name of candidate: Richard Right
Enter name of candidate: Constance Conservative
Enter name of candidate: Hector Rodriquez
*/


bump
You're going to need to save the number of candidates for each party somewhere.
Then you're going to need to loop through each array num-of-candidates times asking for the name of each candidate and also the number of votes for each candidate and store that somewhere.

Suggestion: Make party an attribute of Vote. That way you only have to allocate a single array once you know how many candidates there are. Will make it much easier to find the top six vote getters.

Are you familiar with vectors? This would be easier using a vector since the size of the arrays is variable.

What's the purpose of the instance of Vote named voter on line 45?
ohh sorry, the "voter" is used when i tried to do something else on my codes but failed. XD I just forgot to delete it. And no, i'm still not familiar with vectors.
Topic archived. No new replies allowed.