第五周實驗報告(三)

來源:互聯網
上載者:User
01.#include <iostream>  02.#include <cmath>  03.  04.using namespace std;  05.class Box  06.{  07.public:  08.    void volume();  09.    void area();  10.    void set();  11.    Box (int h = 18,int w = 20,int len = 36):height(h),width(w),length(len){}  12.private:  13.    double length;  14.    double width;  15.    double height;  16.};  17.int main()  18.{  19.    Box a[5] = {  20.  21.    Box(10,12,15),  22.    Box(15,18,20),  23.    Box(16,20,26),  24.    };  25.  26.    a[4].set();  27.  28.    cout << "the volume of a[0] is: " << endl;  29.    a[0].volume();  30.    cout << "the area of a[0] is: " <<  endl;  31.    a[0].area();  32.  33.    cout << "the volume of a[0] is: " << endl;  34.    a[1].volume();  35.    cout << "the area of a[0] is: " << endl;  36.    a[1].area();  37.  38.    cout << "the volume of a[0] is: " << endl;  39.    a[2].volume();   40.    cout << "the area of a[0] is: " << endl;  41.    a[2].area();  42.  43.    cout << "the volume of a[0] is: " << endl;  44.    a[3].volume();  45.    cout << "the area of a[0] is: " << endl;  46.    a[3].area();  47.  48.    cout << "the volume of a[4] is: " << endl;  49.    a[4].volume();  50.    cout << "the area of a[4] is: " << endl;  51.    a[4].area();  52.  53.    system("pause");  54.  55.    return 0;  56.}  57.  58.void Box::area()  59.{  60.    double ar;  61.  62.    ar=2*(length * height + length * width + height * width);  63.  64.    cout << ar << endl;  65.  66.}  67.  68.void Box::volume()  69.{  70.    double vol;  71.  72.    vol = height * width * length;  73.  74.    cout << vol << endl;  75.}  76.  77.void Box::set()  78.{  79.    cin >> height >> length >> width;  80.}  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.