程序11.4:基类和派生类.cpp
来自「学习C++的一些范例」· C++ 代码 · 共 46 行
CPP
46 行
/* 程序11.4:基类和派生类.cpp:*/
#include<iostream>
using namespace std;
class Furniture
{
int width;
int height;
public:
void Accept()
{
cout<<"输入宽度: ";
cin>>width;
cout<<"输入高度: ";
cin>>height;
}
void Display()
{
cout<<"宽度是: "<<width<<endl;
cout<<"高度是: "<<height<<endl;
}
};
class Chair:public Furniture
{
int no_legs;
public:
void Accept()
{
Furniture::Accept();
cout<<"输入腿数: ";
cin>>no_legs;
}
void Display()
{
Furniture::Display();
cout<<"腿数是: "<<no_legs<<endl;
}
};
int main()
{
Chair chairobj;
chairobj.Accept();
chairobj.Display();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?