1: /** @filetime.cpp
2: Implementation file corresponding to time.h.
3: */
5: #include <iostream>
6: using namespace std;
8: #include "time.h"
10: Time::Time
11: (
12: int hours, //in
13: int minutes, //in
14: int seconds //in
15: )
16: {
17: this->hours = hours;
18: this->minutes = minutes;
19: this->seconds = seconds;
21: cout << "\nNow in constructor for base class Time ... ";
22: cout << "\nTime value is: "; this->display();
23: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
24: }
26: Time::Time
27: (
28: const Time& otherTime //in
29: )
30: //Not needed, but inserted to show when a copy is being made.
31: {
32: hours = otherTime.hours;
33: minutes = otherTime.minutes;
34: seconds = otherTime.seconds;
36: cout << "\nNow in copy constructor for base class Time ... ";
37: cout << "\nTime value is: "; this->display();
38: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
39: }
41: Time::~Time()
42: //Not needed, but inserted to help show destruction order.
43: {
44: cout << "\nNow in destructor for base class Time ... ";
45: cout << "\nTime value is: "; this->display();
46: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
47: }
49: void Time::set
50: (
51: int hours, //in
52: int minutes, //in
53: int seconds //in
54: )
55: {
56: this->hours = hours;
57: this->minutes = minutes;
58: this->seconds = seconds;
59: }
61: void Time::increment()
62: {
63: seconds++;
64: if (seconds > 59)
65: {
66: seconds = 0;
67: minutes++;
68: if (minutes > 59)
69: {
70: minutes = 0;
71: hours++;
72: if (hours > 23) hours = 0;
73: }
74: }
75: }
77: void Time::display() const
78: {
79: if (hours < 10) cout << '0';
80: cout << hours << ':';
81: if (minutes < 10) cout << '0';
82: cout << minutes << ':';
83: if (seconds < 10) cout << '0';
84: cout << seconds;
85: }