设计一个基类Employee

一家公司有四类人员:总经理、技术员、销售经理、销售员。设计一个基类Employee,派生出总经理Manager、技术人员Technician、销售经理Salesmanager和销售员Salesman。销售经理既是经理又是销售人员,兼具两类人员的特点,因此同时继承Manager 和Salesman 两个类。

1)Employee 类的基本属性:编号、姓名、性别、出生日期、职位、薪水等;出生日期使用自定义的 Date(日期)类;

2)Date 类的基本属性:年、月、日,均采用int类型;

3)派生类Technician,新增属性:工作时间;

4)派生类Salesman, 新增属性:销售额;

要求:

1)实现人员信息的设置与显示;

2)计算并显示个人月薪:月薪计算办法:总经理拿固定月薪8000 元,技术人员按每小时25 元领取月薪;销售员的月薪按当月销售额的4%提成;销售经理固定月薪5000 元加所管辖部门当月销售总额的5‰提成 。

3)将四类不同员工的工资计算函数pay()和每个类中的信息显示函数display()用虚函数实现。

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class Date
{
private:
	int year, month, day;
public:
	Date(int y = 0, int m = 0, int d = 0)
	{
		year = y;
		month = m;
		day = d;
	}
	void setyear(int y) { year = y; }
	void setmonth(int m) { month = m; }
	void setday(int d) { day = d; }
	int getyear() { return year; }
	int getmonth() { return month; }
	int getday() { return day; }
};
class Employee
{
protected:
	int num;
	string name;
	string sex;
	Date birthday;
	string position;
	float salary;
public:
	Employee() {}
	Employee(int n, string na, string se, Date b, string p) {
		num = n;
		name = na;
		sex = se;
		birthday = b;
		position = p;
	};
	virtual void display() = 0;
	virtual void pay() = 0;
};
class Manager : virtual public Employee
{
public:
	Manager() {}
	Manager(int n, string na, string se, Date b, string p)
		:Employee(n, na, se, b, p) {
		pay();
	}
	void pay()
	{
		salary = 8000;
	}
	void display()
	{
		cout << "编号:" << num << setw(6) << "姓名:" << name << setw(6) << "性别:" << sex << setw(10)
			<< "出生日期:" << birthday.getyear() << "年" << birthday.getmonth() << "月" << birthday.getday() << "日"
			<< setw(6) << "职务:" << position << setw(6) << "工资:" << salary << endl;
	}
};
class Technician :public Employee
{
protected:
	int time;
public:
	Technician() {}
	Technician(int n, string na, string se, Date b, string p, int t) :Employee(n, na, se, b, p), time(t) { pay(); }
	void pay()
	{
		salary = 25 * time;
	}
	void display()
	{
		cout << "编号:" << num << setw(6) << "姓名:" << name << setw(6) << "性别:" << sex << setw(10)
			<< "出生日期:" << birthday.getyear() << "年" << birthday.getmonth() << "月" << birthday.getday() << "日"
			<< setw(6) << "职务:" << position << setw(6) << "工资:" << salary << setw(6) << "工作时间:" << time << endl;
	}
};
class Salesman :virtual public Employee
{
protected:
	float sale;
public:
	Salesman() {}
	Salesman(int n, string na, string se, Date b, string p, float s)
		: Employee(n, na, se, b, p), sale(s) {
		pay();
	}
	void pay()
	{
		salary = sale * 0.04;
	}
	void display()
	{
		cout << "编号:" << num << setw(6) << "姓名:" << name << setw(6) << "性别:" << sex << setw(10)
			<< "出生日期:" << birthday.getyear() << "年" << birthday.getmonth() << "月" << birthday.getday() << "日"
			<< setw(6) << "职务:" << position << setw(6) << "工资:" << salary << setw(6) << "销售额:" << sale << endl;
	}
};
class Salesmanager :public Manager, Salesman
{
public:
	Salesmanager() { Salesman(); }
	Salesmanager(int n, string na, string se, Date b, string p, float s)
		:Employee(n, na, se, b, p), Salesman(n, na, se, b, p, s) {
		pay();
	}
	void pay()
	{
		salary = 5000 + sale * 0.05;
	}
	void display()
	{
		cout << "编号:" << num << setw(6) << "姓名:" << name << setw(6) << "性别:" << sex << setw(10)
			<< "出生日期:" << birthday.getyear() << "年" << birthday.getmonth() << "月" << birthday.getday() << "日"
			<< setw(6) << "职务:" << position << setw(6) << "工资:" << salary << setw(6) << "销售额:" << sale << endl;
	}
};

