C++实验:某学校对教师每月工资的计算规定如下:固定工资+课时补贴。

2022-07-30 教育 240阅读
#include

class Teacher
{
public:
virtual int Salary()=0;
virtual void Print(int)=0;
};

class jiaoshou:public Teacher
{
private:
char name[12];
int keshi;
public:
jiaoshou()
{
printf("请输入姓名:");
scanf("%s",name);
printf("请输入课时:");
scanf("%d",&keshi);
printf("\n");
};
int Salary()
{
return (5000+keshi*50);
};
void Print(int money)
{
printf("职称:教授 姓名:%s 薪水:%d\n",name,money);
};
};

class fujiaoshou:public Teacher
{
private:
char name[12];
int keshi;
public:
fujiaoshou()
{
printf("请输入姓名:");
scanf("%s",name);
printf("请输入课时:");
scanf("%d",&keshi);
printf("\n");
};
int Salary()
{
return (3000+keshi*30);
};
void Print(int money)
{
printf("职称:副教授 姓名:%s 薪水:%d\n",name,money);
};
};

class jiangshi:public Teacher
{
private:
char name[12];
int keshi;
public:
jiangshi()
{
printf("请输入姓名:");
scanf("%s",name);
printf("请输入课时:");
scanf("%d",&keshi);
printf("\n");
};
int Salary()
{
return (2000+keshi*20);
};
void Print(int money)
{
printf("职称:讲师 姓名:%s 薪水:%d\n",name,money);
};
};

void main()
{
Teacher *a = new jiaoshou();
Teacher *b = new fujiaoshou();
Teacher *c = new jiangshi();

//教授
int money = a->Salary();
a->Print(money);
//副教授
money = b->Salary();
b->Print(money);

//讲师
money = c->Salary();
c->Print(money);
}

代码贴给你了,vc6.0环境测试通过!
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com