Datasheet
The displayMenu() function simply outputs the menu and gets input from the user. One important
note is that this code assumes that the user will “play nice” and type a number when a number is
requested. When you read about I/O in Chapter 14, you will learn how to protect against bad input
void doHire(Database& inDB)
{
string firstName;
string lastName;
cout << “First name? “;
cin >> firstName;
cout << “Last name? “;
cin >> lastName;
try {
inDB.addEmployee(firstName, lastName);
} catch (std::exception ex) {
cerr << “Unable to add new employee!” << endl;
}
}
The doHire() function simply gets the new employee’s name from the user and tells the database to
add the employee. It handles errors somewhat gracefully by outputting a message and continuing.
void doFire(Database& inDB)
{
int employeeNumber;
cout << “Employee number? “;
cin >> employeeNumber;
try {
Employee& emp = inDB.getEmployee(employeeNumber);
emp.fire();
cout << “Employee “ << employeeNumber << “ has been terminated.” << endl;
} catch (std::exception ex)
cerr << “Unable to terminate employee!” << endl;
}
}
void doPromote(Database& inDB)
{
int employeeNumber;
int raiseAmount;
cout << “Employee number? “;
cin >> employeeNumber;
cout << “How much of a raise? “;
cin >> raiseAmount;
40
Chapter 1
04_574841 ch01.qxd 12/15/04 3:39 PM Page 40