?? 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 + -