Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pet Sim +Talk() : void+FeedPet() : void+Play() : void-PetMood() : int-PassTime(in time : int = 1) : void+DisplayPetBehavior() : void+Menu() : void-hungerLevel : int-boredomLevel :

Pet Sim

+Talk() : void+FeedPet() : void+Play() : void-PetMood() : int-PassTime(in time : int = 1) : void+DisplayPetBehavior() : void+Menu() : void-hungerLevel : int-boredomLevel : int-name : string

The class also contains an overloaded constructor, set and get functions.

The PetSim puts the player in charge of his own virtual pet. The player is completely responsible for keeping the pet happy. He can feed and play with the pet to keep it in a good mood. He can also listen to the pet to learn how the pet is feeling, which can range from happy to mad. If you fail to feed or entertain your pet, it will have a mood change for the worse. But, with the proper care your pet can return to a sunny mood. NOTE: Improvise the game if necessary.

Constructor

The class must contain an overloaded constructor (no default constructor) to initialize data members. The constructor takes three arguments, hunger, boredom and name. The constructor also prints the initial statistics of the pet.

PetMood()

The pets mood is directly based on its hunger and boredom levels. This function returns the sum of pets hunger and boredom levels, a pets mood gets worse as the number increases. This member function is private because it should only be invoked by another member function of the class.

Talk()

This function allows the pet to be able to tell the player how its feeling. The pets mood can be happy, okay, frustrated, or mad which is determined by the value returned by PetMood() function. The pet is happy if mood is less than than 7, Okay if mood is 7 or higher, frustrated if the mood is between 16 and 21 and mad if greater than 21. Finally, Talk() calls PassTime() to simulate the passage of time.

FeedPet()

The FeedPet function allows the player to be able to feed the pet to reduce its hunger. FeedPet() displays an appropriate message indicating that the pet has been fed. This function reduces pets hunger level by a certain amount. This amount can be passed as a parameter or as default parameter. The max amount of food that can be fed to the pet is value of 4. The pets hunger level is kept in check and is not allowed to go below zero. Finally, PassTime() is called to simulate the passage of time.

Play()

The Play function allows the player to be able to reduce the pets boredom. Play() displays an appropriate message indicating that the pet was allowed to play. The function reduces a pets boredom level by a certain amount. This amount can be passed as a parameter or as default parameter. The max amount of fun a pet can have is value of 4. The pets boredom level is kept in check and is not allowed to go below zero. Finally, PassTime() is called to simulate the passage of time.

PassTime()

PassTime() is a private member function that increases a pets hunger and boredom levels by adding the specified amount of time to the member variables hungerLevel and boredomLevel.

It is invoked at the end of each member function where the pet does something

(eats, plays, or talks) to simulate the passage of time. You can pass the member function the amount of time that has passed; otherwise, time gets the default argument value of 1.

DisplayPetBehavior()

This function displays appropriate pet behavior based on the hunger level and boredom levels. This function must also displays the actual hunger and boredom levels.

The hunger and boredom levels less than 3 indicate that the pet is neither hungry nor bored.

Boredom levels between 3 and 11 indicate that the pet is a little bored, otherwise it is very bored.

Hunger level between 3 and 11 indicate that the pet is modertely hungry.Hunger levels greater than 11 indicate that the pet is very hungry. This function is called by member functions Talk(), FeedPet() and Play().

Menu ()

It is basically be a game loop that asks the player whether he wants to listen to, feed, or play with the pet, or quit the game. Heres the pseudocode:

While the player doesnt want to quit the game

Present a menu of choices to the player

If the player wants to listen to the pet

Make the pet talk

If the player wants to feed the pet

Feed the pet

If the player wants to play with the pet

Make the pet play

main()

In main() instantiates a new Pet object. You can supply specific values for Name, Hunger or

Boredom or leave it at default values. When the data members start out at 0, the pet begins life happy and content.

Set and Get Functions

These functions must provide appropriate code. The set functions must also validate the hunger and boredom levels. The hunger and boredom levels cannot be less than 0 and cannot be greater than 100. Ensure that these functions are used wherever necessary and not the member variables directly.

Rubrics: Measurement of performance of aspect.

Aspect

Objectives Substantially Met

1. Overloaded constructor is used with specified parameters; the constructor correctly initializes the member variables and prints the initial pets stats.

2. Set functions validate the hunger and boredom level and have appropriate code.

3. The get functions have appropriate code.

4. PetMood function has the specified code and this function is called using correct syntax.

5. Talk function contains appropriate control statements to perform the task and correctly displays the appropriate pet mood.

6. FeedPet reduces pets hunger levels as specified and displays appropriate message indicating that the pet has been fed.

7. Play reduces pets boredom levels as specified and displays appropriate message indicating the same.

8. PassTime has code that increments the hunger and boredom levels as specified and this function is called using correct syntax.

9. DisplayPetBehavior displays the actual hunger and boredom levels to the user and uses appropriate control statement(s) to perform the task. This function is invoked using correct syntax by the specified member functions.

10.Menu displays the specified options to the user and uses an anonymous enumerator and a switch..case along with any other appropriate control structure(s) to perform the task. This function must correctly invoke the appropriate functions based on the options user selects.

11.Main contains minimal code required to run the program.

12. Program uses the set and get functions to store or retrieve the hunger and boredom levels.

13. Program runs and completes all required tasks.

14. Program enhancements to make the game more interesting

15. Executes without errors (Logical).

1. Specification is followed correctly and includes all appropriate, descriptive and user friendly input prompts

2. Specification is followed correctly and output is user-friendly, and clearly describes what is expected from the user.

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

Students also viewed these Databases questions