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
|
class Employee
{
protected:
char name[20];
float age;
int Eid;
float pay;
public:
Employee(void); // default constructor function
Employee(char *nam, float ag, int id, float p); // constructor fn
char *getname (void) {return name ;}; // return name
virtual int whoami() = 0;
virtual void cal_pay() = 0; // calculate pay; pure function
virtual void display() = 0; // pure virtual function
};
class Direct : public Employee
{
float basic; // basic salary
float cpf_rate ; // cpf contribuation rate
public:
Direct() ; // constructor
Direct( char * nam, float ag, int id, float bas, float r);
int whoami(); // to determine whether the employee is Direct/Indirect
void cal_pay() ;// calculate pay
void display(); // display a Direct object
friend istream& operator >> (istream& op, Direct& someDirect);
friend ifstream& operator >> (ifstream& , Direct& someDirect);
friend ofstream& operator << (ofstream& , Direct& someDirect);
};
class Indirect : public Employee
{
float hours;
float rate;
public:
Indirect(); //----constructor function
Indirect(char *nam, float ag, int id, float rat, float hr);//constructor function
int whoami();
void cal_pay(); //---- Calculate the pay of the Indirect
void display(void); //---- displays the Indirect object
friend istream& operator>>(istream& op, Indirect& someIndirect);
friend ifstream& operator>>(ifstream&, Indirect& someIndirect);
friend ofstream& operator<<(ofstream& op, Indirect& someIndirect);
};
|