本文主要是介绍第十六周 【项目3-用函数指针调用函数】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题及代码:
/*
*Copyright (c) 2014,烟台大学计算机学院
*ALL right reserved
*文件名:用函数指针调用函数
*作者;童宇
*完成日期:2014年12月16日
*版本号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);elsebreak;}while(true);return 0;
}void eat()
{cout <<"我吃吃吃......"<<endl;
}void sleep()
{cout <<"我睡睡......"<<endl;
}void hitdoudou()
{cout <<"我不打还能干什么......"<<endl;
}void run(void (*f)())
{(*f)();
}
运行结果:
这篇关于第十六周 【项目3-用函数指针调用函数】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!