#include<iostream>
using namespace std;
//计算程序员工资
//1.要求能计算出junior_programmmer mid-programer adv-programmer的工资
//2.要求利用抽象类统一界面 方便程序的扩展 ex:新增计算架构师architect的工资
class programmer
{
public:
virtual void getSal() = 0;
};
class junior_programmer : public programmer {
public:
junior_programmer(const char* name, const char* job, int sal) {
this->name = name;
this->job = job;
this->sal = sal;
}
virtual void getSal() {
cout << name << " " << job << ": " << sal << endl;
}
private:
const char* name;
const char* job;
int sal;
};
class mid_programmer : public programmer {
public:
mid_programmer(const char* name, const char* job, int sal) {
this->name = name;
this->job = job;
this->sal = sal;
}
virtual void getSal() {
cout << name << " " << job << ": " << sal << endl;
}
private:
const char* name;
const char* job;
int sal;
};
class adv_programmer : public programmer {
public:
adv_programmer(const char* name, const char* job, int sal) {
this->name = name;
this->job = job;
this->sal = sal;
}
virtual void getSal() {
cout << name << " " << job << ": " << sal << endl;
}
private:
const char* name;
const char* job;
int sal;
};
class architect : public programmer {
public:
architect(const char* name, const char* job, int sal) {
this->name = name;
this->job = job;
this->sal = sal;
}
virtual void getSal() {
cout << name << " " << job << ": " << sal << endl;
}
private:
const char* name;
const char* job;
int sal;
};
//计算函数 :简单框架
void CalProgSal(programmer* base) {
base->getSal();
}
void main()
{
junior_programmer jp("小王", "jsdla", 6000);
mid_programmer mp("中级", "jla", 6000);
adv_programmer ap("高级 ", "jsa", 10000);
//loading....
architect ar("高", "architect", 15000);
CalProgSal(&jp);
CalProgSal(&mp);
CalProgSal(&ap);
CalProgSal(&ar);
return;
}