欢迎来到天天文库
浏览记录
ID:31956809
大小:60.22 KB
页数:48页
时间:2019-01-29
《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;}voida
2、rea(){s=2*(x*y+x*z+y*z);}voidshow(){cout<<"x="<3、stream>usingnamespacestd;classBox{public:Box(int,int,int);//带参数的构造函数intvolume();private:intlength;intwidth;intheight;};Box::Box(intlen,inth,intw){length=len;height=h;width=w;}Word完美格式可编辑版//Box::Box(intlen,intw,int,h):length(len),height(h),width(w){}int4、Box::volume(){return(length*width*height);}intmain(){Boxbox1(30,20,10);cout<<"Thevolumeofbox1is"<5、程序,且定义两个构造函数,其中一个有参数,一个无参数。#includeusingnamespacestd;classBox{public:Box();Box(intlen,intw,inth):length(len),width(w),height(h){}intvolume();private:intlength;intwidth;intheight;};intBox::volume(){return(length*width*height);}intmain(){Boxbox6、1(10,20,25);cout<<"Thevolumeofbox1is"<usingnamespacestd;Word完美格式可编辑版template//声明一个类模板7、classCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax(){return(x>y)?x:y;}numtypemin(){return(xcmp1(3,7);cout<8、Minimumoftwointedernumbers."<cmp2(45.78,93.6);cout<cmp3('a','A');cout<
3、stream>usingnamespacestd;classBox{public:Box(int,int,int);//带参数的构造函数intvolume();private:intlength;intwidth;intheight;};Box::Box(intlen,inth,intw){length=len;height=h;width=w;}Word完美格式可编辑版//Box::Box(intlen,intw,int,h):length(len),height(h),width(w){}int
4、Box::volume(){return(length*width*height);}intmain(){Boxbox1(30,20,10);cout<<"Thevolumeofbox1is"<5、程序,且定义两个构造函数,其中一个有参数,一个无参数。#includeusingnamespacestd;classBox{public:Box();Box(intlen,intw,inth):length(len),width(w),height(h){}intvolume();private:intlength;intwidth;intheight;};intBox::volume(){return(length*width*height);}intmain(){Boxbox6、1(10,20,25);cout<<"Thevolumeofbox1is"<usingnamespacestd;Word完美格式可编辑版template//声明一个类模板7、classCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax(){return(x>y)?x:y;}numtypemin(){return(xcmp1(3,7);cout<8、Minimumoftwointedernumbers."<cmp2(45.78,93.6);cout<cmp3('a','A');cout<
5、程序,且定义两个构造函数,其中一个有参数,一个无参数。#includeusingnamespacestd;classBox{public:Box();Box(intlen,intw,inth):length(len),width(w),height(h){}intvolume();private:intlength;intwidth;intheight;};intBox::volume(){return(length*width*height);}intmain(){Boxbox
6、1(10,20,25);cout<<"Thevolumeofbox1is"<usingnamespacestd;Word完美格式可编辑版template//声明一个类模板
7、classCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax(){return(x>y)?x:y;}numtypemin(){return(xcmp1(3,7);cout<8、Minimumoftwointedernumbers."<cmp2(45.78,93.6);cout<cmp3('a','A');cout<
8、Minimumoftwointedernumbers."<cmp2(45.78,93.6);cout<cmp3('a','A');cout<
此文档下载收益归作者所有