Datasheet

void Employee::setEmployeeNumber(int inEmployeeNumber)
{
mEmployeeNumber = inEmployeeNumber;
}
int Employee::getEmployeeNumber()
{
return mEmployeeNumber;
}
void Employee::setSalary(int inSalary)
{
mSalary = inSalary;
}
int Employee::getSalary()
{
return mSalary;
}
bool Employee::getIsHired()
{
return fHired;
}
}
A number of accessors and setters perform the simple task of getting and setting values. Even though
these methods seem trivial, it’s better to have trivial accessors and setters than to make your data mem-
bers
public. In the future, you may want to perform bounds checking in the setSalary() method, for
example.
EmployeeTest.cpp
As you write individual classes, it is often useful to test them in isolation. The following code includes a
main() function that performs some simple operations using the Employee class. Once you are confi-
dent that the
Employee class works, you should remove or comment-out this file so that you don’t
attempt to compile your code with multiple
main() functions.
// EmployeeTest.cpp
#include <iostream>
#include “Employee.h”
using namespace std;
using namespace Records;
int main (int argc, char** argv)
{
cout << “Testing the Employee class.” << endl;
33
A Crash Course in C++
04_574841 ch01.qxd 12/15/04 3:39 PM Page 33