预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共12页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

c面向对象程序设计教程习题答案【篇一:c++程序设计教程--面向对象分册(郑秋生)完整答案】、选择题1.c2.b3.c4.a5.c6.a7.c8c9a10c二、阅读题1.x=2,y=32.x=2,y=3x!=y3.cstatic::va1=0cs1.vai=1cs2.val=2cs1.val=4cs2.vai=4四、改错题#includestring.h#includeiostream.hclassperson{public:person(intn,char*nam,chars){num=n;strcpy(name,nam);sex=s;coutconstructorcalled.endl;}~person(){coutdestructorcalled.endl;}voiddisplay(){coutnum:numendl;coutname:nameendl;coutsex:sexendlendl;}private:intnum;charname[10];charsex;};intmain(){persons1(10010,wang_li,f);s1.display();persons2(10011,zhang_fun,m);s2.display();return0;}五、编程题5.1#includeiostreamusingnamespacestd;classcbox{public:cbox(doublel=0,doublew=0,doubleh=0);doublearea();doublevolume();private:doublelengh;doublewidth;doublehigh;};cbox::cbox(doublel,doublew,doubleh){lengh=l;width=w;high=h;}doublecbox::area(){return2*(lengh*width+lengh*high+width*high);}doublecbox::volume(){returnlengh*width*high;}voidmain(){cboxbox1(4,5,6);coutbox1.area()endl;coutbox1.volume()endl;}5.2#includeiostreamusingnamespacestd;classcpoint{public:cpoint(doublea=0,doubleb=0){x=a;y=b;}cpoint(cpointp){x=p.x;y=p.y;}voidprint(){cout(x,y);}private:doublex,y;};classcline{public:cline(doublex1=0,doubley1=0,doublex2=0,doubley2=0):p1(x1,y1),p2(x2,y2){}cline(cpointx,cpointy):p1(x),p2(y){}cline(clinelin){p1=lin.p1;p2=lin.p2;}voiddrawline(){coutlineform;p1.print();coutto;p2.print();coutendl;}voidlinedel(){coutdeletelineendl;}voidmove(cpointx,cpointy){coutmovelineendl;p1=x;p2=y;}private:cpointp1,p2;};voidmain(){cpointpoint1(1,5),point2(5,8),point3(20,30),point4(40,50);clineline1(point1,point2);clineline2(2,3,8,12);line1.drawline();line2.drawline();line2.move(point3,point4);line2.drawline();line2=line1;line2.drawline();line1.linedel();}5.3#includeiostreamusingnamespacestd;classccomplex{public:ccomplex(double,double);ccomplex(ccomplexc);//复数类的拷贝构造函数声明doublegetreal();doublegetimag();voidprint();private:doublereal;doubleimag;};ccomplex::ccomplex(doubler=0.0,doublei=0.0){real=r;imag=i;cout调用两个参数的构造函数endl;}ccomplex::ccomplex(ccomplexc)//复数类的