这是一篇关于继承的一个代码
#include<iostream>
#include<string>
using namespace std;
class mode
{
public:
mode(){}
mode(double high, double broad) :m_high(high), m_broad(broad)
{
}
~mode(){}
protected:
double m_high;
double m_broad;
};
class trigo :public mode
{
public:
trigo(){}
trigo(double high, double broad) :mode(m_high, m_broad)
{
proportion = (2 / 1)*(high*broad);
cout <<"三角形面积"<< proportion << endl;
}
double proportion;
~trigo(){}
};
class quadrilateral :public mode
{
public:
quadrilateral(){}
quadrilateral(double high, double broad) :mode(m_high, m_broad)
{
proportion = high*broad;
cout <<"四边形面积"<< proportion << endl;
}
double proportion;
~quadrilateral(){}
};
int main()
{
trigo price(20,10);
quadrilateral price2(10, 20);
system("pause");
}
补充:继承逻辑图以及取地址图
|