2017年电大 c++复习题及答案(完整版).docVIP

  • 15
  • 0
  • 约1.95万字
  • 约 15页
  • 2017-08-08 发布于湖南
  • 举报
2017年电大c复习题及答案(完整版)

一 填空题() 派生类的生成过程经历了三个步骤:吸收基类成员 、 改造基类成员 、 添加新成员 。 多态分为: 专用多态 和 通用多态 。 二、选择题(10分) 1在一个函数中,要求通过函数来实现一种不太复杂的功能,并且要求加快执行速度,选用( A )比较合适。 A 内联函数 B 重载函数 C 递归调用 D 嵌套调用 2下面对构造函数的描述不正确的是( C ) A 可以重载 B 其名字与类名相同 C 可以显式调用构造函数 D 构造函数是成员函数 E 构造函数不能是虚函数 3、判断题(正确的请写T,错误的请写F)(20分) 静态成员函数可以直接调用类中说明的非静态成员。(F) windows应用程序采用基于消息的事件驱动运行机制。(T) 4、找出程序中的错误并改正(10分) class student() { private: public: display(){} } }; //----------------------------------------------- void g() student g() { student s; return s; } //------------------------------------------------ mian() void main() { student s1; s1-display(); s1.display(); } 5、读程序,在语句后的括号中填入相应的选项,并写出程序运行结果结果(8个小题)(共40分 结果30分 选择10分 ) 选项:A、复制构造函数 B、构造函数 C、内联成员函数 D、对象成员 E、对象作为函数的参数 F、调用复制构造函数 G、对象调用成员函数 1、 #include iostream.h #include math.h class Point { public: Point(int xx=0,int yy=0){X=xx;Y=yy;} //1、( B ) Point(const Point p); //2、( A ) int GetX(){return X;} int GetY(){return Y;} //3、( C ) private: int X,Y; }; Point::Point(const Point p) { X=p.X; Y=p.Y; coutIn Point copy constructor.endl; } class Distance { public: Distance(Point xp1,Point xp2); //4、( E ) double GetDis(){return dist;} private: Point p1,p2; //5、( D ) double dist; }; Distance::Distance(Point xp1,Point xp2):p1(xp1),p2(xp2) //6、( B ) { cout2endl; double x=double(p1.GetX()-p2.GetX()); double y=double(p1.GetY()-p2.GetY()); dist=sqrt(x*x+y*y); } void main() { Point myp1(2,2),myp2(5,6); Distance myd(myp1,myp2); coutThe distance is:; coutmyd.GetDis()endl; //7、( G ) } 程序运行结果: In Point copy constructor. In Point copy constructor. In Point copy constructor. In Point copy constructor. in Distance copy constructor. The distance is:5 填

文档评论(0)

1亿VIP精品文档

相关文档