-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
219 lines (194 loc) · 4.15 KB
/
main.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* main.cpp
*
*/
#include "cTime_t.h"
#include "cDate_t.h"
#include "cDateTime_t.h"
#include <iostream>
using namespace std;
cTime_t time1, time2;
cDate_t date1, date2;
cDateTime_t dateTime1;
int i,h,m,s,d,mo,y;
char c;
void setTime();
void setDate();
cTime_t& getTimeObject();
cDate_t& getDateObject();
int main (int argc, int **argv){
cout << "do you want to set initial value? (y/n)";
cin >> c;
if (c == 'y')
{
setTime();
setDate();
time1.setTime(h,m,s);
time2.setTime(h,m,s);
date1.setDate(d,mo,y);
date2.setDate(d,mo,y);
}
//TODO: add randomize initialization
cout << "\n";
while (1)
{
cout << "Time command list: \n"
<< "****************** \n"
<< "1 - set the time 2 - t1=t1+t2 \n"
<< "3 - change time printing format 4 - get the hour \n"
<< "5 - get the minute 6 - get the second \n"
<< "\n"
<< "Date command list: \n"
<< "****************** \n"
<< "7 - set the Date 8 - change date printing format \n"
<< "9 - get the day 10 - get the month \n"
<< "11 - get the year 12 - get the day of the year \n"
<< "13 - is year leap 14 - get name of the day \n"
<< "15 - get name of the month"
<< "\n"
<< "DateTime command list: \n"
<< "********************** \n"
<< "16 - Set Date time object\n"
<< "17 - Add time object to DateTime \n"
<< "\n"
<< "18 - Exit Program\n\n"
<< "Member status: \n"
<< "************** \n"
<< "time1: "; time1.printTime(); cout << endl;
cout << "time2: "; time2.printTime(); cout << endl;
cout << "date1: "; date1.printDate(); cout << endl;
cout << "date2: "; date2.printDate(); cout << endl;
cout << "dateTime1: "; dateTime1.print();
cout << "\n"
<< "enter command number: ";
cin >> i;
cout << "\n";
if ((i == 1)||((3 < i) && (i < 7))){
cTime_t &timeObj = getTimeObject();
switch(i){
case 1:
setTime();
timeObj.setTime(h,m,s);
continue;
case 4:
cout << timeObj.getHours()<< "hours \n \n";
continue;
case 5:
cout << timeObj.getMinutes() << "minutes \n \n";
continue;
case 6:
cout << timeObj.getSeconds()<< "seconds \n \n";
continue;
}
}else if ((1 < i) && (i < 4)){
switch(i){
case 2:
time1 = time1 + time2;
continue;
case 3:
int f;
cout << "enter print format: ";
cin >> f;
time1.format = f;
continue;
}
}else if((6 < i) && (i < 16)){
cDate_t &dateObj = getDateObject();
switch(i){
case 7:
setDate();
dateObj.setDate(d,mo,y);
continue;
case 8:
int f;
cout << "enter print format: ";
cin >> f;
date1.format = f;
continue;
case 9:
cout << dateObj.getDay() << " day \n \n";
continue;
case 10:
cout << dateObj.getMonth() << " month \n \n";
continue;
case 11:
cout << dateObj.getYear() << " year \n \n";
continue;
case 12:
cout << dateObj.getDayOfTheYear() << "\n \n";
continue;
case 13:
cout << (dateObj.isYearLeap() ? "yes \n \n" : "no \n \ns");
continue;
case 14:
cout << dateObj.getNameOfDay() << "\n \n";
continue;
case 15:
cout << dateObj.getNameOfMonth() << "\n \n";
continue;
}
}else if (i >= 16 && i <= 17){
switch (i){
case 16:
dateTime1.time_p = getTimeObject();
dateTime1.date_p = getDateObject();
continue;
case 17:
dateTime1 = dateTime1 + getTimeObject();
continue;
}
}else{
if (i == 18)
{
exit(0);
}
cout << "illegal command \n";
continue;
}
}
}
void setTime()
{
cout << "\n enter hour:";
cin >> h;
cout << "\n enter minute:";
cin >> m;
cout << "\n enter second:";
cin >> s;
}
void setDate()
{
cout << "\n enter day:";
cin >> d;
cout << "\n enter month:";
cin >> mo;
cout << "\n enter year:";
cin >> y;
}
cTime_t &getTimeObject(){
int num;
cout << "choose time object: ";
cin >> num;
cout << "\n";
if (num == 1)
{
cTime_t &tmp = time1;
return tmp;
}
cTime_t &tmp = time2;
return tmp;
}
cDate_t &getDateObject()
{
int num;
cout << "choose date object: ";
cin >> num;
cout << "\n";
if (num == 1)
{
cDate_t &tmp = date1;
return tmp;
}
cDate_t &tmp = date2;
return tmp;
}