Question
Exercise
"
We have the following 5 classes:
Base
Class: Canidae
Derived from Canidae: Fox, Wolf
Derived from Fox: Red Fox
Derived from Wolf : Gray Wolf
Use these UML diagrams to code your classes; note: the # symbol means Protected access.
Canidae
#social : string
#coatColor : string
#litterSize : int
+Canidae()
+Canidae(soc : string, color : string, litter : int)
<setters and getters can be omitted or coded; they are optional>
+printInfo() : void
Fox
#continent : string
#habitat : string
+Fox()
+Fox(soc : string, color : string, litter : int, cont : string, hab : string)
+setContinent(cont : string) : void
+getContinent() : string
+setHabitat(hab : string) : void
+getHabitat() : string
+printInfo() : void
Wolf
#packSize : int
#habitat : string
+Wolf()
+Wolf(soc : string, color : string, litter : int, pack : int, hab : string)
+setPack(pack : int) : void
+getPack() : int
+setHabitat(hab : string) : void
+getHabitat() : string
+printInfo() : void
RedFox
-avgWeight : double
-activity : string
RedFox()
RedFox(soc : string, color : string, litter : int, cont : string, hab : string, weight : double, act : string)
+setWeight(wgt : double) : void
+getWeight() : double
+setActivity(activity : string) : void
+getActivity() : string
+printInfo() : void
GrayWolf
-packPosition : string
-gender : string
+GrayWolf()
+Gray Wolf(soc : string, color : string, litter : int, pack : int, hab : string, pos : string, gen : string)
+setPosition(pos : string) : void
+getPosition() : string
+setGender(gen : string) : void
+getGender() : string
+printInfo() : void
Code all five classes using header files and putting member function code into separate .cpp files. Be sure to indicate inheritance when you code the header files for Fox, Wolf, RedFox and GrayWolf. Be sure to include the proper header files where needed.
NOTES:
- If you use the Add Class tool of Visual Studio, notice that after you enter the name for a class, there is another box titled "Base Class". For the child classes, you can put in the class name of the immediate Parent and then Visual Studio creates the inheritance code for you, that is, it will start the class as (example):
class Fox : public Canidae {
- The constructors of your derived classes should include the parents' attributes (as shown in the UML) and the current class attributes. Use the parent's constructor for the parent's attributes as shown in the Exercise. Default constructors only need to initialize class attributes; Parent default constructors are automatically called.
- Your printInfo() methods should call the parent's printInfo() and add any unique information. No redundant print statements allowed! Use inheritance.
In the main function:
Make a RedFox object with this data: In the family Canidae with a social structure of "pair/family", a coat color of "red" and a litter size of 6. As a fox, the continent would include "the northern hemisphere" and its common habitat is "diverse". Its average weight is 12 pounds and it is usually active at "dawn/dusk". Print all information.
Make GrayWolf object with this data: In the family Canidae with a social structure of "pack", a coat color of "white to black" and a litter size of 4. As a wolf, the pack size averages 6 and its usual habitat is "diverse". The gray wolf in question is an alpha male.
"
Recently Asked Questions
- I am having problems with finding the correct solution to these questions. Thanks
- I'm having difficultly finding out why I keep getting the error "too few arguments in function call". This occurs with only the functions void
- I need help to do a program that allows the user to enter four spring 2020 classes and the credit hours and course cost for each. the class information input