回覆列表
  • 1 # 錢布斯

    #include<iostream>

    using namespace std;

    class Shape

    {

    public:

    void CreateShape();

    };

    void Shape::CreateShape()

    {

    cout<<"建立一個圖形"<<endl;

    }

    class Rectangle:virtual public Shape

    {

    public:

    Rectangle(float a,float b);

    float getArea();

    private:

    float m_fLength;

    float m_fWidth;

    float m_fArea;

    };

    Rectangle::Rectangle (float a,float b)

    {

    m_fLength=a;

    m_fWidth=b;

    cout<<"The Length of Rectangle is "<<m_fLength;

    cout<<"The Width of Rectangle is "<<m_fWidth;

    }

    float Rectangle::getArea()

    {

    m_fArea=m_fLength*m_fWidth;

    return m_fArea;

    }

    class Circle:virtual public Shape

    {

    public:

    Circle(float r);

    float getArea();

    private:

    float m_fRadius;

    float m_fArea;

    };

    Circle::Circle(float r)

    {

    m_fRadius=r;

    cout<<"The Radius of Circle is "<<m_fRadius;

    }

    float Circle::getArea()

    {

    m_fArea=3.1415*m_fRadius*m_fRadius;

    return m_fArea;

    }

    int main()

    {

    Rectangle R1(3.0,2.0);

    R1.CreateShape();

    cout<<"The area of this rectangle is:"<<R1.getArea()<<endl;

    Circle C1(3.0);

    cout<<"The area of this circle is:"<<C1.getArea()<<endl;

    return 0;

    }

  • 中秋節和大豐收的關聯?
  • dnf大轉移瞎子穿幽靜套怎麼加點?