可以通过下面哪些函数实现类的多态性( )。
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类Office的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 办公室房间号:308 办公室长度:5.6 办公室宽度:4.8 办公室面积:26.88 办公室所属部门:会计科 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#inclUdeiostreamusing namespace std;class Room{//“房间”类 int room no; //房间号 double length; //房间长度(m) double width; //房间宽度(m)public:Room(int the_room_no,double the_length,double the_width):room_no(the_room_no),length(the_length),width(the_width){} int theRoomNo()const{return room_no;}//返回房间号 double theLength()const{return length;)//返回房间长度 double theWidth()const{return width;)//返回房间宽度 //**********found********** double theArea()const{_________}//返回房间面积(矩形面积)};class Office:public Room{//“办公室”类 char*depart;//所属部门public: Office(int the room no,double the_length,double the_width,const char *the depart)//**********found********** :___________{ depart=new char[strlen(the depart)+1];//**********found********** strcpy(________); } ~Office(){delete[]depart;} const char*theDepartment()const{return depart;}//返回所属部门};int main(){ //**********found********** Office__________; cout"办公室房间号:"an_office.theRoomNo()endl "办公室长度:"an office.theLength()endl "办公室宽度:"an_office.theWidth()endl "办公室面积:"an_office.theArea()endl "办公室所属部门:"an_office.theDepartment()endl; return 0;}
请打开考生文件夹下的解决方案文件proj2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序展示,当该班级换教室后,这两个人的教室也同时得到改变。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为: 改换教室前: 学号:0789 姓名:张三 班级:062113 教室:521 学号:0513 姓名:李四 班级:062113 教室:521 改换教室后: 学号:0789 姓名:张三 班级:062113 教室:311 学号:0513 姓名:李四 班级:062113 教室:311 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。#includeiostreamusing namespace std;class class{ //“班级”类public: Class(conSt char*id,constchar*room){ strcpy(class id,id);//*******found******* } conSt char*getclassID()const { return class id;} //返回班号//*******found******* const char*getClassroom()const{__________} //返回所在教室房号 void changeRoomTo(const char*new room) { //改换到另一个指定房号的教室 strcpy(classroom,new room); }private: char class id[20]; //班号 char classroom[20]; //所在教室房号};class Student{ //“学生”类char my id[10];//学号char my name[20]; //姓名 Classmy class; //所在教室public://*******found******* Student(const char*the id,const char*the name,classthe class):_____________{ strcpy(my id,the id); strcpy(my_name,the_name); } const char*getID()const{return my_id;} const char*getName()const{return my_namej} Class getClass()const{return my class;}};void showStudent(Student *stu){ cout"学号:"stu-getID()" ";cout"姓名:"stu-getName()" "; cout"班级:"stu-get-class().getClassID()" "; cout"教室:"stu-get?class().getclassroom()endl;}int main(){ class cla("062113","521"); Student Zhang("0789","张三",cla),Li("0513","李四",cla); cout”改换教室前:"endl; showStudent(Zhang); showStudent(Li); //062113班的教室由521改换到311//*******found******* cout"改换教室后:"endl; showStudent(Zhang); showStudent(Li); return 0;}
请打开考生文件夹下的解决方案文件proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式d=实现的,三角形面积的计算是按公式f=实现的,其中s=请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:Side1:9.43398Side2:5Side3:8area:20注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#include#includeusing namespace std;class Point{//坐标点类public:const double x,y;Point(double x=0.0,doubley=0.0):x(x),y(y){}//*******found*******double distanceTo(_______)const{//到指定点的距离return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));}};class Line{//线段类public:const Point p1,p2//线段的两个端点//*******found*******Line(Point p1,Pointp2):_______{}double length( )const{returnp1.distanceTo(p2);}//线段的长度};class Triangle{//三角形类public:const Point p1,p2,p3;//三角形的三个顶点//*******found*******Triangle(_______):p1(p1),p2(p2),p3(p3){}double lengthl( )const{//边p1,p2的长度return Line(p1,p2).length( );}double length2( )const{//边p2,p3的长度return Line(p2,p3).length( );}double length3( )const{//边p3,p1的长度return Line(p3,p1).length( );}double area( )const{//三角形面积//*******found*******double s=_______;return sqrt(s*(s-lengthl( ))*(s-length2( ))*(s-length3( )));}};int main( ){Triangle r(Point(0.0,8.0),Point(5.0,0.0),Point(0.0,0.0));coutcoutcoutcoutendl;return0;}
下列不是派生类对基类的继承方式的是( )。
