-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.cpp
More file actions
125 lines (110 loc) · 3.17 KB
/
Date.cpp
File metadata and controls
125 lines (110 loc) · 3.17 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
File: Date.cpp
Author: Dominic Rando
Course: CSC402
Professor: **********
Assignment: **********
Purpose: Implementation file for the Date class
Creation Date: April 13, 2021
Due Date: May 11, 2021
*/
#include <iostream>
#include "Date.h"
/*!
* \file Date.cpp
* \brief Implementations for the Date class functions found in Date.h
*
* \class Date
* This class will take three integers that will represent the month, day, and year for the date
*/
using namespace std;
/*!
* Default constructor uses the setDate function to set the values of month, day, and year
*/
Date::Date( int m, int d, int y ){
setDate(m,d,y);
}
/*!
* Copy constructor sets "this" Date object's members to the same ones as the other Date object
*/
Date::Date(const Date &d){
this->day = d.day;
this->month = d.month;
this->year = d.year;
}
/*!
* Sets the date given the 3 parameters
*/
void Date::setDate(int m, int d, int y){
month = m;
day = d;
year = y;
}
/*!
* Function that returns the value for data member "month"
*/
int Date::getMonth(){ return(month); }
/*!
* Function that returns the value for data member "dat"
*/
int Date::getDay(){ return(day); }
/*!
* Function that returns the value for data member "year"
*/
int Date::getYear(){ return(year); }
/*!
* Operator overload that compares two Date objects and determines if "this"
* is less than the other object based on the values of month, day, and year
*/
bool Date::operator<(Date d){
// check if years are different, then months, then days
// make this look genuine
if (this->year < d.year)
return true;
else if (this->year == d.year && this->month < d.month)
return true;
else if (this->year == d.year && this -> month == d.month && this->day < d.day)
return true;
return false;
}
/*!
* Operator overload that compares two Date objects and determines if "this"
* is less than or equal the other object based on the values of month, day, and year
*/
bool Date::operator<=(Date d){
// check if years are different, then months, then days
// make this look genuine
if (this->year == d.year)
return true;
if (this->year < d.year)
return true;
else if (this->year == d.year && this->month < d.month)
return true;
else if (this->year == d.year && this -> month == d.month && this->day < d.day)
return true;
return false;
}
/*!
* Operator overload that compares two Date objects and determines if "this"
* is equal the other object based on the values of month, day, and year
*/
bool Date::operator==(Date d){
if(this->month == d.month && this->day == d.day && this->year == d.year)
return true;
else
return false;
}
/*!
* Operator overload that prints a Date class to the output stream
* It will display the months as their names instead of their integer value
*/
ostream &operator<<( ostream &output, const Date &d )
{
string monthName[13] = { "", "January",
"February", "March", "April", "May", "June",
"July", "August", "September", "October",
"November", "December"};
output << monthName[ d.month ] << ' '
<< d.day << ", " << d.year;
return output; // enables cascading
}