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 2 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 2: Inheritance and Advanced Object-Oriented Concepts)
For Part 2, you will adapt your previous project from Part 1 by incorporating the following
concepts:
1. 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 (e.g., a `Wizard` might have a spellbook or a `Knight` could have
an armor bonus).
2. Polymorphism:
- Implement polymorphism in your banquet seating system. Update the `Guest` class to
be a base class and create specialized classes such as `KnightGuest`,`WizardGuest`,
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.
3. 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.
4. 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:
1. 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()`.
2. Banquet Seating (Polymorphism):
- Modify the `Guest` class to be a base class.
- Create at least two derived classes (e.g.,`KnightGuest` and `WizardGuest`).
- Use polymorphism to display guest information differently based on their type.
3. 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.
4. 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 1: When creating your derived classes, think about how the base class (`Character`,
`Guest`,`Quest`) should generalize the common properties and behaviors. The derived
classes will then add their own unique features.
- Tip 2: Remember to use pointers or references for polymorphism to allow dynamic
dispatch of the `displayInfo()` and `completeQuest()` methods.
- Tip 3: 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 displayKnights(const 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:
Guest(string name, string role, string dietaryPreference)
: name(name), role(role), dietaryPreference(dietaryPreference){}
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 addGuest(const Guest& guest){
guests.push_back(guest);
}
void removeGuest(const string& guestName){
for (auto it = guests.begin(); it != guests.end(); ++it){
if (it->getName()== guestName){
guests.erase(it);
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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!