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, using a constant.  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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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, using a constant.  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.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY