#include"iostream"
using namespace std;
class Teacher{
public:
virtual double salary();
virtual void print();
};
class lecturer:public Teacher{
public:
double h;
double j;
double mh;
lecturer(double h1=0,double j1=0,double mh1=0):h(h1),j(j1),mh(mh1){}
double salary();
void print();
};
double lecturer:: salary()
{
return(h*mh+j);
}
void lecturer:: print()
{
cout<<"Lecturer salary:"<<salary()<<endl;
}
class AssociateProfessor:public Teacher{
public:
double h;
double j;
double mh;
double bt;
AssociateProfessor(double h1=0,double j1=0,double mh1=0,double bt1=0):h(h1),j(j1),mh(mh1),bt(bt1){}
double salary();
void print();
};
double AssociateProfessor:: salary()
{
return(h*mh+j+bt);
}
void AssociateProfessor:: print()
{
cout<<"AssociateProfessor salary:"<<salary()<<endl;
}
class Professor:public Teacher{
public:
double h;
double j;
double mh;
double bt;
Professor(double h1=0,double j1=0,double mh1=0,double bt1=0):h(h1),j(j1),mh(mh1),bt(bt1){}
double salary();
void print();
};
double Professor:: salary()
{
return(h*mh+j+bt);
}
void Professor:: print()
{
cout<<"Professor salary:"<<salary()<<endl;
}
int main()
{
Teacher t;
lecturer l;
AssociateProfessor a;
Professor p;
Teacher *pt=&t;
pt=&l;
pt->print();
pt=&a;
pt->print();
pt=&p;
pt->print();
return 0;
}
上一个运行的窗口没关闭