欢迎来到天天文库
浏览记录
ID:51444268
大小:75.50 KB
页数:23页
时间:2020-03-24
《C++程序的设计教程_面向对象分册(郑秋生)完整答案.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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、ructorcalled."<usin3、gnamespacestd;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(){returnle4、ngh*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、ic: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、{cout<<"moveline"<7、);}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、ructorcalled."<usin
3、gnamespacestd;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(){returnle
4、ngh*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、ic: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、{cout<<"moveline"<7、);}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、ic: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、{cout<<"moveline"<7、);}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、{cout<<"moveline"<7、);}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、);}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){
此文档下载收益归作者所有