-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
316 lines (283 loc) · 8.27 KB
/
main.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
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <vector>
using namespace std;
vector<int> idBarang;
vector<string> namaBarang;
vector<int> stokBarang;
vector<int> hargaBarang;
int masuk = 0;
int k = 0;
void garis(){
cout << "+----------------------------------------------------+\n";
}
void tabelBarang(){
garis();
cout << fixed;
cout << "|";
cout << left << setw(13) << "ID";
cout << right << setw(13) << "PRODUK";
cout << right << setw(13) << "HARGA";
cout << right << setw(13) << "STOK";
cout << "|" << endl;
garis();
}
bool cekVectorBarang(){
int jumlahData = idBarang.size();
if(jumlahData < 1){
return false;
}
else{
return true;
}
}
void insertBarang(int id, string nama, int stok, int harga){
idBarang.push_back(id);
namaBarang.push_back(nama);
stokBarang.push_back(stok);
hargaBarang.push_back(harga);
}
void tampilData(){
int jumlahData;
jumlahData = idBarang.size();
tabelBarang();
for(int i = 0; i < jumlahData; i++){
cout << "|";
cout << left << setw(13) << idBarang[i];
cout << right << setw(13) << namaBarang[i];
cout << right << setw(13) << hargaBarang[i];
cout << right << setw(13) << stokBarang[i];
cout << "|" << endl;
}
garis();
}
void hapusData(int id){
bool status = false;
int jumlahData = idBarang.size();
for (int i = 0; i < jumlahData; i++){
if(id == idBarang[i]){
idBarang.erase(idBarang.begin() + i);
namaBarang.erase(namaBarang.begin() + i);
hargaBarang.erase(hargaBarang.begin() + i);
stokBarang.erase(stokBarang.begin() + i);
cout << "Data berhasil di hapus\n";
status = true;
break;
}
}
if(status == false){
cout << "Data tidak ditemukan!\n";
}
}
void updateStok(int dataStokLama, int dataStokBaru){
for (int i = 0; i < stokBarang.size(); i++){
if(dataStokLama == stokBarang[i]){
stokBarang[i] = dataStokBaru;
}
}
}
void ubahData(int idPilih){
int id, harga, stok;
string nama;
bool status = false;
for (int i = 0; i < idBarang.size(); i++){
if(idPilih == idBarang[i]){
cout << "ID : ";
cin >> id;
cout << "Nama Barang : ";
cin >> nama;
cout << "Harga Barang: ";
cin >> harga;
cout << "Stok : ";
cin >> stok;
idBarang[i] = id;
namaBarang[i] = nama;
hargaBarang[i] = harga;
stokBarang[i] = stok;
cout << "Data berhasil di ubah\n";
status = true;
break;
}
else{
status == false;
}
}
if(status == false){
cout << "Data tidak ditemukan!\n";
}
}
void ubahStok(int stok, int stokLama){
int jumlahData = idBarang.size();
for (int i = 0; i < jumlahData; i++){
if(stokLama == stokBarang[i]){
stokBarang[i] = stok;
break;
}
}
}
void transaksi(){
int pilihID, id, stokLama, jumlahPembelian[99], hargaTotal[99], tambahBelanja = 1, harga[99], kembalian, bayar;
string produk[99];
int stok[99], stokBaru, status = 0, l = 0;
char iterasiTransaksi;
long total = 0;
if(cekVectorBarang()){
while(tambahBelanja == 1){
system("cls");
garis();
cout << "| DATA PRODUK |\n";
tampilData();
cout << "Pilih ID Barang : ";
cin >> id;
for (int i = 0; i < idBarang.size(); i++){
if(id == idBarang[i]){
produk[l] = namaBarang[i];
harga[l] = hargaBarang[i];
stok[l] = stokBarang[i];
status = 1;
break;
}
else{
status = 0;
}
}
if(status == 1){
cout << produk[l] << endl;
cout << "Harga : " << harga[l] << endl;
cout << "Jumlah Pembelian : ";
cin >> jumlahPembelian[l];
hargaTotal[l] = harga[l] * jumlahPembelian[l];
total = total + hargaTotal[l];
stokLama = stok[l];
stokBaru = stok[l] - jumlahPembelian[l];
if(stokBaru >= 0){
updateStok(stokLama, stokBaru);
}
l++;
}
cout << "Lakukan pembelian lagi ? (y/n) " << endl;
cin >> iterasiTransaksi;
if(((iterasiTransaksi == 'n') || (iterasiTransaksi == 'N')) && (stokBaru >= 0)){
while(true){
system("cls");
cout << fixed;
cout << fixed;
cout << "+--------------------------------------------------------------+\n";
cout << "|";
cout << left << setw(13) << "PRODUK";
cout << right << setw(13) << "HARGA";
cout << right << setw(23) << "JUMLAH PEMBELIAN";
cout << right << setw(13) << "TOTAL";
cout << "|" << endl;
cout << "+--------------------------------------------------------------+\n";
for (int z = 0; z < l; z++){
cout << "|";
cout << left << setw(13) << produk[z];
cout << right << setw(13) << harga[z];
cout << right << setw(23) << jumlahPembelian[z];
cout << right << setw(13) << hargaTotal[z];
cout << "|" << endl;
}
cout << "+--------------------------------------------------------------+\n";
cout << "|";
cout << left << setw(13) << "TOTAL PEMBAYARAN";
cout << right << setw(46) << total;
cout << "|" << endl;
cout << "+--------------------------------------------------------------+\n";
cout << "Pembayaran : ";
cin >> bayar;
if (bayar >= total){
kembalian = bayar - total;
cout << "Kembalian : " << kembalian << endl;
cout << "Terima Kasih\n";
tambahBelanja = 0;
break;
}
else{
cout << "Pembayaran kurang!\n";
}
}
}
}
}
else{
cout << "Data masih kosong\n";
}
}
void menu(){
int id , harga, stok, pilih, idPilih;
string nama;
system("cls");
cout<<"Menu Aplikasi POS Atur Warung"<<endl;
garis();
cout<<"1. Insert / Tambah Data Barang"<<endl;
cout<<"2. Lihat Data Barang"<<endl;
cout<<"3. Ubah Data Barang"<<endl;
cout<<"4. Hapus Data Barang"<<endl;
cout<<"5. Aplikasi Kasir"<<endl;
cout<<"6. Keluar"<<endl;
cout<<"Pilih : ";
cin>>pilih;
cout<<endl;
switch(pilih)
{
case 1:
cout << "Input ID Barang : ";
cin >> id;
cout << "Input Nama Barang : ";
cin >> nama;
cout << "Input Harga Barang: ";
cin >> harga;
cout << "Input Stok Barang : ";
cin >> stok;
insertBarang(id, nama, stok, harga);
cout << "Data berhasil di masukan!\n";
getch();
break;
case 2:
system("cls");
garis();
cout << "| DATA PRODUK |\n";
tampilData();
getch();
break;
case 3:
system("cls");
garis();
cout << "| UBAH DATA PRODUK |"<<endl;
tampilData();
cout << "Pilih ID barang yang ingin di ubah : ";
cin >> idPilih;
ubahData(idPilih);
getch();
break;
case 4:
cout<<"Masukan ID yang ingin dihapus : "<<endl;
cin>>id;
hapusData(id);
getch();
break;
case 5:
system("cls");
transaksi();
getch();
break;
case 6:
k = 1;
return;
break;
default: cout<<"Pilihan yang anda masukkan salah!"<<endl;
getch();
break;
}
}
int main(){
while(true){
if(k == 1){
break;
}
menu();
}
return 0;
}