home *** CD-ROM | disk | FTP | other *** search
- // ex07011.cpp
- // Manipulating data members though member functions
- #include <iostream.h>
-
- class Date {
- int mo, da, yr;
- public:
- Date(int m, int d, int y) { mo = m; da = d; yr = y; }
- // ---- a member function to return the year
- int getyear() { return yr; }
- // ---- a member function to allow the year to be changed
- int& year() { return yr; }
- };
-
- main()
- {
- // -------- set up a Date
- Date dt(4, 1, 89);
- // ------- use a member function to read the year value
- cout << "\nThe year is: " << dt.getyear();
- // ------ use a member function to change the year
- dt.year() = 90;
- cout << "\nThe new year is: " << dt.getyear();
- }