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环境测试通过!