欢迎来到天天文库
浏览记录
ID:10489850
大小:26.70 KB
页数:35页
时间:2018-07-06
《c++程序设计教程--面向对象分册(郑秋生)答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第1章类和对象一、选择题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四、改错题#include#includeclassperson{public:person(intn,char*nam,chars){num=n;strcpy(name,nam);sex=s;cout<<"Constructorcalled."<2、<"Destructorcalled."<3、ostream>usingnamespacestd;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:4、:volume(){returnlengh*width*high;}voidmain(){CBoxbox1(4,5,6);cout<usingnamespacestd;classCPoint{public:CPoint(doublea=0,doubleb=0){x=a;y=b;}CPoint(CPoint&p){x=p.x;y=p.y;}voidprint(){cout<<"("<5、blex,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(CLine&lin){p1=lin.p1;p2=lin.p2;}voidDrawLine(){cout<<"Lineform";p1.print();cout<<"to";p2.print();cout<6、l;}voidmove(CPoint&x,CPoint&y){cout<<"moveline"<7、ine1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGetImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
2、<"Destructorcalled."<3、ostream>usingnamespacestd;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:4、:volume(){returnlengh*width*high;}voidmain(){CBoxbox1(4,5,6);cout<usingnamespacestd;classCPoint{public:CPoint(doublea=0,doubleb=0){x=a;y=b;}CPoint(CPoint&p){x=p.x;y=p.y;}voidprint(){cout<<"("<5、blex,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(CLine&lin){p1=lin.p1;p2=lin.p2;}voidDrawLine(){cout<<"Lineform";p1.print();cout<<"to";p2.print();cout<6、l;}voidmove(CPoint&x,CPoint&y){cout<<"moveline"<7、ine1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGetImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
3、ostream>usingnamespacestd;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:
4、:volume(){returnlengh*width*high;}voidmain(){CBoxbox1(4,5,6);cout<usingnamespacestd;classCPoint{public:CPoint(doublea=0,doubleb=0){x=a;y=b;}CPoint(CPoint&p){x=p.x;y=p.y;}voidprint(){cout<<"("<5、blex,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(CLine&lin){p1=lin.p1;p2=lin.p2;}voidDrawLine(){cout<<"Lineform";p1.print();cout<<"to";p2.print();cout<6、l;}voidmove(CPoint&x,CPoint&y){cout<<"moveline"<7、ine1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGetImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
5、blex,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(CLine&lin){p1=lin.p1;p2=lin.p2;}voidDrawLine(){cout<<"Lineform";p1.print();cout<<"to";p2.print();cout<6、l;}voidmove(CPoint&x,CPoint&y){cout<<"moveline"<7、ine1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGetImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
6、l;}voidmove(CPoint&x,CPoint&y){cout<<"moveline"<7、ine1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGetImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
7、ine1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGetImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
此文档下载收益归作者所有