Datasheet

A number of accessors provide mechanisms to change the information about an employee or query the
current information about an employee:
private:
std::string mFirstName;
std::string mLastName;
int mEmployeeNumber;
int mSalary;
bool fHired;
};
}
Finally, the data members are declared as private so that other parts of the code cannot modify them
directly. The accessors provide the only public way of modifying or querying these values.
Employee.cpp
The implementations for the Employee class methods are shown here:
// Employee.cpp
#include <iostream>
#include “Employee.h”
using namespace std;
namespace Records {
Employee::Employee()
{
mFirstName = “”;
mLastName = “”;
mEmployeeNumber = -1;
mSalary = kDefaultStartingSalary;
fHired = false;
}
The Employee constructor sets the initial values for the Employee’s data members. By default, new
employees have no name, an employee number of -1, the default starting salary, and a status of not
hired.
void Employee::promote(int inRaiseAmount)
{
setSalary(getSalary() + inRaiseAmount);
}
void Employee::demote(int inDemeritAmount)
{
setSalary(getSalary() - inDemeritAmount);
}
31
A Crash Course in C++
04_574841 ch01.qxd 12/15/04 3:39 PM Page 31