工人类有name 年龄age 工作部门dept 工资类成员salary中有基本工资wage 岗位津贴subsidy。房租rent。水费waterfee。电费elecfee。并统计工人人数

#include"iostream"
using namespace std;
class salary{
private:
double wage,subsidy,rent,waterfee,elecfee;
public:
salary(double a,double b,double c, double d,double e):wage(a),subsidy(b),rent(c),waterfee(d),elecfee(e){}
salary(){
wage=subsidy=rent=waterfee=elecfee=0;
}
void setwage(double f){ wage=f; }
void setsubsidy(double f){ subsidy=f; }
void setrent(double f){ subsidy=f; }
void setwaterfee(double f){ waterfee=f; }
void setelecfee(double f){ elecfee=f; }
double getwage(){ return wage; }
double getsubsidy(){ return subsidy; }
double getrent(){ return rent; }
double getwaterfee(){ return waterfee; }
double getelecfee(){ return elecfee; }
double realsalary();
};


double salary::realsalary(){
double realsalary;
realsalary=wage+subsidy-rent-waterfee-elecfee;
return realsalary;
}


class worker{
private:
static int m;
char name[8];
int age;
char dept[8];
salary A;
public:
worker::worker(char* a,int b,char* c,double d,double e,double f,double g,double h):age(b),A(d,e,f,g,h)
{
strcpy(name,a);
strcpy(dept,c);
m++;


};
int getm(){ return m; }
};






int worker::m=0;


void main(){
worker x1("liu",20,"suibian",1000,200,500,100,200);
worker x2("pp",21,"suibian",1000,200,500,100,200);
cout << x1.getm() << endl;
}


你可能感兴趣的:(C++)