#include
#include
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<
};
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++初学者~水平有限啦~~
#include
#include
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<<"职工"<
int main()
{
Employee e1(1001,"张明",1200,1800,300,0,0);
e1.show();
cout<
e2.show();
cout<
e3.show();
cout<
e4.show();
cout<
e5.show();
cout<
}
我也是新手,费了我九牛二虎之力,中间不知道出现了多少错,还好功夫不负有心人终于成功了,不知道人满意不满意,不过没关系,全当自己锻炼下,献丑了,呵呵,一起加油吧!