C++程序设计教程--面向对象分册(郑秋生)完整答案.doc

C++程序设计教程--面向对象分册(郑秋生)完整答案.doc

  1. 1、本文档共23页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第1章 类和对象 选择题 1.C 2.B 3.C 4.A 5.C 6.A 7.C 8 C 9A 10 C 二、阅读题 1.x=2,y=3 2.x=2,y=3 x!=y 3. Cstatic::va1=0 cs1.vaI=1 cs2.val=2 cs1.val=4 cs2.vaI=4 四、改错题 #include string.h #include iostream.h class person { public: person(int n,char* nam,char s) { num=n; strcpy(name,nam); sex=s; coutConstructor called.endl; } ~person( ) { coutDestructor called.endl; } void display( ) { coutnum: numendl; coutname: nameendl; coutsex: sexendlendl; } private: int num; char name[10]; char sex; }; int main( ) { person s1(10010,Wang_li,f); s1.display( ); person s2(10011,Zhang_fun,m); s2.display( ); return 0; } 五、编程题 5.1 #include iostream using namespace std; class CBox { public : CBox(double l=0,double w=0,double h=0); double area(); double volume (); private : double lengh; double width; double high; }; CBox::CBox(double l,double w,double h) { lengh=l; width=w; high=h; } double CBox::area() { return 2*(lengh*width+lengh*high+width*high); } double CBox::volume () { return lengh*width*high; } void main() { CBox box1(4,5,6); coutbox1.area()endl; coutbox1.volume()endl; } 5.2 #include iostream using namespace std; class CPoint { public : CPoint(double a=0,double b=0) { x=a; y=b; } CPoint(CPoint p) { x=p.x; y=p.y; } void print() { cout(x,y); } private : double x,y; }; class CLine { public: CLine(double x1=0,double y1=0,double x2=0,double y2=0):p1(x1,y1),p2(x2,y2) { } CLine(CPoint x,CPoint y):p1(x),p2(y) { } CLine(CLine lin) { p1=lin.p1; p2=lin.p2; } void DrawLine() { coutLine form; p1.print(); coutto; p2.print(); coutendl; } void Linedel() { coutdelete lineendl; } void move(CPoint x,CPoint y) { coutmove line

文档评论(0)

139****7971 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档