home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ANSICPP.ZIP / EX06007.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  762 b   |  43 lines

  1. // ex06007.cpp
  2. // Call by reference
  3. #include <iostream.h>
  4.  
  5. // ------ simple date class
  6. struct date {
  7.     int da, mo, yr;
  8.     void display(void);
  9. };
  10. void date::display()
  11. {
  12.     cout << da << '/' << mo << '/' << yr;
  13. }
  14. void swapper(date&, date&);
  15. void display(date&, date&);
  16.  
  17. main()
  18. {
  19.     date now  = {23,2,90};    // two dates
  20.     date then = {10,9,60};    
  21.     
  22.     display(now, then);        // display the dates
  23.     swapper(now, then);        // swap them
  24.     display(now, then);         // display them swapped
  25. }
  26.  
  27. // ----- this function swaps the caller's dates
  28. void swapper(date& dt1, date& dt2)
  29. {
  30.     date save;
  31.     save = dt1;
  32.     dt1 = dt2;
  33.     dt2 = save;
  34. }
  35.  
  36. void display(date& now, date& then)
  37. {
  38.     cout << "\n Now:  ";
  39.     now.display();
  40.     cout << "\n Then: ";
  41.     then.display();
  42. }
  43.