Cpp1.cpp
上传用户:ynftjgj
上传日期:2022-07-21
资源大小:216k
文件大小:1k
- #include <iostream.h>
- #include <string.h>
- class teacher
- { public:
- teacher( char tname[],int time )
- { strcpy( name,tname );
- coursetime = time;
- }
- virtual int pay() = 0;
- virtual void print() = 0;
- char *getname()
- { return name; }
- int getcoursetime()
- { return coursetime; }
- protected:
- char name[30];
- int coursetime;
- };
- class professor:public teacher
- { public:
- professor( char pname[],int time ):teacher( pname,time ){ }
- int pay()
- { return 5000+coursetime*50; }
- void print()
- { cout<<"教授:"<<getname(); }
- };
- class associateprofessor:public teacher
- { public:
- associateprofessor( char pname[],int time ):teacher( pname,time ){ }
- int pay()
- { return 3000 + coursetime * 30; }
- void print()
- { cout << "副教授:" << getname(); }
- };
- class lecturer:public teacher
- { public:
- lecturer( char pname[],int time ):teacher( pname,time ){ }
- int pay()
- { return 2000 + coursetime * 20;}
- void print()
- { cout << "讲师:" << getname();}
- };
- void main()
- { professor pobj( "李小平",32 );
- pobj.print();
- cout << 't' << "工资:" << pobj.pay() << endl;
- associateprofessor apobj( "王芳芳",56 );
- apobj.print();
- cout << 't' << "工资:" << apobj.pay() << endl;
- lecturer lobj( "何大建",72 );
- lobj.print();
- cout << 't' << "工资:" << lobj.pay() << endl;
- }