C++ 菜鸟笔记-虚函数多态
2019-01-02 本文已影响0人
chbeychevelle
#include <iostream>
using namespace std;
class baseNum {
public:
virtual void one() { cout << "one" << endl; two(); }
void two() { cout << "two" << endl; three(); }
void three() { cout << "three" << endl; four(); }
void four() { cout << "four" << endl; five(); }
void five() { cout << "five" << endl; }
};
class chinaNum : public baseNum
{
public:
void one() { cout << "一" << endl; two(); }
void two() { cout << "二" << endl; three(); }
void three() { cout << "三" << endl; four(); }
void four() { cout << "四" << endl; five(); }
void five() { cout << "五" << endl; }
};
class aliNum :public baseNum
{
public:
void one() { cout << "1" << endl; two(); }
void two() { cout << "2" << endl; three(); }
void three() { cout << "3" << endl; four(); }
void four() { cout << "4" << endl; five(); }
void five() { cout << "5" << endl; }
};
int main()
{
baseNum * num;
int chonice;
while (1)
{
bool falg = false;
cout << "退出(0)英文(1)中文(2)阿拉伯数字(3):";
cin >> chonice;
switch (chonice)
{
case 0 :
falg = true;
break;
case 1:
num = new baseNum;
num->one();
break;
case 2:
num = new chinaNum;
num->one();
break;
case 3:
num = new aliNum;
num->one();
break;
default:
cout << "选择不正确,请重新输入!" << endl;
break;
}
if (falg) {
break;
}
}
return 0;
}