- 1、本文档共162页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
考前练兵-试题详解
应用题(6)
案例分析题(6)
简答题(5)
(1)
请在横线处填上适当的字句,以使程序完整。#include iostream.h#include ″math.h″class Point{private:double X,Y;①____?______Line;public:Point(double x=0, double y=0){ X=x; Y=y; }Point(Point p){ X=p.X; Y=p.Y; }};class Line{private:Point p1,p2;public:Line(Point xp1, Point xp2): ②___?_______{}double GetLength();};double Line::GetLength(){double dx=p2.X-p1.X;double dy=p2.Y-p1.Y;return sqrt(dx*dx + dy*dy);}void main(){Point p1,p2(3,4);Line L1(p1,p2);coutL1.GetLength()endl;}
正确答案:
(1) friend class(2) p1(xp1),p2(xp2)
(2)
请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为5。#includeiostream.hclass Integer{int x;public:Integer(int a=0){x=a;}void display( ){coutxendl;}①?;};Integer Max(Integer a,Integer b){if(②?)return a;return b;}void main( ){Integer a(3),b(5),c;c=Max(a,b);c.display( );}
正确答案:
(1) friend Integer Max(Integer a,Integer b);(2) a.xb.x
(3)
设计一个三角形类Triangle,包含三角形三条边长的私有数据成员,另有一个重载运算符“+”,以实现求两个三角形对象的面积之和。
正确答案:
参考程序:#includeiostream.h#includemath.hclass Triangle{int x,y,z;double area;public:Triangle(int i,int j,int k){double s;x=i;y=j;z=k;s=(x+y+z)/2.0;area=sqrt(s*(s-x)*(s-y)*(s-z));}void disparea(){ coutArea=areaendl; }friend double operator+(Triangle t1,Triangle t2){ return t1.area+t2.area; }};void main(){Triangle t1(3,4,5),t2(4,5,6);double s;coutt1:; t1.disparea();coutt2:; t2.disparea();s=t1+t2;cout总面积=sendl;}
(4)
下面程序中A是抽象类,为使其输出是:This is class B printing.This is class C printing.请在横线处填写适当内容,以使程序完整。#include iostream.hclass A{public:①____?____;};class B: public A{public:void printMe() {cout This is class B printing. endl;}};class C: public B {void printMe() {cout This is class C printing. endl;}};void print (②__?______){a.printMe();}void main (){B b;C c;print (b); print (c);}
正确答案:
(1)virtual void printMe()=0(2)A a
(5)
设计一个复数类Complex,包含实部real和虚部image两个私有数据成员,另有一个重载运算符“+”(用成员函数实现),以实现求两个复数对象之和,和一个重载运算符“”,以实现输出复数类的对象。在主程序中用实例进行测试。
正确答案:
参考程序:?????? #includeiostre
您可能关注的文档
- C程序设计(高起专).doc
- Flash动画设计(高起专).doc
- VB程序设计(高起专).doc
- 比较教育概论.docx
- 比较学前教育学.docx
- 比较政府体制.docx
- 部门行政管理.doc
- 财务报表分析.doc
- 财务成本管理.docx
- 财务管理(高起专).doc
- 第十一章 电流和电路专题特训二 实物图与电路图的互画 教学设计 2024-2025学年鲁科版物理九年级上册.docx
- 人教版七年级上册信息技术6.3加工音频素材 教学设计.docx
- 5.1自然地理环境的整体性 说课教案 (1).docx
- 4.1 夯实法治基础 教学设计-2023-2024学年统编版九年级道德与法治上册.docx
- 3.1 光的色彩 颜色 电子教案 2023-2024学年苏科版为了八年级上学期.docx
- 小学体育与健康 四年级下册健康教育 教案.docx
- 2024-2025学年初中数学九年级下册北京课改版(2024)教学设计合集.docx
- 2024-2025学年初中科学七年级下册浙教版(2024)教学设计合集.docx
- 2024-2025学年小学信息技术(信息科技)六年级下册浙摄影版(2013)教学设计合集.docx
- 2024-2025学年小学美术二年级下册人美版(常锐伦、欧京海)教学设计合集.docx
文档评论(0)