-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.cpp
More file actions
117 lines (102 loc) · 2.91 KB
/
Copy pathinheritance.cpp
File metadata and controls
117 lines (102 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Abstract Character class
class Character {
public:
virtual void print() = 0; // Pure virtual function to print details
virtual string getSecretIdentity() = 0; // Pure virtual function to get realName
virtual ~Character() {} // Virtual destructor
};
// Person class
class Person {
public:
string realName;
string jobTitle;
Person(string realName, string jobTitle) {
this->realName = realName;
this->jobTitle = jobTitle;
}
};
// Hero class
class Hero : public Character, public Person {
public:
string name;
vector<string> superPowers;
string weakness;
Hero(string realName, string jobTitle, string name, vector<string> superPowers, string weakness)
: Person(realName, jobTitle) {
this->name = name;
this->superPowers = superPowers;
this->weakness = weakness;
}
void print() override {
cout << "Hero's Secret Identity:" << endl;
cout << "Real Name: " << realName << endl;
cout << "Job Title: " << jobTitle << endl;
cout << endl;
cout << "But you know them as...\n" << name << endl;
cout << "Super Powers: ";
for (const string& power : superPowers) {
cout << power << " ";
}
cout << endl;
cout << "Weakness: " << weakness << endl;
}
string getSecretIdentity() override {
return realName;
}
};
// Villain class
class Villain : public Character, public Person {
public:
string name;
vector<string> superPowers;
string weakness;
Villain(string realName, string jobTitle, string name, vector<string> superPowers, string weakness)
: Person(realName, jobTitle) {
this->name = name;
this->superPowers = superPowers;
this->weakness = weakness;
}
void print() override {
cout << "Villain's Somewhat Secret Identity:" << endl;
cout << "Real Name: " << realName << endl;
cout << "Job Title: " << jobTitle << endl;
cout << endl;
cout << "But you know them as...\n" << name << endl;
cout << "Super Powers: ";
for (const string& power : superPowers) {
cout << power << " ";
}
cout << endl;
cout << "Weakness: " << weakness << endl;
}
string getSecretIdentity() override {
return realName;
}
};
int main() {
// Create a Hero
Hero hero(
"Seol Hee",
"K-Pop Idol",
"Luna Snow",
{"Ice Manipulation", "Dark-Ice", "Healing-Ice", "Charm"},
"Fire"
);
// Create a Villain
Villain villain(
"JARVIS",
"Helper to Tony Stark",
"Ultron",
{"Robot intellect", "Technology integration", "Manipulation"},
"Humanity"
);
// Display Hero and Villain details
hero.print();
cout << endl;
villain.print();
return 0;
}