-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-date-RTOBJ.cpp
More file actions
72 lines (67 loc) · 1.55 KB
/
class-date-RTOBJ.cpp
File metadata and controls
72 lines (67 loc) · 1.55 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
#include <iostream>
#include <conio.h>
using namespace std;
class Date{
private:
int Day;
int month;
int year;
public:
void setDate(int h, int m, int s){
year = h;
month = m;
Day = s;
}
Date add(Date D1)
{
Date tempd;
tempd.Day = tempd.month = tempd.year = 0;
tempd.Day += Day + D1.Day;
if(tempd.Day >= 30){
tempd.Day -= 30;
tempd.month ++;
}
tempd.month += month + D1.month;
if(tempd.month >= 12){
tempd.month -= 12;
tempd.year ++;
}
tempd.year += year + D1.year;
return tempd;
}
Date minus(Date D1)
{
Date tempd;
tempd.Day = tempd.month = tempd.year = 0;
tempd.Day = Day - D1.Day;
if(tempd.Day < 0){
tempd.Day = tempd.Day + 30;
tempd.month --;
}
tempd.month = month - D1.month;
if(tempd.month < 0){
tempd.month = tempd.month + 12;
tempd.year --;
}
tempd.year -= year - D1.year;
return tempd;
}
void displayDate(){
cout << "year: " << year << " | month: " << month << " | Days: "<<Day<< endl;
}
};
int main()
{
Date D1, D2, D3;
cout << "Enter the first date (dd/mm/yyyy): " << endl;
int d, m, y;
cin >> d >> m >> y;
D1.setDate(d, m, y);
cout << "Enter the second date (dd/mm/yyyy): " << endl;
cin >> d >> m >> y;
D2.setDate(d, m, y);
D3 = D1.add(D2);
D3.displayDate();
getch();
return 0;
}