#include #include using namespace std; class person { public: string fname, lname; double salary; string dept; person(string f, string l, double s, string d) { fname = f; lname = l; salary = s; dept = d; } person() { salary = 0.0; } void print() { cout << fname << " " << lname << ", of " << dept << ", $" << salary << " per year\n"; } }; const int max_emps = 100; person employee[max_emps]; int num_emps = 0; void add_employee(string f, string l, double s, string d) { if (num_emps >= max_emps) { cerr << "Too many employees, not added\n"; return; } employee[num_emps] = person(f, l, s, d); cout << "OK, added " << num_emps << ": "; employee[num_emps].print(); num_emps += 1; } void list_employees() { for (int i = 0; i < num_emps; i += 1) { cout << i << ": "; employee[i].print(); } } person find_employee(string wanted) { for (int i = 0; i < num_emps; i += 1) if (employee[i].fname == wanted || employee[i].lname == wanted) return employee[i]; } int main() { add_employee("Mary", "Marlowe", 123456.00, "Management"); add_employee("Dennis", "Dog", 54321.50, "Design"); add_employee("Eric", "Earwig", 34567.75, "Engineering"); add_employee("Tammy", "Teapot", 23500.00, "Tetrahedrons"); add_employee("Francine", "Frogge", 168742.50, "Management"); add_employee("Geoffrey", "Georaffe", 21005.99, "Geography"); add_employee("Lolita", "Lambchop", 25300.00, "Lighting"); add_employee("Indiana", "Impediment", 1500.00, "Intern"); add_employee("Germania", "Gastropod", 47299.99, "Geography"); add_employee("Olivia", "Ointment", 25000000.00, "Owner"); string cmd; while (true) { cout << "> "; cin >> cmd; if (cmd == "list") list_employees(); else if (cmd == "find") { string who; cin >> who; person p = find_employee(who); // this fails when an employee name is mistyped. // in that case find_employee never returns a correctly constructed person object // p is just a mess. Anything could happen. p.print(); } else if (cmd == "exit") break; else cout << "command '" << cmd << "' not recognised\n"; } }