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

  1. // ex07011.cpp
  2. // Manipulating data members though member functions
  3. #include <iostream.h>
  4.  
  5. class Date {
  6.     int mo, da, yr;
  7. public:
  8.     Date(int m, int d, int y) { mo = m; da = d; yr = y; }
  9.     // ---- a member function to return the year
  10.     int getyear() { return yr; }
  11.     // ---- a member function to allow the year to be changed
  12.     int& year() { return yr; }
  13. };
  14.  
  15. main()
  16. {
  17.     // -------- set up a Date
  18.     Date dt(4, 1, 89);
  19.     // ------- use a member function to read the year value
  20.     cout << "\nThe year is: " << dt.getyear();
  21.     // ------ use a member function to change the year
  22.     dt.year() = 90;
  23.     cout << "\nThe new year is: " << dt.getyear();
  24. }
  25.