精品偷拍一区二区三区,亚洲精品永久 码,亚洲综合日韩精品欧美国产,亚洲国产日韩a在线亚洲

  • <center id="usuqs"></center>
  • 
    
  • 定義一個Box(盒子)類,在該類定義中包括數據成員: length(長),width(寬)和height(

    定義一個Box(盒子)類,在該類定義中包括數據成員: length(長),width(寬)和height(

    定義一個Box(盒子)類,在該類定義中包括數據成員: length(長)、width(寬)和height(高);成員函數: 構造函數Box,設置盒子長、寬和高三個初始數據;用函數volume 計算并輸出盒子的體積.在main函數中,要求創(chuàng)建Box對象,并求盒子的體積.

    int main()

    {

           Box b1,b2(2,3,4);

           float v1,v2;

           v1 = b1.GetVolume();

           v2 = b2.GetVolume();

           if (v1>v2)

                       cout<<v1<<" "<<v2<<endl;

                  else

                          cout<<v2<<" "<<v1<<endl;

           return 0;

    }


    其他人氣:683 ℃時間:2020-04-26 06:51:23
    優(yōu)質解答
    #include <iostream>
    using namespace std;

    class Box {
    \x09float length, width, height;
    public:
    \x09Box(float l, float w, float h);
    \x09float GetVolume() const;
    };

    Box::Box(float l = 1, float w = 1, float h = 1) 
    \x09: length(l), width(w), height(h) {}

    float Box::GetVolume() const {
    \x09return height * width * length;
    }

    int main()
    {
    \x09Box b1, b2(2, 3, 4);
    \x09float v1, v2;
    \x09v1 = b1.GetVolume();
    \x09v2 = b2.GetVolume();
    \x09if (v1>v2)
    \x09\x09cout << v1 << " " << v2 << endl;
    \x09else
    \x09\x09cout << v2 << " " << v1 << endl;
    \x09return 0;
    }Box b1, b2(2, 3, 4);
    這行有錯哎~error C2512: 'Box' : no appropriate default constructor available
    怎么改呢???
    #include <iostream>
    using namespace std;

    class Box {
    \x09float length, width, height;
    public:
    \x09Box();
    \x09Box(float l, float w, float h);
    \x09float GetVolume() const;
    };

    Box::Box() : length(1), width(1), height(1) {}

    Box::Box(float l, float w, float h)
    : length(l), width(w), height(h) {}

    float Box::GetVolume() const {
    \x09return height * width * length;
    }

    int main()
    {
    \x09Box b1, b2(2, 3, 4);
    \x09float v1, v2;
    \x09v1 = b1.GetVolume();
    \x09v2 = b2.GetVolume();
    \x09if (v1>v2)
    \x09\x09cout << v1 << " " << v2 << endl;
    \x09else
    \x09\x09cout << v2 << " " << v1 << endl;
    \x09return 0;
    }
    我來回答
    類似推薦
    請使用1024x768 IE6.0或更高版本瀏覽器瀏覽本站點,以保證最佳閱讀效果。本頁提供作業(yè)小助手,一起搜作業(yè)以及作業(yè)好幫手最新版!
    版權所有 CopyRight © 2012-2024 作業(yè)小助手 All Rights Reserved. 手機版