5. 编写一个程序实现小型公司的工资管理。定义一个职员类(Employee),由职员类派生出经理(Manager)、销
5.编写一个程序实现小型公司的工资管理。定义一个职员类(Employee),由职员类派生出经理(Manager)、销售人员(Sales)、工程师(Engineer)。要求...
5. 编写一个程序实现小型公司的工资管理。定义一个职员类(Employee),由职员类派生出经理(Manager)、销售人员(Sales)、工程师(Engineer)。要求存储公司职员的工号、姓名和月基本工资,计算月工资并且显示全部信息。月工资的计算方法如下:经理的月基本工资为8000,月工资为绩效系数*月基本工资,销售人员的月基本工资为4000,月工资为月基本工资+销售提成,销售提成为月销售额的5%,工程师的月基本工资为6000,月工资为月基本工资+开发奖励工资,开发奖励工资为300*功能模块完成数量。抽象基类和各派生类均有一个公有成员函数salary_computing() ,用于计算各位职员的工资总额。
设计抽象基类Employee和派生类Manager、Sales和Engineer。
主函数中定义了一个基类Employee的动态指针数组 pt2employ,数组长度n来自输入数据
Employee **pt2employ = new Employee*[n];
主函数根据输入的职员类型和职员基本信息,建立相应的类对象,并且取址按序赋给基类指针数组元素,最后遍历基类指针数组 pt2employ,找出具有最高工资的Manager、Sales和Engineer,并且输出。
输入格式: 测试输入包含一个测试用例,该测试用例的第一行输入职员的人数n,接下来n行每一行给出一个职员的基本信息,每行的第一个数字为当前职员的工号,第二个为一个字符串,是职员的姓名,第三个数据是一个字符串,是职员的职位,若职位为Manager,后面跟随一个数字是其绩效系数,若职位为Sales,后面跟随一个数字是其月销售额,若职位为Engineer,后面跟随一个数字是其完成的模块数目。
输出格式:见输出样例
说明:本题中绩效系数、工资等数据均为double型,输出不保留小数部分
输入实例:
6
101 bob Manager 1.4
102 Sam Sales 100000
103 Apple Sales 150000
104 Bill Engineer 12
105 Mike Manager 1.3
106 Henry Engineer 15
输出实例:
Top Manager: 101 bob A Manager with salary 11200
Top Sales: 103 Apple A Sales with salary 11500
Top Engineer: 106 Henry A Engineer with salary 10500 展开
设计抽象基类Employee和派生类Manager、Sales和Engineer。
主函数中定义了一个基类Employee的动态指针数组 pt2employ,数组长度n来自输入数据
Employee **pt2employ = new Employee*[n];
主函数根据输入的职员类型和职员基本信息,建立相应的类对象,并且取址按序赋给基类指针数组元素,最后遍历基类指针数组 pt2employ,找出具有最高工资的Manager、Sales和Engineer,并且输出。
输入格式: 测试输入包含一个测试用例,该测试用例的第一行输入职员的人数n,接下来n行每一行给出一个职员的基本信息,每行的第一个数字为当前职员的工号,第二个为一个字符串,是职员的姓名,第三个数据是一个字符串,是职员的职位,若职位为Manager,后面跟随一个数字是其绩效系数,若职位为Sales,后面跟随一个数字是其月销售额,若职位为Engineer,后面跟随一个数字是其完成的模块数目。
输出格式:见输出样例
说明:本题中绩效系数、工资等数据均为double型,输出不保留小数部分
输入实例:
6
101 bob Manager 1.4
102 Sam Sales 100000
103 Apple Sales 150000
104 Bill Engineer 12
105 Mike Manager 1.3
106 Henry Engineer 15
输出实例:
Top Manager: 101 bob A Manager with salary 11200
Top Sales: 103 Apple A Sales with salary 11500
Top Engineer: 106 Henry A Engineer with salary 10500 展开
展开全部
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Employee
{
protected:
int id;
string name;
double basic_salary;
string title;
public:
Employee(int i, string n, double b, string t)
: id(i), name(n), basic_salary(b), title(t) {}
virtual double salary_computing() const = 0;
string get_title() const
{
return title;
}
void print() const
{
cout << id << " " << name << " A " << title << " with salary " << fixed << setprecision(0) << salary_computing() << endl;
}
};
class Manager : public Employee
{
static Employee* top;
double effiency;
public:
Manager(int id, string name, double e)
: Employee(id,name,8000,"Manager"), effiency(e)
{
if(top==NULL || salary_computing() > top->salary_computing())
top = this;
}
double salary_computing() const
{
return effiency * basic_salary;
}
static void printmax()
{
cout << "Top Manager: ";
if(top) top->print();
}
};
Employee* Manager::top = NULL;
class Sales : public Employee
{
static Employee* top;
double sales;
public:
Sales(int id, string name, double s)
: Employee(id,name,4000,"Sales"), sales(s)
{
if(top==NULL || salary_computing() > top->salary_computing())
top = this;
}
double salary_computing() const
{
return basic_salary + 0.05 * sales;
}
static void printmax()
{
cout << "Top Sales: ";
if(top) top->print();
}
};
Employee* Sales::top = NULL;
class Engineer : public Employee
{
static Employee* top;
double num;
public:
Engineer (int id, string name, double m)
: Employee(id,name,6000,"Engineer"), num(m)
{
if(top==NULL || salary_computing() > top->salary_computing())
top = this;
}
double salary_computing() const
{
return basic_salary + 300 * num;
}
static void printmax()
{
cout << "Top Engineer: ";
if(top) top->print();
}
};
Employee* Engineer::top = NULL;
int main()
{
int n, i;
cin >> n;
Employee **pt2employ = new Employee*[n];
for(i=0;i<n;i++)
{
int id;
cin >> id;
string name;
cin >> name;
string title;
cin >> title;
double e;
cin >> e;
if(title == "Manager")
{
pt2employ[i] = new Manager(id,name,e);
}
else if(title == "Sales")
{
pt2employ[i] = new Sales(id,name,e);
}
else if(title == "Engineer")
{
pt2employ[i] = new Engineer(id,name,e);
}
}
Manager::printmax();
Sales::printmax();
Engineer::printmax();
}
#include <string>
#include <iomanip>
using namespace std;
class Employee
{
protected:
int id;
string name;
double basic_salary;
string title;
public:
Employee(int i, string n, double b, string t)
: id(i), name(n), basic_salary(b), title(t) {}
virtual double salary_computing() const = 0;
string get_title() const
{
return title;
}
void print() const
{
cout << id << " " << name << " A " << title << " with salary " << fixed << setprecision(0) << salary_computing() << endl;
}
};
class Manager : public Employee
{
static Employee* top;
double effiency;
public:
Manager(int id, string name, double e)
: Employee(id,name,8000,"Manager"), effiency(e)
{
if(top==NULL || salary_computing() > top->salary_computing())
top = this;
}
double salary_computing() const
{
return effiency * basic_salary;
}
static void printmax()
{
cout << "Top Manager: ";
if(top) top->print();
}
};
Employee* Manager::top = NULL;
class Sales : public Employee
{
static Employee* top;
double sales;
public:
Sales(int id, string name, double s)
: Employee(id,name,4000,"Sales"), sales(s)
{
if(top==NULL || salary_computing() > top->salary_computing())
top = this;
}
double salary_computing() const
{
return basic_salary + 0.05 * sales;
}
static void printmax()
{
cout << "Top Sales: ";
if(top) top->print();
}
};
Employee* Sales::top = NULL;
class Engineer : public Employee
{
static Employee* top;
double num;
public:
Engineer (int id, string name, double m)
: Employee(id,name,6000,"Engineer"), num(m)
{
if(top==NULL || salary_computing() > top->salary_computing())
top = this;
}
double salary_computing() const
{
return basic_salary + 300 * num;
}
static void printmax()
{
cout << "Top Engineer: ";
if(top) top->print();
}
};
Employee* Engineer::top = NULL;
int main()
{
int n, i;
cin >> n;
Employee **pt2employ = new Employee*[n];
for(i=0;i<n;i++)
{
int id;
cin >> id;
string name;
cin >> name;
string title;
cin >> title;
double e;
cin >> e;
if(title == "Manager")
{
pt2employ[i] = new Manager(id,name,e);
}
else if(title == "Sales")
{
pt2employ[i] = new Sales(id,name,e);
}
else if(title == "Engineer")
{
pt2employ[i] = new Engineer(id,name,e);
}
}
Manager::printmax();
Sales::printmax();
Engineer::printmax();
}
参考资料: http://ideone.com/MLG4J
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询