第十一周上機任務項目4

來源:互聯網
上載者:User
01./*      02.* 程式的著作權和版本聲明部分      03.* Copyright (c)2013, 煙台大學電腦學院學生      04.* All rightsreserved.      05.* 檔案名稱: point.cpp                                 06.* 作    者:趙冠哲                                  07* 完成日期:2013年5月9日      08.* 版本號碼: v1.0            09.* 輸入描述:      10.* 問題描述:    11.*/#include<iostream.h>#include<Cmath>#define PI 3.1415926//定義符號常量class Point //定義座標點類{private:    double x;//橫座標    double y;//縱座標public:    Point(double x0,double y0) {x=x0; y=y0;}    ~Point ()    {cout<<"Destructor called"<<endl;}    double get_x(){return x;} //公用基類的私人資料成員在衍生類別中不能訪問,需要擷取私人資料成員的公用介面    double get_y(){return y;}    friend ostream &operator << (ostream &, Point &);//聲明運算子"<<"的重載};//利用座標點類定義圓類, 其基類的資料成員表示圓的中心class Circle: public Point{private:    double d;public:    Circle(double xx,double yy,double dd): Point(xx,yy)    {        d=dd;    }    ~Circle()    {    }    friend ostream &operator << (ostream &, Circle &);    double get_d(){return d;}};class Cylinder: public Circle{private:    double h;public:    Cylinder(double xx,double yy,double dd,double hh): Circle (xx,yy,dd)    {        h=hh;    }   ~Cylinder()    {    }    friend ostream &operator << (ostream &,Cylinder &);    double get_h(){return h;}    double superficial_area();//表面積    double volume();//圓柱體的體積};ostream &operator << (ostream & output, Point & c){    output<<"點的橫座標為:"<<c.x<<endl;    output<<"點的縱座標為:"<<c.y<<endl;    return output;}ostream &operator << (ostream & output, Circle & c){    output<<"圓的半徑為:"<<c.get_d()<<endl;    output<<"圓的圓心為"<<"("<<c.get_x()<<","<<c.get_y()<<")"<<endl;    return output;}ostream &operator << (ostream & output,Cylinder & c){    output<<"圓柱的高為:"<<c.get_h()<<endl;    output<<"圓柱底面圓的半徑為:"<<c.get_d()<<endl;    output<<"圓柱底面圓的圓心為"<<"("<<c.get_x()<<","<<c.get_y()<<")"<<endl;    return output;}//圓柱體的表面積double  Cylinder::superficial_area(){    double s=2*PI*get_d()*get_d()+2*PI*get_d()*get_h();     return s;}//圓柱體的體積double  Cylinder::volume(){    double v=PI*get_d()*get_d()*get_h();    return v;}int main(){    Point p(1,1);    cout<<p;    Circle ci(1,2,3);    cout<<ci;    Cylinder cy(1,2,4,6);    cout<<cy;    cout<<"圓柱的體積為:"<<cy.volume ()<<endl;    cout<<"圓柱的表面積為:"<<cy.superficial_area ()<<endl;       return 0;}

運行結果:

相關文章

聯繫我們

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