#include<iostream>
using namespace std;
class Shape
{
public:
void CreateShape();
};
void Shape::CreateShape()
cout<<"建立一個圖形"<<endl;
}
class Rectangle:virtual public Shape
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
Circle(float r);
float m_fRadius;
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;
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;
#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;
}