#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(); } } bool same(string a, string b) // a case-insensitive string comparison { int len = a.length(); if (len != b.length()) return false; for (int i = 0; i < len; i += 1) if (tolower(a[i]) != tolower(b[i])) return false; return true; } person find_employee(string wanted) { for (int i = 0; i < num_emps; i += 1) if (same(employee[i].fname, wanted) || same(employee[i].lname, wanted)) return employee[i]; return employee("*", "*", 0.0, "*"); } 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); if (p.fname == "*") cout << "not found\n"; else p.print(); } else if (cmd == "raise") { string who; double percent; cin >> who >> percent; person p = find_employee(who); if (p.fname == "*") cout << "not found\n"; else p.salary *= (1 + percent/100); cout << "new salary "; p.print(); } // this has no lasting effect. p contains just // a temporary copy of the data in the array, changing it // has no effect on the original still in the array. else if (cmd == "exit") break; else cout << "command '" << cmd << "' not recognised\n"; } }