-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
76 lines (58 loc) · 1.89 KB
/
main.cc
File metadata and controls
76 lines (58 loc) · 1.89 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
#include "filesystem.h"
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
/* ====================== NOTE =====================
Dear Recruiter,
Thank you for reading over this code, I have truly enjoyed
writing this challenge. Please read the documentation.pdf
for more information on how my program works and to see
a list of commands if you haven't already!
I look forward to talking in the future.
Thanks,
Kefan Cao
====================================================*/
int main(){
unsigned totalSize;
int blockSize;
totSize:
cout << "Please specify the total size of the disk in MB: ";
// In case the user inputs an invalid value.
if (!(cin >> totalSize)){
cin.clear();
cin.ignore();
cout << "Invalid size, please try again" << endl;
goto totSize;
}
// In case the user inputs an value greater than 1TB of storage.
if (totalSize > 1048576){
cout << "Total size of disk must be or under 1TB." << endl;
cout << "Please try again" << endl;
goto totSize;
}
totalSize *= 1024;
block:
cout << "Please specify the size of each block in KB: ";
// In case the user decides to enter an invalid value.
if (!(cin >> blockSize)){
cin.clear();
cin.ignore();
cout << "Invalid size, please try again" << endl;
goto block;
}
// In case the user decides to input a block size that does not divide into the total
// memory size.
if (totalSize % blockSize){
cout << "The block size requested does not divide evenly into the disk memory." << endl;
cout << "Some memory may be truncated if you continue." << endl;
cout << "Would you like to reconsider the block size? (y/n)" << endl;
char c;
cin >> c;
// A choice to allow the user to reconsider and enter a divisible block size.
if (c == 'y' || c == 'Y') goto block;
}
FileSystem manager{totalSize, blockSize};
// Actual file manager procedure.
manager.open();
}