/*
* 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 return 0;
}
while(true);
return 0;
}
void eat()
{
cout<<"我吃吃吃。。。"<<endl;
}
void sleep()
{
cout<<"我睡睡睡。。。"<<endl;
}
void hitdoudou()
{
cout<<"我不打还能干什么。。。"<<endl;
}
void run(void (*f)())
{
f();
}
运算结果:
知识点总结:
函数的调用,用函数指针调用函数
学习心得:
1.2.3都想选,继续努力,加油!