c++面向抽象类编程计算程序员员工工资

#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;//05
//面向抽象类编程,计算程序员工资
//要求:1.能计算出初级程序员( junior_programmer ) 中级程序员 ( mid_programmer )高级程序员( adv_programmer)的工资
//2.利用抽象类统一界面, 方便程序的扩展, 比如:新增, 计算 架构师(architect) 的工资

class Programmer
{
public:
	virtual void getSalary() = 0;
};

class Junior_programmer :public Programmer
{
public:
	Junior_programmer(char *name, char *job, int sal)
	{
		this->name = name;
		this->job = job;
		this->sal = sal;
	}
	virtual void getSalary()
	{
		cout << job << " " << sal << endl;
	}
private:
	char *name;
	char *job;
	int sal;
};

class Mid_programmer :public Programmer
{
public:
	Mid_programmer(char *name, char *job, int sal)
	{
		this->name = name;
		this->job = job;
		this->sal = sal;
	}
	virtual void getSalary()
	{
		cout << job << " " << sal << endl;
	}
private:
	char *name;
	char *job;
	int sal;
};

class Adv_programmer :public Programmer
{
public:
	Adv_programmer(char *name, char *job, int sal)
	{
		this->name = name;
		this->job = job;
		this->sal = sal;
	}
	virtual void getSalary()
	{
		cout << job << " " << sal << endl;
	}
private:
	char *name;
	char *job;
	int sal;
};

//计算函数 简单的框架
void CalSalary(Programmer *base)
{
	base->getSalary();
}
int main()
{
	Junior_programmer	    jp("Mike", "Junior_programmer", 5000);
	Mid_programmer		    mp("Rita", "Mid_programmer", 10000);
	Adv_programmer			ap("Hermione", "Adv_programmer", 20000);

	CalSalary(&jp);
	CalSalary(&mp);
	CalSalary(&ap);

	system("pause");
	return 0;
}

没有更多推荐了,返回首页