#include #include #include #include using namespace std; class person { public: string fname, lname; double salary; string dept; person(string f, string l, double s, string d); void print(ostream & out) const; }; person::person(string f, string l, double s, string d) { fname = f; lname = l; salary = s; dept = d; }; void person::print(ostream & out) const { out << fname << " " << lname << " of " << dept << ", $" << setprecision(2) << salary << "."; } ostream & operator<<(ostream & out, const person & p) { p.print(out); return out; } class database { protected: vector employees; public: void add_employee(string f, string l, double s, string d); void list_employees(); person * find_employee(string name); }; void database::add_employee(string f, string l, double s, string d) { person * p = new person(f, l, s, d); employees.push_back(p); } void database::list_employees() { for (int i = 0; i < employees.size(); i += 1) cout << * employees[i] << "\n"; } person * database::find_employee(string name) { for (person * p: employees) if (p->fname == name || p->lname == name) return p; return NULL; } int main() { database db; db.add_employee("Mary", "Marlowe", 123456.00, "Management"); db.add_employee("Dennis", "Dog", 54321.50, "Design"); db.add_employee("Eric", "Earwig", 34567.75, "Engineering"); db.add_employee("Tammy", "Teapot", 23500.00, "Tetrahedrons"); db.add_employee("Francine", "Frogge", 168742.50, "Management"); db.add_employee("Geoffrey", "Georaffe", 21005.99, "Geography"); db.add_employee("Lolita", "Lambchop", 25300.00, "Lighting"); db.add_employee("Indiana", "Impediment", 1500.00, "Intern"); db.add_employee("Germania", "Gastropod", 47299.99, "Geography"); db.add_employee("Olivia", "Ointment", 25000000.00, "Owner"); cout << fixed; // opposite and default is scientific string line, cmd; while (true) { cout << "\n> "; getline(cin, line); if (cin.fail()) { cout << "\n"; break; } istringstream in(line); in >> cmd; if (in.fail()) continue; else if (cmd == "list") db.list_employees(); else if (cmd == "find") { string name; in >> name; if (in.fail()) { cout << "name missing\n"; continue; } person * p = db.find_employee(name); if (p == NULL) cout << "no such person\n"; else cout << * p << "\n"; } else if (cmd == "raise") { string name; double percent; in >> name >> percent; if (in.fail()) { cout << "name or percentage or both missing\n"; continue; } person * p = db.find_employee(name); if (p == NULL) cout << "no such person\n"; else p->salary *= (1.0 + percent / 100.0); } else if (cmd == "exit") break; else cout << "command '" << cmd << "' not recognised\n"; } }