forked from hariom20singh/food-delivery-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDate.cpp
82 lines (80 loc) · 1.78 KB
/
Date.cpp
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
#include <iostream>
#include <ctime>
using namespace std;
class Date
{
private:
int day, month, year;
public:
Date()
{
time_t now = time(0);
tm *ltime = localtime(&now);
day = ltime->tm_mday;
month = ltime->tm_mon + 1;
year = ltime->tm_year + 1900;
}
void CalculateDate(int d, Date ob)
{
year = ob.year + d / 365;
day = ob.day + d % 365;
month = ob.month;
int mon_days = 0;
if (month == 2)
{
if (year % 4 == 0)
mon_days = 29;
else
mon_days = 28;
}
else
{
if (month == 4 || month == 6 || month == 9 || month == 11)
mon_days = 30;
else
mon_days = 31;
}
while (day > mon_days)
{
day = day - mon_days;
month++;
if (month > 12)
{
month = month - 12;
year++;
}
if (month == 2)
{
if (year % 4 == 0)
mon_days = 29;
else
mon_days = 28;
}
else
{
if (month == 4 || month == 6 || month == 9 || month == 11)
mon_days = 30;
else
mon_days = 31;
}
}
}
void Display()
{
cout << day << "/" << month << "/" << year << endl;
}
};
int main()
{
Date Cu_date;
cout << "The current date is:";
Cu_date.Display();
int no_days;
cout << "Enter no of days";
cin >> no_days;
Date Fu_date;
Fu_date.CalculateDate(no_days, Cu_date);
cout << "The Future Date is:";
Fu_date.Display();
return 0;
}