/*
* Copyright (c) 2014,烟台大学计算机学院
* All right reserved.
*文件名:sixteen week 3.app
* 作者:柴银平
* 完成时间:2014年12月15日
* 版本号:v1.0
*
* 问题描述:用函数指针调用函数。
*程序输入:输入iChoice,你的选择。
*程序输出:输出你要做的。。。
*/
#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
break;
}
while(true);
return 0;
}
void eat()
{
cout<<"我吃吃吃..."<<endl;
}
void sleep()
{
cout<<"我睡睡..."<<endl;
}
void hitdoudou()
{
cout<<"我不能打还能干嘛..."<<endl;
}
void run(void (*f)())
{
f();
}
学习心得;
还需努力!