Question
SET-252 C Programming #2 Homework: 6 Overloading and Const Continue with your code from homework #3 Encapsulation and Inheritance, or start a new project if
SET-252 C Programming #2
Homework: 6 Overloading and Const
Continue with your code from homework #3 Encapsulation and Inheritance, or start a new project if you prefer.
Step 1 Overloading and Const
Create a CDog class using the class file template.
Add the following private properties: m_pstrName, m_intAge, m_sngWeight. Note that m_pstrName is a character pointer (char*) not a character array (char[]).
Create public get/set methods for each property. Be sure to boundary check in the ALL set methods.
In the set method for name, dynamically allocate memory large enough to store the new name. Clip any new names to 49 characters.
In the set methods for age and weight, clip negative numeric values to zero.
Make the get methods all constant methods. Make the return value for the get name method constant too.
Add the following constructors and a protected Initialize method. Call the initialize method from all constructors. Pass in blank/zero values if no parameters values are given. Be sure to initialize m_pstrName to zero in the initialize method before calling any set methods.
Add a destructor and protected CleanUp and DeleteString methods. The destructor should call CleanUp and in CleanUp call DeleteString for all char* properties, which, in this case, is just once for m_pstrName.
Create a public, constant Bark method. Inside the Bark method print "Yip, yip, yip" if the dog's weight is less than 15.0f. Print "Woof, woof" if the dog's weight is greater than or equal to 15.0f.
Add a public, constant Print method that prints outs out all the properties and calls all the methods.
Step 2 Inheritance Again
Create a CTrainedDog class that inherits CDog.
Add matching constructors to the ones for CDog. Add an additional parameterized constructor that takes all the parameters for CDog and one for breed. Create a protected Initialize method and call it from the constructors.
Add a destructor and a protected CleanUp method. In the CleanUp method call the DeleteString method for breed only. Do not call for name. The destructor for CDog, which is inherited, will clean up the name.
Add the following private property: m_pstrBreed. Note that m_pstrBreed is a character pointer (char*) not a character array (char[]).
In the set method for breed, dynamically allocate memory large enough to store the new breed. Clip any new breed names to 49 characters.
Add a public, constant Fetch method that prints something like "Fetching the tasty stick. ".
Add a public, constant PlayDead method with something similar to Fetch.
Add a public, constant Print method that prints outs out all the properties and calls all the methods including those inherited from CDog.
Step 3 Test
Set break points in all the constructors and destructors. Make an instance of CDog and step through the procedure calls. Make an instance of CTrainedDog and step through all the procedures calls. Notice how the CDog constructor called before the CTrainedDog constructor. Notice how the CTrainedDog destructor is called before the CDog destructor.
Make a Homework6.cpp file add a main function and in the main function declare a variable of type CDog and CTrainedDog. Use the parameterized constructors. Call the print method after creating the instances.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started