欢迎来到天天文库
浏览记录
ID:48483191
大小:44.50 KB
页数:11页
时间:2020-02-04
《指针虚函数继承c++练习.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第一题#includeusingnamespacestd;classteacher{protected:charname[30];intcoursetime;public:teacher(chartname[],inttime);virtualintpay()=0;virtualvoidprint()=0;char*getname();intgetcoursetime();};classprofessor:publicteacher{public:professor(charpname[],inttime);intpay();voidprint(
2、){cout<<"教授:"<3、ogram**********/teacher::teacher(chartname[],inttime){for(inti=0;;i++){name[i]=tname[i];if(tname[i]==' ')break;}coursetime=time;}char*teacher::getname(){returnname;}intteacher::getcoursetime(){return(coursetime);}professor::professor(charpname[],inttime):teacher(pname,time){for(inti=04、;;i++){name[i]=pname[i];if(pname[i]==' ')break;}coursetime=time;}intprofessor::pay(){return(5000+50*coursetime);}associateprofessor::associateprofessor(charpname[],inttime):teacher(pname,time){for(inti=0;;i++){name[i]=pname[i];if(pname[i]==' ')break;};coursetime=time;}intassociatepro5、fessor::pay(){return(3000+30*coursetime);}lecturer::lecturer(charpname[],inttime):teacher(pname,time){for(inti=0;;i++){name[i]=pname[i];if(pname[i]==' ')break;};coursetime=time;}intlecturer::pay(){return(2000+20*coursetime);}/**********End**********/intmain(){professorpobj("李小平",32);p6、obj.print();cout<<'t'<<"工资:"<usingnamespacestd;constdoublePI=3.14159265;/**********Progr7、am**********/classcircle{public:circle(doubler){radius=r;}virtualdoublearea(){return0.0;}virtualdoublevolume(){return0.0;}protected:doubleradius;};classsphere:publiccircle{public:sphere(doubler):circle(r){}doublearea(){return4.0*PI*radius*radius;}doublevolume(){return4.0*PI*radius*ra
3、ogram**********/teacher::teacher(chartname[],inttime){for(inti=0;;i++){name[i]=tname[i];if(tname[i]==' ')break;}coursetime=time;}char*teacher::getname(){returnname;}intteacher::getcoursetime(){return(coursetime);}professor::professor(charpname[],inttime):teacher(pname,time){for(inti=0
4、;;i++){name[i]=pname[i];if(pname[i]==' ')break;}coursetime=time;}intprofessor::pay(){return(5000+50*coursetime);}associateprofessor::associateprofessor(charpname[],inttime):teacher(pname,time){for(inti=0;;i++){name[i]=pname[i];if(pname[i]==' ')break;};coursetime=time;}intassociatepro
5、fessor::pay(){return(3000+30*coursetime);}lecturer::lecturer(charpname[],inttime):teacher(pname,time){for(inti=0;;i++){name[i]=pname[i];if(pname[i]==' ')break;};coursetime=time;}intlecturer::pay(){return(2000+20*coursetime);}/**********End**********/intmain(){professorpobj("李小平",32);p
6、obj.print();cout<<'t'<<"工资:"<usingnamespacestd;constdoublePI=3.14159265;/**********Progr
7、am**********/classcircle{public:circle(doubler){radius=r;}virtualdoublearea(){return0.0;}virtualdoublevolume(){return0.0;}protected:doubleradius;};classsphere:publiccircle{public:sphere(doubler):circle(r){}doublearea(){return4.0*PI*radius*radius;}doublevolume(){return4.0*PI*radius*ra
此文档下载收益归作者所有