题目要求:
模拟4S店的工资管理系统,设计多继承的层次结构,主要有4类人员:经理、兼职技术人员、销售员和销售经理。要求存储这些人的编号、姓名和月工资,计算月工资并显示全部信息。
月工资计算办法是:经理拿固定月薪8000元,兼职技术人员按每小时100元领取月薪,销售员按当月销售额的4%提成,销售经理既拿固定月工资也领取销售提成,固定月工资为5000元,销售提成为所管辖部门当月销售总额的5‰。
提示:
- 设计管理类对各类人员进行管理,可采用异质数组或者链表存储各类人员,并统计所有人的工资和。
- 在主函数中根据用户需求创建不同的人员对象,并对其进行有效的初始化,并以高效的方式输出完成的工资单
代码
#include<iostream>
#include<string>
using namespace std;
class Employee
{
protected:
int num;
string name;
public:
Employee(const int num1, string name1)
{
num = num1;
name = name1;
}
virtual ~Employee(){}
string getname()const
{
return name;
}
int getnum()const
{
return num;
}
virtual double page()const = 0;
virtual void print()const
{
cout << "编号:" << num << endl << "姓名:" << name << endl << "工资:"<< page() << endl;
}
virtual void setname(string name1)
{
name = name1;
}
};
class Engineer :public Employee
{
double hour;
public:
Engineer(const int num1,string name1,double hour1):Employee(num1,name1),hour(hour1){}
double page()const
{
return 100 * hour;
}
};
class Manager :virtual public Employee
{
public:
Manager(const int num1,string name1):Employee(num1,name1){}
double page()const
{
return 8000;
}
};
class Sale :virtual public Employee
{
protected:
double allmoney;
public:
Sale(const int num1,string name1,double all):Employee(num1,name1),allmoney(all){}
double page()const
{
return 0.04*allmoney;
}
};
class Salemanager :public Sale,public Manager
{
public:
Salemanager(const int num1,string name1,double all):Employee(num1,name1), Sale(num1,name1,all),Manager(num1,name1){}
double page()const
{
return 5000 + 0.005*allmoney;
}
};
class ListItem {
public:
ListItem(Employee *n) :item(n), next(0) {}
Employee *item;
ListItem *next;
};
class List
{
private:
ListItem *head;
public:
List():head(0){}
void print()const;
void add(Employee *);
void del(int);
ListItem* search(int)const;
void mulify(Employee *);
};
void List::mulify(Employee *e)
{
ListItem *p = head;
while (p != NULL)
{
if (e->getnum() == p->item->getnum())
{
p->item = e;
}
p = p->next;
}
}
ListItem* List::search(int id)const
{
ListItem *p = head;
while (p != NULL)
{
if (id == p->item->getnum())
{
return p;
}
p = p->next;
}
return NULL;
}
void List::print()const
{
ListItem *p = head;
while (p)
{
p->item->print();
p = p->next;
}
}
void List::add(Employee *pn)
{
ListItem *end = head;
ListItem *temp = new ListItem(pn);
temp->item = pn;
temp->next = NULL;
if (end)
{
while (end->next)
{
end = end->next;
}
end->next = temp;
}
else
{
head = temp;
}
}
void List::del(int id)
{
ListItem* p = head;
if (head->item->getnum() == id)
{
head = p->next;
delete p;
}
else
{
ListItem* prev = head;
p = p->next;
while (p)
{
if (p->item->getnum() == id)
{
prev->next = p->next;
delete p;
break;
}
else
{
prev = p;
p = p->next;
}
}
}
}
int main()
{
List test;
Engineer en1(1, "tom", 34.5);
Manager m1(2, "tim");
Sale s1(3, "pig", 300000);
Salemanager s2(4, "pigking", 300000);
Engineer en2(1, "wow", 37.5);
Employee *em[100] = { &en1,&m1,&s1};
for (int i = 0; i < 3; i++)
test.add(em[i]);
test.add((Employee*)&s2);
test.print();
test.search(2)->item->print();
test.mulify(&en2);
test.print();
test.del(3);
test.print();
return 0;
}