下列哪些是正确的声明变量的方式?
A: int length; int width;
B: int length, width;
C: int length; width;
D: int length, int width;
A: int length; int width;
B: int length, width;
C: int length; width;
D: int length, int width;
举一反三
- 下列程序的输出结果为 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
- 有以下定义: 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; 则以下哪种使用是正确的___
- void area( int length, int width ){ int s; s= length * width ; printf(“长%d,宽%d的长方形面积是%d ”, length , width ,s);}有如上求长方形面积函数,正确的调用方法是( )。提示:本题area是无返回值的函数。 A: c=area(1,2); B: area(1,2); C: area( ); D: c=area( );
- int area( int length, int width ){ int s; s= length * width ; return s;}有如上求长方形面积函数,正确的调用方法是( )。提示:本题area是有返回值的函数。 A: c=area(1,2); B: area(1); C: c=area("12","34" ); D: area( );