Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise #5B Complete the following constructor Mario(Mario &p2) : Finish the declaration of the Copy constructor. NOTE: Remember to constantly verify the Mario class to

Exercise #5B

Complete the following constructor Mario(Mario &p2): Finish the declaration of the Copy constructor.

NOTE: Remember to constantly verify the Mario class to see if there is anything that can help with the solution.

For example:

Test Result
Mario p0(1, 12, 36, 3, 0); Mario p1(p0); cout << p1.toString() << endl;
{Player: 1,Stars: 12, Coins: 36, Lives: 3, Lvl Cleared: 0} 

Answer:(penalty regime: 0 %)

/*.......................................................................................................................................................................................................*/

/*Mario.h*/

#include

#include

#include

using namespace std;

class Mario{

private:

int playerNum;

int numStars;

int numCoins;

int numLives;

int levelsCleared;

public:

//Constructor

Mario(int playerNum, int numStars, int numCoins, int numLives, int levelsCleared);

//Copy Constructor

Mario(Mario &p2);

// Getters

int getPlayerNum() { return playerNum; }

int getNumStars() { return numStars; }

int getNumCoins() { return numCoins; }

int getNumLives() { return numLives; }

int getLevelsCleared() { return levelsCleared; }

// Setters

void setPlayerNum(int playerNum) { this->playerNum = playerNum; }

void setNumStars(int numStars) { this->numStars = numStars; }

void setNumCoins(int numCoins) { this->numCoins = numCoins; }

void setNumLives(int numLives) { this->numLives = numLives; }

void setLevelsCleared ( int levelsCleared ) { this->levelsCleared = levelsCleared; }

string toString(){

return "{Player: " + to_string(getPlayerNum()) + ","

+ "Stars: " + to_string(getNumStars()) + ", "

+ "Coins: " + to_string(getNumCoins()) + ", "

+ "Lives: " + to_string(getNumLives()) + ", "

+ "Lvl Cleared: " + to_string(getLevelsCleared()) + "}";

}

//EXERCISES

Mario decisionPlayer(Mario p2);

void passedLevel();

bool readyForNewWorld();

bool buyStar();

int surviveBowser();

};

/*.................................................................................................................................................................*/

/*mario.cpp*/

#include "Mario.h"

/*

EXERCISE #5A

Finish the declaration of the constructor

*/

Mario::Mario(int playerNum, int numStars, int numCoins, int numLives, int levelsCleared){

// YOUR CODE HERE

}

/*

EXERCISE #5B

Finish the declaration of the copy constructor

*/

Mario::Mario(Mario &p2) {

// YOUR CODE HERE

}

/*

EXERCISE #6

WARNING: To run the test cases in VSC, you will need to have finished the constructor in this file,

in Moodle you will be able to run the test cases without completing the constructor

Return the Mario object that is making the decisions between the target Mario and the paremeter Mario

The Mario that makes the decisions is the one with the LOWEST number. If both Mario's have the same

number, the target Mario should be returned.

*/

Mario Mario::decisionPlayer(Mario p2){

// YOUR CODE HERE

return p2;

}

/*

EXECISE #7

Add one to the amount of levels cleared if target Mario has at least 10 stars and 25 coins.

HINT: MUST USE GETTERS AND SETTERS

*/

void Mario::passedLevel() {

// YOUR CODE HERE

}

/*

EXERCISE #8

Return true if target Mario has cleared enough levels to move to the next world.

Mario has to have cleared at least 5 levels.

*/

bool Mario::readyForNewWorld() {

// YOUR CODE HERE

return false;

}

/*

EXERCISE #9

Return true if Mario has at least 10 coins to buy a new star.

If Mario has enough coins, add one to the amount of stars Mario has

and reduce the number of coins by 10.

HINT: USE THE GETTERS AND SETTERS

*/

bool Mario::buyStar(){

// YOUR CODE HERE

return false;

}

/*

EXERCISE #10

Return -1 if Mario will only survive one attack from Bowser

0 if Mario will survive two attacks from Bowser

1 if Mario will survive three or more attacks from Bowser

HINT: Mario will lose one live for every attack it survives

*/

int Mario::surviveBowser() {

// YOUR CODE HERE

return 36;

}

/*.................................................................................................................................................................*/

#include "MarioV2.h" /* EXERCISE #5B Finish the declaration of the copy constructor */ Mario::Mario(Mario &p2) { // YOUR CODE HERE }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions