#include<iostream>
using namespace std;
class rectangle{
public:
void SetParameter()
{
cout<<"Input length width"<<endl;
cin>>length>>width;
}
double computerArea()
{
return length*width;
}
void output()
{
cout<<"Area: "<<computerArea()<<endl;
}
private:
double length,width;
};
class rectangular :public rectangle
{
public:
void SetParameter1()
{
SetParameter();
cout<<"Input heigh"<<endl;
cin>>height;
}
double computeVolume()
{
return height*computerArea();///不可以直接调用基函数的私有成员
}
void Output()
{
cout<<"Volume"<< computeVolume()<<endl;
}
private:
double height;
};
int main()
{
rectangle c1;
c1.SetParameter();
c1.computerArea();
c1.output();
rectangular c2;
c2.SetParameter1();
c2. computeVolume();
c2.Output();
}
C++一个类的简单继承
最新推荐文章于 2022-12-22 00:31:36 发布