#include using namespace std; #include #define NOI(_arr) (sizeof(_arr)/sizeof(_arr[0])) typedef const char * String; typedef unsigned short ushort; class Person{ public: String Name; Person(String name):Name(name){} }; class Student:public Person{ public: float CGPA; Student(String name, float cgpa):Person(name),CGPA(cgpa){ } //Student():Name(""),CGPA(0.0F){ Student():Student("",0.0F){ } }; class Staff:public Person{ protected: const double EPF_CONTRIBUTION=0.11; public: double Salary; Staff(String name, double salary):Person(name),Salary(salary){ } virtual double getMonthlySalary()=0; }; class Lecturer:public Staff{ public: float Allowance; Lecturer(String name, double salary, float allowance): Staff(name,salary),Allowance(allowance){ } double getMonthlySalary(){//The operation return (1.0-EPF_CONTRIBUTION)*Salary + Allowance;//The Method! } }; class Clerk:public Staff{ public: ushort OTHours; float OTRate; Clerk(String name, double salary, float otRate): Staff(name,salary),OTRate(otRate){ OTHours = 0; } double getMonthlySalary(){//The operation return (1.0-EPF_CONTRIBUTION)*Salary + (OTRate*OTHours);//The Method! } }; class Manager:public Staff{ public: float CarAllowance; Manager(String name, double salary, float carAllowance): Staff(name,salary),CarAllowance(carAllowance){ } double getMonthlySalary(){//The operation return (1.0-EPF_CONTRIBUTION)*Salary + CarAllowance;//The Method! } }; class HRManager:public Manager{ public: HRManager(String name, double salary):Manager(name,salary,500.0F){ } }; class SalesManager:public Manager{ public: float PetrolAllowance; double MonthlySales; SalesManager(String name, double salary, float carAllowance,float petrolAllowance): Manager(name,salary,carAllowance), PetrolAllowance(petrolAllowance),MonthlySales(0.0){ } double getMonthlySalary(){//The operation return (1.0-EPF_CONTRIBUTION)*(0.6*Salary) + (0.1*MonthlySales) + CarAllowance + PetrolAllowance;//The Method! } }; typedef bool (*Swap)(Staff* ,Staff*); void ShowManagerInfo(Manager *m){ cout<<"Monthly Salary:$"<getMonthlySalary()<<"\tName:"<Name<getMonthlySalary()<< "\tName:"<Name<getMonthlySalary()>rhs->getMonthlySalary(); } bool bySalaryDesc(Staff *lhs,Staff *rhs){ return lhs->getMonthlySalary()getMonthlySalary(); } bool byName(Staff *lhs,Staff *rhs){ return strcmp(lhs->Name,rhs->Name)>0; } int main(){ Staff *staff[]={ new Lecturer ("Low Mai Kai",4500,450.0F), new Clerk ("Low Mee",2500,25.0F), new Manager ("Yong Tau Foo",5000,700), new HRManager ("Chow Kui Teao",5500), new SalesManager("Low See Fun",4000,600,800), }; showStaffInfo(staff,NOI(staff)); sortStaff(staff,NOI(staff),bySalary); showStaffInfo(staff,NOI(staff)); sortStaff(staff,NOI(staff),bySalaryDesc); showStaffInfo(staff,NOI(staff)); sortStaff(staff,NOI(staff),byName); showStaffInfo(staff,NOI(staff)); for(int i=0;i