-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
487 lines (394 loc) · 9.79 KB
/
main.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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/*
Author Names:
Ryan Cole - 2106111
Wolde Kristos - 2304844
Sheriann Sewell - 2210110
Davin Simpson - 2301564
Matthew Webster 2305616
Tutor Name: Michelle March
Occurrence: UN2
*/
#include <conio.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define E87CAP 75708.23
#define E90CAP 113562.35
#define DIESELCAP 94635.29
#define E87PRICE 184.90
#define E90PRICE 193.60
#define DIESELPRICE 182.30
#define L5W30PRICE 2900
#define L5W40PRICE 3500
#define L15W40PRICE 3600
#define LSAR40PRICE 2100
typedef enum { E10_87 = 1, E10_90, DIESEL } FuelType;
typedef enum { L5W30 = 1, L5W40, L15W40, LSAE40 } LubeType;
// Data structures
#define Correct_Password "123456"
// Command line options for clearing screen: Windows/Mac
#define clear system("cls || clear")
#define pause system("pause || sleep 5");
typedef struct {
FuelType fuelType;
float cost; // Cost per gallon
} Tank;
typedef struct {
FuelType fuelType;
float fuelAmt;
char lubeReq;
enum { Cash = 1, Card = 2 } payType;
} CoD;
/*typedef struct {
union {
int id;
char businessName[50];
};
int licenseNo;
char fuelAmt;
char lubeReq;
char payType;
} Charge;*/
typedef struct {
int idNo;
char name[40];
int repNum;
char licenseNo[6];
FuelType fuel;
float fuelAmt;
char lubeRequest;
float depositAmt;
} Charge;
Charge customers[50];
// Function prototypes
void mainMenu();
void welcomeScreen();
void serveCustomer();
void generateReceipt();
void codServe();
void chargeServe();
void printReceipt();
void addCharge();
Charge blankCharge();
void existingCharge();
void deleteCharge();
int randomInteger(int, int);
char randomCharacter(int);
void paytoCharge();
void updateCharge();
void refuelTank();
void chargeSearch();
void chargePayment();
void generateReport();
void exitProgram();
bool enterPassword(); // Returns true if password is valid
char *getLicensePlateInfo();
int main() {
welcomeScreen();
clear;
mainMenu();
return 0;
}
void welcomeScreen() {
printf("Welcome to Stateline Gas Station Program\n"
"This program was created by:\n"
"\tRyan Cole (2106111)\n"
"\tWolde Kristos (2304844)\n"
"\tSheriann Sewell (2210110)\n"
"\tDavin Simpson (2301564) \n"
"\tMatthew Webster - 2305616\n"
"\nOcc : UN2\n"
"Tutor: Michelle March\n"
"\nAdmin Password is:123456\n");
pause;
clear;
}
bool enterPassword() {
char password[100] = {0};
clear;
printf("Authorization Required\n");
printf("Enter Password:");
int i = 0;
char c;
// User enters the password
do {
c = getch(); // Record each charcter
if (c == 13 || c == 3)
break;
if (c == 8) { // Allow backspace
if (strlen(password) == 0) {
continue;
}
printf("\b \b");
password[strlen(password) - 1] = '\0';
continue;
}
sprintf(password, "%s%c", password, c);
printf("*"); // Print a mask instead of the character
} while (c != EOF);
printf("\n");
clear;
if (strcmp(password, Correct_Password) == 0) {
printf("Access Granted\n");
return true;
} else {
printf("Invalid Password Entered\n");
return false;
}
clear;
}
void mainMenu() {
// Declare variables for menu use
int choice;
// Main menu loop
do {
// Display menu options
printf("\nMain Menu\n");
printf("1. Serve Customer\n");
printf("2. Add Charge Customer\n");
printf("3. Update Charge Customer\n");
printf("4. Delete Charge Customer\n");
printf("5. Make Payment to Charge Account\n");
printf("6. Refuel Tank\n");
printf("7. Generate Report\n");
printf("8. Search for existing Charge Customer \n");
printf("9. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
// Execute corresponding function based on user choice
switch (choice) {
case 1:
serveCustomer();
break;
case 2:
addCharge();
break;
case 3:
updateCharge();
break;
case 4:
deleteCharge();
break;
case 5:
chargePayment();
break;
case 6:
refuelTank();
break;
case 7:
generateReport();
break;
case 8:
chargeSearch();
break;
case 9:
return;
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 9);
return;
}
void serveCustomer() {
Charge *charge;
CoD *cod;
// Example
CoD cust;
cod = &cust;
Charge cst;
charge = &cst;
bool valid;
int fuelType;
enum { CoDCustomer = 1, ChargeCustomer = 2 } choice;
valid = true;
do {
if (!valid) {
printf("Incorrect option entered. Please choose 1 or 2\n");
}
printf("Select type of Customer\n\t 1- Cash on Delivery (CoD) \n\t 2 - "
"Charge Customer\n");
printf("Enter choice:");
scanf("%d", &choice);
valid = false;
clear;
} while (choice != 1 && choice != 2);
if (choice == CoDCustomer) {
valid = true;
do {
if (valid == false) {
printf(
"Incorrect Fuel Type entered. Please select an optuion from 1-3\n");
}
printf("Select Fuel Type\n\t1. E10-87\n\t 2. E10-90\n\t 3.Diesel\n");
printf("Enter option:");
scanf("%d", &fuelType);
valid = false;
clear;
} while (fuelType < 1 || fuelType > 3);
cod->fuelType = fuelType;
printf("Enter Fuel Amount:");
scanf("%f", &cod->fuelAmt);
clear;
cod->lubeReq = randomInteger(0, 1) ? 'Y' : 'N';
do {
printf("Select Payment Type\n\t 1. Cash \n\t 2. Card\n");
printf("Enter Choice:");
scanf("%d", &cod->payType);
clear;
} while (cod->payType != 1 && cod->payType != 2);
} else if (choice == ChargeCustomer) {
char idname[50];
int id = 0;
printf("Enter ID or Business Name:");
scanf("%s", idname);
if (isdigit(idname[0])) { // Digit characters are id number
sscanf(idname, "%d", &id);
charge->idNo = id;
} else {
strcpy(charge->name, idname);
}
clear;
int numReps;
valid = true;
do {
printf("Enter number of representatives:");
scanf("%d", &numReps);
valid = false;
} while (numReps > 5 || numReps < 1);
charge->repNum = numReps;
strcpy(charge->licenseNo, getLicensePlateInfo());
bool prefDeposit = randomInteger(0, 1) ? true : false;
int minDepo = 0;
int litr;
if (prefDeposit) {
minDepo = 10000;
litr = 50;
printf("Minimum Deposit is $%d for %d liters", minDepo, litr);
}
}
}
void printReceipt() {
printf("\nProcessing Successful.\n");
printf("RECEIPT\n");
printf("Transaction Date: %s\n", __DATE__);
printf("Type of Customer: Cash on Delivery (COD)\n");
printf("Items Purchased: \n");
printf("GCT Amount: \n");
printf("Total Amount: \n");
printf("Cash Given/Charge Amount: \n");
printf("Change: \n");
}
void codServe() {}
void chargeServe() {}
void addCharge(Charge *ch) {
int licenseNo, i, index;
char licenseletters[2], licenseNums[5], fullLicense[6];
srand(time(0));
ch->idNo = randomInteger(999, 100);
// printf("ID: %d\n\n", ch->idNo);
printf("Business Name: ");
gets(ch->name);
printf("Number of Representatives (no more than 5): ");
scanf("%d", &ch->repNum);
licenseNo = randomInteger(9999, 1000);
// printf("%d\n\n", licenseNo);
for (i = 0; i < 2; i++) {
index = rand() % 26;
licenseletters[i] = randomCharacter(index);
// printf("%c\n", licenseletters[i]);
}
sprintf(licenseNums, "%d", licenseNo);
strcpy(fullLicense, licenseNums);
strcat(fullLicense, licenseletters);
strcpy(ch->licenseNo, fullLicense);
// puts(fullLicense);
// puts(ch->licenseNo);
printf("Preference (Deposit or Maximum Litres): ");
}
Charge blankCharge() {
Charge ch;
ch.idNo = 0;
strcpy(ch.name, " ");
// ch.fuelType = ' ';
ch.fuel = 0;
ch.fuelAmt = 0;
ch.lubeRequest = ' ';
ch.depositAmt = 0;
return ch;
}
void existingCharge() {}
void deleteCharge() { enterPassword(); }
char *getLicensePlateInfo() {
static char licNo[7];
bool valid = false;
do {
printf("Enter Lisense Plate Number:");
scanf("%s", licNo);
// Valid
if (strlen(licNo) != 6) {
clear;
printf("Invalid. License Plate should have 6 characters\n");
continue;
}
valid = isdigit(licNo[0]) && licNo[1] && licNo[2] && licNo[3];
valid &= isalpha(licNo[4]) && isalpha(licNo[5]);
if (!valid) {
clear;
printf(
"Invalid. License Plate should use the following format 5786KW \n");
}
} while (!valid);
return licNo;
}
int randomInteger(int upper, int lower) {
int randomNum;
srand(time(0));
randomNum = rand() % ((upper - lower + 1) + lower);
return randomNum;
}
char randomCharacter(int index) {
char charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return charset[index];
}
void paytoCharge(Charge *cust) {}
void updateCharge(Charge *cust) {
bool correct = enterPassword();
if (correct) {
int idNo;
printf("Enter customer id:");
scanf("%d", &idNo);
bool valid;
int i = 0;
for (i = 0; i < 30; i++) {
if ((cust + i)->idNo == idNo) {
cust = cust + i;
printf("Enter Amount (mimumum 1000);");
valid = true;
do {
if (!valid) {
printf("Invalid. Remember, amount shouldn't be less than 1000");
}
scanf("%f", &cust->fuelAmt);
valid = cust->fuelAmt >= 1000;
int payType;
do {
printf("Select Payment Type\n\t 1. Cash \n\t 2. Card\n");
printf("Enter Choice:");
scanf("%d", &payType);
clear;
} while (payType != 1 && payType != 2);
} while (valid);
break;
}
}
}
}
void refuelTank() { enterPassword(); }
void chargeSearch() {}
void chargePayment() {}
void generateReport() {}
void exitProgram() {}