-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrarynew.h
344 lines (321 loc) · 11.5 KB
/
librarynew.h
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
#ifndef LIBRARYNEW_H
#define LIBRARYNEW_H
#include <ctime>
#include <iomanip>
#include <iostream>
using namespace std;
// Sistem Program Kasir di Cafeshop
struct WDF
{
string nama;
int harga;
int qty;
WDF *next;
WDF *prev;
};
struct CoffeeShop
{
private:
WDF *head;
WDF *tail;
public:
CoffeeShop()
{
head = NULL;
tail = NULL;
}
// fungsi untuk menampilkan menu di CoffeeShop
void displayMenu()
{
cout << endl << endl;
cout << "=====================================" << endl;
cout << " WDF Coffee Haven" << endl;
cout << " Gang Jeruk No. 5" << endl;
cout << " Telp. 1500-212" << endl;
cout << "=====================================" << endl;
cout << "Menu" "\t\t\t\t" << "Harga" << endl;
cout << "=====================================" << endl;
cout << "~~~~~~~~~~~~~ Kopi :) ~~~~~~~~~~~~~~~" << endl;
cout << "1. Espresso" << "\t\t\t" << "15000" << endl;
cout << "2. Cappucino" << "\t\t\t" << "20000" << endl;
cout << "3. Latte" << "\t\t\t" << "20000" << endl;
cout << "4. Mocha" << "\t\t\t" << "25000" << endl;
cout << "5. Americano" << "\t\t\t" << "15000" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl << endl;
cout << "~~~~~~~~~~~~~ Snack :) ~~~~~~~~~~~~~~" << endl;
cout << "1. Donut" << "\t\t\t" << "10000" << endl;
cout << "2. Brownies" << "\t\t\t" << "15000" << endl;
cout << "3. Cookies" << "\t\t\t" << "10000" << endl;
cout << "4. Pie" << "\t\t\t\t" << "20000" << endl;
cout << "5. Cake" << "\t\t\t\t" << "25000" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "=====================================" << endl << endl << endl;
}
// fungsi untuk menambahkan menu
void addMenu(string nama, int harga, int qty)
{
WDF *baru = new WDF;
baru->nama = nama;
baru->harga = harga;
baru->qty = qty;
baru->next = NULL;
baru->prev = NULL;
if (head == NULL)
{
head = baru;
tail = baru;
}
else
{
tail->next = baru;
baru->prev = tail;
tail = baru;
}
}
//fungsi untuk melihat daftar pesanan yang telah dipesan
void displayOrder()
{
cout << endl << endl;
cout << "---------- Daftar Pesanan ----------" << endl;
cout << "=====================================" << endl;
cout << "Menu" "\t\t" << "Qty" << "\t" << "Harga" << "\t" << "Total" << endl;
cout<< "-------------------------------------" << endl;
//tampilkan menu yang dipesan
WDF *curr = head;
while (curr != NULL)
{
cout << curr->nama << "\t\t" << curr->qty << "\t" << curr->harga << "\t" << curr->qty * curr->harga << endl;
curr = curr->next;
}
cout << "-------------------------------------" << endl << endl << endl;
}
//fungsi untuk mengedit pesanan berdasarkan nama
void editOrder(string nama, string namaBaru, int hargaBaru, int qtyBaru)
{
WDF* curr = head;
while (curr != NULL)
{
if (curr->nama == nama)
{
curr->nama = namaBaru;
curr->harga = hargaBaru;
curr->qty = qtyBaru;
return; // Menggunakan return untuk keluar dari fungsi setelah mengedit pesanan
}
curr = curr->next;
}
cout << "Pesanan tidak ditemukan." << endl; // Menambahkan pesan jika pesanan tidak ditemukan
}
// fungsi untuk menghapus menu
void deleteOrder(string nama)
{
WDF *curr = head;
while (curr != NULL)
{
if (curr->nama == nama)
{
if (curr == head)
{
head = curr->next;
head->prev = NULL;
delete curr;
break;
}
else if (curr == tail)
{
tail = curr->prev;
tail->next = NULL;
delete curr;
break;
}
else
{
curr->prev->next = curr->next;
curr->next->prev = curr->prev;
delete curr;
break;
}
}
curr = curr->next;
}
}
//fungsi untuk mencari pesanan berdasarkan nama
void searchOrder(string nama)
{
WDF *curr = head;
while (curr != NULL)
{
if (curr->nama == nama)
{
cout << endl << endl;
cout << "--------- Pesanan Ditemukan ---------" << endl;
cout << "Nama Pesanan" "\t\t\t" << curr->nama << endl;
cout << "Harga" "\t\t\t\t" << curr->harga << endl;
cout << "Qty" "\t\t\t\t" << curr->qty << endl;
cout << "Total" "\t\t\t\t" << curr->harga * curr->qty << endl;
cout << "-------------------------------------" << endl << endl << endl;
break;
}
curr = curr->next;
}
if (curr == NULL)
{
cout << "Pesanan tidak ditemukan." << endl;
}
}
//fungsi untuk mengurutkan pesanan berdasarkan harga total termurah menggunakan insertion sort
void sortOrder()
{
WDF *curr = head;
while (curr != NULL)
{
string nama = curr->nama;
int harga = curr->harga;
int qty = curr->qty;
WDF *temp = curr->prev;
while (temp != NULL && (temp->harga * temp->qty) > (harga * qty))
{
temp->next->nama = temp->nama;
temp->next->harga = temp->harga;
temp->next->qty = temp->qty;
temp = temp->prev;
}
if (temp == NULL)
{
head->nama = nama;
head->harga = harga;
head->qty = qty;
}
else
{
temp->next->nama = nama;
temp->next->harga = harga;
temp->next->qty = qty;
}
curr = curr->next;
}
}
/*-------------------------------- Tampilan untuk struk --------------------------------*/
// fungsi untuk kode struk random angka 4 digit
int kodestruk(int min, int max)
{
srand(time(NULL));
int kodestruk = rand() % (max - min + 1) + min;
return kodestruk;
}
// fungsi untuk nomor meja
void nomor_meja()
{
int no_meja;
cout << "No.Meja : ";
cin >> no_meja;
}
// fungsi untuk waktu saat ini
void waktu()
{
// Mendapatkan waktu saat ini
chrono::system_clock::time_point now = chrono::system_clock::now();
// Mengubah waktu ke dalam bentuk waktu kalender
time_t time_now = chrono::system_clock::to_time_t(now);
// Membuat objek tm untuk memformat waktu sesuai keinginan
tm *timeinfo = localtime(&time_now);
// Mencetak waktu dengan format yang diinginkan
cout << "Tanggal : " << put_time(timeinfo, "%d/%m/%Y %H:%M:%S") << endl;
}
// fungsi untuk mencetak struk
void printReceipt(int sub_total, int& PPN10, int& total, int& tunai, int& kembalian)
{
cout << endl << endl << endl;
cout << "=====================================" << endl;
cout << " WDF Coffee Haven" << endl;
cout << " Gang Jeruk No. 5" << endl;
cout << " Telp. 1500-212" << endl;
cout << "=====================================" << endl;
cout << "Kode Struk : " << kodestruk(1000, 9999) << endl;
nomor_meja();
waktu();
cout << "=====================================" << endl;
cout << "Menu" "\t\t" << "Qty" << "\t" << "Harga" << "\t" << "Total" << endl;
cout << "-------------------------------------" << endl;
// Tampilkan menu yang dipesan
WDF *curr = head;
while (curr != NULL)
{
cout << curr->nama << "\t\t" << curr->qty << "\t" << curr->harga << "\t" << curr->qty * curr->harga << endl;
sub_total += (curr->qty * curr->harga);
curr = curr->next;
}
cout << "-------------------------------------" << endl;
PPN10 = sub_total * 0.1;
total = sub_total + PPN10;
// Menampilkan sub total, ppn, total, tunai, kembalian
cout << "Sub Total\t\t\t" << sub_total << endl;
cout << "PPN 10%\t\t\t\t" << PPN10 << endl;
cout << "Total\t\t\t\t" << total << endl;
cout << "Masukkan Uang\t\t\t";
cin >> tunai;
kembalian = tunai - total;
cout << "Kembalian\t\t\t" << kembalian << endl;
cout << "=====================================" << endl;
cout << " ~ Brewing Love, Serving Happiness ~ " << endl;
cout << " ( ^◡^)◞ ♥ ◟(^◡^✿)" << endl;
cout << "=====================================" << endl << endl << endl;
}
/*--------------------------------------------------------------------------------------*/
//fungsi untuk melihat statistik pesanan berdasarkan
//harga total, total pesanan, harga pesanan termurah, harga pesanan termahal, jumlah pesanan terbanyak, dan jumlah pesanan tersedikit
void statistikOrder()
{
WDF *curr = head;
int min = curr->harga * curr->qty;
int max = curr->harga * curr->qty;
int total = 0;
int count = 0;
int minQty = curr->qty;
int maxQty = curr->qty;
string minNama = curr->nama;
string maxNama = curr->nama;
string minQtyNama = curr->nama;
string maxQtyNama = curr->nama;
while (curr != NULL)
{
total += curr->harga * curr->qty;
count += curr->qty;
if ((curr->harga * curr->qty) < min)
{
min = curr->harga * curr->qty;
minNama = curr->nama;
}
if ((curr->harga * curr->qty) > max)
{
max = curr->harga * curr->qty;
maxNama = curr->nama;
}
if (curr->qty < minQty)
{
minQty = curr->qty;
minQtyNama = curr->nama;
}
if (curr->qty > maxQty)
{
maxQty = curr->qty;
maxQtyNama = curr->nama;
}
curr = curr->next;
}
cout << endl << endl;
cout << "=====================================" << endl;
cout << " WDF Coffee Haven" << endl;
cout << " Gang Jeruk No. 5" << endl;
cout << " Telp. 1500-212" << endl;
cout << "=====================================" << endl;
cout << "Total Penjualan" "\t\t\t" << total << endl;
cout << "Total Pesanan" "\t\t\t" << count << endl;
cout << "Pesanan Termurah" "\t" << minNama << " - " << min << endl;
cout << "Pesanan Termahal" "\t" << maxNama << " - " << max << endl;
cout << "Pesanan Terbanyak" "\t" << maxQtyNama << " - " << maxQty << endl;
cout << "Pesanan Tersedikit" "\t" << minQtyNama << " - " << minQty << endl;
cout << "=====================================" << endl << endl << endl;
}
};
#endif