CS120
Lab #6
Due at the end of lab.
For this lab you will be modifying the pet program
from the textbook/course schedule. If you
have already made modifications you may use
either your modified version or the original version.
- Add a case to the switch statement
for when the player enters a 0 to quit the program. The case can print a
simple good-bye type message.
- Add a new, numeric data member to the pet class. It could be health,
money, tiredness, etc. Modify the existing interaction functions (play() and
feed()) to also affect this new data member. For example, playing with a
pet makes it healthier or more tired.
- Add a new interaction function that changes the new data member.
For example, you can have your pet nap() to change tiredness. This
function could change other data members, e.g. nap() decreases tiredness,
but increases hunger.
- Modify the print() function so that instead
of simply printing the pet's data values it uses if statements to
also print appropriate messages. For example, if the pet's hunger value is
high (you determine what high is) it prints a message about being hungry. You
can make the message general like "Your pet is hungry" or make it seem that
the message comes from the pet "I'm hungry :( feed me please." Include at least 6 different
messages for different ranges of hungry and happy.
- Change the feed() member function so that it
prints different messages pseudo-randomly. The function will need to generate a random
number in some range and then use that number (and if or switch statements) to
pick which message to print.
Turn in: Use the script command to demonstrate how your program runs.
Place the output from the script command into a file named Lab6output.txt.
In the sample output, make sure you show that you've tested all of the
new functionality of the program.
Turn in a copy of your program code and the Lab6output.txt file to Canvas.