您的位置:首页 > 其它

第16周项目3函数指针调用函数

2014-12-15 12:51 363 查看
/*。
*Copyright(c)2014,烟台大学计算机学院
*All right reserved,
*文件名:test.cpp
*作者:biyutang
*完成日期:2014年12月13日
*版本号:v1.0
*
问题描述:
*输入描述:输入x
*程序输出:输出Y
*/
#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
return 0;
}
while(true);
return 0;
}
void eat()
{
cout<<"我吃吃吃......"<<endl;
}
void sleep()
{
cout<<"我睡睡......"<<endl;
}
void hitdoudou()
{
cout<<"我不打还干什么......"<<endl;
}
void run(void (*f)())
{
f();
}

运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: