定义一个飞机类CPlane,其中有两个私有成员变量x,y以及两个公有成员函数Set(设置xy坐标)和Display(显示xy坐标);再定义一个加油飞机类COilPlane,该类是从CPlane公有派生方式派生而来,新增加一个私有成员变量Oil和公有成员函数Add(加油功能)。在main函数定义加油飞机类对象完成测试
#include <iostream>
using namespace std;
class CPlane
{
private:
int x;
int y;
public:
CPlane() { }
void Set(int _x, int _y) { x = _x; y = _y; }
void Display() { cout << x << "," << y << endl; }
};
COilPlane : public CPlane
{
private:
int Oil;
public:
COilPlane() { Oil = 0; }
void Add(int n) { Oil += n; }
};
int main()
{
COilPlane op;
op.set(10, 10);
op.Display();
op.Add(100);
}