📄 poly-pure.cpp
字号:
// Poly-Pure.cpp
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
//---- 宣告类别 Shape --------
class Shape
{
private:
int i;
public:
Shape(): i(7){}
~Shape(){}
virtual void Draw() =0;
virtual void Erase()=0;
};
//---- 宣告类别 Circle--------
class Circle : public Shape
{
private:
int r;
public:
Circle(): r(5) {}
Circle(int N): r(N) {}
~Circle() {}
void Draw() {cout<<"画一个圆形\n";}
void Erase() {cout<<"把圆形清除\n";}
};
//---- 宣告类别 Cylinder--------
class Cylinder : public Circle
{
private:
int r, h;
public:
Cylinder(): r(5), h(1) {}
Cylinder(int M, int N): r(M), h(N) {}
~Cylinder() {}
void Draw() {cout<<"画一个圆柱形\n";}
void Erase() {cout<<"把圆柱形清除\n";}
};
void Make(Shape &S1) {S1.Draw();}
void Remove(Shape *pS) {pS->Erase();}
// ----主程式---------------------------
main()
{
Circle C1;
Cylinder CyL;
Shape *pS;
cout << "“Make(C1))” : ";
Make(C1);
cout << "“Make(CyL))”: ";
Make(CyL);
cout << "执行 “pS=&C1” 之后: " << endl;
pS=&C1;
cout << "“Remove(pS)”: ";
Remove(pS);
cout << "执行 “pS=&CyL” 之后: " << endl;
pS=&CyL;
cout << "“Remove(pS)”: ";
Remove(pS);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -