I am needing help with polymorphism. I have no clue how to work with this. I have to write a program that creates an Orc and a Human and demonstrates the behavior of the classes. I am just needing some help with setting this program up. I have set up the classes with the information, but how do I get the createCharacter function to work? I know my program is not correct right now and I have some errors and things, but I am still just trying to get a better understanding of this. These are the requirements:
We will have a “Character” class first. Character class takes care of creation of a character.
Protected Member Variable:
characterTotal - This will hold the total of character stats.
Public Member Functions:
createCharacter - This function should be a pure virtual function.
Next, define a class named Human. It should be derived from the Character class.
It should have the following members:
Private Member Variables:
characterStrength - STR of the Character (0 to 18)
characterDexterity - DEX of the Character (0 to 18)
characterIntelligence - INT of the Character (0 to 18)
characterType - (Can be “Paladin”, “Ranger” or “Wizard”)
Public Member Functions:
constructor - accepts values for STR, DEX, INT and character type. Should call
the overridden createCharacter function.
getStrength - returns the value of characterStrength.
getDexterity - returns the value of characterDexterity.
getIntelligence - returns the value of characterIntelligence.
getType - returns the value of characterType.
Next, define a class named Orc. It should be derived from the Character class. It should have the following members:
Private Member Variables:
characterStrength - STR of the Character (0 to 18)
characterDexterity - DEX of the Character (0 to 18)
characterIntelligence - INT of the Character (0 to 18)
characterClan - (Can be “Barbarian”, “Berserker” or “Vanguard”)
Public Member Functions:
constructor - accepts values for STR, DEX, INT and character clan. Should call
the overridden createCharacter function.
getStrength - returns the value of characterStrength.
getDexterity - returns the value of characterDexterity.
getIntelligence - returns the value of characterIntelligence.
getClan - returns the value of characterClan.
At this step we can define createCharacter and showCharacter functions of each of the classes.
For Human class createCharacter will:
Get the values of STR, DEX and INT. Will calculate the total of the values.
(Let’s assume STR = 17, DEX = 12 and INT = 10. It will store 37 into characterTotal.Itwill print out a message: “The strong human Paladin, has a total scoreof 37.” (Strong adjective comes due to STR being 17. If something is above 17 you should say something related. STR = strong, DEX = dexterous, INT =
intelligent).
For Orc class createCharacter will:
Get the values of STR, DEX and INT. Will calculate the total of the values.
However Orcs receive -2 to INT and DEX. They receive +2 to STR. (Let’s
assume STR = 16, DEX = 10 and INT = 8. It will store 16+2,10-2,8-2 = 28 into
characterTotal.
It will print out a message “The berserker Orc has a total score of 28.” (Here the
Orcs get their adjectives from their clan names so you do not need to do
something specific to STR, DEX or INT.)