「已注销」 2020-03-11 23:48 采纳率: 0%
浏览 159
已采纳

求助一个C++填空题,有一半思路了,但是不太理解,求帮助!!

用拷贝构造函数进行对象构造。

个人感觉第二空应该是:Box box4(10,10,10);不知道对不对。
第一空没思路,求大神指点

#include

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 box1 is "<<box1.volume()<<endl;

( 2 ) //用box1对象拷贝构造box2对象

cout<<"The volume of box4 is "<<box2.volume()<<endl;

}

  • 写回答

1条回答 默认 最新

  • 程序猿的技术空间 2020-03-12 09:20
    关注

    第一个空:Box(Box &a),看下边方法的实现

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波