【c++程序】模拟抽象类
2015-01-06 20:51
363 查看
#include<iostream> using namespace std; class Human { public: Human(){cout<<"构造Human"<<endl;} virtual void smart(){} virtual void beautiful(){} virtual ~Human(){cout<<"析构Human"<<endl;} }; class father:virtual public Human { public: father(){cout<<"构造father"<<endl;} virtual void smart(){cout<<"父亲很聪明"<<endl;} virtual ~father(){cout<<"析构父亲"<<endl;} }; class mother:virtual public Human { public: mother(){cout<<"构造mother"<<endl;} virtual void beautiful(){cout<<"mother is very beautiful!"<<endl;} virtual ~mother(){cout<<"析构mother"<<endl;} }; class son:public father,public mother { public: son(){cout<<"构造son"<<endl;} virtual void smart(){cout<<"儿子也很聪明"<<endl;} virtual void beautiful(){cout<<"儿子也很帅"<<endl;} ~son (){cout<<"析构儿子"<<endl;} }; int main() { Human *p; int choice=0; while(1) { bool quit=false; cout<<"0-退出1-父亲2-儿子3-母亲"<<endl; cin>>choice; switch(choice) { case 0:quit=true; break; case 1:p=new father; p->beautiful(); delete p; break; case 2:p=new son; p->beautiful(); p->smart(); delete p; break; case 3:p=new mother; p->beautiful(); delete p; break; default:cout<<"请输入0-3"<<endl; break; } if(quit) { break; } } cout<<"END!!"; return 0; }
相关文章推荐
- C++: 对双线程下载程序的封装和模拟
- C++程序示例:涉及到抽象类、继承…
- C/C++经典程序训练3---模拟计算器
- C/C++经典程序训练3---模拟计算器
- C/C++经典程序训练3---模拟计算器
- [c++]模拟键盘热键调别的程序
- C/C++经典程序训练3---模拟计算器
- sdut_java_C/C++经典程序训练3---模拟计算器
- C/C++经典程序训练3---模拟计算器
- C/C++经典程序训练3---模拟计算器 oj
- 模拟记事本程序(C++实践)
- 第十五周 刷OJ题-C/C++经典程序训练3之模拟计算器
- c++多线程,2个线程模拟卖火车票的小程序
- C/C++经典程序训练3---模拟计算器
- 一个有趣的基于C++的模拟发牌程序
- 用抽象类设计计算二维平面图形面积的程序,在基类TDshape中设计纯虚函数area()和printName()......C++的158页5题
- [1133]C/C++经典程序训练3—模拟计算器
- 立此存照(22)[C++]模拟电子时钟的小程序
- C++ 多线程编程实例【2个线程模拟卖火车票的小程序】
- C++ 计166-1 C/C++经典程序训练3---模拟计算器