getter and setter for array type

Once again hi to all,

So sorry to keep troubling you guys. I would like to seek help on this program that i'm trying to create.


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
#include <iostream>

using namespace std;

class GamePlayer {
private:
	char *name;
	char player_id[8];
	int currentLevel;
	int topFiveScores; <-- this should be an array of five int elements representing the top five highest scores the player has achieved so far.

public: 
	GamePlayer(char *p_name, char p_player_id[], int p_currentLevel, int p_topFiveScores)	{
	
	player_id[8]=p_player_id[8];
	currentLevel=p_currentLevel;
	topFiveScores=p_topFiveScores;
	
	name = new char [strlen(p_name)];
	strcpy(name,p_name);
	
	}

	~GamePlayer(){}

	char *getName() {
		return name;
	}

	char *getPlayerID(){
		return player_id;
	}

	int getCurrentLevel(){
		return currentLevel;
	}




my lecturer told us that we will require to use this for the top 5 score in order for it to work but I got not idea how to use it =\

/*void setTopfiveScores(int scores[]) { 

}*/

int getTopFiveScores() {
	return topFiveScores;
}

};


int main(int argc, char* argv[]) {
GamePlayer a("John","A1234567",2,80);
cout <<"name: "<<a.getName()<<endl;
cout <<"userid: "<<a.getPlayerID()<<endl;
cout <<"current Level: "<<a.getCurrentLevel()<<endl;
cout <<"top 5 score: "<<a.getTopFiveScores()<<endl;

cin.ignore(2);
}




As of now the code is working but with some bugs. The first bug would be my userid is showing weird character instead of "A1234567" which I had define. I guess the problem is at the constructor coding line.

Another help would be for the top 5 score. can anyone guide me along how can I display 5 top score of a player? i'm really bad at using array =\ I understand that under the private sector I should probably define int topFivescore[5]. but if I assign that I cant seems to get my program to run.

It will show an error like unable to convert int parameter to int[]

=\


Any help is greatly appreciated!
Last edited on
hmm I was wondering if it is alright if I initialize the topfivescore array at the default constructor as we are allow to hardcore the top five scores.
e.g

Gameplayer(){
int topFivescores[5]: {50,60,70,80,90}
}

any ideas?
Last edited on
Topic archived. No new replies allowed.