欢迎来到天天文库
浏览记录
ID:31884384
大小:296.02 KB
页数:61页
时间:2019-01-24
《c编程题库(word版)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、31.定义盒子Box类,要求具有以下成员:长、宽、高分别为x,y,z,可设置盒子形状;可计算盒子体积;可计算盒子的表面积。#include#includeusingnamespacestd;classBox{public:intweight;intlength;inthight;voidbox_shape(intw,intl,inth);intbox_volume(intw,intl,inth);intbox_area(intw,intl,inth);};intmain(){Boxmybox;cout<<"PleaseEnterweightandl
2、engthandhight:";cin>>mybox.weight>>mybox.length>>mybox.hight;intbox_v,box_a;mybox.box_shape(mybox.weight,mybox.length,mybox.hight);box_v=mybox.box_volume(mybox.weight,mybox.length,mybox.hight);cout<<"Thisbox'svolume="<3、"Thisbox'sarea="<4、,20。分别求他们的体积。编一个基于对象的程序,在类中用带参数的构造函数。#includeclassBox{private:intlength;intweight;inthight;public:Box(int,int,int);intvolume();};intmain(){usingnamespacestd;Boxmybox1(30,20,10);cout<<"ThefirstBox'svolume="<5、volume()<classBox{private:intlength;intwight;intheight;public:Box();6、Box(int,int,int);intvolume();};intmain(){usingnamespacestd;Boxmybox1;cout<<"Thefirstbox'svolume="<7、ntBox::volume(){returnlength*wight*height;}33.声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。【第61页共61页】#includeusingnamespacestd;templateclassCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax
3、"Thisbox'sarea="<4、,20。分别求他们的体积。编一个基于对象的程序,在类中用带参数的构造函数。#includeclassBox{private:intlength;intweight;inthight;public:Box(int,int,int);intvolume();};intmain(){usingnamespacestd;Boxmybox1(30,20,10);cout<<"ThefirstBox'svolume="<5、volume()<classBox{private:intlength;intwight;intheight;public:Box();6、Box(int,int,int);intvolume();};intmain(){usingnamespacestd;Boxmybox1;cout<<"Thefirstbox'svolume="<7、ntBox::volume(){returnlength*wight*height;}33.声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。【第61页共61页】#includeusingnamespacestd;templateclassCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax
4、,20。分别求他们的体积。编一个基于对象的程序,在类中用带参数的构造函数。#includeclassBox{private:intlength;intweight;inthight;public:Box(int,int,int);intvolume();};intmain(){usingnamespacestd;Boxmybox1(30,20,10);cout<<"ThefirstBox'svolume="<5、volume()<classBox{private:intlength;intwight;intheight;public:Box();6、Box(int,int,int);intvolume();};intmain(){usingnamespacestd;Boxmybox1;cout<<"Thefirstbox'svolume="<7、ntBox::volume(){returnlength*wight*height;}33.声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。【第61页共61页】#includeusingnamespacestd;templateclassCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax
5、volume()<classBox{private:intlength;intwight;intheight;public:Box();
6、Box(int,int,int);intvolume();};intmain(){usingnamespacestd;Boxmybox1;cout<<"Thefirstbox'svolume="<7、ntBox::volume(){returnlength*wight*height;}33.声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。【第61页共61页】#includeusingnamespacestd;templateclassCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax
7、ntBox::volume(){returnlength*wight*height;}33.声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。【第61页共61页】#includeusingnamespacestd;templateclassCompare{public:Compare(numtypea,numtypeb){x=a;y=b;}numtypemax
此文档下载收益归作者所有