Your input screen should look something like this: Main Menu 1 - Dog 2 - Rabbit 3 - Fish 4 - Snake Enter selection: As each animal is selected, you should see messages like the following: Invoking Animal 2-argument constructor Invoking Dog 2-argument constructor Your final output screen shout look something like this: My name is Buttercup, and I am 6 years old. I run. My name is Hoppy, and I am 17 years old. I hop. My name is Nemo, and I am 16 years old. I swim. My name is Snakey, and I am 5 years old. I slither. My name is Princess, and I am 5 years old. I run. Invoking the Dog destructor Invoking the Animal destructor Invoking the Rabbit destructor Invoking the Animal destructor Invoking the Fish destructor Invoking the Animal destructor Invoking the Snake destructor Invoking the Animal destructor Invoking the Dog destructor Invoking the Animal destructor Press any key to continue . . . To give you an idea of the general criteria that will be used for grading, here is a checklist that you might find helpful: Program executes without crashing Appropriate Internal Documentation Base Animal Class: Correct Private Data Members Constructors function appropriately (correct number of constructors, number of arguments, output of messages, etc.) Correct get and set functions Derived Dog, Rabbit, Fish, and Snake classes Correct Private Data Members Constructors/destructors function appropriately (correct number of constructors, number of arguments, output of messages, etc.) Correct get and set functions Move function implementation Dynamic allocation of animals Random generation of ages and correct seed value Output contains appropriate information Array used to store 5 animals correctly Memory is deallocated appropriately Review the submission instructions document prior to uploading your work to Blackboard. Submit this assignment by 11:59 p.m. (ET) on Friday of Module/Week 8.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

1. Create a base class called Animal. All animals have a name (i.e. “Fido,” “Thumper,” “Princess,” “Nemo,” etc.) and an age. Provide a default constructor that initializes the age to zero and outputs the message “Invoking the default Animal constructor” and another constructor that allows the name and age to be set by the client. This other constructor should also output the message “Invoking the 2-argument Animal constructor.” Also construct a destructor for this class that outputs the message “Invoking the default Animal destructor.” Your Animal class should have a function called Move that cannot be implemented. That is, it should be declared as a purely virtual function. Your class should also have Get and Set methods to allow the name and age to be accessed.

2. From the Animal class, derive Dog, Rabbit, Fish, and Snake classes. The derived classes should each have constructors and destructors that output an appropriate message (e.g., the Dog constructor outputs “Invoking Dog constructor,” and the Dog destructor outputs “Invoking Dog destructor”). The constructor of each derived class should allow the name and age of the Animal to be set (think member initialization list). The derived classes should each have a member function called Move that overrides the Animal Move version. Dog Move should output “I run,” Rabbit Move should output “I hop,” Fish Move should output “I swim,” and Snake Move should output “I slither.”

3. Write a main function that uses the Animal and derived classes as needed to do the following. You must perform the actions below in the sequence described (i.e., do not take a shortcut around using dynamic memory allocation/deallocation and virtual methods since they are the whole point of the lab).

a. Use the rand() function to generate a random age between 1 and 20 years. Your program should use a seed value of 100 and set the seed only once. Each animal should have its own randomly generated age. (i.e. Don’t generate one age and use it for all of the animals.)
b. Prompt the user to make an animal selection [e.g. (1) for dog, (2) for rabbit, (3) for fish, and (4) for snake] and to enter a name for the animal. Dynamically create a Dog, Rabbit, Fish, or Snake object (depending on what the user entered) and initialize it with a constructor to which is passed its name and age. Save the object (use an array).
c. Repeat steps a. and b. 4 more times. You do not know what animals the user will select or in what order, so you must figure out how to create and store the appropriate objects.
d. After the user has entered all 5 selections, execute another loop that cycles through the 5 selections and invokes the Move function and also displays the name and age of the animal. If you have done it properly, each of your outputs will correspond to the type of Animal the user selected in the order he or she entered them.

