#include #include #include using namespace std; class person { protected: string fname, lname; public: person(string f, string l); virtual void print(); string get_fname(); string get_lname(); }; person::person(string f, string l) { fname = f; lname = l; }; void person::print() { cout << fname << " " << lname << "\n"; } string person::get_fname() { return fname; } string person::get_lname() { return lname; } class employee: public person { protected: int salary; string position; public: employee(string f, string l, int s, string n); virtual void print(); }; employee::employee(string f, string l, int s, string n): person(f, l) { salary = s; position = n; } void employee::print() { person::print(); cout << " $" << salary << ", " << position << "\n"; } class criminal: public person { protected: string crime; public: criminal(string f, string l, string c); virtual void print(); }; criminal::criminal(string f, string l, string c): person(f, l) { crime = c; } void criminal::print() { cout << crime << ": "; person::print(); } class banker: public criminal { protected: int amount; public: banker(string f, string l, int ae); void print(); }; banker::banker(string f, string l, int ae): criminal(f, l, "fraud") { amount = ae; } void banker::print() { person::print(); cout << " a banker\n"; } vector people; void add_person(person * p) { people.push_back(p); } void list_people() { for (int i = 0; i < people.size(); i += 1) people[i]->print(); } person * find_person(string name) { for (int i = 0; i < people.size(); i += 1) if (people[i]->get_fname() == name || people[i]->get_lname() == name) return people[i]; return NULL; } int main() { add_person(new person("Mary", "Marlowe")); add_person(new person("Dennis", "Dog")); add_person(new person("Eric", "Earwig")); add_person(new person("Tammy", "Teapot")); add_person(new person("Francine", "Frogge")); add_person(new person("Geoffrey", "Georaffe")); add_person(new person("Lolita", "Lambchop")); add_person(new person("Indiana", "Impediment")); add_person(new person("Germania", "Gastropod")); add_person(new person("Olivia", "Ointment")); add_person(new employee("Colin", "Nostril", 34500, "manager")); add_person(new employee("Evangelina", "Smith", 64250, "designer")); add_person(new employee("Lumpy", "Morris", 52000, "secretary")); add_person(new employee("Ravioli", "Johnson", 57500, "typist")); add_person(new criminal("Knuckles", "Badman", "burglary")); add_person(new criminal("Basher", "McRough", "assault")); add_person(new criminal("Murgatroyd", "Madd", "murder")); add_person(new banker("Arthur", "Arthropod-Smythe", 57000000)); add_person(new banker("Melinda", "Machiavelli", 72500000)); string cmd; while (true) { cout << "> "; cin >> cmd; if (cmd == "list") list_people(); else if (cmd == "find") { string n; cin >> n; person * e = find_person(n); if (e == NULL) cout << "Not found\n"; else e->print(); } /* else if (cmd == "raise") { string n; cin >> n; double pct; cin >> pct; person * e = find_employee(n); e->salary *= 1.0 + pct / 100.0; } */ else if (cmd == "exit") break; else cout << "command '" << cmd << "' not recognised\n"; } }