Sams Teach Yourself C++ in 21 Days

(singke) #1
23: switch (choice)
24: {
25: case 1: pFunc = GetVals; break;
26: case 2: pFunc = Square; break;
27: case 3: pFunc = Cube; break;
28: case 4: pFunc = Swap; break;
29: default: fQuit = true; break;
30: }
31:
32: if (fQuit == false)
33: PrintVals ( pFunc, valOne, valTwo);
34: }
35:
36: return 0;
37: }
38:
39: void PrintVals( void (*pFunc)(int&, int&),int& x, int& y)
40: {
41: cout << “x: “ << x << “ y: “ << y << endl;
42: pFunc(x,y);
43: cout << “x: “ << x << “ y: “ << y << endl;
44: }
45:
46: void Square (int & rX, int & rY)
47: {
48: rX *= rX;
49: rY *= rY;
50: }
51:
52: void Cube (int & rX, int & rY)
53: {
54: int tmp;
55:
56: tmp = rX;
57: rX *= rX;
58: rX = rX * tmp;
59:
60: tmp = rY;
61: rY *= rY;
62: rY = rY * tmp;
63: }
64:
65: void Swap(int & rX, int & rY)
66: {
67: int temp;
68: temp = rX;
69: rX = rY;
70: rY = temp;
71: }
72:

524 Day 15


LISTING15.8 continued
Free download pdf