作业题目:
假设某销售公司有一般员工、销售员工和销售经理。月工资的计算方法是:
一般员工月薪=基本工资
销售员工月薪=基本工资+销售额提成率
销售经理月薪=基本工资+职务工资+销售额*提成率
编写程序,定义一个表示一般员工的基类Employee,它包含三个表示员工基本信息的数据成员:编号 number、姓名name 和基本工资basicSalary。
由Employee类派生销售员工Salesman类,Salesman类包含两个新数据成员:销售额sales和静态数据成员提成比例commrate
再由Salesman类派生表示销售经理的Salesmanager类。Salesmanager类包含新数据成员:岗位工资jobSalary。
为这些类定义初始化数据的构造函数,以及输入数据input、计算工资pay和输出工资条print的成员函数。
设该公司员工的基本工资是2000元,销售经理的岗位工资是3000元,提成率=5/1000。在main函数中,输入若干个不同类型的员工信息测试你的类结构。
新增功能:① 在类Salesman与类Salesmanager中增加奖励函数award,用于判断这两类员工每月的销售额是否达到奖励条件。
②将原题目中静态数据成员提成比例commrate改为动态的数据成员,这样更符合现实的需求,在重载流插入运算符的时输入该数据成员。
#include <iostream>
using namespace std;
class Employee
{
public:
char number[10];
char name[10];
double basicSlary;
Employee(double);
void printEm();
friend istream& operator >>(istream& in, Employee& x);
};
Employee::Employee(double a):basicSlary(a) {
}
void Employee::printEm()
{
cout << "一般员工工资条:" << endl;
cout << "姓名" << "\t" << "编号" << "\t" << "工资" << endl;
cout << name << "\t" << number << "\t" << basicSlary << endl;
}
//Employee >>
istream& operator >>(istream& in, Employee& x)
{
cout << "请输入普通员工姓名:" << endl;
cin >> x.name;
cout << "请输入普通员工编号:" << endl;
cin >> x.number;
return in;
}
class Salesman : public Employee
{
public:
double sales;
double add;
Salesman(double );
void printSa();
void award1();
friend istream& operator >>(istream& in, Salesman& x);
};
Salesman::Salesman(double b):Employee(b) {
}//Salesman 构造
//Salesman >>
istream& operator >>(istream& in, Salesman& x)
{
cout << "请输入销售员工姓名:" << endl;
cin >> x.name;
cout << "请输入销售员工编号:" << endl;
cin >> x.number;
cout << "该员工销售额为:" << endl;
cin >> x.sales;
cout << "该公司的提成率为:" << endl;
cin >> x.add;
return in;
}
void Salesman::printSa()
{
cout << " Salesman 工资条:" << endl;
cout << "姓名" << "\t" << "编号" << "\t" << endl;
cout << name << "\t" << number << "\t" << endl;
cout << "销售额" <<"\t"<<"提成率"<< endl;
cout << sales<<"\t"<<add<<endl;
cout << "工资明细: (总=基本工资+销售额*提成率)" << endl;
cout << basicSlary << "+" << sales << "*" << add << " = " << basicSlary + (sales * add) << endl;
}
//每月奖条件1(增加功能)
void Salesman:: award1()
{
if (sales >= 100)
{
basicSlary += 500;
cout << "该月销售额到达100,获得奖金500." << endl;
}
else
{
cout << "该月销售额未到达奖励条件!~继续努力哦!" << endl;
}
}
class Salesmanager:public Salesman
{
public:
double manager;
Salesmanager(double);
friend istream& operator >>(istream& in, Salesmanager& x);
void award2();
void printMa();
//工资计算
};
Salesmanager::Salesmanager(double c):Salesman(c) {
} //manager 构造
istream& operator >>(istream& in, Salesmanager& x)
{
cout << "请输入销售经理姓名:" << endl;
cin >> x.name;
cout << "请输入销售经理编号:" << endl;
cin >> x.number;
cout << "该员工销售额为:" << endl;
cin >> x.sales;
cout << "该公司的提成率为:" << endl;
cin >> x.add;
cout << "manger 的职务工资 " << endl;
cin >> x.manager;
return in;
}
void Salesmanager::printMa()
{
cout << " Salesman 工资条:" << endl;
cout << "姓名" << "\t" << "编号" << "\t" << endl;
cout << name << "\t" << number << "\t" << endl;
cout << "销售额" << "\t" << "提成率" <<"\t" <<"manager 职位工资"<<endl;
cout << sales << "\t" << add << "\t" <<manager<<endl;
cout << "工资明细: (总=基本工资+职务工资+销售额*提成率)" << endl;
cout << basicSlary << "+" <<manager<<"+"<< sales << "*" << add << " = " << basicSlary +manager+ (sales * add) << endl;
}
void Salesmanager:: award2()
{
if (sales >= 100)
{
basicSlary += 500;
cout << "该月销售额到达100,获得奖金500." << endl;
}
else
{
cout << "该月销售额未到达奖励条件!~继续努力哦!" << endl;
}
}
int main()
{
Employee a(2000);
cin >> a;
a.printEm();
Salesman b(2000);
cin >> b;
b.award1();
b.printSa();
Salesmanager c(2000);
cin >> c;
c.award2();
c.printMa();
}