#include <iostream>
usingnamespace 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 = newchar [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 thisfor 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[]
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}
}