欢迎来到天天文库
浏览记录
ID:35620587
大小:57.11 KB
页数:48页
时间:2019-04-03
《c++面向对象程序设计上机考试题库》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C++面向对象程序设计上机考试题库一、第一类题目(20道,每题7分,在word中保留代码并将输出结果窗口保留)1.定义盒子Box类,要求具有以下成员:长、宽、高分别为x,y,z,可设置盒子形状;可计算盒子体积;可计算盒子的表面积。#includeclassBox{private:intx,y,z;intv,s;public:voidint(intx1=0,inty1=0,intz1=0){x=x1;y=y1;z=z1;}voidvolue(){v=x*y*z;}voidarea(){s=2*(x*y+x*z+y*z);}voidshow(){cout<<
2、"x="<usingnamespacestd;classBox{public:Box(int,int,int);//带参数的构造函数intvolume();
3、private:intlength;intwidth;intheight;};Box::Box(intlen,inth,intw){length=len;height=h;width=w;【第48页共48页】}//Box::Box(intlen,intw,int,h):length(len),height(h),width(w){}intBox::volume(){return(length*width*height);}intmain(){Boxbox1(30,20,10);cout<<"Thevolumeofbox1is"<4、xbox2(12,10,20);cout<<"Thevolumeofbox2is"<usingnamespacestd;classBox{public:Box();Box(intlen,intw,inth):length(len),width(w),height(h){}intvolume();private5、:intlength;intwidth;intheight;};intBox::volume(){return(length*width*height);}intmain(){Boxbox1(10,20,25);cout<<"Thevolumeofbox1is"<6、ream>usingnamespacestd;template//声明一个类模板classCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax(){return(x>y)?x:y;}numtypemin(){return(xcmp1(3,7);cout<7、p1.min()<<"istheMinimumoftwointedernumbers."<cmp2(45.78,93.6);cout<cmp3('a','A');cout<
4、xbox2(12,10,20);cout<<"Thevolumeofbox2is"<usingnamespacestd;classBox{public:Box();Box(intlen,intw,inth):length(len),width(w),height(h){}intvolume();private
5、:intlength;intwidth;intheight;};intBox::volume(){return(length*width*height);}intmain(){Boxbox1(10,20,25);cout<<"Thevolumeofbox1is"<6、ream>usingnamespacestd;template//声明一个类模板classCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax(){return(x>y)?x:y;}numtypemin(){return(xcmp1(3,7);cout<7、p1.min()<<"istheMinimumoftwointedernumbers."<cmp2(45.78,93.6);cout<cmp3('a','A');cout<
6、ream>usingnamespacestd;template//声明一个类模板classCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax(){return(x>y)?x:y;}numtypemin(){return(xcmp1(3,7);cout<7、p1.min()<<"istheMinimumoftwointedernumbers."<cmp2(45.78,93.6);cout<cmp3('a','A');cout<
7、p1.min()<<"istheMinimumoftwointedernumbers."<cmp2(45.78,93.6);cout<cmp3('a','A');cout<
此文档下载收益归作者所有