forked from Ansi007/Programming-Fundamentals-Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubtraction of two dates
81 lines (78 loc) · 1.33 KB
/
Subtraction of two dates
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
#include<iostream>
using namespace std;
class sub_date
{
private:
int year;
string month;
bool status;
public:
int day;
sub_date();
sub_date(string mnth, int dy, int yer);
void setdata(string m, int d, int y);
bool operator > (sub_date& obj);
sub_date operator - (sub_date& obj);
};
sub_date::sub_date()
{
month = " ";
year = 0;
day = 0;
}
sub_date::sub_date(string mnth, int dy, int yer)
{
month = mnth;
day = dy;
year = yer;
}
void sub_date::setdata(string m, int d, int y)
{
month = m;
year = y;
day = d;
}
bool sub_date::operator>(sub_date& obj)
{
if (day > obj.day)
{
status = true;
}
else
{
status = false;
}
return status;
}
sub_date sub_date::operator-(sub_date& obj)
{
sub_date temp;
operator > (obj);
if (status == true)
{
temp.day = day - obj.day;
}
else
{
temp.day = obj.day - day;
}
return temp;
}
int main()
{
int day,year;
string month;
cout << "PLEASE! first enter MONTH then enter DAY and then YEAR" << endl;
cout << "enter the first date : " << "\t";
cin >> month;
cin >> day >> year;
sub_date date1(month, day, year);
sub_date date2,date3;
cout << "enter the second date : " << "\t";
cin >> month;
cin >> day >> year;
date2.setdata(month, day, year);
date3 = date1 - date2;
cout << "AFTER SUBTRACTION OF TWO DATE " << endl;
cout << month <<" " << date3.day << " , " << year << endl;
}