某学校教职工的工资计算方法为:
所有教职工都有基本工资;
教师月工资为固定工资+课时补贴。课时补贴根据职称和课时计算。例如,每课时教授补贴50元,副补贴30元,讲师补贴20元。
管理人员月薪为基本工资+职务工资;
实验室人员月薪为基本工资+工作日补贴。工作日补贴等于日补贴×月工作日数。
定义教职工抽象类,派生教师、管理人员和实验室类,编写程序测试这个类体系。
#include <iostream> using namespace std; class staff { public: staff ( double bSalary) { basicSalary=bSalary; } virtual void input() = 0; virtual void output() = 0; protected: char name[30]; double basicSalary; }; class teacher : public staff { public: teacher( int basicsalary=3000 ) : staff( basicsalary ){ } void input() { cout<<"姓名?"; cin>>name; cout<<"职称 1,教授 2,副教授 3,讲师 (输入1,2或3):"; cin>>title; cout<<"课时?"; cin>>coursetime; } void output() { double salary; switch(title) { case 1: salary = basicSalary+coursetime *50; break; case 2: salary=basicSalary+coursetime*30; break; case 3: salary=basicSalary+coursetime*20; } cout<<"姓名:"<<name<<"\t本月工资:"<<salary<<endl; } protected: int coursetime; int title; }; class manage : public staff { public: manage( int basicsalary=2500 ) : staff( basicsalary ){ } void input() { cout<<"姓名?"; cin>>name; cout<<"职务工资?"; cin>>jobSalary; } void output() { double salary; salary = basicSalary+jobSalary; cout<<"姓名:"<<name<<"\t本月工资:"<<salary<<endl; } protected: double jobSalary; }; class technician : public staff { public: technician( int basicsalary=2000 ) : staff( basicsalary ){ } void input() { cout<<"姓名?"; cin>>name; cout<<"工作日?"; cin>>workdays; } void output() { double salary; salary = basicSalary+workdays*20; cout<<"姓名:"<<name<<"\t本月工资:"<<salary<<endl; } protected: int workdays; }; int main() { teacher t; t.input(); t.output(); manage m; m.input(); m.output(); technician h; h.input(); h.output(); }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题
#include <iostream> using namespace std; class staff { public: staff ( double bSalary) { basicSalary=bSalary; } virtual void input() = 0; virtual void output() = 0; protected: char name[30]; double basicSalary; }; class teacher : public staff { public: teacher( int basicsalary=3000 ) : staff( basicsalary ){ } void input() { cout<<"姓名?"; cin>>name; cout<<"职称 1,教授 2,副教授 3,讲师 (输入1,2或3):"; cin>>title; cout<<"课时?"; cin>>coursetime; } void output() { double salary; switch(title) { case 1: salary = basicSalary+coursetime *50; break; case 2: salary=basicSalary+coursetime*30; break; case 3: salary=basicSalary+coursetime*20; } cout<<"姓名:"<<name<<"\t本月工资:"<<salary<<endl; } protected: int coursetime; int title; }; class manage : public staff { public: manage( int basicsalary=2500 ) : staff( basicsalary ){ } void input() { cout<<"姓名?"; cin>>name; cout<<"职务工资?"; cin>>jobSalary; } void output() { double salary; salary = basicSalary+jobSalary; cout<<"姓名:"<<name<<"\t本月工资:"<<salary<<endl; } protected: double jobSalary; }; class technician : public staff { public: technician( int basicsalary=2000 ) : staff( basicsalary ){ } void input() { cout<<"姓名?"; cin>>name; cout<<"工作日?"; cin>>workdays; } void output() { double salary; salary = basicSalary+workdays*20; cout<<"姓名:"<<name<<"\t本月工资:"<<salary<<endl; } protected: int workdays; }; int main() { teacher t; t.input(); t.output(); manage m; m.input(); m.output(); technician h; h.input(); h.output(); }