1
1
#include < iostream>
2
2
#include < string>
3
+
3
4
using namespace std ;
4
- class DayTime {
5
+
6
+ class DayTime
7
+ {
5
8
private:
6
9
int hour, minute, second;
10
+
7
11
public:
8
- DayTime () {
12
+ DayTime ()
13
+ {
9
14
hour = 0 ;
10
15
minute = 0 ;
11
16
second = 0 ;
@@ -17,64 +22,81 @@ class DayTime {
17
22
minute = m;
18
23
second = s;
19
24
}
20
- int getHour () const {
25
+ int getHour () const
26
+ {
21
27
return hour;
22
28
}
23
- int getMinute () const {
29
+ int getMinute () const
30
+ {
24
31
return minute;
25
32
}
26
- int getSecond () const {
33
+ int getSecond () const
34
+ {
27
35
return second;
28
36
}
29
-
30
- void DisplayTime () {
31
- cout << " HH: " << hour << endl << " MM: " << minute << endl << " SS: " << second << endl;
37
+
38
+ void DisplayTime ()
39
+ {
40
+ cout << " HH: " << hour << endl
41
+ << " MM: " << minute << endl
42
+ << " SS: " << second << endl;
32
43
}
33
- int asSeconds () const {
44
+ int asSeconds () const
45
+ {
34
46
return (3600 * hour + 60 * minute + second);
35
47
}
36
-
37
- friend void operator <<(ostream& out, DayTime& h);
38
- friend void operator >>(istream& in, DayTime& h);
39
- friend void operator ++(DayTime &MainDayTime);
40
- friend void operator --(DayTime& MainDayTime2);
48
+
49
+ friend void operator <<(ostream & out, DayTime & h);
50
+ friend void operator >>(istream & in, DayTime & h);
51
+ friend void operator ++(DayTime &MainDayTime);
52
+ friend void operator --(DayTime & MainDayTime2);
41
53
};
42
54
43
- void operator >> (istream& in, DayTime& h) {
44
- cout << " Input hours ( 0 , 24 ): " ;
55
+ void operator >>(istream &in, DayTime &h)
56
+ {
57
+ cout << " Input hours ( 0 , 24 ): " ;
45
58
in >> h.hour ;
46
59
47
- cout << " Input minutes (0 , 60 ): " ;
60
+ cout << " Input minutes (0 , 60 ): " ;
48
61
in >> h.minute ;
49
62
50
63
cout << " Input seconds ( 0 ,60 ): " ;
51
64
in >> h.second ;
52
65
}
53
66
54
- void operator << (ostream& out, DayTime& h) {
55
- out << " HH: " << h.hour << endl << " MM: " << h.minute << endl << " SS: " << h.second << endl;
67
+ void operator <<(ostream &out, DayTime &h)
68
+ {
69
+ out << " HH: " << h.hour << endl
70
+ << " MM: " << h.minute << endl
71
+ << " SS: " << h.second << endl;
56
72
}
57
- void operator ++ (DayTime& MainDayTime) {
73
+ void operator ++(DayTime &MainDayTime)
74
+ {
58
75
MainDayTime.second ++;
59
- if (MainDayTime.second >= 60 ) {
76
+ if (MainDayTime.second >= 60 )
77
+ {
60
78
MainDayTime.second = 0 ;
61
79
MainDayTime.minute ++;
62
80
}
63
- if (MainDayTime.minute >= 60 ) {
81
+ if (MainDayTime.minute >= 60 )
82
+ {
64
83
MainDayTime.minute = 0 ;
65
84
MainDayTime.hour ++;
66
85
}
67
86
}
68
- void operator -- (DayTime& MainDayTime2) {
87
+ void operator --(DayTime &MainDayTime2)
88
+ {
69
89
MainDayTime2.minute --;
70
- if (MainDayTime2.minute < 0 ) {
90
+ if (MainDayTime2.minute < 0 )
91
+ {
71
92
MainDayTime2.minute = 59 ;
72
93
MainDayTime2.hour --;
73
94
}
74
95
}
75
96
76
97
// Class 'Dollar' for the program 2
77
- class Dollar {
98
+ class Dollar
99
+ {
78
100
private:
79
101
float currency, mktrate, offrate;
80
102
@@ -85,34 +107,37 @@ class Dollar {
85
107
mktrate = 9000 ;
86
108
offrate = 7000 ;
87
109
}
88
- float getDollar ()
110
+ float getDollar ()
89
111
{
90
- cout << endl<< " Currency: " << endl;
112
+ cout << endl
113
+ << " Currency: " << endl;
91
114
return currency;
92
115
}
93
- float getMarketSoums ()
116
+ float getMarketSoums ()
94
117
{
95
118
cout << " Markent currency: " << endl;
96
- return currency* mktrate;
119
+ return currency * mktrate;
97
120
}
98
- float getofficialSoums () {
121
+ float getofficialSoums ()
122
+ {
99
123
cout << " Official currency:" << endl;
100
- return currency* offrate;
124
+ return currency * offrate;
101
125
}
102
- void setRates ()
126
+ void setRates ()
103
127
{
104
128
cout << " Enter current market rate: " << endl;
105
129
cin >> mktrate;
106
130
cout << " Enter current official rate: " << endl;
107
131
cin >> offrate;
108
132
}
109
- friend void operator << (ostream &output, Dollar &p);
133
+ friend void operator <<(ostream &output, Dollar &p);
110
134
};
111
135
112
- void operator << (ostream &output, Dollar &p)
136
+ void operator << (ostream &output, Dollar &p)
113
137
{
114
138
output << " Details of a dollar " << endl;
115
- output << " Currency is " << p.currency <<endl<< " Market rate is " << p.mktrate <<endl;
139
+ output << " Currency is " << p.currency << endl
140
+ << " Market rate is " << p.mktrate << endl;
116
141
output << " Official rate is " << p.offrate << endl;
117
142
}
118
143
@@ -131,40 +156,45 @@ int main()
131
156
switch (choice)
132
157
{
133
158
// for program 1
134
- case 1 : {
159
+ case 1 :
160
+ {
135
161
system (" cls" );
136
162
int choice2;
137
-
163
+
138
164
DayTime h1 (10 , 10 , 10 );
139
165
DayTime h2;
140
166
cin >> h2;
141
-
167
+
142
168
showChoicesforMainMenu2 ();
143
169
144
- do {
170
+ do
171
+ {
145
172
cin >> choice2;
146
173
switch (choice2)
147
174
{
148
175
case 1 :
149
176
cout << h2;
150
- cout << endl << endl;
177
+ cout << endl
178
+ << endl;
151
179
cout << " Enter your choice: " ;
152
180
break ;
153
181
case 2 :
154
- cout << h2.asSeconds () <<endl;
182
+ cout << h2.asSeconds () << endl;
155
183
cout << " Enter your choice: " ;
156
184
break ;
157
185
case 3 :
158
186
++h2;
159
- h2.DisplayTime ();
160
- cout << h2.asSeconds ();
161
- cout << endl << endl;
187
+ h2.DisplayTime ();
188
+ cout << h2.asSeconds ();
189
+ cout << endl
190
+ << endl;
162
191
cout << " Enter your choice: " ;
163
192
break ;
164
193
case 4 :
165
194
--h2;
166
195
h2.DisplayTime ();
167
- cout << endl << endl;
196
+ cout << endl
197
+ << endl;
168
198
cout << " Enter your choice: " ;
169
199
break ;
170
200
case 5 :
@@ -174,33 +204,37 @@ int main()
174
204
default :
175
205
system (" cls" );
176
206
cout << " Invalid input! Try again." << endl;
177
-
178
207
}
179
208
180
209
} while (choice2 != 5 );
181
210
break ;
182
211
}
183
212
// for program 2
184
- case 2 : {
213
+ case 2 :
214
+ {
185
215
system (" cls" );
186
216
cout << " \t [2] Currency converter" << endl;
187
217
Dollar money;
188
- cout << money.getDollar () << endl;
189
- cout << money.getMarketSoums () << endl;
190
- cout << money.getofficialSoums () << endl << endl;
191
- money.setRates ();
192
- cout << money.getDollar () << endl;
193
- cout << money.getMarketSoums () << endl;
194
- cout << money.getofficialSoums () << endl;
195
- cout << " Overloading: " << endl << endl;
196
-
197
- cout << money;
198
-
218
+ cout << money.getDollar () << endl;
219
+ cout << money.getMarketSoums () << endl;
220
+ cout << money.getofficialSoums () << endl
221
+ << endl;
222
+ money.setRates ();
223
+ cout << money.getDollar () << endl;
224
+ cout << money.getMarketSoums () << endl;
225
+ cout << money.getofficialSoums () << endl;
226
+ cout << " Overloading: " << endl
227
+ << endl;
228
+
229
+ cout << money;
230
+ }
231
+ break ;
232
+
233
+ case 3 :
234
+ {
199
235
}
200
- break ;
236
+ break ;
201
237
202
- case 3 : {}
203
- break ;
204
238
default :
205
239
cout << " Invalid input! Try again." << endl;
206
240
}
@@ -209,22 +243,26 @@ int main()
209
243
return 0 ;
210
244
}
211
245
212
- void showChoicesforMainMenu (){
246
+ void showChoicesforMainMenu ()
247
+ {
213
248
214
- cout << endl << endl;
249
+ cout << endl
250
+ << endl;
215
251
cout << " \t\t\t M A I N M E N U" << endl;
216
252
cout << " \t\t\t 1: Day Time " << endl;
217
253
cout << " \t\t\t 2: Dollar & Soums" << endl;
218
254
cout << " \t\t\t 3: Exit " << endl;
219
255
cout << " \t\t\t Enter your choice : " ;
220
256
}
221
- void showChoicesforMainMenu2 () {
257
+
258
+ void showChoicesforMainMenu2 ()
259
+ {
222
260
cout << " \t [1] First program" << endl;
223
261
cout << " \t\t\t M A I N M E N U 2" << endl;
224
262
cout << " \t\t\t 1. To Display Time." << endl;
225
263
cout << " \t\t\t 2. To Display Time in Seconds." << endl;
226
264
cout << " \t\t\t 3. To Increment seconds." << endl;
227
265
cout << " \t\t\t 4. To decrements minutes." << endl;
228
266
cout << " \t\t\t 5. Exit." << endl;
229
- cout << " \t\t\t Enter your choise : " ;
267
+ cout << " \t\t\t Enter your choice : " ;
230
268
}
0 commit comments