实验内容 某学校对月工资的计算公式加下:国定工资+课 时补贴。 救授的固定工资为00每个课附补贴50元 副教授的因定工资3为00元,每个课,补贴30元 讲师的固定工资为000元、每个课时补贴20元

 设计一

#include<iostream>
using namespace std;
class Teacher{
protected:
	int fixsalary;
	int classhour;
public:
	Teacher(int a,int b):fixsalary(a),classhour(b){}
	void worktime(int a);
	virtual int Mouthsalary()=0;
};
void Teacher::worktime(int a){
	classhour+= a;
}
class Professor:public Teacher{
public:
	Professor():Teacher(5000,0){}
	int Mouthsalary();
};
int Professor::Mouthsalary(){
	return classhour*50+fixsalary;
}
class Aprofessor:public Teacher{
public:
	Aprofessor():Teacher(3000,0){}
	int Mouthsalary();
};
int Aprofessor::Mouthsalary(){
	return classhour*30+fixsalary;
}
class Lecturer:public Teacher{
public:
	Lecturer():Teacher(2000,0){}
	int Mouthsalary();
};
int Lecturer::Mouthsalary(){
	return classhour*20+fixsalary;
}
int main(){
	Teacher *p;
	Professor s1;
	p=&s1;
	s1.worktime(10);
	cout<<p->Mouthsalary()<<endl;
	Aprofessor s2;
	p = &s2;
	s2.worktime(20);
	cout<<p->Mouthsalary()<<endl;
	Lecturer s3;
	p=&s3;
	s3.worktime(30);
	cout<<p->Mouthsalary()<<endl;
	return 0;
}

设计二

#include<iostream>
using namespace std;
class Teacher{
protected:
	int fixsalary;//固定工资
	int classhour;//课时
public:
	Teacher(int a):fixsalary(a){}
	void Classhour(int a);
	virtual int Mouthsalary()=0;
};
void Teacher::Classhour(int a){
	classhour= a;
}
class Professor:public Teacher{		//教授类
public:
	Professor():Teacher(5000){}
	int Mouthsalary();
};
int Professor::Mouthsalary(){	
	return classhour*50+fixsalary;
}
class Aprofessor:public Teacher{	//副教授类
public:
	Aprofessor():Teacher(3000){}
	int Mouthsalary();
};
int Aprofessor::Mouthsalary(){
	return classhour*30+fixsalary;
}
class Lecturer:public Teacher{		//讲师类
public:
	Lecturer():Teacher(2000){}
	int Mouthsalary();
};
int Lecturer::Mouthsalary(){
	return classhour*20+fixsalary;
}
int main(){
	Teacher *p;
	Professor s1;
	p=&s1;
	s1.Classhour(15);
	cout<<p->Mouthsalary()<<endl;
	Aprofessor s2;
	p = &s2;
	s2.Classhour(35);
	cout<<p->Mouthsalary()<<endl;
	Lecturer s3;
	p=&s3;
	s3.Classhour(50);
	cout<<p->Mouthsalary()<<endl;
	return 0;
}

设计三

#include<iostream>
#include<string.h> 
using namespace std;
class Teacher{
protected:
	int fixsalary;//固定工资
	int classhour;//课时
	char name[15];
	int id;
public:
	Teacher(int a,char *name,int id):fixsalary(a),id(id){
		strcpy(name,name);
	}
	void Classhour(int a);
	void print();
	virtual int Mouthsalary()=0;
};
void Teacher::Classhour(int a){
	classhour= a;
}
void Teacher::print(){
	cout<<"编号:"<<id<<endl;
	cout<<"姓名:"<<name<<endl;
}
class Professor:public Teacher{		//教授类
public:
	Professor():Teacher(5000,"教授",1){
		strcpy(name,"教授");
	}
	int Mouthsalary();
};
int Professor::Mouthsalary(){	
	return classhour*50+fixsalary;
}
class Aprofessor:public Teacher{	//副教授类
public:
	Aprofessor():Teacher(3000,"副教授",2){
		strcpy(name,"副教授");
	}
	int Mouthsalary();
};
int Aprofessor::Mouthsalary(){
	return classhour*30+fixsalary;
}
class Lecturer:public Teacher{		//讲师类
public:
	Lecturer():Teacher(2000,"讲师",3){
		strcpy(name,"讲师");
	}
	int Mouthsalary();
};
int Lecturer::Mouthsalary(){
	return classhour*20+fixsalary;
}
int main(){
	Teacher *p;
	Professor s1;
	p=&s1;
	s1.Classhour(15);
	s1.print();
	cout<<"月收入:"<<p->Mouthsalary()<<endl;
	Aprofessor s2;
	p = &s2;
	s2.Classhour(35);
	s2.print();
	cout<<"月收入:"<<p->Mouthsalary()<<endl;
	Lecturer s3;
	p=&s3;
	s3.Classhour(50);
	s3.print();
	cout<<"月收入:"<<p->Mouthsalary()<<endl;
	return 0;
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

diary_chao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值