Datasheet

case 1:
doHire(employeeDB);
break;
case 2:
doFire(employeeDB);
break;
case 3:
doPromote(employeeDB);
break;
case 4:
employeeDB.displayAll();
break;
case 5:
employeeDB.displayCurrent();
break;
case 6:
employeeDB.displayFormer();
break;
case 0:
done = true;
break;
default:
cerr << “Unknown command.” << endl;
}
}
return 0;
}
The main() function is a loop that displays the menu, performs the selected action, then does it all
again. For most actions, separate functions are defined. For simpler actions, like displaying employees,
the actual code is put in the appropriate case.
int displayMenu()
{
int selection;
cout << endl;
cout << “Employee Database” << endl;
cout << “-----------------” << endl;
cout << “1) Hire a new employee” << endl;
cout << “2) Fire an employee” << endl;
cout << “3) Promote an employee” << endl;
cout << “4) List all employees” << endl;
cout << “5) List all current employees” << endl;
cout << “6) List all previous employees” << endl;
cout << “0) Quit” << endl;
cout << endl;
cout << “---> “;
cin >> selection;
return selection;
}
39
A Crash Course in C++
04_574841 ch01.qxd 12/15/04 3:39 PM Page 39