-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphone_reseller.c
408 lines (331 loc) · 10.8 KB
/
phone_reseller.c
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#include<stdio.h>
#include<conio.h>
#include<unistd.h>
#include<stdlib.h>
// defining our own datatype to store users name and passcode
struct sris{
char Name[100];
int passcode;
};
// defining structure to store products
struct pro{
char product_name[50];
char seller_name[50];
int ram;
int storage;
int price;
};
struct pro products[30];
struct sris users[30];
int cursor = 0;
int cursor_product = 0;
int fare;
// function to print welcome message
void welcome(){
printf("\n\n\n\n\n");
char mes1[21] = "Welcome to Phone Kart";
printf("*\
*********************************************************************\n\
* *\n\
* *\n\
* **** { WELCOME } < USER/ > **** *\n\
* *\n\
* *\n\
* ^^^ TO ^^^ -> (PHONE KART ) => { *\n\
* *\n\
* Platform to SELL and BUY Old refurnished Phones } *\n\
* *\n\
* SOURCECODE ON GITHUB UNDER Apache-2.0 license *\n\
********************************************************************* ");
char mes5[85] = " Project developed by Divyansh ";
printf("\n \n \n \n \n ");
printf("\n ");
usleep(3000000);
for(int y = 0 ;y<45;y++){
printf("%c" , mes5[y]);
usleep(30000);
}
}
// function for configuring
void config(int seconds){
printf("\n \n \n ");
printf("configuring");
for(int i= 20 ; i<=40;i++){
usleep(seconds);
printf(".");
}
}
// function for login
void login(){
// login user
char m[45] = "< Please LOGIN to proceed /> ";
for(int i = 0 ;i<45 ;i++){
printf("%c" , m[i]);
usleep(10000);}
printf("\n\n\n Enter YOUR NAME ");
scanf("%s" , &users[cursor].Name);
printf("Enter YOUR MobileNumber ");
scanf("%s" , &users[cursor].passcode);
printf("\n\n\n\n\n ");
printf("USER LOGGEED IN SUCCESSFULLY !!");
char mX[45] = "< redirecting to welcome screen.. !!!/> ";
printf("\n\n\n\n\n ");
for(int i = 0 ;i<45 ;i++){
printf("%c" , mX[i]);
usleep(10000);}
for(int n = 0;n<50;n++){
printf("*");
}welcome_page();
}
// welcome page after login or registering successful
void welcome_page(){
printf("\n\n\n ");
printf("\n\n\n ");
for(int n = 0;n<50;n++){
printf("*");
}
printf("\n");
char m[45] = "< Welcome";
for(int i = 0 ;i<45 ;i++){
printf("%c" , m[i]);
usleep(10000);}
printf("%s />",users[cursor].Name);
printf("\n\n ");
printf("ENTER 1 -> SELLING OLD PHONES \n");
usleep(50000);
printf("\n\n ");
printf("ENTER 2 -> BUYING REFURNISHED PHONES \n");
usleep(50000);
printf("\n\n ");
printf("ENTER 3 -> MY LISTED PRODUCTS\n");
printf("\n\n ");
printf("ENTER 4 -> LOG OUT \n");
printf("\n\n ");
int ch;
scanf("%d" , &ch);
if(ch==1){
for(int n = 0;n<50;n++){
printf("*");
}
selling_page();
}else if(ch == 2){
for(int n = 0;n<50;n++){
printf("*");
}
buying_page();
}
else if(ch==3){
sell_pro();
}
else if(ch==4){
logout();
printf("\n \n");
}else{
printf("invalid input"); welcome_page(); }
for(int n = 0;n<50;n++){
printf("*");
}
}
// logout function to handle logout screen
void logout(){
++cursor;
printf("\n\n\n ");
for(int n = 0;n<50;n++){
printf("*");
}
printf("\n\n\n ");
char m[45] = "< logged out !!/> ";
for(int i = 0 ;i<45 ;i++){
printf("%c" , m[i]);
usleep(10000);}
printf("\n\n SEE YOU soon { %s } ",users[cursor-1].Name);
printf("\n\n\n\n\n ");
for(int n = 0;n<50;n++){
printf("*");
}
usleep(10000);
printf("\n\n\n ");
printf("\n\n\n\n LAST logged in USER --> %s " , users[cursor-1].Name );
printf("\n\n\n ");
login();
}
// function to display selling products of particular
void sell_pro(){
int flag = 0;
for(int i =0 ;i<cursor_product;i++){
if(strcmp(products[i].seller_name , users[cursor].Name) == 0){
printf("PRODUCT : %s \t SELLER : %s \t RAM : %d \t STORAGE : %d \t PRICE : %d" , products[i].product_name ,products[i].seller_name,products[i].ram, products[i].storage,products[i].price);
flag=1;
}
}
if(flag!=1){
printf("\n\n THERE ARE NO PRODUCTS LISTED BY YOU \n\n");
usleep(50000);
welcome_page();
}
}
// add_item for adding selling items
void add_item(){
printf("\n\n\n\n");
for(int n = 0;n<50;n++){
printf("*");
}
printf("\n\n\n\n");
printf("Enter Product name ");
scanf("%s" , &products[cursor_product].product_name);
printf("Enter RAM ");
scanf("%d" , &products[cursor_product].ram);
printf("Enter STORAGE ");
scanf("%d" , &products[cursor_product].storage);
printf("Enter Seller's name ");
scanf("%s" , &products[cursor_product].seller_name);
products[cursor_product].price = fare;
printf("\n\n\n");
for(int i=0;i<40;i++){
printf("*");
}
printf("\n\n\n Following Item's Were Added\n\n\n");
printf("PRODUCT : %s \t SELLER : %s \t RAM : %d \t STORAGE : %d \t PRICE : %d" , products[cursor_product].product_name ,products[cursor_product].seller_name,products[cursor_product].ram, products[cursor_product].storage,products[cursor_product].price);
++cursor_product;
logout();
}
// selling function
void selling_page(){
printf("\n\n\n\n");
printf("Welcome to the seller's hub \n\n Start Selling From Today --> Reach the Global Audience!!");
printf("\n\n\n ENTER 1 to start QUALITY CHECK ");
int ch ;
scanf("%d" , & ch);
if(ch==1){
printf("\n\n\n");
for(int p =0;p<=40;p++){ printf("*"); }
printf("\n\n\n WELCOME !! to Quality Check - GET the best Price for your Product");
// returning the fare of the product
fare = Quality_check();
printf("\n\n FARE : %d RS/- \n\n" , fare);
for(int n = 0;n<50;n++){
printf("*");
}
printf("\n\n\n");
printf("\n\n Do you want to Sell this Product \n\n-> ENTER 1 to sell \n\n -> ENTER 2 for MAIN MENU\n\n -> ENTER 3 to LOGOUT ");
int c ;
scanf("%d" , &c);
if(c == 1){
// coding for adding item to structure
add_item();
}
else if(c==2){
welcome_page();
}
else{
logout();
}
printf("\n\n\n\n LAST logged in USER --> %s " , users[cursor].Name );
}
else{
printf("invalid input !!!");
selling_page();
printf("\n\n\n");
}
printf("\n\n\n\n\n");
}
// buying page to show products available to buy
void buying_page(){
printf("\n\n\n\n ");
printf("Welcome to the BUYER's hub \n\n GET MOBILE PHONES AT CHEAPEST RATES !!");
printf("\n\n\n\n ");
if(cursor_product==0){
printf("\n\n NO ITEM AVAILABLE \n\n ");
welcome_page();
}
for(int i=0;i<cursor_product;i++){
printf("\n\n");
printf("PRODUCT : %s \t SELLER : %s \t RAM : %d \t STORAGE : %d \t PRICE : %d" , products[i].product_name ,products[i].seller_name,products[i].ram, products[i].storage,products[i].price);
}
printf("\n\n\n\n ");
for(int n = 0;n<50;n++){
printf("*");
}
welcome_page();
}
// Quality check function
int Quality_check(){
printf("\n\nenter 1 -> Iphones \n 2 -> Smartphones \n 3 -> Keypad Phones\n\n");
int brand ;
int ram;
int storage;
int usage_days;
scanf("%d" , &brand);
if(brand==1){
// iphone section
printf("\n\nPROVIDE US DETAILS FOR IPHONE RESOURCES\n\n");
printf("\n\nenter RAM ");
scanf("%d" , &ram);
printf("\n\nenter STORAGE in GB ");
scanf("%d" , &storage);
printf("\n\nenter YEARS useage ");
scanf("%d" , &usage_days);
if(ram < 4 && storage < 40 && usage_days > 3){
return 15000;
}
else if(ram > 4 && ram < 50 && storage > 10 && storage< 40 && usage_days > 3){
return 20000;
}
else if(ram > 10 && storage > 60 && usage_days < 3){
return 30000;
}
else{return 10000;}
}
else if(brand == 2){
// smartphone section
// iphone section
printf("\n\nPROVIDE US DETAILS FOR SMARTPHONE RESOURCES\n\n");
printf("\nenter RAM ");
scanf("%d" , &ram);
printf("\n\nenter STORAGE in GB ");
scanf("%d" , &storage);
printf("\n\nenter YEARS useage ");
scanf("%d" , &usage_days);
if(ram < 4 && storage < 40 && usage_days > 3){
return 8000;
}
else if(ram > 4 && ram < 10 && storage > 10 && storage< 40 && usage_days > 3){
return 9000;
}
else if(ram > 10 && storage > 40 && usage_days < 3){
return 10000;
}
else{
return 5000;
}
}
else if(brand ==3){
// keypad section
// iphone section
printf("\n\nPROVIDE US DETAILS FOR keypad RESOURCES\n\n");
printf("\n\nEnter YEARS Useage ");
scanf("%d" , &usage_days);
if(usage_days > 3){
return 150;
}
else if(usage_days < 3){
return 200;
}
else {
return 100;
}
}
else{
printf("Invalid choice !!! ---> Program not directed from here");
return 0;
}
}
// drivers code
int main(){
usleep(700000);
welcome();
usleep(800000);
config(300000);
usleep(7000000);
login();
}