【C++作业】求高手帮忙解答一下,明天要用! 第三题

定义职工类Employee,描述职工的信息有:工号(num)、姓名(name)、基本工资(base_salary)、岗位工资(post_salary)、医疗住房基金(fu... 定义职工类Employee,描述职工的信息有:工号(num)、姓名(name)、基本工资(base_salary)、岗位工资(post_salary)、医疗住房基金(fund)、税金(tax)与实发工资(fact_salary)。声明构造函数为工号(num)、姓名(name)、基本工资(base_salary)、岗位工资(post_salary)、医疗住房基金(fund)赋值;声明函数computeTax计算税金;声明函数computeSalary计算实发工资(实发工资=基本工资+岗位工资-医疗住房基金-税金);函数show显示信息。
税金=应发工资*税率
税率设为:<2000:2% 2000-3000:5% 3000-4000:10% >4000:15%
输入职工的信息,并进行计算输出:
1001,张明,1200,1800,300,100
1002,周明,1300,2000,310,110
1003,李明,1400,2200,320,120
1004,陈明,1500,2400,330,130
1005,赵明,1600,2600,340,140
展开
 我来答
在龙泉山哈哈大笑的白肩雕
2009-12-04
知道答主
回答量:8
采纳率:0%
帮助的人:6.7万
展开全部
#include<string>;
#include<iostream>;
using namespace std;

class Employee
{
private:
int num;
double base_salary,post_salary,fund,tax,fact_salary;
string name;
public:
Employee(int in_num,string in_name,float in_base,float in_post,float in_fund)
{
num=in_num;
name=in_name;
base_salary=in_base;
post_salary=in_post;
fund=in_fund;
}
void compute_tax()
{
float e,x;
x=base_salary+post_salary;
if (x<2000) e=.02;
else if (x<3000) e=.05;
else if (x<4000) e=.10;
else e=.15;
tax=x*e;
}
void compute_salary()
{
fact_salary=base_salary+post_salary-fund-tax;
}
void show()
{
cout<<num<<" "<<name<<" 实际工资:"<<fact_salary;
}
};

int main()
{
int i,num;
string name;
float base,post,fund1,fund2;
Employee *data[100];
for (i=0;i<5;i++)
{
cin>>num>>name>>base>>post>>fund1>>fund2;
fund1+=fund2;
data[i]=new Employee(num,name,base,post,fund1);
data[i]->compute_tax();
data[i]->compute_salary();
data[i]->show();
}
return 0;
}

这个程序没办法在输入时用“,”分隔数据,只能用空格分隔,咱是C++初学者~水平有限啦~~
zblyf
2009-12-04 · TA获得超过186个赞
知道答主
回答量:100
采纳率:0%
帮助的人:70.1万
展开全部
#include<iostream>
#include<string>
using namespace std;
class Employee{
public:
Employee(double n,string nam,double b,double p,double fun,double t,double f)
{
num=n;
name=nam;
base_salary=b;
post_salary=p;
fund=fun;
tax=t;
fact_salary=f;
}
double computeTax(double,double);
double computeSalary(double,double,double);
void show();
private:
int num;
string name;
double base_salary;
double post_salary;
double fund;
double tax;
double fact_salary;
};
double Employee::computeTax(double b,double p)
{
double y;
y=base_salary+post_salary;
if(y<2000)
return tax=y*0.02;
else if(y<3000)
return tax=y*0.05;
else if(y<4000)
return tax=y*0.1;
else return tax=y*0.15;
}
double Employee::computeSalary(double b,double p,double fun)
{

tax=computeTax(base_salary,post_salary);
return fact_salary=base_salary+post_salary-fund-tax;
}
void Employee::show()
{
cout<<"职工"<<name<<"的实发工资为:"<<computeSalary(base_salary,post_salary,fund);
}
int main()
{
Employee e1(1001,"张明",1200,1800,300,0,0);
e1.show();
cout<<endl;
Employee e2(1002,"周明",1300,2000,310,0,0);
e2.show();
cout<<endl;
Employee e3(1003,"李明",1400,2200,320,0,0);
e3.show();
cout<<endl;
Employee e4(1004,"陈明",1500,2400,330,0,0);
e4.show();
cout<<endl;
Employee e5(1005,"赵明",1600,2600,340,0,0);
e5.show();
cout<<endl;
return 0;
}
我也是新手,费了我九牛二虎之力,中间不知道出现了多少错,还好功夫不负有心人终于成功了,不知道人满意不满意,不过没关系,全当自己锻炼下,献丑了,呵呵,一起加油吧!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式