forked from Rustam-Z/cpp-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain1.cpp
More file actions
268 lines (242 loc) · 4.73 KB
/
Copy pathmain1.cpp
File metadata and controls
268 lines (242 loc) · 4.73 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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include <iostream>
#include <string>
using namespace std;
class DayTime
{
private:
int hour, minute, second;
public:
DayTime()
{
hour = 0;
minute = 0;
second = 0;
}
DayTime(int h, int m, int s)
{
hour = h;
minute = m;
second = s;
}
int getHour() const
{
return hour;
}
int getMinute() const
{
return minute;
}
int getSecond() const
{
return second;
}
void DisplayTime()
{
cout << "HH: " << hour << endl
<< "MM: " << minute << endl
<< "SS: " << second << endl;
}
int asSeconds() const
{
return (3600 * hour + 60 * minute + second);
}
friend void operator<<(ostream &out, DayTime &h);
friend void operator>>(istream &in, DayTime &h);
friend void operator++(DayTime &MainDayTime);
friend void operator--(DayTime &MainDayTime2);
};
void operator>>(istream &in, DayTime &h)
{
cout << "Input hours ( 0 , 24 ): ";
in >> h.hour;
cout << "Input minutes (0 , 60 ): ";
in >> h.minute;
cout << "Input seconds ( 0 ,60 ): ";
in >> h.second;
}
void operator<<(ostream &out, DayTime &h)
{
out << "HH: " << h.hour << endl
<< "MM: " << h.minute << endl
<< "SS: " << h.second << endl;
}
void operator++(DayTime &MainDayTime)
{
MainDayTime.second++;
if (MainDayTime.second >= 60)
{
MainDayTime.second = 0;
MainDayTime.minute++;
}
if (MainDayTime.minute >= 60)
{
MainDayTime.minute = 0;
MainDayTime.hour++;
}
}
void operator--(DayTime &MainDayTime2)
{
MainDayTime2.minute--;
if (MainDayTime2.minute < 0)
{
MainDayTime2.minute = 59;
MainDayTime2.hour--;
}
}
// Class 'Dollar' for the program 2
class Dollar
{
private:
float currency, mktrate, offrate;
public:
Dollar()
{
currency = 100;
mktrate = 9000;
offrate = 7000;
}
float getDollar()
{
cout << endl
<< "Currency: " << endl;
return currency;
}
float getMarketSoums()
{
cout << "Markent currency: " << endl;
return currency * mktrate;
}
float getofficialSoums()
{
cout << "Official currency:" << endl;
return currency * offrate;
}
void setRates()
{
cout << "Enter current market rate: " << endl;
cin >> mktrate;
cout << "Enter current official rate: " << endl;
cin >> offrate;
}
friend void operator<<(ostream &output, Dollar &p);
};
void operator<<(ostream &output, Dollar &p)
{
output << "Details of a dollar " << endl;
output << "Currency is " << p.currency << endl
<< "Market rate is " << p.mktrate << endl;
output << "Official rate is " << p.offrate << endl;
}
void showChoicesforMainMenu();
void showChoicesforMainMenu2();
int main()
{
int choice;
DayTime t2(25, 0, 0);
int hour, minute, second;
do
{
showChoicesforMainMenu();
cin >> choice;
switch (choice)
{
// for program 1
case 1:
{
system("cls");
int choice2;
DayTime h1(10, 10, 10);
DayTime h2;
cin >> h2;
showChoicesforMainMenu2();
do
{
cin >> choice2;
switch (choice2)
{
case 1:
cout << h2;
cout << endl
<< endl;
cout << "Enter your choice: ";
break;
case 2:
cout << h2.asSeconds() << endl;
cout << "Enter your choice: ";
break;
case 3:
++h2;
h2.DisplayTime();
cout << h2.asSeconds();
cout << endl
<< endl;
cout << "Enter your choice: ";
break;
case 4:
--h2;
h2.DisplayTime();
cout << endl
<< endl;
cout << "Enter your choice: ";
break;
case 5:
system("cls");
main();
break;
default:
system("cls");
cout << "Invalid input! Try again." << endl;
}
} while (choice2 != 5);
break;
}
// for program 2
case 2:
{
system("cls");
cout << "\t[2] Currency converter" << endl;
Dollar money;
cout << money.getDollar() << endl;
cout << money.getMarketSoums() << endl;
cout << money.getofficialSoums() << endl
<< endl;
money.setRates();
cout << money.getDollar() << endl;
cout << money.getMarketSoums() << endl;
cout << money.getofficialSoums() << endl;
cout << "Overloading: " << endl
<< endl;
cout << money;
}
break;
case 3:
{
}
break;
default:
cout << "Invalid input! Try again." << endl;
}
} while (choice != 3);
return 0;
}
void showChoicesforMainMenu()
{
cout << endl
<< endl;
cout << "\t\t\t M A I N M E N U" << endl;
cout << "\t\t\t1: Day Time " << endl;
cout << "\t\t\t2: Dollar & Soums" << endl;
cout << "\t\t\t3: Exit " << endl;
cout << "\t\t\tEnter your choice : ";
}
void showChoicesforMainMenu2()
{
cout << "\t[1] First program" << endl;
cout << "\t\t\t M A I N M E N U 2" << endl;
cout << "\t\t\t1. To Display Time." << endl;
cout << "\t\t\t2. To Display Time in Seconds." << endl;
cout << "\t\t\t3. To Increment seconds." << endl;
cout << "\t\t\t4. To decrements minutes." << endl;
cout << "\t\t\t5. Exit." << endl;
cout << "\t\t\tEnter your choice : ";
}