< previous page page_334 next page >

Page 334
LISTING 20.6 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
14:       int choice, i;
15:       const int MaxArray = 5;
16:       void (*pFuncArray[MaxArray]) (int&, int&);
17:
18:       for (i=0;i<MaxArray;i++)
19:       {
20:          cout << (1)Change Values (2)Square (3)Cube (4)Swap: ;
21:          cin >> choice;
22:          switch (choice)
23:          {
24:             case 1:pFuncArray[i] = GetVals; break;
25:             case 2:pFuncArray[i] = Square; break;
26:             case 3:pFuncArray[i] = Cube; break;
27:             case 4:pFuncArray[i] = Swap; break;
28:             default:pFuncArray[i] = 0;
29:          }
30:       }
31:
32:       for (i=0;i<MaxArray; i++)
33:       {
34:          pFuncArray[i](valOne,valTwo);
35:          PrintVals(valOne,valTwo);
36:       }
37:       return 0;
38:    }
39:    void PrintVals(int x, int y)
40:    {
41:       cout << x:  << x <<  y:  << y << endl;
42:    }
43:
44:    void Square (int & rX, int & rY)
45:    {
46:       rX *= rX;
47:       rY *= rY;
48:    }
49:
50:    void Cube (int & rX, int & rY)
51:    {
52:       int tmp;
53:
54:       tmp = rX;
55:       rX *= rX;
56:       rX = rX * tmp;
57:
58:       tmp = rY;
59:       rY *= rY;
60:       rY = rY * tmp;
61:    }
62:
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
continues

 
< previous page page_334 next page >

If you like this book, buy it!