1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
class Employee
{
private:
int id; // employee ID
char name[21]; // employee name in c-string
double hourlyPay; // pay per hour
int numDeps; // number of dependents
int type; // employee type
public:
Employee( int initId=0, char initName[]=0, double initHourlyPay=0.0, int initNumDeps=0, int initType=0 ); // Constructor
bool set(int newId, char newName[], double newHourlyPay, int newNumDeps, int newType);
int getID() {return id;}
char getName() {return name[21];}
double getHourlyPay() {return hourlyPay;}
int getNumDeps() {return numDeps;}
int getType() {return type;}
};
Employee::Employee( int initId, char initName[], double initHourlyPay, int initNumDeps, int initType)
{
bool status = set( initId, initName, initHourlyPay, initNumDeps, initType );
if ( !status )
{
id = 0;
strcpy(name, " ");
hourlyPay = 0.0;
numDeps = 0;
type = 0;
}
}
bool Employee::set( int newId, char newName[], double newHourlyPay, int newNumDeps, int newType )
{
bool status = false;
if ( newId > 0 && newHourlyPay > 0 && newNumDeps >= 0 && newType >= 0 && newType <= 1 )
{
status = true;
id = newId;
strcpy(newName, name);
hourlyPay = newHourlyPay;
numDeps = newNumDeps;
type = newType;
}
return status;
}
|