Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class called Pet that contains an animals name, type, and weight. Include a default constructor and destructor for the class. The constructor should

Write a class called Pet that contains an animal’s name, type, and weight.  Include a default constructor and destructor for the class.  The constructor should print out the following message:  “Creating a new pet”.  The destructor should print out the following message:  “In the Pet destructor.”  Include appropriate get/set functions for the class.

In main(), prompt the user to enter the number of pets in his or her household.  Dynamically create a built-in array based on this number (not a vector or object of the array class) to hold pointers to Pet objects.

Construct a loop in main() that executes once for each of the number of pets that the user indicated.  Within this loop, ask the user to enter the name and type of pet.  Using a random number generator, generate a weight between 1-100 pounds. Seed this random number generator with 100.  Next, dynamically create a Pet object (remember that this requires the use of the “new” keyword which returns a pointer to the location in memory where this pet object was created.)  Create each object using the default constructor of the class, and call the set functions to store the name, type, and weight of each pet.  Store each Pet pointer in the array.

After all of the pet objects have been constructed and added to the array, print out the contents of the array.

Because the program uses dynamic memory to store the array as well as the objects in the array, be sure to de-allocate all of the memory before exiting.

Step by Step Solution

3.49 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

include using namespace std class Pet public string name string type ... 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

Document Format ( 2 attachments)

PDF file Icon
60618495aa00e_55313.pdf

180 KBs PDF File

Word file Icon
60618495aa00e_55313.docx

120 KBs Word File

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

Computer Networking A Top-Down Approach

Authors: James F. Kurose, Keith W. Ross

5th edition

136079679, 978-0136079675

More Books

Students also viewed these Programming questions

Question

Implement the method contains() for HashST.

Answered: 1 week ago

Question

Briefly describe each of the seven quality tools.

Answered: 1 week ago