Question: Your task in Part 2 is to expand your original project by applying the concepts of inheritance, polymorphism, abstract classes, and other relevant techniques from
Your task in Part is to expand your original project by applying the concepts of
inheritance, polymorphism, abstract classes, and other relevant techniques from your
recent lessons.
Requirements Part : Inheritance and Advanced ObjectOriented Concepts
For Part you will adapt your previous project from Part by incorporating the following
concepts:
Derived Classes:
Modify your Knight struct or class into a base class called Character Then, create
derived classes for Knights and other types of characters such as Wizards or Archers to
show inheritance.
These derived classes should inherit from Character and have additional unique
attributes and methods eg a Wizard might have a spellbook or a Knight could have
an armor bonus
Polymorphism:
Implement polymorphism in your banquet seating system. Update the Guest class to
be a base class and create specialized classes such as KnightGuestWizardGuest
and RoyalGuest each with their own displayInfo method that behaves differently
depending on the type of guest.
Use a vector to store a list of guests and dynamically call the appropriate
displayInfo method using polymorphism.
Abstract Classes:
Introduce an abstract class Quest with a pure virtual function completeQuest
Create derived quest types such as RescueQuest or BattleQuest which implement
this function differently depending on the type of quest.
When displaying the quest log use polymorphism to call completeQuest on each
quest object, and show how each quest is completed.
Static Data Members and Functions:
Add a static member to one of your classes to keep track of how many guests or knights
have been added to the seating chart or knight roster.
Updated Technical Requirements:
Character and Derived Classes:
Create a Character base class with at least:
string name
int health
A method displayInfo that outputs character details.
Derive at least two character types, such as Knight and Wizard which inherit from
Character and override displayInfo
Banquet Seating Polymorphism:
Modify the Guest class to be a base class.
Create at least two derived classes egKnightGuest and WizardGuest
Use polymorphism to display guest information differently based on their type.
Quest Log Abstract Classes:
Modify the Quest class to be an abstract class.
Derive at least two specific quest types that inherit from Quest and implement their
own completeQuest function.
Static Members:
Add a static data member to keep track of how many guests have been seated or how
many quests have been completed.
Helpful Tips:
Tip : When creating your derived classes, think about how the base class Character
GuestQuest should generalize the common properties and behaviors. The derived
classes will then add their own unique features.
Tip : Remember to use pointers or references for polymorphism to allow dynamic
dispatch of the displayInfo and completeQuest methods.
Tip : Use virtual and override keywords appropriately to ensure that your derived
classes can override base class methods
c code#include
#include
#include
using namespace std;
struct Weapon
string name;
int damage;
int rarity;
;
struct Knight
string name;
int armorClass;
int hitPoints;
Weapon weapon;
;
Function to display the list of knights
void displayKnightsconst vector& knights
for const auto& knight : knights
cout "Name: knight.name
Armor Class: knight.armorClass
Hit Points: knight.hitPoints
Weapon: knight.weapon.name
Damage: knight.weapon.damage Rarity: knight.weapon.rarity
;
class Guest
public:
Gueststring name, string role, string dietaryPreference
: namename rolerole dietaryPreferencedietaryPreference
string getName const return name;
string getRole const return role;
string getDietaryPreference const return dietaryPreference;
private:
string name;
string role;
string dietaryPreference;
;
class BanquetHall
public:
void addGuestconst Guest& guest
guests.pushbackguest;
void removeGuestconst string& guestName
for auto it guests.begin; it guests.end; it
if itgetName guestName
guests.eraseit;
return;
cout "Guest not found!
;
void displaySeatingChart const
cout "Banquet Hall Seating Chart:
;
for const auto& guest : guests
cout guest.getName guest.getRole
guest.getDietary
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
