第五周上機任務項目3-(編寫基於對象的程式)

來源:互聯網
上載者:User
01./*      02.* 程式的著作權和版本聲明部分      03.* Copyright (c)2013, 煙台大學電腦學院學生      04.* All rightsreserved.      05.* 檔案名稱: bulk.cpp                                 06.* 作    者:趙冠哲                                  07.* 完成日期:2013年3月29日      08.* 版本號碼: v1.0            09.* 輸入描述:      10.* 問題描述:    11.*/ #include<iostream>using namespace std;class Bulk{public:Bulk(double a=1.0,double b=1.0,double c=1.0):length(a),width(b),height(c){}double volune(void);double area(void);void get_value();void showmessage();private:double length,width,height;};int main(){Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};//下面分別輸出這5個長方柱的體積和表面積for(int i=0;i<4;i++){cout<<"第"<<i+1;b[i].showmessage();}b[4].get_value();b[4].showmessage();}void Bulk::get_value(){cout<<"請輸入長柱體的長、寬、高:";cin>>length>>width>>height;}double Bulk::volune(void){return(length*width*height);}double Bulk::area(void){return(2*length*width+2*length*height+2*length*width);}void Bulk::showmessage(){cout<<"個柱體的體積是:"<<volune()<<"該柱體的表面積是:"<<area()<<endl;}

運行結果:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.