Consists of Part A and Part B Consider the following class c

Consists of Part A and Part B: Consider the following class called Myscores that stores all the scores for a game class Myscores {public: Myscores() {//constructor nScores = 0;} void addScore(int newscore) {score[nScores] = newscore; nScores++;} private: int score 110]; int nScores;//number of scores stored}; The score member variable can store at most 10 scores. Change the code so that, score can store as many scores as needed when a Myscores object is created (use dynamic memory). Change/add constructor and destructors as needed. Add a copy constructor for the above case.

Solution

class Myscores {
public:
Myscores() {// default constructor
nScores = 0;
totalScores = 10;
score = new int[totalScores];
}

Myscores(int n) {
score = new int[n];
nScores = 0;
totalScores = n;
}

Myscores(const Myscores& m) {
nScores = m.nScores;
totalScores = m.totalScores;
score = m.score;
}

void addScore(int newscore) {
if (nScores < totalScores) {
score[nScores] = newscore;
nScores++;
}
}

int getNScores() {
return nScores;
}

int getTotalScores() {
return totalScores;
}

int* getScore() {
return score;
}

private:
int *score;
int nScores;
int totalScores;
};

 Consists of Part A and Part B: Consider the following class called Myscores that stores all the scores for a game class Myscores {public: Myscores() {//constru

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site