-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskCompilation.cpp
More file actions
executable file
·290 lines (248 loc) · 14.3 KB
/
Copy pathtaskCompilation.cpp
File metadata and controls
executable file
·290 lines (248 loc) · 14.3 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
/*
File ini berguna sebagai API untuk tiap subprogram yang ada di tiap chapter sehingga memudahkan proses penjelajahan dalam melakukan
pengoperasian baik di dalam subprogram maupun antarmuka chapter.
*/
#include "Program Interface Files/programInterface.hpp"
#include "Custom Utility Files/customUtility.hpp"
#include "Stack Chapter Files/stackChapter.hpp"
#include "Queue Chapter Files/queueChapter.hpp"
#include "Linked List Chapter Files/linkedListChapter.hpp"
#include "Sort Chapter Files/sortChapter.hpp"
#include "Sort Chapter (Advanced) Files/advancedSortChapter.hpp"
#include "Hash Chapter Files/hashChapter.hpp"
/*--------------------------------------------------------------------------------------------------------------------------------------
PART 1: Objek "StackChapter" berperan sebagai derived class dari base "Program" dan menjalankan program khusus yang ada di Chapter
Tumpukan (Stack).
--------------------------------------------------------------------------------------------------------------------------------------*/
class StackChapter: public Program {
private:
const short chapterID {1};
std::string invalidIntInput;
std::map<const short, Program*> stackProgramDictionary { // Seluruh objek subProgram dari Chapter Tumpukan (Stack)
{1, new StackOneOne},
{2, new StackOneTwo},
{3, new StackOneThree},
{4, new StackOneFour}
};
public:
void start() override { // Menjalankan metode polymorphism dari kontrak virtual void start()
while (true) {
bool flag {subProgramSelection(&chapterID, &invalidIntInput, &stackProgramDictionary)}; // Akses ke fungsi PART 2 dari "programInterface.hpp"
if (flag) {break;}
}
}
~StackChapter() { // Desctructor untuk mencegah memory leaks
for (std::pair<const short, Program*>& pair : stackProgramDictionary) { // Menghapus seluruh objek subProgram dari dictionary
delete pair.second;
}
}
};
/*--------------------------------------------------------------------------------------------------------------------------------------
END OF SCOPE FOR PART 1.
--------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------------
PART 2: Objek "QueueChapter" berperan sebagai derived class dari base "Program" dan menjalankan program khusus yang ada di Chapter
Antrian (Queue).
--------------------------------------------------------------------------------------------------------------------------------------*/
class QueueChapter: public Program {
private:
const short chapterID {2};
std::string invalidIntInput;
std::map<const short, Program*> queueProgramDictionary { // Seluruh objek subProgram dari Chapter Antrian (Queue)
{1, new QueueTwoOne},
{2, new QueueTwoTwo},
{3, new QueueTwoThree},
{4, new QueueTwoFour}
};
public:
void start() override { // Menjalankan metode polymorphism dari kontrak virtual void start()
while (true) {
bool flag {subProgramSelection(&chapterID, &invalidIntInput, &queueProgramDictionary)}; // Akses ke fungsi PART 2 dari "programInterface.hpp"
if (flag) {break;}
}
}
~QueueChapter() { // Desctructor untuk mencegah memory leaks
for (std::pair<const short, Program*>& pair : queueProgramDictionary) { // Menghapus seluruh objek subProgram dari dictionary
delete pair.second;
}
}
};
/*--------------------------------------------------------------------------------------------------------------------------------------
END OF SCOPE FOR PART 2.
--------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------------
PART 3: Objek "LinkedListChapter" berperan sebagai derived class dari base "Program" dan menjalankan program khusus yang ada di
Chapter Senarai Berantai (Linked List).
--------------------------------------------------------------------------------------------------------------------------------------*/
class LinkedListChapter: public Program {
private:
const short chapterID {3};
std::string invalidIntInput;
std::map<const short, Program*> linkedListProgramDictionary { // Seluruh objek subProgram dari Chapter Senarai Berantai (Linked List)
{1, new linkedListThreeOne},
{2, new linkedListThreeTwo},
{3, new linkedListThreeThree},
{4, new linkedListThreeFour},
{5, new linkedListThreeFive},
{6, new linkedListThreeSix}
};
public:
void start() override { // Menjalankan metode polymorphism dari kontrak virtual void start()
while (true) {
bool flag {subProgramSelection(&chapterID, &invalidIntInput, &linkedListProgramDictionary)}; // Akses ke fungsi PART 2 dari "programInterface.hpp"
if (flag) {break;}
}
}
~LinkedListChapter() { // Desctructor untuk mencegah memory leaks
for (std::pair<const short, Program*>& pair : linkedListProgramDictionary) { // Menghapus seluruh objek subProgram dari dictionary
delete pair.second;
}
}
};
/*--------------------------------------------------------------------------------------------------------------------------------------
END OF SCOPE FOR PART 3.
--------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------------
PART 4: Objek "SortChapter" berperan sebagai derived class dari base "Program" dan menjalankan program khusus yang ada di
Chapter Pengurutan Data (Sort).
--------------------------------------------------------------------------------------------------------------------------------------*/
class SortChapter: public Program {
private:
const short chapterID {4};
std::string invalidIntInput;
std::map<const short, Program*> sortProgramDictionary { // Seluruh objek subProgram dari Chapter Pengurutan Data (Sort)
{1, new SortFourOne},
{2, new SortFourTwo},
{3, new SortFourThree},
{4, new SortFourFour}
};
public:
void start() override { // Menjalankan metode polymorphism dari kontrak virtual void start()
while (true) {
bool flag {subProgramSelection(&chapterID, &invalidIntInput, &sortProgramDictionary)}; // Akses ke fungsi PART 2 dari "programInterface.hpp"
if (flag) {break;}
}
}
~SortChapter() { // Desctructor untuk mencegah memory leaks
for (std::pair<const short, Program*>& pair : sortProgramDictionary) { // Menghapus seluruh objek subProgram dari dictionary
delete pair.second;
}
}
};
/*--------------------------------------------------------------------------------------------------------------------------------------
END OF SCOPE FOR PART 4.
--------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------------
PART 5: Objek "SortChapter(Advanced)" berperan sebagai derived class dari base "Program" dan menjalankan program khusus yang ada di
Chapter Pengurutan Data Tingkat Lanjut.
--------------------------------------------------------------------------------------------------------------------------------------*/
class SortChapterAdvanced: public Program {
private:
const short chapterID {5};
std::string invalidIntInput;
std::map<const short, Program*> sortProgramDictionary { // Seluruh objek subProgram dari Chapter Pengurutan Data Tingkat Lanjut
{1, new SortFiveOne},
{2, new SortFiveTwo},
{3, new SortFiveThree},
{4, new SortFiveFour}
};
public:
void start() override { // Menjalankan metode polymorphism dari kontrak virtual void start()
while (true) {
bool flag {subProgramSelection(&chapterID, &invalidIntInput, &sortProgramDictionary)}; // Akses ke fungsi PART 2 dari "programInterface.hpp"
if (flag) {break;}
}
}
~SortChapterAdvanced() { // Desctructor untuk mencegah memory leaks
for (std::pair<const short, Program*>& pair : sortProgramDictionary) { // Menghapus seluruh objek subProgram dari dictionary
delete pair.second;
}
}
};
/*--------------------------------------------------------------------------------------------------------------------------------------
END OF SCOPE FOR PART 5.
--------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------------
PART 6: Objek "SortChapter(Advanced)" berperan sebagai derived class dari base "Program" dan menjalankan program khusus yang ada di
Chapter Pengurutan Data Tingkat Lanjut.
--------------------------------------------------------------------------------------------------------------------------------------*/
class Hash: public Program {
private:
const short chapterID {6};
std::string invalidIntInput;
std::map<const short, Program*> sortProgramDictionary { // Seluruh objek subProgram dari Chapter Pengurutan Data Tingkat Lanjut
{1, new hashSixOne},
{2, new hashSixTwo},
{3, new hashSixThree},
{4, new hashSixFour}
};
public:
void start() override { // Menjalankan metode polymorphism dari kontrak virtual void start()
while (true) {
bool flag {subProgramSelection(&chapterID, &invalidIntInput, &sortProgramDictionary)}; // Akses ke fungsi PART 2 dari "programInterface.hpp"
if (flag) {break;}
}
}
~Hash() { // Desctructor untuk mencegah memory leaks
for (std::pair<const short, Program*>& pair : sortProgramDictionary) { // Menghapus seluruh objek subProgram dari dictionary
delete pair.second;
}
}
};
/*--------------------------------------------------------------------------------------------------------------------------------------
END OF SCOPE FOR PART 6.
--------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------------
PART 7: Fungsi "chapterSelection" menjadi gerbang untuk melihat seluruh subprogram yang ada di dalam tiap chapter.
--------------------------------------------------------------------------------------------------------------------------------------*/
void chapterSelection(short menuChosen) {
Program* chapter = nullptr; // Inisialisasi pointer objek kelas Program
if (menuChosen == 1) {
chapter = new StackChapter(); // Membuat objek kelas StackChapter
} else if (menuChosen == 2) {
chapter = new QueueChapter(); // Membuat objek kelas QueueChapter
} else if (menuChosen == 3) {
chapter = new LinkedListChapter(); // Membuat objek kelas LinkedListChapter
} else if (menuChosen == 4) {
chapter = new SortChapter(); // Membuat objek kelas SortChapter
} else if (menuChosen == 5) {
chapter = new SortChapterAdvanced(); // Membuat objek kelas SortChapterAdvanced
} else if (menuChosen == 6) {
chapter = new Hash(); // Membuat objek kelas Hash
}
chapter->start(); // Menjalankan metode polymorphism dari kontrak virtual void start()
delete chapter; // Mencegah memory leaks
}
/*--------------------------------------------------------------------------------------------------------------------------------------
END OF SCOPE FOR PART 7.
--------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------------
PART 8: Eksekusi "taskCompilation.cpp".
--------------------------------------------------------------------------------------------------------------------------------------*/
int main() {
std::string invalidIntInput;
while (true) {
std::cout << "\nProgram Dinamis Struktur Data dan Algoritma" // Standard output untuk pilihan menu
<< "\n 1. Tumpukan (Stack)"
<< "\n 2. Antrian (Queue)"
<< "\n 3. Senarai Berantai (Linked List)"
<< "\n 4. Urutan (Sort)"
<< "\n 5. Urutan Tingkat Lanjut (Advanced Sort)"
<< "\n 6. Hash"
<< "\n 7. Selesai\n\nSilahkan masukkan angka pilihan menu => ";
short menuChosen {short(inputIntValidator(&invalidIntInput))}; // Akses ke fungsi PART 2 dari "customUtility.hpp"
if (menuChosen >= 1 && menuChosen <= 6) { // Jika input di dalam jangkauan yang diminta
chapterSelection(menuChosen);
} else if (menuChosen == 7) { // Mengakhiri program
std::cout << "*** SELESAI ***";
break;
} else { // Jika input di luar jangkauan yang diminta
invalidMenuChosen(&menuChosen, &invalidIntInput); // Akses ke fungsi PART 4 dari "customUtility.hpp"
outputBuffer(); // Akses ke fungsi PART 3 dari "customUtility.hpp"
}
}
return 0;
}
/*--------------------------------------------------------------------------------------------------------------------------------------
END OF SCOPE FOR PART 8.
--------------------------------------------------------------------------------------------------------------------------------------*/