Sams Teach Yourself C in 21 Days

(singke) #1
Working with C++ Classes and Objects 681

BD3


18:
19: int get_hours( void );
20: int get_minutes( void );
21: int get_seconds( void );
22: };
23:
24: int main(int argc, char* argv[])
25: {
26: time myTime;
27:
28: myTime.init(11, 43, 20);
29:
30: //print the initialized time
31: cout << “\nMy time is: “;
32: myTime.print_time();
33:
34: //reset the time data members individually
35: cout << “\n\nResetting time to 3:12:30...\n”;
36:
37: myTime.set_hours( 3 );
38: myTime.set_minutes(12);
39: myTime.set_seconds (30);
40:
41: //print the time data members individually
42: cout << “\nThe hours are now: “ << myTime.get_hours();
43: cout << “\nThe minutes are now: “ << myTime.get_minutes();
44: cout << “\nThe seconds are now: “ << myTime.get_seconds();
45:
46: return 0;
47: }
48:
49: // Print a time structure in h:m:s format
50: //----------------------------------------
51: void time::print_time(void)
52: {
53: cout << hours << “:” << minutes << “:” << seconds;
54: }
55:
56: // Initialize data member values
57: //-------------------------------
58: void time::init(int h, int m, int s)
59: {
60: hours = h;
61: minutes = m;
62: seconds = s;
63: }
64:
65: // Access functions
66: //------------------

LISTINGB3.5 continued

38 448201x-Bonus3 8/13/02 11:19 AM Page 681

Free download pdf