void Test()
{
	Employee* p;
	Manager m1(1001, "张三", "男", Date(89, 06, 10), "总经理  ");
	Technician t1(1002, "李四", "男", Date(83, 01, 23), "技术人员", 120);
	Salesman s1(1003, "王五", "男", Date(84, 02, 23), "推销员  ", 3000);
	Salesman s2(1004, "王红", "女", Date(89, 01, 24), "推销员  ", 5000);
	Salesmanager s3(1005, "李兵", "男", Date(80, 2, 10), "销售经理", 1000);
	Salesmanager s4(1006, "陈云", "女", Date(82, 1, 11), "销售经理", 2000);

	p = &m1;
	p->display();
	p = &t1;
	p->display();
	p = &s1;
	p->display();
	p = &s2;
	p->display();
	p = &s3;
	p->display();
	p = &s4;
	p->display();
	Employee* f[6] = { &m1, &t1, &s1, &s2, &s3, &s4 };
	for (int i = 0; i < 6; i++)
	{
		f[i]->display();
	}
}

int main()
{
	cout << "\n人员信息-----------------------------------------------------------------------------------------" << endl;
	Test();
	cout << "-------------------------------------------------------------------------------------------------" << endl;
	return 0;
}

设计一个Python程序,该程序需要实现一个复杂的员工信息管理系统。要求使用面向对象编程(OOP)的高级特性,包括类、对象、继承、封装、多态、类属性、类方法、私有属性和方法、静态方法等概念。 具体任务: 1. 基类设计: ○ 设计一个基类Employee,包含以下属性: ■ 类属性company_name(公司名称,所有员工共享) ■ 实例属性name(姓名)、age(年龄)、employee_id(员工编号) ○ 包含以下方法: ■ __init__:构造函数,用于初始化对象的实例属性。 ■ introduce:实例方法,用于打印员工的个人信息和公司名称。 ■ 私有方法_calculate_bonus:计算员工的奖金(此处为模拟,可以固定返回一个值或根据实际需求设计)。 ■ 类方法set_company_name:设置公司名称。 ■ 静态方法generate_employee_id:生成唯一的员工编号(此处为模拟,可以返回递增的整数或根据实际需求设计,例:全局变量+递增)。 2. 子类设计: ○ 设计一个子类Manager,继承自Employee类,并扩展以下属性: ■ 实例属性department(部门) ■ 私有属性_salary(薪资,不希望被外部直接访问,初始化时给定固定值) ○ 包含以下方法: ■ __init__:重写父类的构造函数,同时初始化子类特有的属性。 ■ promote:实例方法,接受一个薪资增长的百分比作为参数,并更新薪资。 ■ get_salary:公共方法,返回员工的薪资(通过访问私有属性_salary)。 ■ 重写introduce方法,除了打印员工的个人信息和公司名称外,还打印部门信息。 ■ 静态方法calculate_annual_income:计算员工的年收入(薪资 + 奖金,奖金有默认值)。 3. 程序运行: ○ 在主程序中,创建几个Employee和Manager对象,并调用它们的方法来展示其功能。 ○ 使用类方法和静态方法来设置公司名称和生成员工编号。 ○ 展示私有属性和方法的封装性,确保它们不能被外部直接访问。
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值