Datasheet
Employee emp;
emp.setFirstName(“Marni”);
emp.setLastName(“Kleper”);
emp.setEmployeeNumber(71);
emp.setSalary(50000);
emp.promote();
emp.promote(50);
emp.hire();
emp.display();
return 0;
}
The Database Class
The Database class uses an array to store Employee objects. An integer called mNextSlot is used as a
marker to keep track of the next unused array slot. This method for storing objects is probably not ideal
because the array is of a fixed size. In Chapters 4 and 21, you will learn about data structures in the C++
standard library that you can use instead
Database.h
// Database.h
#include <iostream>
#include “Employee.h”
namespace Records {
const int kMaxEmployees = 100;
const int kFirstEmployeeNumber = 1000;
Two constants are associated with the database. The maximum number of employees is a constant
because the records are kept in a fixed-size array. Because the database will also take care of automati-
cally assigning an employee number to a new employee, a constant defines where the numbering begins.
class Database
{
public:
Database();
~Database();
Employee& addEmployee(std::string inFirstName, std::string inLastName);
Employee& getEmployee(int inEmployeeNumber);
Employee& getEmployee(std::string inFirstName, std::string inLastName);
The database provides an easy way to add a new employee by providing a first and last name. For con-
venience, this method will return a reference to the new employee. External code can also get an
34
Chapter 1
04_574841 ch01.qxd 12/15/04 3:39 PM Page 34