The image contains a guide for programming an animal selection menu, output messages, and a grading checklist for an educational assignment.

---

**Programming Guide:**

1. **Input Screen Example:**

   ```
   Main Menu
   1 - Dog
   2 - Rabbit
   3 - Fish
   4 - Snake
   Enter selection:
   ```

2. **Messages on Animal Selection:**

   ```
   Invoking Animal 2-argument constructor
   Invoking Dog 2-argument constructor
   ```

3. **Final Output Screen Example:**

   ```
   My name is Buttercup, and I am 6 years old.
   I run.

   My name is Hoppy, and I am 17 years old.
   I hop.

   My name is Nemo, and I am 16 years old.
   I swim.

   My name is Snakey, and I am 5 years old.
   I slither.

   My name is Princess, and I am 5 years old.
   I run.

   Invoking the Dog destructor
   Invoking the Animal destructor
   Invoking the Rabbit destructor
   Invoking the Animal destructor
   Invoking the Fish destructor
   Invoking the Animal destructor
   Invoking the Snake destructor
   Invoking the Animal destructor
   Invoking the Dog destructor
   Invoking the Animal destructor

   Press any key to continue . . .
   ```

---

**Grading Checklist:**

- **Program Execution:**
  - Executes without crashing

- **Documentation:**
  - Appropriate internal documentation

- **Base Animal Class:**
  - Correct private data members
  - Constructors function correctly (number of constructors, arguments, output of messages)
  - Correct get and set functions

- **Derived Dog, Rabbit, Fish, and Snake Classes:**
  - Correct private data members
  - Constructors/destructors function correctly (number of constructors, arguments, output of messages)
  - Correct get and set functions

- **Function Implementation:**
  - Move function implementation
  - Dynamic allocation of animals
  - Random generation of ages and correct seed value
  - Output contains appropriate information

- **Array Usage:**
  - Array used to store 5 animals correctly

- **Memory Management:**
  - Memory is deallocated appropriately

---

**Submission Instructions:**

- Review the submission instructions document prior to uploading your work to Blackboard.
Transcribed Image Text:The image contains a guide for programming an animal selection menu, output messages, and a grading checklist for an educational assignment. --- **Programming Guide:** 1. **Input Screen Example:** ``` Main Menu 1 - Dog 2 - Rabbit 3 - Fish 4 - Snake Enter selection: ``` 2. **Messages on Animal Selection:** ``` Invoking Animal 2-argument constructor Invoking Dog 2-argument constructor ``` 3. **Final Output Screen Example:** ``` My name is Buttercup, and I am 6 years old. I run. My name is Hoppy, and I am 17 years old. I hop. My name is Nemo, and I am 16 years old. I swim. My name is Snakey, and I am 5 years old. I slither. My name is Princess, and I am 5 years old. I run. Invoking the Dog destructor Invoking the Animal destructor Invoking the Rabbit destructor Invoking the Animal destructor Invoking the Fish destructor Invoking the Animal destructor Invoking the Snake destructor Invoking the Animal destructor Invoking the Dog destructor Invoking the Animal destructor Press any key to continue . . . ``` --- **Grading Checklist:** - **Program Execution:** - Executes without crashing - **Documentation:** - Appropriate internal documentation - **Base Animal Class:** - Correct private data members - Constructors function correctly (number of constructors, arguments, output of messages) - Correct get and set functions - **Derived Dog, Rabbit, Fish, and Snake Classes:** - Correct private data members - Constructors/destructors function correctly (number of constructors, arguments, output of messages) - Correct get and set functions - **Function Implementation:** - Move function implementation - Dynamic allocation of animals - Random generation of ages and correct seed value - Output contains appropriate information - **Array Usage:** - Array used to store 5 animals correctly - **Memory Management:** - Memory is deallocated appropriately --- **Submission Instructions:** - Review the submission instructions document prior to uploading your work to Blackboard.
Expert Solution
Step 1

THe program for the above-given question is given below.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education