Project 3 in week 3 -- use function pointers to call functions (eat, sleep, and Doudou), and 3 in week 3 --
/** Copyright (c) 2014, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Liu Chang * Completion Date: July 15, December 14, 2014 * version number: v1.0 ** Problem description: Call a function using a function pointer; * input Description: enter a command; * program output: output.
# Include <iostream> using namespace std; void eat (); void sleep (); void hitdoudou (); void run (void (* f) (); int main () {int iChoice; do {cout <"select (1-eat; 2-sleep; 3-beat; Other-return):"; cin> iChoice; if (iChoice = 1) run (eat); else if (iChoice = 2) run (sleep); else if (iChoice = 3) run (hitdoudou ); else {cout <"It's boring to go out and play. "<Endl; break;} while (true); return 0;} void run (void (* f) () {(* f )();} void eat () {cout <"My stomach has been hungry and impatient. Let me have a full seat. "<Endl;} void sleep () {cout <" never stayed up late again. Let me wake up naturally. "<Endl;} void hitdoudou () {cout <", this year is quite a year, so let me play all the beans! "<Endl ;}
Running result:
Learning Experience:
What does it seem to understand.