10. 某單位的職工工資包括基本工資Wage,崗位巾Subsidy,房租Rent,水費Waterfee,電費Elecfee,設計實現工資管理的類Salary,該類的形式以下: class salary{ private: double wage,subsidy,rent,waterfee,elecfee; public: salary(-----){初始化工資數據的各分項} salary(){初始化工資的各分項數據爲0} void setXX (double f){xx=f;} double getXX(){return xx;} double realsalary() //計算實發工資 ------- }; 其中,成員函數setXX()用於設置工資的各分項數據,成員函數getXX()用於獲取工資的各分項數據,XX表明Wage,Subsidy等數據成員,如Wage對應的成員函數爲setWage()和getWage(). 實發工資=Wage+Subsidy-Rent-Waterfee-elecfee 編程序完善該類的設計,並寫出測試該類各成員函數的主函數main. 11. 設計工人類Worker,它具備姓名name,年齡age,工做部門Dept,工資salary等數據成員。其中,Salary使用上題上定義的類。完成Worker類的設計,並統計工人的人數,編寫測試程序進行測試 // test.cpp : 定義控制檯應用程序的入口點。 // #include<iostream> #include<string.h> #include<string> using namespace std; class Salary{ private: double Wage,Subsidy,Rent,WaterFee,ElecFee; double RealSalary; public: Salary(int wag=0,int s=0,int r=0,int wat=0,int ele=0){ Wage=wag;Subsidy=s;Rent=r;WaterFee=wat;ElecFee=ele; RealSalary=Wage+Subsidy-Rent-WaterFee-ElecFee; } void setWage(int xx){Wage=xx;} void setSubsidy(int xx){Subsidy=xx;} void setRent(int xx){Rent=xx;} void setWaterFee(int xx){WaterFee=xx;} void setElecFee(int xx){ElecFee=xx;} double getWage(){return Wage;} double getSubsidy(){return Subsidy;} double getRent(){return Rent;} double getWaterFee(){return WaterFee;} double getElecFee(){return ElecFee;} double getRealSalary(){ return RealSalary; } }; class Worker{ private: static int numbers; char *name; int age; char *Dept; Salary salary; public: Worker(const char* Name,int Age,const char* Department,int wag=0,int s=0,int r=0,int wat=0,int ele=0):salary(wag,s,r,wat,ele) { name=new char[strlen(Name)+1]; Dept=new char[strlen(Department)+1]; strcpy(Dept,Department); strcpy(name,Name); age=Age; numbers++; } void setName(const char *Name){ name=new char[strlen(Name)+1]; strcpy(name,Name); } void setAge(int a){ age=a; } void setDept(const char *Department){ Dept=new char[strlen(Department)+1]; strcpy(Dept,Department); } void setSalary(int wag, int s, int r, int wat, int e){ salary.setWage(wag); salary.setSubsidy(s); salary.setRent(r); salary.setWaterFee(wat); salary.setElecFee(e); }; static int getNumbers(){ return numbers; } char *getName(){ return name; } char *getDept(){ return Dept; } int getAge(){ return age; } double getSalary(){ return salary.getRealSalary(); } }; int Worker::numbers=0; int main() { Worker worker1("JayChen",19,"開發部",3000,1000,500,100,50); Worker worker2("JayChen1",19,"開發部",3000,1000,500,100,50); cout<<"worker1"<<endl; cout<<"name: "<<worker1.getName()<<endl; cout<<"Department:"<<worker1.getDept()<<endl; cout<<"age: "<<worker1.getAge()<<endl; cout<<"salary: "<<worker1.getSalary()<<endl; return 0; }