1
+ #include < iostream>
2
+ #include < conio.h>
3
+ #include < iomanip>
4
+ #include < string>
5
+ #include < fstream>
6
+ using namespace std ;
7
+ class file
8
+ {
9
+ string name;
10
+ int age;
11
+ public:
12
+ void getdata ()
13
+ {
14
+ cout << " Enter your name: " ;
15
+ cin >> name;
16
+ cout << " Enter your Age: " ;
17
+ cin >> age;
18
+ fstream obj;
19
+ obj.open (" File.dat" , ios::in | ios::out | ios::app);
20
+ obj.write ((char *)this , sizeof (*this ));
21
+ }
22
+ void showdata ()
23
+ {
24
+ fstream obj;
25
+ obj.seekg (0 );
26
+ obj.open (" File.dat" , ios::in | ios::out | ios::app);
27
+ obj.read ((char *)this , sizeof (*this ));
28
+ while (!obj.eof ())
29
+ {
30
+ cout << setw (10 ) << name << setw (8 ) << age << endl;
31
+ obj.read ((char *)this , sizeof (*this ));
32
+ }
33
+ }
34
+ };
35
+ class shoping
36
+ {
37
+ public:
38
+ void main_menu () {
39
+ cout << " ********************** Welcome to Mega Mart ************************ " << endl << endl;
40
+ cout << " Press 1 for Cutomer menu: " << endl;
41
+ cout << " Press 2 for Owner menu: " << endl;
42
+ cout << " Press 3 to Exit the store:" << endl;
43
+ cout << " Enter Options : " ;
44
+ }
45
+
46
+ void cutomer_menu () {
47
+ cout << " \n\n ****************** Welcome to Cutomer menu ********************************* " << endl << endl;
48
+ cout << " Press B to buy items: " << endl;
49
+ cout << " Press D to delete items: " << endl;
50
+ cout << " Press V to View your buying:" << endl;
51
+ cout << " Press M for bill/money:" << endl;
52
+ cout << " Press R to return to Main menu:" << endl;
53
+ cout << " Enter Options : " ;
54
+ }
55
+
56
+ void owner_menu () {
57
+ cout << " \n\n ******************* Welcome to Owner menu ********************************* " << endl << endl;
58
+ cout << " Press A to Add items: " << endl;
59
+ cout << " Press D to Delete items: " << endl;
60
+ cout << " Press V to Display items: " << endl;
61
+ cout << " Press S to View Total sales: " << endl;
62
+ cout << " Press p to Show list of customer :" << endl;
63
+ cout << " Press R to return to Main menu:" << endl;
64
+ cout << " Enter Options : " ;
65
+ }
66
+
67
+ void buy_items () {
68
+ cout << " \n\n ****************** Buy Items ********************************* " << endl << endl;
69
+ cout << " Press S to Buy Shirts: " << endl;
70
+ cout << " Press P to Buy Pants: " << endl;
71
+ cout << " Press J to Buy Jackets: " << endl;
72
+ cout << " Press R to return to Cutomer menu:" << endl;
73
+ cout << " Enter Options : " ;
74
+ }
75
+
76
+ void delete_items () {
77
+ cout << " \n\n ******************** Buy Items ********************************* " << endl << endl;
78
+ cout << " Press S to Delete Shirts: " << endl;
79
+ cout << " Press P to Delete Pants: " << endl;
80
+ cout << " Press J to Delete Jackets: " << endl;
81
+ cout << " Press R to return to Cutomer menu:" << endl;
82
+ cout << " Enter Options : " ;
83
+ }
84
+
85
+ void add_items () {
86
+ cout << " \n\n ********************* Add Items ********************************* " << endl << endl;
87
+ cout << " Press S to Add Shirts: " << endl;
88
+ cout << " Press P to Add Pants: " << endl;
89
+ cout << " Press J to Add Jackets: " << endl;
90
+ cout << " Press R to return to Owner menu:" << endl;
91
+ cout << " Enter Options : " ;
92
+ }
93
+
94
+ };
95
+
96
+
97
+ int main ()
98
+ {
99
+ shoping obj;
100
+ file f;
101
+ string u_input;
102
+ int value;
103
+ int t_shirt = 50 , t_pents = 50 , t_jackets = 50 ;
104
+ int shirt = 0 , pents = 0 , jackets = 0 ;
105
+ int t_bill = 0 ;
106
+
107
+
108
+
109
+ movetoTop:
110
+ obj.main_menu ();
111
+ cin >> u_input;
112
+
113
+ if (u_input == " 1" )
114
+ {
115
+ f.getdata ();
116
+ movetoCM:
117
+ obj.cutomer_menu ();
118
+ cin >> u_input;
119
+
120
+
121
+ if (u_input == " B" || u_input == " b" )
122
+ {
123
+ movetoItems:
124
+ obj.buy_items ();
125
+ cin >> u_input;
126
+ // Portiobn for buying shirts
127
+ if (u_input == " S" || u_input == " s" ) {
128
+ cout << " How many shirts you want to purchase = " ;
129
+ cin >> value;
130
+ shirt = shirt + value;
131
+ t_shirt = t_shirt - shirt;
132
+ goto movetoItems;
133
+ }
134
+ // Portiobn for buying pents
135
+ else if (u_input == " P" || u_input == " p" ) {
136
+ cout << " How many pants you want to purchase = " ;
137
+ cin >> value;
138
+ pents = pents + value;
139
+ t_pents = t_pents - pents;
140
+ goto movetoItems;
141
+ }
142
+ // Portiobn for buying Jackets
143
+ else if (u_input == " J" || u_input == " j" ) {
144
+ cout << " How many jackets you want to purchase = " ;
145
+ cin >> value;
146
+ jackets = jackets + value;
147
+ t_jackets = t_jackets - jackets;
148
+ goto movetoItems;
149
+ }
150
+ else if (u_input == " R" || u_input == " r" ) {
151
+ goto movetoCM;
152
+ }
153
+ else {
154
+ cout << " You Enter Invalid Option\n\n\n " ;
155
+ goto movetoItems;
156
+ }
157
+ }
158
+
159
+
160
+ // Portion for delete items
161
+ else if (u_input == " D" || u_input == " d" ) {
162
+ moveto_d_Items:
163
+ obj.delete_items ();
164
+ cin >> u_input;
165
+ // Portiobn for delete shirts
166
+ if (u_input == " S" || u_input == " s" ) {
167
+ cout << " How many shirts you want to delete = " ;
168
+ cin >> value;
169
+ if (shirt != 0 && (shirt - value) >= 0 )
170
+ {
171
+ shirt = shirt - value;
172
+ cout << " Done " ;
173
+ }
174
+ else
175
+ cout << " You Enter Invalid Option\n\n\n " ;
176
+ goto movetoItems;
177
+ }
178
+ // Portiobn for delete pents
179
+ else if (u_input == " P" || u_input == " p" ) {
180
+ cout << " How many pents you want to delete = " ;
181
+ cin >> value;
182
+ if (pents != 0 && (pents - value) >= 0 )
183
+ {
184
+ pents = pents - value;
185
+ cout << " Done " ;
186
+ }
187
+ else
188
+ cout << " You Enter Invalid Option\n\n\n " ;
189
+ goto movetoItems;
190
+ }
191
+ // Portiobn for delete Jackets
192
+ else if (u_input == " J" || u_input == " j" ) {
193
+ cout << " How many jackets you want to delete = " ;
194
+ cin >> value;
195
+ if (jackets != 0 && (jackets - value) >= 0 )
196
+ {
197
+ jackets = jackets - value;
198
+ cout << " Done " ;
199
+ }
200
+ else
201
+ cout << " You Enter Invalid Option\n\n\n " ;
202
+ goto movetoItems;
203
+ }
204
+ else if (u_input == " R" || u_input == " r" ) {
205
+ goto movetoCM;
206
+ }
207
+ else {
208
+ cout << " You Enter Invalid Option\n\n\n " ;
209
+ goto moveto_d_Items;
210
+ }
211
+ }
212
+
213
+ // view portion
214
+ else if (u_input == " V" || u_input == " v" ) {
215
+ cout << " \n\n\n Total shirts = " << shirt << endl;
216
+ cout << " Total pants = " << pents << endl;
217
+ cout << " Total jackets = " << jackets << endl;
218
+ goto movetoCM;
219
+ }
220
+
221
+
222
+ // billing portion
223
+ else if (u_input == " M" || u_input == " m" ) {
224
+
225
+ // file handling for billing
226
+ ofstream billing (" bill.txt" );
227
+ billing << " Your Total Bill = " << t_bill;
228
+ billing.close ();
229
+
230
+ t_bill = (shirt * 100 ) + (pents * 100 ) + (jackets * 100 );
231
+ cout << " \n\n\n Your Total Bill = " << t_bill << endl << endl;
232
+ cout << " ***** Thanks For Purchasing ******* " << endl << endl;
233
+ cout << " ***** ALLAH HAFIZ *********" << endl << endl;
234
+
235
+ goto movetoTop;
236
+ }
237
+ else if (u_input == " R" || u_input == " r" ) {
238
+ goto movetoTop;
239
+ }
240
+ else {
241
+ cout << " You Enter Invalid Option\n\n\n " ;
242
+ goto movetoCM;
243
+ }
244
+ }
245
+
246
+ else if (u_input == " 2" ) {
247
+ moveto_owner:
248
+ obj.owner_menu ();
249
+ cin >> u_input;
250
+
251
+ if (u_input == " A" || u_input == " a" ) {
252
+ moveto_additems:
253
+ obj.add_items ();
254
+ cin >> u_input;
255
+
256
+ // Portiobn for adding shirts
257
+ if (u_input == " S" || u_input == " s" ) {
258
+ cout << " How many shirts you want to Add = " ;
259
+ cin >> value;
260
+ t_shirt = t_shirt + value;
261
+ goto moveto_additems;
262
+ }
263
+ // Portiobn for adding pents
264
+ else if (u_input == " P" || u_input == " p" ) {
265
+ cout << " How many pants you want to Add = " ;
266
+ cin >> value;
267
+ t_pents = t_pents + value;
268
+ goto moveto_additems;
269
+ }
270
+ // Portiobn for adding Jackets
271
+ else if (u_input == " J" || u_input == " j" ) {
272
+ cout << " How many Jackets you want to Add = " ;
273
+ cin >> value;
274
+ t_jackets = t_jackets + value;
275
+ goto moveto_additems;
276
+ }
277
+ else if (u_input == " R" || u_input == " r" ) {
278
+ goto moveto_owner;
279
+ }
280
+ else {
281
+ cout << " You Enter Invalid Option\n\n\n " ;
282
+ goto moveto_additems;
283
+ }
284
+
285
+ }
286
+
287
+ if (u_input == " D" || u_input == " d" ) {
288
+ moveto_del:
289
+ obj.delete_items ();
290
+ cin >> u_input;
291
+
292
+ // Portiobn for deleting shirts
293
+ if (u_input == " S" || u_input == " s" ) {
294
+ cout << " How many shirts you want to delete = " ;
295
+ cin >> value;
296
+ t_shirt = t_shirt - value;
297
+ goto moveto_del;
298
+ }
299
+ // Portiobn for deleting pents
300
+ else if (u_input == " P" || u_input == " p" ) {
301
+ cout << " How many pants you want to delete = " ;
302
+ cin >> value;
303
+ t_pents = t_pents - value;
304
+ goto moveto_del;
305
+ }
306
+ // Portiobn for deleting Jackets
307
+ else if (u_input == " J" || u_input == " j" ) {
308
+ cout << " How many jackets you want to delete = " ;
309
+ cin >> value;
310
+ t_jackets = t_jackets - value;
311
+ goto moveto_del;
312
+ }
313
+ else if (u_input == " R" || u_input == " r" ) {
314
+ goto moveto_owner;
315
+ }
316
+ else {
317
+ cout << " You Enter Invalid Option\n\n\n " ;
318
+ goto moveto_del;
319
+ }
320
+
321
+ }
322
+ else if (u_input == " V" || u_input == " v" ) {
323
+ cout << " \n\n Total Shirts in store = " << t_shirt << endl;
324
+ cout << " Total Pants in store = " << t_pents << endl;
325
+ cout << " Total Jackets in store = " << t_jackets << endl << endl;
326
+ goto moveto_owner;
327
+ }
328
+ else if (u_input == " S" || u_input == " s" ) {
329
+ // View sales in file using filehandling
330
+ ofstream sales (" sales.txt" );
331
+ sales << " Total Shirts sale today = " << shirt << endl;
332
+ sales << " Total Pants sale today = " << pents << endl;
333
+ sales << " Total Jackets sale today = " << jackets << endl;
334
+ sales << " Total Sales today = " << t_bill << endl << endl;
335
+ sales.close ();
336
+
337
+ cout << " \n\n Total Shirts sale today = " << shirt << endl;
338
+ cout << " Total Pants sale today = " << pents << endl;
339
+ cout << " Total Jackets sale today = " << jackets << endl;
340
+ cout << " Total Sales today = " << t_bill << endl << endl << endl;
341
+ goto moveto_owner;
342
+ }
343
+ else if (u_input == " R" || u_input == " r" ) {
344
+ goto movetoTop;
345
+ }
346
+ else {
347
+ goto moveto_owner;
348
+ }
349
+ }
350
+ else if (u_input == " p" || u_input == " P" )
351
+ {
352
+ f.getdata ();
353
+ goto moveto_owner;
354
+ }
355
+ else if (u_input == " 3" ) {
356
+ cout << " \n\n *************** Thanks For your Visit **************** " << endl;
357
+ cout << " \n ****************** ALLAH HAFIZ ******************" << endl;
358
+ return 0 ;
359
+ }
360
+ else {
361
+ cout << " You Enter Invalid Option\n\n\n " ;
362
+ goto movetoTop;
363
+ }
364
+
365
+
366
+ return 0 ;
367
+ }
0 commit comments