欢迎来到天天文库
浏览记录
ID:19459031
大小:26.70 KB
页数:35页
时间:2018-10-02
《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、~person(){cout<<"Destructorcalled."<3、();return0;}五、编程题5.1#includeusingnamespacestd;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*(le4、ngh*width+lengh*high+width*high);}doubleCBox::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=p5、.x;y=p.y;}voidprint(){cout<<"("<6、t();cout<<"to";p2.print();cout<7、8,12);line1.DrawLine();line2.DrawLine();line2.move(point3,point4);line2.DrawLine();line2=line1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGe8、tImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
2、~person(){cout<<"Destructorcalled."<3、();return0;}五、编程题5.1#includeusingnamespacestd;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*(le4、ngh*width+lengh*high+width*high);}doubleCBox::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=p5、.x;y=p.y;}voidprint(){cout<<"("<6、t();cout<<"to";p2.print();cout<7、8,12);line1.DrawLine();line2.DrawLine();line2.move(point3,point4);line2.DrawLine();line2=line1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGe8、tImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
3、();return0;}五、编程题5.1#includeusingnamespacestd;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*(le
4、ngh*width+lengh*high+width*high);}doubleCBox::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
5、.x;y=p.y;}voidprint(){cout<<"("<6、t();cout<<"to";p2.print();cout<7、8,12);line1.DrawLine();line2.DrawLine();line2.move(point3,point4);line2.DrawLine();line2=line1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGe8、tImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
6、t();cout<<"to";p2.print();cout<7、8,12);line1.DrawLine();line2.DrawLine();line2.move(point3,point4);line2.DrawLine();line2=line1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGe8、tImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
7、8,12);line1.DrawLine();line2.DrawLine();line2.move(point3,point4);line2.DrawLine();line2=line1;line2.DrawLine();line1.Linedel();}5.3#includeusingnamespacestd;classCComplex{public:CComplex(double,double);CComplex(CComplex&c);//复数类的拷贝构造函数声明doubleGetReal();doubleGe
8、tImag();voidPrint();private:doublereal;doubleimag;};CComplex::CComplex(doubler=0.0,doublei=0.0){
此文档下载收益归作者所有