Need help finishing code

ASAP if possible

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
class SadPirate : public Pirate
{
public:
	SadPirate(string n, int numP)
	{
		favColor = "blue";
		// Set the name here.
		// Set the numParrots here.
	}
	virtual void buyParrot()
	{
		string retParrot;
		int makeFav = rand() % 3;
		if (makeFav == 1)
			retParrot = this->favColor;
		else
		{
			int parrotIndex = rand() % NUMCOLORS;
			retParrot = colors[parrotIndex];
		}
		// Call the printParrot of Pirate and pass in the retParrot here.
	}
};

/*
	Create the AngryPirate class here.
*/

int main()
{
	srand((unsigned)time(NULL));
	// Make an object of SadPirate here.
	// Make an object of AngryPirate here.
	/*
		Add the code snippets from question 12 here.
	*/
	// Do not change the below two lines. Only add what goes between the comments.
	cout << "Yar! Two parrots fly down onto the sad pirate's ship...\n";
	cout << "Jack now has " << /* Something goes here */ << " parrots.\n";
	return 0;
}

/*
	Create the overloaded operator+ function here.
*/



The requirements are
Ensure that the SadPirate class inherits publically from the Pirate class.
3) In the Pirate class, we want to ensure that the name, favColor and numParrots are inherited. Currently they cannot be. Fix this.
4) In the printParrot method of the Pirate class, increment the numParrots of the object that invoked the function. Hint: this
5) Create an AngryPirate class which for the most part will be very similar to the SadPirate class as it should inherit publically from the Pirate base class as well.
6) In its constructor, set the favColor of the AngryPirate class to “red”.
7) Create a buyParrot in the AngryPirate class similar to the one in SadPirate. In this function, however, the color chosen will either be “red” or “orange” based on a 50% chance. Use the buyParrot of SadPirate for help. Also, make sure that you invoke the printParrot method of Pirate just like in the buyParrot of the SadPirate class.
8) Create an overloaded buyParrot in the Pirate base class that takes in a number of parrots to buy as an int parameter. Then in the function, invoke the parameterless buyParrot of the object that invoked the function as many times as specified. Sounds complicated? It’s not really.
9) Create an object of the SadPirate class with a variable name of your choice. In order to invoke the proper constructor, pass in the name “Jack” and number of parrots as 1.
10)Create an object of the AngryPirate class with a variable name of your choice. In order to invoke the proper constructor, pass in the name “Barbossa” and number of parrots as 3.
COURSE CODE: GAME1011 – Object Oriented Programming Page 2 of 3
11)Create an overloaded operator+ function that takes in two parameters: an integer and pointer (or reference if you prefer) to a Pirate class. References are much easier to work with, trust me. In the function, add the integer to the numParrots from the object that is the second parameter then return the result. Yes, you CAN use Pirate as the second parameter’s type and not a specific SadPirate or AngryPirate if we want to access the numParrots.
12)In the main() add the following extra code snippets:
a. Using the SadPirate object, call its buyParrot
b. Using the AngryPirate object, call its buyParrot
c. Using either of the Pirate objects, call the overloaded buyParrot located in the Pirate base class by passing in 3 as the number of parrots to buy. Hint: you’ll need to access the Parrot base class through the object and use the scope resolution operator.
d. Finally, use the two cout lines provided for you and replace the commented out text with a call to the overloaded operator+ function you made. It’s up to you to figure out how to use it and with what operands. Hint: there are two
13)Ensure that Pirate cannot be instantiated. Hint: Abstract. I WILL be checking for this. Part of the Code Snippet criteria. There is a function I declared in Pirate and commented it out that would work for this.
14)Finally, get the program to compile and run. Good luck
Last edited on
do not double post..
Topic archived. No new replies allowed.