home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / CTUTOR / ANSWERS.ZIP / CH03_2.CPP < prev    next >
C/C++ Source or Header  |  1990-07-20  |  1KB  |  64 lines

  1.                   // Chapter 3 - Programming exercise 2
  2. #include "iostream.h"
  3. #include "stdio.h"
  4.  
  5. void print_stuff(float data_to_ignore);
  6. void print_message(float list_this_data);
  7. void print_float(float data_to_print);
  8. void (*function_pointer)(float);
  9. void print_int(int data);
  10.  
  11. main()
  12. {
  13. float pi = 3.14159;
  14. float two_pi = 2.0 * pi;
  15.  
  16.    print_stuff(pi);
  17.    function_pointer = print_stuff;
  18.    function_pointer(pi);
  19.    function_pointer = print_message;
  20.    function_pointer(two_pi);
  21.    function_pointer(13.0);
  22.    function_pointer = print_float;
  23.    function_pointer(pi);
  24.    print_float(pi);
  25.  
  26.    function_pointer = print_int;
  27.    function_pointer(37);
  28. }
  29.  
  30.  
  31. void print_stuff(float data_to_ignore)
  32. {
  33.    printf("This is the print stuff function.\n");
  34. }
  35.  
  36.  
  37. void print_message(float list_this_data)
  38. {
  39.    printf("The data to be listed is %f\n", list_this_data);
  40. }
  41.  
  42.  
  43. void print_float(float data_to_print)
  44. {
  45.    printf("The data to be printed is %f\n", data_to_print);
  46. }
  47.  
  48.  
  49. void print_int(int data)
  50. {
  51.    printf("This is an integer %d\n", data);
  52. }
  53.  
  54.  
  55. // Result of execution
  56. //
  57. // This is the print stuff function.
  58. // This is the print stuff function.
  59. // The data to be listed is 6.283180
  60. // The data to be listed is 13.000000
  61. // The data to be printed is 3.141590
  62. // The data to be printed is 3.141590
  63. // This is an integer 0
  64.