項目四

/*
* Copyright (c) 2011, 煙臺大學計算機學院
* All rights reserved.
* 作    者:王靜
* 完成日期:2013  年 5  月  21  日
* 版 本 號:v1.0
* 輸入描述:
* 問題描述:
* 程序輸出:
* 問題分析:
* 算法設計:略
*/
#include<iostream>
#include<Cmath>
#define pi 3.14
using namespace std;
class Point //定義座標點類
{
public:
    Point():x(0),y(0) {};
    Point(double x0, double y0):x(x0), y(y0) {};
    //void PrintPoint();
    friend ostream&operator<<(ostream&,Point&);
    double x,y;   //數據成員,表示點的橫座標和縱座標
};
ostream&operator<<(ostream&cout,Point&c)
{
    cout<<"("<<c.x<<","<<c.y<<")";    //輸出點
 return cout;
}
class Circle: public Point   //利用座標點類定義直線類, 其基類的數據成員

表示直線的中點
{
public:
    Circle():oo(0,0),r(1){};
    Circle(double x0,double y0,double r0):oo(x0,y0),r(r0){};
    friend ostream&operator<<(ostream&,Circle&);
    //void PrintCircle();
    double arge();
    double circle();
    double r;
    Point oo;
};
double Circle::arge()
{
    return pi*r*r;
}
double Circle::circle()
{
    return 2*pi*r;
}
 //void Circle::PrintCircle()
 ostream&operator<<(ostream&cout,Circle&c)
 {
     cout<<"圓心爲:"<<c.oo;
     //oo.PrintPoint();
     cout<<"半徑是:"<<c.r<<"的圓";
     return cout;
 }
 class Cylinder:public Circle
 {
     public:
     Cylinder():cc(0,0,1),h(1){};
     Cylinder(double x0,double y0,double r0,double h0):cc(x0,y0,r0),h

(h0){};
     //void PrintCylinder();
     friend ostream&operator<<(ostream&,Cylinder&);
     double cylindervirmle();
     double cylinderarge();
     private:
     double h;
     Circle cc;
 };
 double Cylinder::cylindervirmle()
 {
     return h*cc.arge();
 }
 double Cylinder::cylinderarge()
 {
     return h*cc.circle()+cc.arge()*2;
 }
 //void Cylinder::PrintCylinder()
 ostream&operator<<(ostream&cout,Cylinder&c)
 {
     cout<<"底面爲:"<<c.cc;
     //cc.PrintCircle();
     cout<<"高爲:"<<c.h<<"的圓柱體的";
     cout<<"表面積爲:"<<c.cylinderarge();
     cout<<"體積爲:"<<c.cylindervirmle()<<endl;
     return cout;
 }
int main()
{
    Cylinder c(1,1,2,4);
   cout<<c;
    return 0;
}



 運行結果:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章