Question
code needs to be in c++ The UML diagram does not indicate which functions need to be virtual. You must decide which functions need to
code needs to be in c++
The UML diagram does not indicate which functions need to be virtual. You must decide which functions need to be virtual to behave correctly. Use inheritance to minimize code duplication. Make sure you call parent versions of functions instead of redoing the work. Below you can find specific notes about the classes. They are listed in the order you probably want to tackle them. Any getXXX functions not mentioned below simply return the value of a member variable.
Item - Represents anything a Character can carry.
toString should return a string formatted to look like: Lump of coal (value: 1)
Armor Represents a piece of armor a character can wear. The protection will be used to reduce the damage the character takes when attacked.
toString should return a string formatted to look like: Leather pants (value: 10) Protection: 2
Weapon A basic weapon used for attacking at close range.
getRange should return 0 (no range)
toString should return a string formatted to look like: Sword (value: 10) Damage: 5
use should return the damage an attack will do. Any attack on a target that is out of range of the weapon should do 0 damage. Attacks on targets in range of the weapon should do damage amount.
RangedWeapon A weapon which can attack at longer range, but has a limited amount of ammunition.
toString should return a string formatted to look like: Bow (value: 30) Damage: 3 Ammo: 20 Range: 10
use should check to see if there is ammo available (more than 0). If so, remove one ammo and then behave like a weapon (check if target is in range to decide how much damage is done). If there is no ammo left, 0 damage is done.
Item name: string -value: int Item(itemName: string, cost: int) - getName(: string + getValueint +toStringo: string -protection int Weapon *Armor(itemName: string, protectionValue:int, cost: int) toStringo: string lgetProtection : int -damage: int +Weapon (itemName: string, damageValue: int cost: int) +toString: string +getDamage: int +getRange: int +use(rangeToTargetint): int Ranged Weapon -range: int -ammoint +RangedWeapon itemName: string, damageValue:int,rangeValue:int ammoValue: int, costint) to String: string -getRange: int +getAmmoint +use(rangeToTargetint): int Build the hierarchy of classes shown above so that they pass the unit tests provided. Item name: string -value: int Item(itemName: string, cost: int) - getName(: string + getValueint +toStringo: string -protection int Weapon *Armor(itemName: string, protectionValue:int, cost: int) toStringo: string lgetProtection : int -damage: int +Weapon (itemName: string, damageValue: int cost: int) +toString: string +getDamage: int +getRange: int +use(rangeToTargetint): int Ranged Weapon -range: int -ammoint +RangedWeapon itemName: string, damageValue:int,rangeValue:int ammoValue: int, costint) to String: string -getRange: int +getAmmoint +use(rangeToTargetint): int Build the hierarchy of classes shown above so that they pass the unit tests providedStep 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