Datasheet
employee reference by calling the getEmployee() method. Two versions of this method are declared.
One allows retrieval by employee number. The other requires a first and last name.
void displayAll();
void displayCurrent();
void displayFormer();
Because the database is the central repository for all employee records, it has methods that will output
all employees, the employees who are currently hired, and the employees who are no longer hired.
protected:
Employee mEmployees[kMaxEmployees];
int mNextSlot;
int mNextEmployeeNumber;
};
}
The mEmployees array is a fixed-size array that contains the Employee objects. When the database is
created, this array will be filled with nameless employees, all with an employee number of -1. When
the
addEmployee() method is called, one of these blank employees will be populated with real data.
The
mNextSlot data member keeps track of which blank employee is next in line to be populated. The
mNextEmployeeNumber data member keeps track of what employee number will be assigned to the
new employee.
Database.cpp
// Database.cpp
#include <iostream>
#include <stdexcept>
#include “Database.h”
using namespace std;
namespace Records {
Database::Database()
{
mNextSlot = 0;
mNextEmployeeNumber = kFirstEmployeeNumber;
}
Database::~Database()
{
}
The Database constructor takes care of initializing the next slot and next employee number members to
their starting values.
mNextSlot is initialized to zero so that when the first employee is added, it will go
into slot 0 of the
mEmployees array.
35
A Crash Course in C++
04_574841 ch01.qxd 12/15/04 3:39 PM Page 35