Language: C++ This is the program that it needs to be based off of: Modify the e
ID: 3737958 • Letter: L
Question
Language: C++
This is the program that it needs to be based off of:
Modify the existing pet interaction functions (feed) and play)) to also change this value. For example, if the new data is money feeding the pet costs money (for food), but playing with the pet gains money (your pet is doing tricks for tips). Or if your new data is sleepy then both feeding and playing with your pet makes it sleepier Add a new interaction function (like feed and play) that allows users to interact with the pet in a new way that affects all of the current data For example, if you added a sleepy data member, then there should be a nap) function that reduces sleepy, but increases hungry. Make sure to include this new interaction in the player menu so the player can select it Remember to add your new data member to the pet printo function so it tells the player how sleepy their pet is, or how much money they have left, etc Add a new random event function that is called after the player interacts with the pet ie. at the end of the main loop. This function should have a chance of one of several random events occurring (and a large chance that no random event occurs). Random events should print a message to the player telling them what the event was and should affect the member data of the pet. You should make up your own random events. Examples would be "Your pet found a bone happiness goes up and hunger goes down or "Your pet escaped from the backyard and was caught by animal control." happiness goes up, money (if you created it) goes down or "Your pet found a skunk." happiness goes way down One way to implement the random event function is to generate a random number in some range (e g.0-9) and use a switch statement to determine the outcome. Many of the switch cases can default to no event, and a few of the cases can call functions with the special eventsExplanation / Answer
I have answered the question as per the sequence of part of question from top to down order. Try reading the solution with question and compare and insert the code sequentially at their respective place, once you have read and understood the question thoroghly. Include following block of code at their respective places:-
class pet{
private:
int sleepy;
public:
void nap();
In int main(), let's add another option in 'what would you like to do with your pet?'
The option can be 3. Sleep.
Then case3 in switch statement will include pet.nap();
Then in the constructor pet(), we can declare sleepy = 50; just like hunger and happy is.
Now , in the play function let's increase the sleepy by 5 in both the fetch and roll over case of switch.
In function feed, let's increase the sleep by 2.
Now let's create a function nap:-
void pet :: nap(){
hunger = hunger +2;
happy += 10;
sleepy -=10;
}
In print function add this instruction:-
cout<< "Sleepy : "<<sleepy<<endl;
And finally, in check_health use following conditional statement:-
if(sleepy>60){
cout<<" Your pet needs sleep "
return 1;
}
Now, in the end of main add the following function:-
void randomEvent(){
switch(rand){
case 1:
cout<<"Found a bone";
break;
case 2:
cout<<"Got Lost";
break;
default:
cout<<"Nothing happened";
}
}
Hope this wil help!!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.