forked from GhifariADR/Tubes-std
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.cpp
256 lines (233 loc) · 5.98 KB
/
utility.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
#include "utility.h"
#include <cstdlib>
void menu(listgames &Lg,listrelation &Lr,listuser &Lu){
int pilih;
do{
system("cls");
cout << "|=======================|" << endl;
cout << "|WELCOME TO 05-GAMESTORE|" << endl;
cout << "|=======================|" << endl;
cout << "|(0) Exit |" << endl;
cout << "|(1) User baru |" << endl;
cout << "|(2) Game baru |" << endl;
cout << "|(3) Isi saldo user |" << endl;
cout << "|(4) Beli game |" << endl;
cout << "|(5) Jual game |" << endl;
cout << "|(6) Hapus user |" << endl;
cout << "|(7) Hapus game |" << endl;
cout << "|(8) Lihat info user |" << endl;
cout << "|(9) Lihat info game |" << endl;
cout << "|(10)Lihat semua users |" << endl;
cout << "|(11)Lihat semua games |" << endl;
cout << "|(12)Semua user & games |" << endl;
cout << "|=======================|" << endl;
cout << "====Pilih -> ";
cin >> pilih;
switch(pilih){
case 1:
inputUser(Lu);
break;
case 2:
inputGame(Lg);
break;
case 3:
isiSaldo(Lu);
break;
case 4:
buyGames(Lr,Lg,Lu);
break;
case 5:
sellGames(Lr,Lg,Lu);
break;
case 6:
deletinguser(Lu);
break;
case 7:
deletinggames(Lg);
break;
case 8:
cariUser(Lu,Lr);
break;
case 9:
cariGame(Lg,Lr);
break;
case 10:
showAllUser(Lu);
break;
case 11:
showAllGames(Lg);
break;
case 12:
allUsersGame(Lu,Lr);
break;
}
system("pause");
}while(pilih!=0);
}
void mostPlayedGames(listgames L,listrelation Lr){
g_address G=first(L);
int Max=users(info(G));
while(G!=NULL){
if(users(info(G))>Max){
Max=users(info(G));
}
G=next(G);
}
G=first(L);
while(G!=NULL){
if(users(info(G))==Max){
gamesUser(G,Lr);
}
G=next(G);
}
}
void inputUser(listuser &L){
u_address U;
infotypeU info;
cout << "Nama User\t: ";
cin >> info.nama;
cout << "ID User\t: ";
cin >> info.id;
info.saldo=0;
U=createuser(info);
insertuser(U,L);
}
void inputGame(listgames &L){
g_address G;
infotypeG info;
cout << "Nama Game\t: ";
cin >> info.nama;
cout << "ID Game\t: ";
cin >> info.id;
cout << "Harga Game\t: ";
cin >> info.harga;
G=creategames(info);
insertgames(G,L);
}
void isiSaldo(listuser L){
string kode;
int saldo;
u_address U;
cout << "ID/nama user\t: ";
cin >> kode;
U=searchuser(kode,L);
if(U!=NULL){
cout << "Tambah saldo\t: ";
cin >> saldo;
if(saldo>0){
saldo(info(U))=saldo(info(U))+saldo;
}else{
cout << "Ada yang salah..." <<endl;
}
}else{
cout << "Nama/ID tidak terdaftar" << endl;
}
}
void buyGames(listrelation &L,listgames Lg,listuser Lu){
u_address U;
g_address G;
r_address R;
int pilihan=0;
string kode;
cout << "ID/nama user\t: ";
cin >> kode;
U=searchuser(kode,Lu);
if(U!=NULL){
showUser(U);
cout << "ID/nama game\t: ";
cin >> kode;
G=searchgames(kode,Lg);
if(G!=NULL){
showGames(G);
if(harga(info(G))<=saldo(info(U))){
while(pilihan!=1&&pilihan!=2){
cout << "(1) Beli game" << endl;
cout << "(2) Tidak beli" << endl;
}
if(pilihan==1){
saldo(info(U))=saldo(info(U))-harga(info(G));
R=createrelation(G,U);
insertrelation(R,L);
}
}else{
cout << "Saldo tidak cukup untuk membeli" << endl;
}
}else{
cout << "Games tidak terdaftar" << endl;
}
}else{
cout << "User tidak terdaftar" << endl;
}
}
void sellGames(listrelation &L,listgames Lg,listuser Lu){
u_address U;
g_address G;
r_address R;
int pilihan=0;
string kode;
cout << "ID/nama user\t: ";
cin >> kode;
U=searchuser(kode,Lu);
if(U!=NULL){
showUser(U);
cout << "ID/nama game\t: ";
cin >> kode;
G=searchgames(kode,Lg);
if(G!=NULL){
R=searchrelation(U,G,L);
if(R!=NULL){
showGames(G);
while(pilihan!=1&&pilihan!=2){
cout << "(1) Jual game" << endl;
cout << "(2) Tidak jadi" << endl;
}
if(pilihan==1){
saldo(info(U))=saldo(info(U))+harga(info(G));
deleterelationsearch(U,G,L);
}
}else{
cout << "Game tidak dibeli user" << endl;
}
}else{
cout << "Games tidak terdaftar" << endl;
}
}else{
cout << "User tidak terdaftar" << endl;
}
}
void cariUser(listuser Lu,listrelation Lr){
u_address U;
string kode;
cout << "Cari nama/id user : ";
cin >> kode;
U=searchuser(kode,Lu);
if(U!=NULL){
usersGames(U,Lr);
}
}
void cariGame(listgames Lg,listrelation Lr){
g_address G;
string kode;
cout << "Cari nama/id user : ";
cin >> kode;
G=searchgames(kode,Lg);
if(G!=NULL){
gamesUser(G,Lr);
}
}
void deletinggames(listgames &L){
g_address P;
string kode;
cout << "ID/Nama games : ";
cin >> kode;
P=searchgames(kode,L);
deletegames(P,L);
}
void deletinguser(listuser &L){
u_address P;
string kode;
cout << "ID/Nama user : ";
cin >> kode;
P=searchuser(kode,L);
deleteuser(P,L);
}