-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.cpp
More file actions
95 lines (84 loc) · 2.23 KB
/
Time.cpp
File metadata and controls
95 lines (84 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
File: Time.cpp
Author: Dominic Rando
Course: CSC402
Professor: **********
Assignment: **********
Purpose: Implementation file for the Time class
Creation Date: April 13, 2021
Due Date: May 11, 2021
*/
#include <iostream>
#include "Time.h"
/*!
* \file Time.cpp
* \brief Implementations for the Time class functions found in Time.h
*
* \class Time
* This class will take three integers that will represent the hour, minute, and second for the Time object
*/
using namespace std;
/*!
* Default constructor uses the setTime function to set the values of hour, minute, and second
*/
Time::Time(int h, int m, int s){
setTime(h,m,s);
}
/*!
* Copy constructor sets "this" Time object's members to the same ones as the other Time object
*/
Time::Time(const Time &t){
this->hour = t.hour;
this->minute = t.minute;
this->second = t.second;
}
/*!
* Sets the Time given the 3 parameters for hour, minute, and second
*/
void Time::setTime(int h, int m, int s){
hour = h;
minute = m;
second = s;
}
/*!
* Function that returns the value for data member "hour"
*/
int Time::getHour(){ return(hour); }
/*!
* Function that returns the value for data member "minute"
*/
int Time::getMinute(){ return(minute); }
/*!
* Function that returns the value for data member "second"
*/
int Time::getSecond(){ return(second); }
/*!
* Operator overload that compares two Time objects and determines if "this"
* is less than the other object based on the values of hour, minute, and second
*/
bool Time::operator<(Time t){
if (this->hour < t.hour)
return true;
else if (this->hour == t.hour && this->minute < t.minute)
return true;
else if (this->hour == t.hour && this->minute == t.minute && this->second < t.second)
return true;
return false;
}
/*!
* Operator overload that prints a Time class to the output stream
* It will add 0's to the end of each member (except hour) if they are less than 10
*/
ostream &operator<<( ostream &output, const Time &t){
output << t.hour << ":";
if (t.minute < 10)
output << 0 << t.minute;
else
output << t.minute;
output << ":";
if (t.second < 10)
output << 0 << t.second;
else
output << t.second;
return output;
}