Datasheet

The promote() and demote() methods simply call the setSalary() method with a new value. Note
that the default values for the integer parameters do not appear in the source file. They only need to
exist in the header.
void Employee::hire()
{
fHired = true;
}
void Employee::fire()
{
fHired = false;
}
The hire() and fire() methods just set the fHired data member appropriately.
void Employee::display()
{
cout << “Employee: “ << getLastName() << “, “ << getFirstName() << endl;
cout << “-------------------------” << endl;
cout << (fHired ? “Current Employee” : “Former Employee”) << endl;
cout << “Employee Number: “ << getEmployeeNumber() << endl;
cout << “Salary: $” << getSalary() << endl;
cout << endl;
}
The display() method uses the console output stream to display information about the current
employee. Because this code is part of the Employee class, it could access data members, such as
mSalary, directly instead of using the getSalary() accessor. However, it is considered good style to
make use of accessors when they exist, even within the class.
// Accessors and setters
void Employee::setFirstName(string inFirstName)
{
mFirstName = inFirstName;
}
string Employee::getFirstName()
{
return mFirstName;
}
void Employee::setLastName(string inLastName)
{
mLastName = inLastName;
}
string Employee::getLastName()
{
return mLastName;
}
32
Chapter 1
04_574841 ch01.qxd 12/15/04 3:39 PM Page 32