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; }