In addition to throwing ints, characters, etc - you can also throw classes that you create as objects. Create three anim
Posted: Tue Jul 12, 2022 8:21 am
In addition to throwing ints, characters, etc - you can also throw classes that you create as objects. Create three animal classes: Dog, Cat, and Bird. Create the following methods in each: Dog: bark (print woof), sleep (print zzzz) Cat: purr (print purr), sleep (print zzzz) Bird: fly (print whosh), sleep (print zzzz) Obviously, the "sleep" function is common to all. However, the other methods are not. Create a function that will take in the animal type that you want, along with the action. Check to see if the method is available in your animal. You CANNOT do something like this... Dog d; string x; cin << x << endl; d.x; Rather, use if/else statements to direct the program to each action for the animal. If the user inputs an action that the animal a cannot do (for instance, cat and bark), throw a. Use a catch to print an appropriate error output. Please enter an animal: Dog Please enter an action: purr Dogs don't purr Please enter an animal: Bird Please enter an action: fly whoosh