第16周项目3--用函数指针调用函数(吃饭,睡觉,打豆豆)
2014-12-14 12:39
495 查看
/* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作 者:刘畅 * 完成日期:2014 年 12 月 14 日 * 版 本 号:v1.0 * * 问题描述:用函数指针调用函数; * 输入描述:输入命令; * 程序输出:输出要求输出的。
#include <iostream> using namespace std; void eat(); void sleep(); void hitdoudou(); void run(void (*f)()); int main() { int iChoice; do { cout<<"请选择(1-吃; 2-睡; 3-打; 其他-退):"; cin>>iChoice; if (iChoice==1) run (eat); else if (iChoice==2) run (sleep); else if (iChoice==3) run (hitdoudou); else { cout<<"好无聊,出去玩了。"<<endl; break; } } while (true); return 0; } void run(void (*f)()) { (*f)(); } void eat() { cout<<"我的胃早已饥渴难耐,让我来份满汉全席。"<<endl; } void sleep() { cout<<"再也不熬夜了,让我一觉睡到自然醒吧。"<<endl; } void hitdoudou() { cout<<"豆豆年年有,今年特别多,让我打爆一切豆豆!"<<endl; }
运行结果:
学习心得:
似乎明白了什么。
相关文章推荐
- 第16周项目3-用函数指针调用函数(吃饭、睡觉、打豆豆)
- 第16周项目3-用函数指针调用函数
- 2014秋C++第16周 项目3参考 用函数指针调用函数
- 第16周项目3—用函数指针调用函数
- 第16周项目3 用函数指针调用函数
- 第十周项目6-吃饭,睡觉,打豆豆(不使用自定义函数)(使用if-else语句)
- 第16周项目3-用函数指针调用函数
- 第16周项目3-用函数指针调用函数
- 第16周项目3 用函数指针调用函数
- 第16周项目3函数指针调用函数
- 第16周上机实践项目3——用函数指针调用函数
- 第16周项目3 用函数指针调用函数
- 第16周项目3-用函数指针调用函数
- 第16周项目3-用函数指针调用函数
- 第16周 项目3 用函数指针调用函数
- 第16周 项目3-用函数指针调用函数
- 第16周项目3-用函数指针调用函数
- 第16周 项目3-用函数指针调用函数
- 第十周项目6-吃饭,睡觉,打豆豆(不使用自定义函数)(使用switch语句)
- 第16周项目3-用函数指针调用函数