#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! } }; void ShowManagerInfo(Manager *m){ cout<<"Monthly Salary:$"<getMonthlySalary()<<"\tName:"<Name<getMonthlySalary()<< "\tName:"<Name<getMonthlySalary()>ss[y+1]->getMonthlySalary()){ Staff *s = ss[y]; ss[y] = ss[y+1]; ss[y+1] = s; } } } } void sortStaffBySalaryDesc(Staff **ss,int noi){ for(int x=0;x<(noi-1);x++){ for(int y=0;y<(noi-1-x);y++){ if(ss[y]->getMonthlySalary()getMonthlySalary()){ Staff *s = ss[y]; ss[y] = ss[y+1]; ss[y+1] = s; } } } } void sortStaffByName(Staff **ss,int noi){ for(int x=0;x<(noi-1);x++){ for(int y=0;y<(noi-1-x);y++){ if(strcmp(ss[y]->Name,ss[y+1]->Name)>0){ Staff *s = ss[y]; ss[y] = ss[y+1]; ss[y+1] = s; } } } } 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)); sortStaffBySalary(staff,NOI(staff)); showStaffInfo(staff,NOI(staff)); sortStaffBySalaryDesc(staff,NOI(staff)); showStaffInfo(staff,NOI(staff)); sortStaffByName(staff,NOI(staff)); showStaffInfo(staff,NOI(staff)); for(int i=0;i