-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cpp
327 lines (306 loc) · 9.22 KB
/
Program.cpp
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
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <stack>
#include <iomanip>
#include <vector>
using namespace std;
struct user {
string nama, id, alamat;
};
vector<user> e;
int total = 0;
typedef struct {
int top;
int data[20];
} stacktype;
stacktype A;
void push(int d) {
if (A.top != 19) {
A.top++;
A.data[A.top] = d;
cout << "Judul " << d << " Ditambahkan\n";
} else {
cout << "\nStack Penuh\n";
}
}
void pop() {
if (A.top != -1) {
cout << "POP Data : " << A.data[A.top] << "\n";
A.top--;
} else {
cout << "Stack Kosong\n";
}
}
void print() {
if (A.top != -1) {
for (int i = A.top; i >= 0; i--)
cout << A.data[i] << "\n";
} else {
cout << "Stack Kosong\n";
}
}
int isEmpty() {
if (A.top == -1) {
return 1;
} else {
return 0;
}
}
int isFull() {
if (A.top == 19) {
return 1;
} else {
return 0;
}
}
void adddata() {
int choise;
cout << "Jumlah Data yang Akan Anda Add : ";
cin >> choise;
for (int i = 0; i < choise; i++) {
cout << "=================================\n";
cout << "Data Ke-" << total + 1 << "\n";
cout << "=================================\n";
user newUser;
cout << "Nama : ";
cin >> newUser.nama;
cout << "ID : ";
cin >> newUser.id;
cout << "Alamat : ";
cin >> newUser.alamat;
e.push_back(newUser);
total++;
}
}
void update() {
if (total != 0) {
string id;
cout << "Pilih Data yang akan di Update : ";
cin >> id;
for (int i = 0; i < total; i++) {
if (id == e[i].id) {
cout << "Data Ke- : " << i + 1 << "\n";
cout << "Nama : " << e[i].nama << "\n";
cout << "ID : " << e[i].id << "\n";
cin >> e[i].nama;
cout << "ID : ";
cin >> e[i].id;
break;
}
if (i == total - 1) {
cout << "Data Kosong\n";
}
}
} else {
cout << "Data Kosong !!\n";
}
}
void remove() {
if (total != 0) {
char user;
cout << "\n1. Remove Full\n";
cout << "\n2. Remove Specific\n";
cin >> user;
if (user == '1') {
total = 0;
cout << "=================================\n";
cout << "Data Sudah Terhapus!!\n";
} else if (user == '2') {
string id;
cout << "Enter untuk remove\n";
cin >> id;
for (int i = 0; i < total; i++) {
if (id == e[i].id) {
for (int j = i; j < total; j++) {
e[j].nama = e[j + 1].nama;
e[j].id = e[j + 1].id;
e[j].alamat = e[j + 1].alamat;
}
total--;
break;
}
if (i == total - 1) {
cout << "Tidak ada Data !!\n";
}
}
}
} else {
cout << "Data Kosong\n";
}
}
vector<string> names;
vector<int> prices;
vector<int> quantities;
int totalHarga = 0;
void AntrianMasuk(int no) {
names.push_back(to_string(no));
totalHarga += no;
}
void AntrianKeluar() {
if (names.empty()) {
cout << "Antrian Kosong!!";
getch();
} else {
names.erase(names.begin());
totalHarga -= 0;
}
}
void clear() {
names.clear();
totalHarga = 0;
}
void view() {
if (names.empty()) {
cout << "Daftar Kosong!!";
} else {
system("cls");
cout << "=================================\n";
cout << " ANTRIAN PERPUSTAKAAN \n";
cout << "=================================\n";
cout << "| NO | NAMA | HARGA | JUMLAH |\n";
for (int i = 0; i < names.size(); i++) {
cout << "|" << setw(2) << i + 1 << "|"
<< setw(6) << names[i] << "|"
<< setw(5) << prices[i] << "|"
<< setw(6) << quantities[i] << "|\n";
}
cout << "=====================================\n";
cout << "TOTAL HARGA : Rp." << totalHarga << "\n";
cout << "=====================================\n";
}
}
int main() {
int menuutama, menustack, menuuser, judulbuku, jawab, no, add, choose;
char jawabuser, jawabstack, jawabqueue;
cout << "========== SILAHKAN LOGIN ==========\n";
cout << "\nUsername : ";
string username, password;
cin >> username;
cout << "\nPassword : ";
cin >> password;
cout << "\nMohon Menunggu";
for (int i = 0; i < 20; i++) {
cout << ".";
}
cout << "\nID yang dimasukkan Benar" << endl;
system("cls");
cout << "====================================";
cout << "\n MENU UTAMA ";
cout << "\n====================================";
cout << "\n1. USER MANAGER";
cout << "\n2. PROGRAM STACK";
cout << "\n3. PROGRAM QUEUE";
cout << "\n4. EXIT";
cout << "\n====================================";
cout << "\nPilih Menu : ";
cin >> menuutama;
if (menuutama == 1) {
do {
system("cls");
cout << " MENU USER MANAGER ";
cout << "\n====================================";
cout << "\n1. Add Data";
cout << "\n2. Update Data";
cout << "\n3. Delete Data";
cout << "\n4. Exit";
cout << "\n====================================";
cout << "\nPilih Menu : ";
cin >> menuuser;
if (menuuser == 1) {
cout << "\nMasukkan Data : ";
cin >> add;
adddata();
} else if (menuuser == 2) {
update();
} else if (menuuser == 3) {
remove();
} else {
cout << "Masukkan Salah" << endl;
}
cout << "\nApakah Ingin Kembali Ke Menu User Manager? [Y/T] ";
cin >> jawabuser;
} while (jawabuser == 'y' || jawabuser == 'Y');
cin >> jawabuser;
getch();
} else if (menuutama == 2) {
do {
system("cls");
cout << " MENU STACK ";
cout << "\n====================================";
cout << "\n1. PUSH";
cout << "\n2. POP";
cout << "\n3. PRINT";
cout << "\n====================================";
cout << "\nPilih Menu : ";
cin >> menustack;
if (menustack == 1) {
cout << "\nMasukkan Judul : ";
cin >> judulbuku;
push(judulbuku);
} else if (menustack == 2) {
pop();
} else if (menustack == 3) {
cout << "\nStack Adalah : ";
print();
} else {
cout << "\nPilih Menu dari 1-3";
}
cout << "\nApakah Ingin Kembali Ke Menu Stack ? [Y/T] ";
cin >> jawabstack;
} while (jawabstack == 'Y' || jawabstack == 'y');
getche();
} else if (menuutama == 3) {
do {
system("cls");
cout << "=================================\n";
cout << " ANTRIAN PERPUSTAKAAN \n";
cout << "=================================\n";
view();
cout << "\n1. Tambah Buku \n";
cout << "\n2. Keluarkan Buku \n";
cout << "\n3. Daftar \n";
cout << "\n4. Keluar \n";
cout << "=================================\n";
cout << "\nMasukkan Pilihan Anda : ";
cin >> choose;
if (choose == 1) {
string judul;
int harga, jumlah;
cout << "Judul buku yang akan di beli :";
cin >> judul;
cout << "Harga buku yang di beli : ";
cin >> harga;
cout << "Jumlah yang di beli :";
cin >> jumlah;
names.push_back(judul);
prices.push_back(harga);
quantities.push_back(jumlah);
totalHarga += harga * jumlah;
} else if (choose == 2) {
if (names.empty()) {
cout << "tidak ada buku yang dapat di keluarkan !" << endl;
continue;
}
cout << "Buku " << names.front() << " Seharga Rp." << prices.front() << " berjumlah " << quantities.front() << " telah dikeluarkan" << endl;
names.erase(names.begin());
prices.erase(prices.begin());
quantities.erase(quantities.begin());
} else if (choose == 3) {
view();
} else if (choose == 4) {
cout << "Exit";
break;
} else {
cout << "Pilih Menu Dari 1-4";
}
cout << "\nKembali Ke Menu ? [Y/T] ";
cin >> jawabqueue;
} while (jawabqueue == 'y' || jawabqueue == 'Y');
} else if (menuutama == 4) {
exit(0);
} else {
cout << "Masukkan Salah";
}
return 0;
}