Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here is the code for the assignment 7 #include #include using namespace std; string species; class Pet { private : int hunger; int happy; int

image text in transcribed

here is the code for the assignment 7

#include #include  using namespace std; string species; class Pet { private: int hunger; int happy; int thirst; int choice; int foodchoice; string name; public: Pet(); void Play(); void Feed(); void Givewater(); void Print(); int check_health(); }; int main() { Pet pet1; int choice; int foodchoice; int alive; do{ pet1.Print(); cout> choice; switch (choice){ case 0: cout break; case 1: pet1.Play(); pet1.check_health(); alive=1; break; case 2: pet1.Feed(); pet1.check_health(); alive=1; break; case 3: pet1.Givewater(); pet1.check_health(); alive=1; break; } } while(choice != 0 && alive ==1); cin.ignore(); return 0; } Pet::Pet (){ hunger = 50; happy = 50; thirst = 50; cout > name; cout > species; } void Pet::Play(){ int choice = 0; cout > choice; switch (choice){ case 1: happy += 10; hunger += 5; thirst += 5; cout break; case 2: happy += 5; hunger += 1; thirst += 1; cout break; default: cout void Pet::Feed() { int foodchoice = 0; cout > foodchoice; switch (foodchoice){ case 1: happy += 10; hunger -= 10; thirst += 5; if(hungerelse cout break; case 2: happy += 5; hunger -= 15; thirst +=1; if(hungerelse coutbreak; default: cout int x= rand()%3; switch(x){ case 0: coutbreak; case 1: coutbreak; case 2: coutbreak; } } void Pet::Givewater() { cout void Pet::Print() { cout int Pet::check_health() { int status; if (hunger >= 100){ cout else if (hunger >= 50 && hunger else if (hunger else if (happy else if (happy >= 50 && happy else if (happy >= 100){ cout else if (thirst >= 100){ cout if (thirst else status =1; return status; }
For this assignment, you will be modifying the Pet Program we worked with earlier. You should work from the version you created in assignment 7. If you didn't complete Assignment 7 you may work from the original Pet program, but make that clear in the comments at the beginning of your program. For either approach it is recommended that you begin with a copy of the code, so you have the old version to go back to The general idea for this program is that the player has four pets, stored as an array, rather than just one pet that they can interact with. This will require making the following additions to the progran: Create an array of four pet objects Change the ending condition of the main loop so that the loop only ends if all four pets die. This will probably require creating an extra variable to keep track of the number of pets that are still alive (or that have died) Each loop of the program should begin by giving the player a choice of pets (by name) to interact with. For example: Which pet do vou want to interact with? 1) Bob 2) Sally 3) Rover 4) Tiddles The player then enters a number (1-4) and the program moves onto the regular interaction menu (play, feed, etc.). Note that pets that have died should not be included in the list .When the player interacts with a pet that interaction should only effect that pet. For example, if the player chooses to feed Bob then only Bob should get less hungry However, the random events may occur to other pets. So, even though the player fed Bob Sally may have had a random event occur to her Turn in: A copy of the program and sample, annotated output showing the program runs. Note that the sample output will be fairly long to show all of the new features of the program. To annotate the output, use a pen or pencil and mark exactly where different "events" occur. For example, point out, in the output, how only the selected pet is interacted with, and where a random event occurs to a different pet than the one the player choose to interact with For this assignment, you will be modifying the Pet Program we worked with earlier. You should work from the version you created in assignment 7. If you didn't complete Assignment 7 you may work from the original Pet program, but make that clear in the comments at the beginning of your program. For either approach it is recommended that you begin with a copy of the code, so you have the old version to go back to The general idea for this program is that the player has four pets, stored as an array, rather than just one pet that they can interact with. This will require making the following additions to the progran: Create an array of four pet objects Change the ending condition of the main loop so that the loop only ends if all four pets die. This will probably require creating an extra variable to keep track of the number of pets that are still alive (or that have died) Each loop of the program should begin by giving the player a choice of pets (by name) to interact with. For example: Which pet do vou want to interact with? 1) Bob 2) Sally 3) Rover 4) Tiddles The player then enters a number (1-4) and the program moves onto the regular interaction menu (play, feed, etc.). Note that pets that have died should not be included in the list .When the player interacts with a pet that interaction should only effect that pet. For example, if the player chooses to feed Bob then only Bob should get less hungry However, the random events may occur to other pets. So, even though the player fed Bob Sally may have had a random event occur to her Turn in: A copy of the program and sample, annotated output showing the program runs. Note that the sample output will be fairly long to show all of the new features of the program. To annotate the output, use a pen or pencil and mark exactly where different "events" occur. For example, point out, in the output, how only the selected pet is interacted with, and where a random event occurs to a different pet than the one the player choose to interact with

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 Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

=+ (c) The same, but suppose that 22 is uncountable.

Answered: 1 week ago