C++ Programming Assignment 6 Dynamic Pets The objective of this lab is to demonstrate dynamic allocation and deallocation of memory. Instructions: 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 peť". 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 dvnamic memorv to store the array as well as the Select All Smart Lookup lemory before exiting.
C++ Programming Assignment 6 Dynamic Pets The objective of this lab is to demonstrate dynamic allocation and deallocation of memory. Instructions: 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 peť". 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 dvnamic memorv to store the array as well as the Select All Smart Lookup lemory before exiting.
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
Related questions
Question
Can i get help writing this program

Transcribed Image Text:02:41
M
4G
CSIS112_C_Plus_P._Instructions(1)-1 - Read-only
C++ Programming Assignment 6
Dynamic Pets
The objective of this lab is to demonstrate dynamic allocation and deallocation of
memory.
Instructions:
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 dvnamic memorv to store the array as well as the
LA Select All Smart Lookup emory before exiting.
A sample of the program running is shown below:
How many pets do you have?
3
What is the name of your pet?
Buttercup
What type of pet is Buttercup?
dog
Creating a new pet
What is the name of your pet?
Charlie
What type of pet is Charlie?
cat
Creating a new pet
What is the name of your pet?
Porky
What type of pet is Porky?
pig
Creating a new pet
These are the pets you have:
Pet name:
Buttercup
Pet type:
dog
Pet weight:
66

Transcribed Image Text:02:41
M
4G
CSIS112_C_Plus_P._Instructions(1)-1 - Read-only
What is the name of your pet?
Charlie
What type of pet is Charlie?
cat
Creating a new pet
What is the name of your pet?
Porky
What type of pet is Porky?
pig
Creating a new pet
These are the pets you have:
Pet name:
Buttercup
Pet type:
dog
Pet weight:
66
Pet name:
Charlie
Pet type:
cat
Pet weight:
17
Porky
pig
Pet name:
Pet type:
Pet weight:
16
In the pet destructor
In the pet destructor
In the pet 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:
Executes without crashing
Appropriate Internal Documentation
Pet Class
Data members: name, type, weight
Constructor/destructor
Getters/setters as appropriate
Main: The following items must be implemented in main() or by functions called from main
be implemented in the Pet class
Prompts user for the number of pets
Creates the pet array using dynamic memory allocation
Dynamically creates a pet object
Generates a random weight (between 1-100 inclusive) for each pet
Seed is 100
Prints contents of array as illustrated in diagram
De-allocates memory (both the array and the contents of the array) before exiting
Style:
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images

Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education