-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
512 lines (458 loc) · 21.7 KB
/
Copy pathmain.cpp
File metadata and controls
512 lines (458 loc) · 21.7 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
/*
===============================================================================
SMART DATA CONVERTER v2.0
===============================================================================
* Program Name: Smart Data Converter
* Description: A professional utility for converting data units and number
* systems. Supports bidirectional conversion between various
* storage units (Byte to Yottabyte) and number base conversion
* (Binary to Decimal and vice versa).
*
* Features: - Enhanced professional UI with styled menu system
* - Data unit conversion (Byte, KB, MB, GB, TB, PB, EB, ZB, YB)
* - Number system conversion (Binary ↔ Decimal)
* - Interactive console-based user interface
* - Input validation and error handling
* - Bidirectional conversion support
*
* Author: Amr Saadawy
* Version: 2.0
* Date: 2025
* License: Open Source
*
* GitHub: https://github.com/Amr4924
* TikTok: https://www.tiktok.com/@3mr675
* LinkedIn: https://www.linkedin.com/in/amr-sa3dwy-53a51a343/
===============================================================================
*/
#include "convert.h" // Custom conversion functions header
#include <iostream> // Input/output stream operations
#include <string> // String manipulation
#include <vector> // Dynamic array container
#include <cmath> // Mathematical functions
#include <cstdlib> // System functions (cls, links)
using namespace std;
/*
===============================================================================
MAIN FUNCTION
===============================================================================
* Purpose: Entry point of the Smart Data Converter application
* Description: Handles the main program loop, user interface navigation,
* and coordinates all conversion operations
* Returns: int - Exit status (0 for successful execution)
===============================================================================
*/
int main()
{
char again; // Variable to control program loop continuation
// Main program loop - continues until user chooses to exit
do
{
// Display main menu options
int pick; // User's main menu selection
welcome(); // Display welcome message and main menu
cin >> pick; // Get user's choice
system("cls"); // Clear screen for better user experience
// ═══════════════════════════════════════════════════════════════════
// NUMBER SYSTEM CONVERSION SECTION
// ═══════════════════════════════════════════════════════════════════
if (pick == 1)
{
// Sub-menu for number system conversions
int pickList; // User's conversion type selection
vector<string> lisconvert =
{
"[1] Convert from decimal to binary",
"[2] Convert from binary to decimal"
};
list(lisconvert); // Display number conversion options
cout << "Choose from the following list" << endl;
cout << ":";
cin >> pickList; // Get conversion type choice
// Handle decimal to binary conversion
if (pickList == 1)
{
cout << "===============================================" << endl;
cout << "== You chose Convert from decimal to binary. ==" << endl;
cout << "===============================================" << endl;
cout << endl;
int Decimal; // Input decimal number
cout << "Enter a decimal number" << endl;
cout << ":";
cin >> Decimal;
DecimalToBinary(Decimal); // Perform conversion and display result
}
// Handle binary to decimal conversion
else if (pickList == 2)
{
cout << "===============================================" << endl;
cout << "== You chose Convert from binary to decimal. ==" << endl;
cout << "===============================================" << endl;
cout << endl;
string binary; // Input binary number as string
cout << "Enter a binary number" << endl;
cout << ":";
cin >> binary;
// Display conversion result
cout << "The number (" << binary << ") after conversion to decimal : " << BinaryToDecimal(binary);
}
// Handle invalid number conversion selection
else
{
cout << "*********************************" << endl;
cout << "** Please select from the list **" << endl;
cout << "*********************************" << endl;
continue; // Return to main menu
}
}
// ═══════════════════════════════════════════════════════════════════
// DATA UNIT CONVERSION SECTION
// ═══════════════════════════════════════════════════════════════════
else if (pick == 2)
{
// Sub-menu for unit conversion direction
int pickConvertUnits; // Direction of conversion selection
vector<string> convertUnits =
{
"| >>[1] Converting from larger units to smaller units |",
"| >>[2] Converting from smaller units to larger units |"
};
Menu(convertUnits); // Display conversion direction options
cin >> pickConvertUnits; // Get direction choice
system("cls"); // Clear screen for next menu
// ───────────────────────────────────────────────────────────────
// LARGER TO SMALLER UNITS CONVERSION
// ───────────────────────────────────────────────────────────────
if (pickConvertUnits == 1)
{
int unit; // Source unit selection
cout << "==============================================================" << endl;
cout << "== You chose Converting from larger units to smaller units. ==" << endl;
cout << "==============================================================" << endl;
cout << endl;
// Display available larger units for conversion
vector<string> pickConvert =
{
"| >>[1] Yottabyte |",
"| >>[2] Zettabyte |",
"| >>[3] Exabyte |",
"| >>[4] Petabyte |",
"| >>[5] Terabyte |",
"| >>[6] Gigabyte |",
"| >>[7] Megabyte |",
"| >>[8] Kilobyte |"
};
MenuUnits(pickConvert); // Display unit options
cin >> unit; // Get source unit selection
double value; // Variable for user input value
system("cls"); // Clear screen before conversion menu
// Handle Yottabyte conversions
if (unit == 1)
{
int start_1; // Target unit for Yottabyte conversion
vector<string> ConvertYottabyte =
{
"| >>[1] Yottabyte -----> Zettabyte |",
"| >>[2] Yottabyte -----> Exabyte |",
"| >>[3] Yottabyte -----> Petabyte |",
"| >>[4] Yottabyte -----> Terabyte |",
"| >>[5] Yottabyte -----> Gigabyte |",
"| >>[6] Yottabyte -----> Megabyte |",
"| >>[7] Yottabyte -----> Kilobyte |"
};
MenuConvert(ConvertYottabyte); // Display Yottabyte conversion options
cin >> start_1; // Get target unit
Yottabytes(start_1); // Perform Yottabyte conversion
}
// Handle Zettabyte conversions
else if (unit == 2)
{
int start_2; // Target unit for Zettabyte conversion
vector<string> ConvertZettabyte =
{
"| >>[1] Zettabyte -----> Exabyte |",
"| >>[2] Zettabyte -----> Petabyte |",
"| >>[3] Zettabyte -----> Terabyte |",
"| >>[4] Zettabyte -----> Gigabyte |",
"| >>[5] Zettabyte -----> Megabyte |",
"| >>[6] Zettabyte -----> Kilobyte |"
};
MenuConvert(ConvertZettabyte); // Display Zettabyte conversion options
cin >> start_2; // Get target unit
Zettabyte(start_2); // Perform Zettabyte conversion
}
// Handle Exabyte conversions
else if (unit == 3)
{
int start_3; // Target unit for Exabyte conversion
vector<string> ConvertExabyte =
{
"| >>[1] Exabyte -----> Petabyte |",
"| >>[2] Exabyte -----> Terabyte |",
"| >>[3] Exabyte -----> Gigabyte |",
"| >>[4] Exabyte -----> Megabyte |",
"| >>[5] Exabyte -----> Kilobyte |"
};
MenuConvert(ConvertExabyte); // Display Exabyte conversion options
cin >> start_3; // Get target unit
Exabyte(start_3); // Perform Exabyte conversion
}
// Handle Petabyte conversions
else if (unit == 4)
{
int start_4; // Target unit for Petabyte conversion
vector<string> ConvertPetabyte =
{
"| >>[1] Petabyte -----> Terabyte |",
"| >>[2] Petabyte -----> Gigabyte |",
"| >>[3] Petabyte -----> Megabyte |",
"| >>[4] Petabyte -----> Kilobyte |"
};
MenuConvert(ConvertPetabyte); // Display Petabyte conversion options
cin >> start_4; // Get target unit
Petabyte(start_4); // Perform Petabyte conversion
}
// Handle Terabyte conversions
else if (unit == 5)
{
int start_5; // Target unit for Terabyte conversion
vector<string> ConvertTerabyte =
{
"| >>[1] Terabyte -----> Gigabyte |",
"| >>[2] Terabyte -----> Megabyte |",
"| >>[3] Terabyte -----> Kilobyte |"
};
MenuConvert(ConvertTerabyte); // Display Terabyte conversion options
cin >> start_5; // Get target unit
Terabyte(start_5); // Perform Terabyte conversion
}
// Handle Gigabyte conversions
else if (unit == 6)
{
int start_6; // Target unit for Gigabyte conversion
vector<string> ConvertGigabyte =
{
"| >>[1] Gigabyte -----> Megabyte |",
"| >>[2] Gigabyte -----> Kilobyte |"
};
MenuConvert(ConvertGigabyte); // Display Gigabyte conversion options
cin >> start_6; // Get target unit
Gigabyte(start_6); // Perform Gigabyte conversion
}
// Handle Megabyte conversions
else if (unit == 7)
{
int start_7; // Target unit for Megabyte conversion
vector<string> ConvertMegabyte =
{
"| >>[1] Megabyte -----> Kilobyte |"
};
MenuConvert(ConvertMegabyte); // Display Megabyte conversion options
cin >> start_7; // Get target unit
Megabyte(start_7); // Perform Megabyte conversion
}
// Handle Kilobyte conversions
else if (unit == 8)
{
int start_8; // Target unit for Kilobyte conversion
vector<string> ConvertKilobyte =
{
"| >>[1] Kilobyte -----> byte |"
};
MenuConvert(ConvertKilobyte); // Display Kilobyte conversion options
cin >> start_8; // Get target unit
Kilobyte(start_8); // Perform Kilobyte conversion
}
// Handle invalid unit selection
else
{
cout << "*********************************" << endl;
cout << "** Please select from the list **" << endl;
cout << "*********************************" << endl;
}
}
// ───────────────────────────────────────────────────────────────
// SMALLER TO LARGER UNITS CONVERSION
// ───────────────────────────────────────────────────────────────
else if (pickConvertUnits == 2)
{
int pickSmall; // Source unit selection for smaller units
cout << "==============================================================" << endl;
cout << "== You chose Converting from smaller units to larger units. ==" << endl;
cout << "==============================================================" << endl;
cout << endl;
// Display available smaller units for conversion
vector<string> smallUnits =
{
"| >>[1] Kilobyte |",
"| >>[2] Megabyte |",
"| >>[3] Gigabyte |",
"| >>[4] Terabyte |",
"| >>[5] Petabyte |",
"| >>[6] Exabyte |",
"| >>[7] Zettabyte |",
};
MenuUnits(smallUnits); // Display smaller unit options
cin >> pickSmall; // Get source unit selection
system("cls"); // Clear screen for conversion menu
// Handle Kilobyte to larger units conversion
if (pickSmall == 1)
{
int kb; // Target unit for Kilobyte conversion
vector<string> cKilobyte =
{
"| >>[1] Kilobyte -----> Megabyte |",
"| >>[2] Kilobyte -----> Gigabyte |",
"| >>[3] Kilobyte -----> Terabyte |",
"| >>[4] Kilobyte -----> Petabyte |",
"| >>[5] Kilobyte -----> Exabyte |",
"| >>[6] Kilobyte -----> Zettabyte |",
"| >>[7] Kilobyte -----> Yottabyte |"
};
MenuConvert(cKilobyte); // Display Kilobyte conversion options
cin >> kb; // Get target unit
kilobyte(kb); // Perform Kilobyte conversion
}
// Handle Megabyte to larger units conversion
else if (pickSmall == 2)
{
int mb; // Target unit for Megabyte conversion
vector<string> cMegabyte =
{
"| >>[1] Megabyte -----> Gigabyte |",
"| >>[2] Megabyte -----> Terabyte |",
"| >>[3] Megabyte -----> Petabyte |",
"| >>[4] Megabyte -----> Exabyte |",
"| >>[5] Megabyte -----> Zettabyte |",
"| >>[6] Megabyte -----> Yottabyte |"
};
MenuConvert(cMegabyte); // Display Megabyte conversion options
cin >> mb; // Get target unit
megabyte(mb); // Perform Megabyte conversion
}
// Handle Gigabyte to larger units conversion
else if (pickSmall == 3)
{
int gb; // Target unit for Gigabyte conversion
vector<string> cGigabyte =
{
"| >>[1] Gigabyte -----> Terabyte |",
"| >>[2] Gigabyte -----> Petabyte |",
"| >>[3] Gigabyte -----> Exabyte |",
"| >>[4] Gigabyte -----> Zettabyte |",
"| >>[5] Gigabyte -----> Yottabyte |"
};
MenuConvert(cGigabyte); // Display Gigabyte conversion options
cin >> gb; // Get target unit
gigabyte(gb); // Perform Gigabyte conversion
}
// Handle Terabyte to larger units conversion
else if (pickSmall == 4)
{
int tb; // Target unit for Terabyte conversion
vector<string> cTerabyte =
{
"| >>[1] Terabyte -----> Petabyte |",
"| >>[2] Terabyte -----> Exabyte |",
"| >>[3] Terabyte -----> Zettabyte |",
"| >>[4] Terabyte -----> Yottabyte |"
};
MenuConvert(cTerabyte); // Display Terabyte conversion options
cin >> tb; // Get target unit
terabyte(tb); // Perform Terabyte conversion
}
// Handle Petabyte to larger units conversion
else if (pickSmall == 5)
{
int pb; // Target unit for Petabyte conversion
vector<string> cPetabyte =
{
"| >>[1] Petabyte -----> Exabyte |",
"| >>[2] Petabyte -----> Zettabyte |",
"| >>[3] Petabyte -----> Yottabyte |"
};
MenuConvert(cPetabyte); // Display Petabyte conversion options
cin >> pb; // Get target unit
petabyte(pb); // Perform Petabyte conversion
}
// Handle Exabyte to larger units conversion
else if (pickSmall == 6)
{
int eb; // Target unit for Exabyte conversion
vector<string> cExabyte =
{
"| >>[1] Exabyte -----> Zettabyte |",
"| >>[2] Exabyte -----> Yottabyte |"
};
MenuConvert(cExabyte); // Display Exabyte conversion options
cin >> eb; // Get target unit
exabyte(eb); // Perform Exabyte conversion
}
// Handle Zettabyte to Yottabyte conversion
else if (pickSmall == 7)
{
int zb; // Target unit for Zettabyte conversion
vector<string> cZettabyte =
{
"| >>[1] Zettabyte -----> Yottabyte |"
};
MenuConvert(cZettabyte); // Display Zettabyte conversion options
cin >> zb; // Get target unit
zettabyte(zb); // Perform Zettabyte conversion
}
// Handle invalid smaller unit selection
else
{
cout << "*********************************" << endl;
cout << "** Please select from the list **" << endl;
cout << "*********************************" << endl;
}
}
// Handle invalid conversion direction selection
else
{
cout << "*********************************" << endl;
cout << "** Please select from the list **" << endl;
cout << "*********************************" << endl;
}
}
// Handle invalid main menu selection
else
{
cout << "*********************************" << endl;
cout << "** Please select from the list **" << endl;
cout << "*********************************" << endl;
}
// ═══════════════════════════════════════════════════════════════════
// PROGRAM CONTINUATION
// ═══════════════════════════════════════════════════════════════════
cout << "Do you want to do another operation? (y/n)" << endl;
cout << ":";
cin >> again; // Get user's choice to continue or exit
system("cls"); // Clear screen for next iteration
} while (again == 'y' || again == 'Y'); // Continue loop if user wants more operations
// ═══════════════════════════════════════════════════════════════════
// FAREWELL MESSAGE
// ═══════════════════════════════════════════════════════════════════
cout << "\n";
cout << "╔════════════════════════════════════════════════════════════════╗" << endl;
cout << "║ ║" << endl;
cout << "║ THANK YOU FOR USING ║" << endl;
cout << "║ SMART DATA CONVERTER v1.0 ║" << endl;
cout << "║ ║" << endl;
cout << "║ We hope our tool helped you with your conversions! ║" << endl;
cout << "║ ║" << endl;
cout << "║ 🔗 Connect with the developer: ║" << endl;
cout << "║ • GitHub: github.com/Amr4924 ║" << endl;
cout << "║ • TikTok: @3mr675 ║" << endl;
cout << "║ • LinkedIn: amr-sa3dwy-53a51a343 ║" << endl;
cout << "║ ║" << endl;
cout << "║ Your feedback is greatly appreciated! ║" << endl;
cout << "║ ║" << endl;
cout << "║ See you next time! 👋 ║" << endl;
cout << "║ ║" << endl;
cout << "╚════════════════════════════════════════════════════════════════╝" << endl;
cout << "\n";
ads(); // Open developer's social media links
return 0; // Successful program termination
}