有以下定义: class Box{ int width,length,height; public: void set(int x=0,int y=0,int z=0) {width=x;length=y;height=z;} }; Box *box; 则以下哪种使用是正确的___
举一反三
- 有以下定义:classBox{intwidth,length,height;public:voidset(intx=0,inty=0,intz=0){width=x;length=y;height=z;}};Box*box;则以下哪种使用是正确的___ A: box->width=3; B: cout<height; C: box->set(1,2); D: p.set(1,2);
- 下列程序的输出结果为 class Box{ int length,width,height; public void setInfo(int l,int w,int h){ length = l; width = w; height = h; } public int volumn(){ return length*width*height; } public int area(){ return (length*width + length*height + width*height) * 2; } public String toString(){ return "Length:" + length + " width:" + width + " height:" + height + " volumn: " + volumn() + " area:" + area(); }} public class BoxTest { public static void main(String[] args) { Box b = new Box(); b.setInfo(5,2,4); System.out.println(b.toString()); }}
- 【填空题】用拷贝构造函数进行对象构造。 #include<iostream> using namespace std; class Box { public: Box(int h,int w,int len); //构造函数声明 ( 1 ) //拷贝构造函数声明 int volume(); //求立方体体积函数 private: int height; int width; int length; }; Box::Box(int h,int w,int len) { height=h; width=w; length=len; } Box::Box(Box &a) { height=a.height+5; width=a.width+5; length=a.length+5; } int Box::volume() { return(height*width*length); } void main() { Box box1(5,5,5); cout<<"The volume of box
- Rectangle类中的成员变量有( )和( ) public class Rectangle{ int width; int height; public void setWidth(int x){ width = x; } public void setHeight(int y){ height = y; } public void show(){ System.out.println("宽:"+width",高:"+height); } }
- 阅读下列程序,写出程序运行的结果:class Cube{int width;int height;int depth;Cube(int x,int y,int z){this.width=x;this.height=y;this.depth=z;}public int vol(){return width*height*depth;}}public class UseCube {public static void main(String[] args) {Cube a=new Cube(3,4,5);System.out.println("长度="+a. width);System.out.println("体积="+a.vol());}}