-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
804 lines (668 loc) · 22 KB
/
Source.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
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;
// Global Constants
const int MAX_RECORDS = 80; // (Actual Maximum Number of Records That Can Be Processed)
const int TEXT_WIDTH = 15; // Width for Car ID and Model
const int NUM_WIDTH = 12; // Width for Quantity and Price
const int MIN_PRICE = 5000; // Minimum Vehicle Price
const int MIN_MODEL_LEN = 3; // Minimum Model Name Length
const int REQ_ID_LEN = 9; // Required Car ID length
const int ID_PART1_END = 2; // Length of first part of Car ID
const int ID_PART2_END = 7; // Length of the first and second part of Car ID
const int HEADER_WIDTH = 54; // Width for header
// Enumerated type for menu selection
enum Selection { VALID = 1, INVALID, SORT, QUIT };
enum Fields { ID = 1, MODEL, QUANTITY, PRICE, RETURN_TO_MAIN };
class Car {
private:
string carID;
string model;
int quantity;
double price;
public:
Car() { setCar("N/a", "N/a", 0, 0); }
Car(string n_carID, string n_model, int n_quantity, double n_price) { setCar(n_carID, n_model, n_quantity, n_price); }
void setCar(string n_carID, string n_model, int n_quantity, double n_price);
void setCarID(string n_carID) { setCar(n_carID, model, quantity, price); }
void setModel(string n_model) { setCar(carID, n_model, quantity, price); }
void setQuantity(int n_quantity) { setCar(carID, model, n_quantity, price); }
void setPrice(double n_price) { setCar(carID, model, quantity, n_price); }
string getCarID() const { return carID; }
string getModel() const { return model; }
int getQuantity() const { return quantity; }
double getPrice() const { return price; }
string toString() const;
};
class Inventory {
private:
Car cars[MAX_RECORDS];
Car* carPtrs[MAX_RECORDS];
int numCars = 0;
public:
Inventory() { ParseData(); }
void setNumCars(int n_numCars) { numCars = n_numCars; }
void ParseData();
bool ValidateRecord(string carID, string model, int quantity, double price, string& errorMessage);
bool ValidateCarID(string carID, string& errorMessage);
bool ValidateModel(string model, string& errorMessage);
bool ValidateQuantity(int quantity, string& errorMessage);
bool ValidatePrice(double price, string& errorMessage);
void SortBy(int field);
void MakeStringUppercase(string& str);
void PrintInventory();
};
// Function Prototypes
int GetMenuSelection();
void SortMenu(Inventory& inventory); // Wrapper function for sorting menu
int GetSortKey();
void PrintInvalidRecords();
void PurgeInputErrors(string errMess);
int main() {
Inventory inventory;
int selection;
do {
selection = GetMenuSelection();
switch (selection) {
case VALID:
inventory.PrintInventory();
break;
case INVALID:
PrintInvalidRecords();
break;
case SORT:
SortMenu(inventory);
break;
case QUIT:
cout << "Terminating Program\n";
break;
default:
PurgeInputErrors("ERROR: Invalid input. Please enter a valid option.\n\n");
}
} while (selection != QUIT);
return 0;
}
void Car::setCar(string n_carID, string n_model, int n_quantity, double n_price) {
carID = n_carID;
model = n_model;
quantity = n_quantity;
price = n_price;
}
string Car::toString() const {
stringstream recordString;
recordString << fixed << showpoint << setprecision(2) << left << setw(TEXT_WIDTH) << carID << setw(TEXT_WIDTH) << model
<< setw(NUM_WIDTH) << right << quantity << setw(NUM_WIDTH) << price << left << endl;
return recordString.str();
}
void Inventory::ParseData() {
string fileName{ "Data.txt" };
string errorFileName{ "ErrorFile.txt" };
stringstream ssHeader;
cout << fixed << showpoint << setprecision(2);
ssHeader << fixed << showpoint << setprecision(2) << left
<< setw(TEXT_WIDTH) << "Vehicle ID"
<< setw(TEXT_WIDTH) << "Model"
<< setw(NUM_WIDTH) << right << "Quantity"
<< setw(NUM_WIDTH) << "Price" << left << "\n\n";
ifstream Infile(fileName);
if (!Infile.is_open()) {
cout << "ERROR: Unable to open '" << fileName << "'. Terminating Program\n";
exit(EXIT_FAILURE);
}
else if (Infile.peek() == EOF) {
cout << "ERROR: '" << fileName << "' is empty. No data to process. Terminating Program\n";
exit(EXIT_FAILURE);
}
ofstream Errfile(errorFileName);
if (!Errfile) {
cout << "ERROR: Unable to open '" << errorFileName << "'. Terminating Program\n";
Infile.close();
exit(EXIT_FAILURE);
}
string errorMessage{ "" };
string carID, model;
int quantity;
double price;
bool isValidRecord;
int currentRecord{ 0 };
int totalCars = 0;
string line;
while (getline(Infile, line) && currentRecord < MAX_RECORDS) {
errorMessage = ""; // Reset error message before each line is read
stringstream ss(line);
ss >> carID >> model >> quantity >> price;
isValidRecord = ValidateRecord(carID, model, quantity, price, errorMessage);
if (isValidRecord) {
MakeStringUppercase(carID);
MakeStringUppercase(model);
cars[totalCars].setCar(carID, model, quantity, price);
carPtrs[totalCars] = &cars[totalCars];
totalCars++;
}
else {
Errfile << left << setw(TEXT_WIDTH) << carID << setw(TEXT_WIDTH) << model << setw(NUM_WIDTH) << right << quantity
<< setw(NUM_WIDTH) << right << price << left << " " << errorMessage << "\n";
}
currentRecord++;
}
// Check if records processed exceeds the total number of records
if (currentRecord == MAX_RECORDS && !Infile.eof()) {
cout << "ERROR: The total number of records exceed the maximum limit of " << MAX_RECORDS
<< ". Any records beyond the maximum " << MAX_RECORDS << " will be discarded.\n\n";
}
setNumCars(totalCars);
Infile.close();
Errfile.close();
}
// Calls individual validator functions and returns true if all validators return true
bool Inventory::ValidateRecord(const string carID, const string model, const int quantity, const double price, string& errorMessage) {
bool validID, validModel, validQuantity, validPrice;
validID = ValidateCarID(carID, errorMessage);
validModel = ValidateModel(model, errorMessage);
validQuantity = ValidateQuantity(quantity, errorMessage);
validPrice = ValidatePrice(price, errorMessage);
return (validID && validModel && validQuantity && validPrice);
}
// Validate the car ID by checking if the length is 9 characters, the first 2 characters are letters, the next 4 characters are alphanumeric, and the remaining 3 are numbers
bool Inventory::ValidateCarID(string carID, string& errorMessage) {
bool isValidID = false;
bool isValidLength = true;
bool validReq1 = true, validReq2 = true, validReq3 = true;
string errorMessageTemp{ "" };
if (carID.length() != REQ_ID_LEN) {
errorMessageTemp += "Car ID must be " + to_string(REQ_ID_LEN) + " characters long ";
isValidLength = false;
}
else {
for (int i{ 0 }; i < REQ_ID_LEN; i++) {
char c = carID[i];
// Check that the first requirement is satisfied
if (i < ID_PART1_END) {
if (!(c >= 'A' && c <= 'Z' && c != 'O') && validReq1 == true) {
errorMessageTemp += "First 2 characters of Car ID must be letters alpha only (A-Z, letter O is not allowed) ";
validReq1 = false;
}
} // Check that the second requirement is satisfied
else if (i <= ID_PART2_END && validReq2 == true) {
if (!((c >= 'A' && c <= 'Z' && c != 'O') || (c >= '0' && c <= '9')) && validReq2 == true) {
errorMessageTemp += "Characters 3-6 of Car ID must be alphanumeric (A-Z, 0-9, letter 0 is not allowed) ";
validReq2 = false;
}
} // Check that the final requirement is satisfied
else {
if (!(c >= '0' && c <= '9') && validReq3 == true) {
errorMessage += "Characters 7-9 of Car ID must be numeric ";
validReq3 = false;
}
}
}
}
if (isValidLength && validReq1 && validReq2 && validReq3) {
isValidID = true;
}
else {
errorMessage = "Invalid ID: [ " + errorMessageTemp + "]";
}
return isValidID;
}
// Check if the model starts with a capital letter, is at least 3 characters long, and is alphanumeric
bool Inventory::ValidateModel(string model, string& errorMessage) {
bool validModel = false;
bool validFirst = true, validLength = true, validAlphanumeric = true;
int length = model.length();
string errorMessageTemp{ "" };
// Check that the model meets the minimum length requirement
if (length < MIN_MODEL_LEN) {
validLength = false;
errorMessageTemp += "Model must be at least " + to_string(MIN_MODEL_LEN) + " characters long";
}
else {
// Check that the model starts with a capital letter that isn't O
if (model[0] < 'A' || model[0] > 'Z' || model[0] == 'O') {
validFirst = false;
errorMessageTemp += "Model must start with a capital letter (A-Z, letter O is not allowed) ";
}
else {
for (int i{ 1 }; i < length; i++) {
char c = model[i];
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) && validAlphanumeric) {
errorMessageTemp += "Model must must be alphanumeric (A-Z, 0-9, letter 0 is not allowed) ";
validAlphanumeric = false;
}
}
}
}
if (validFirst && validLength && validAlphanumeric) {
validModel = true;
}
else {
errorMessage = "Invalid Model: [ " + errorMessageTemp + "] ";
}
return validModel;
}
// Check if the quantity is greater than or equal to 0
bool Inventory::ValidateQuantity(int quantity, string& errorMessage) {
bool validQuantity = false;
if (quantity >= 0) {
validQuantity = true;
}
else {
errorMessage += "Invalid Quant: [ Quantity must be greater than or equal to 0 ] ";
}
return validQuantity;
}
// Check if the price is greater than MIN_PRICE
bool Inventory::ValidatePrice(double price, string& errorMessage) {
bool validPrice = false;
if (price > MIN_PRICE) {
validPrice = true;
}
else {
errorMessage += "Invalid Price: [ Price must be greater than $5000 ]";
}
return validPrice;
}
// Sorts the inventory by user-specified field in descending order
void Inventory::SortBy(int field) {
Car* temp;
for (int i{ 0 }; i < numCars; i++) {
int minIndex = i;
for (int j = i + 1; j < numCars; j++) {
bool isMinVal = false;
switch (field) {
case ID: // Sort by ID
isMinVal = carPtrs[j]->getCarID() > carPtrs[minIndex]->getCarID();
break;
case MODEL: // Sort by Model
isMinVal = carPtrs[j]->getModel() > carPtrs[minIndex]->getModel();
break;
case QUANTITY: // Sort by Quantity
isMinVal = carPtrs[j]->getQuantity() > carPtrs[minIndex]->getQuantity();
break;
case PRICE: // Sort by Price
isMinVal = carPtrs[j]->getPrice() > carPtrs[minIndex]->getPrice();
break;
default:
cout << "ERROR: Invalid field. Terminating Program\n";
exit(EXIT_FAILURE);
}
if (isMinVal) {
minIndex = j;
}
}
temp = carPtrs[minIndex];
carPtrs[minIndex] = carPtrs[i];
carPtrs[i] = temp;
}
}
// Takes in a string and converts all alphabetical characters to uppercase
void Inventory::MakeStringUppercase(string& str) {
for (int i{ 0 }; i < str.length(); i++) {
str[i] = toupper(str[i]);
}
}
void Inventory::PrintInventory() {
stringstream ssHeader;
ssHeader << fixed << showpoint << setprecision(2) << left
<< setw(TEXT_WIDTH) << "Vehicle ID"
<< setw(TEXT_WIDTH) << "Model"
<< setw(NUM_WIDTH) << right << "Quantity"
<< setw(NUM_WIDTH) << "Price" << left << "\n\n";
cout << "VALID ITEMS IN THE INVENTORY\n"
<< setfill('-') << setw(HEADER_WIDTH) << "-" << "\n" //use setfill print -
<< setfill(' ') // Reset setfill to default space character
<< ssHeader.str();
string recordString{ "" };
if (carPtrs == nullptr) {
cout << "Error: Inventory not initialized properly. Terminating Program\n\n";
exit(EXIT_FAILURE);
}
for (int i{ 0 }; i < numCars; i++) {
recordString = carPtrs[i]->toString();
cout << recordString;
}
cout << "\nTotal Records: " << numCars << "\n"
<< setfill('-') << setw(HEADER_WIDTH) << "-" << "\n"
<< setfill(' ') << "\n\n";
}
int GetMenuSelection() {
int selection;
cout << "Main Menu:\n"
"Please select one of the following options:\n"
"1. Valid Records\n"
"2. Invalid Records\n"
"3. Sort Inventory\n"
"4. Quit program\n"
"Selection: ";
cin >> selection;
cout << endl;
return selection;
}
void SortMenu(Inventory& inventory) {
int field = GetSortKey();
if (field != RETURN_TO_MAIN) {
switch (field) {
case ID:
cout << "Sorting by ID\n\n";
break;
case MODEL:
cout << "Sorting by Model\n\n";
break;
case QUANTITY:
cout << "Sorting by Quantity\n\n";
break;
case PRICE:
cout << "Sorting by Price\n\n";
break;
default:
PurgeInputErrors("ERROR: Invalid case in SortMenu. Terminating Program.\n");
exit(EXIT_FAILURE);
}
inventory.SortBy(field);
inventory.PrintInventory();
}
else {
cout << "Returning to Main Menu\n\n";
}
}
int GetSortKey() {
int key;
do {
cout << "Sort Menu:\n"
"Please select one of the following sorting options:\n"
"1. ID\n"
"2. Model\n"
"3. Quantity\n"
"4. Price\n"
"5. Return to Main Menu\n"
"Selection: ";
cin >> key;
cout << "\n";
if (key < ID || key > RETURN_TO_MAIN) {
PurgeInputErrors("Error: Invalid menu selection\n\n");
}
} while (key < ID || key > RETURN_TO_MAIN);
return key;
}
void PrintInvalidRecords() {
string errorFileName{ "ErrorFile.txt" };
ifstream Errfile(errorFileName);
stringstream ssHeader;
int invalidRecordCount{ 0 };
cout << fixed << showpoint << setprecision(2);
ssHeader << fixed << showpoint << setprecision(2) << left
<< setw(TEXT_WIDTH) << "Vehicle ID"
<< setw(TEXT_WIDTH) << "Model"
<< setw(NUM_WIDTH) << right << "Quantity"
<< setw(NUM_WIDTH) << "Price" << left << "\n\n";
if (!Errfile.is_open()) {
cout << "ERROR: Unable to open file.\n\n";
exit(EXIT_FAILURE);
}
else if (Errfile.peek() == EOF) {
cout << "No Invalid Records Found.\n\n";
}
else {
cout << "INVALID RECORDS\n"
<< setfill('-') << setw(HEADER_WIDTH) << "-" << "\n"
<< setfill(' ') << ssHeader.str();
string line;
while (getline(Errfile, line)) {
cout << line << endl;
}
cout << "\nTotal Records: " << invalidRecordCount << "\n"
<< setfill('-') << setw(HEADER_WIDTH) << "-" << "\n"
<< setfill(' ') << "\n\n";
Errfile.close();
}
}
// Clears the error state of cin and ignores any remaining invalid input in the buffer
void PurgeInputErrors(string errMess) {
cout << errMess;
if (cin.fail()) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
}
/*
TEST DATA
AB12MP349 Fusion5 20 17000.00 (Valid)
35KMOP324 Civic 7 11999.00 (Invalid Car ID: Contains 'O' in Car ID)
AB12MP34 RX5 1 17000.00 (Invalid Car ID: Incorrect length)
AB12MP349 gwaggon 17000.00 (Invalid Model Name: Contains non-alphanumeric characters)
XY34LK678 Mustang7 15 21500.00 (Valid)
KL67NM123 accord3 8 9800.00 (Invalid Model Name: Starting with lowercase)
PQ78RS901 Camry9 0 7500.00 (Valid)
JK90AB234 RX510 -3 7500.00 (Invalid Quantity: Negative quantity)
DE56FG789 Corolla4 12 6900.00 (Valid)
MN12CD567 Sonata6 5 6700.00 (Valid)
UV45EF890 Optima4 0 5200.00 (Valid)
UV45EF891 Optima5 0 5300.00 (Valid)
UV45EF892 Optima6 0 5400.00 (Valid)
GH23IJ457 Civic6 10 14500.00 (Valid)
GH23IJ458 Civic7 8 15000.00 (Valid)
ZA89BC124 Prius8 7 12000.00 (Valid)
ZA89BC125 Prius9 5 12500.00 (Valid)
AB12MP350 Fusion6 9 17500.00 (Valid)
AB12MP351 Fusion7 7 18000.00 (Valid)
XY34LK679 Mustang8 12 22500.00 (Valid)
XY34LK680 Mustang9 10 23000.00 (Valid)
KL67NM126 Accord6 6 11000.00 (Valid)
KL67NM127 Accord7 4 11500.00 (Valid)
PQ78RS904 Camry12 3 8100.00 (Valid)
PQ78RS905 Camry13 2 8200.00 (Valid)
JK90AB237 RX513 4 7900.00 (Valid)
JK90AB238 RX514 3 8000.00 (Valid)
DE56FG792 Corolla7 5 7300.00 (Valid)
DE56FG793 Corolla8 3 7400.00 (Valid)
MN12CD570 Sonata9 6 7100.00 (Valid)
MN12CD571 Sonata10 4 7200.00 (Valid)
ZA89BC123 Prius7 10 11000.00 (Valid)
35KMOP324 Fusion5 10 6700.00 (Invalid Car ID: Contains 'O' in Car ID)
AB12MP349 R 15 8800.00 (Invalid Model Name: Less than 3 characters)
XY34LK678 Mustang7 0 21500.00 (Invalid Quantity: Zero quantity)
KL67NM123 Accord3 6 3500.00 (Invalid Price: Below $5,000.00)
9PQRST123 MercC 7 9800.00 (Invalid Model Name: Contains non-alphanumeric characters)
MN12CD567 Sonata6 2 12000 (Invalid Price: Missing decimal)
UV45EF890 P 0 5200.00 (Invalid Model Name: Less than 3 characters)
AB12MP349 Fusion5 20 17000.00 (Valid)
XY34LK678 Mustang7 15 21500.00 (Valid)
KL67NM123 Accord3 8 9800.00 (Valid)
PQ78RS901 Camry9 0 7500.00 (Valid)
JK90AB234 RX510 10 7500.00 (Valid)
DE56FG789 Corolla4 12 6900.00 (Valid)
MN12CD567 Sonata6 5 6700.00 (Valid)
UV45EF890 Optima4 0 5200.00 (Valid)
GH23IJ456 Civic5 18 13500.00 (Valid)
ZA89BC123 Prius7 10 11000.00 (Valid)
KL67NM124 Accord4 5 10500.00 (Valid)
KL67NM125 Accord5 3 11500.00 (Valid)
PQ78RS902 Camry10 2 7600.00 (Valid)
PQ78RS903 Camry11 0 8000.00 (Valid)
JK90AB235 RX511 7 7700.00 (Valid)
JK90AB236 RX512 6 7800.00 (Valid)
DE56FG790 Corolla5 4 7100.00 (Valid)
DE56FG791 Corolla6 2 7200.00 (Valid)
MN12CD568 Sonata7 5 6900.00 (Valid)
MN12CD569 Sonata8 3 7000.00 (Valid)
GH23IJ456 Pass@t 1 1200.00 (Invalid Model Name: Contains non-alphanumeric characters)
ZA89BC123 Prius4 10 4200.00 (Valid)
JK78EF901 MustangGT 3 22000.00 (Valid)
LM12CD345 CorollaLE 12 15000.00 (Valid)
HJ23IJ486 Civic8 4 17700.00 (Valid)
XY56GH789 Wrangler4X4 8 28750.00 (Valid)
AB34JK567 CamryXSE 5 32000.00 (Valid)
OP67UV890 CivicSi 20 21000.00 (Valid)
PQ90RS123 SonataSEL 0 -17800.00 (Invalid Price: Negative price)
KL23MN456 ExplorerXLT 15 27000.00 (Valid)
EF45AB678 OptimaEX 10 23000.00 (Valid)
AZ12BC345 MustangGT500 1 75000.00 (Valid)
ZZ99YY123 CorvetteZ06 25 102000.00 (Valid)
AB12CD345 Corolla-SE 5 16500.00 (Invalid Model Name: Contains hyphen)
EF56GH789 ElectricCar 0 28000.00 (Valid)
OP67UV890 Sedan123 20 5000.00 (Valid)
KL23MN456 4RunnerLimited 8 50000.00 (Valid)
EF45AB678 LongModelName 10 5000.01 (Valid)
AB55AB678 OptimaEX 10 2300.00 (Invalid Price: Below $5,000.00)
----------- RUN PROGRAM THEN COPY PASTE OUTPUT HERE ---------------
*****Test Case #1: User inputs an invalid option in Main Menu*****
Menu:
Please select one of the following options:
1. Print all valid items in the inventory (unsorted)
2. Print invalid records
3. Quit program
Selection: asdf
ERROR: Invalid input. Please enter a valid option.
Menu:
Please select one of the following options:
1. Print all valid items in the inventory (unsorted)
2. Print invalid records
3. Quit program
Selection: -15
ERROR: Invalid input. Please enter a valid option.
Menu:
Please select one of the following options:
1. Print all valid items in the inventory (unsorted)
2. Print invalid records
3. Quit program
Selection:
*****Test Case #2: User inputs an invalid option in Sort Menu*****
Sort Menu:
Please select one of the following sorting options:
1. ID
2. Model
3. Quantity
4. Price
5. Return to Main Menu
Selection: asdf
Error: Invalid menu selection
Sort Menu:
Please select one of the following sorting options:
1. ID
2. Model
3. Quantity
4. Price
5. Return to Main Menu
Selection: 1234
Error: Invalid menu selection
Sort Menu:
Please select one of the following sorting options:
1. ID
2. Model
3. Quantity
4. Price
5. Return to Main Menu
Selection:
*****Test Case #3: The data file is empty*****
ERROR: 'Data.txt' is empty. No data to process. Terminating Program
*****Test Case #4: The data file contains only invalid records*****
Main Menu:
Please select one of the following options:
1. Valid Records
2. Invalid Records
3. Sort Inventory
4. Quit program
Selection: 1
VALID ITEMS IN THE INVENTORY
------------------------------------------------------
Vehicle ID Model Quantity Price
Total Records: 0
------------------------------------------------------
Main Menu:
Please select one of the following options:
1. Valid Records
2. Invalid Records
3. Sort Inventory
4. Quit program
Selection: 2
INVALID RECORDS
------------------------------------------------------
Vehicle ID Model Quantity Price
X234LK678 Mustang7 0 21500 Invalid ID: [ First 2 characters of Car ID must be letters alpha only (A-Z, letter O is not allowed) ]
KL670M123 Accord3 6 3500 Invalid Price: [ Price must be greater than $5000 ]
9PQRST123 MercC 7 9800 Invalid ID: [ First 2 characters of Car ID must be letters alpha only (A-Z, letter O is not allowed) ]
Total Records: 3
------------------------------------------------------
Main Menu:
Please select one of the following options:
1. Valid Records
2. Invalid Records
3. Sort Inventory
4. Quit program
Selection: 3
Terminating Program
*****Test Case #5: The data file contains only valid records*****
Main Menu:
Please select one of the following options:
1. Valid Records
2. Invalid Records
3. Sort Inventory
4. Quit program
Selection: 1
VALID ITEMS IN THE INVENTORY
------------------------------------------------------
Vehicle ID Model Quantity Price
AB12MP349 Fusion5 20 17000.00
KL23MN456 ExplorerXLT 15 27000.00
AZ12BC345 MustangGT500 1 75000.00
ZZ99YY123 CorvetteZ06 25 102000.00
EF56GH789 ElectricCar 0 28000.00
EF45AB678 LongModelName 10 5000.01
Total Records: 6
------------------------------------------------------
*****Test Case #6: Only Invalid Records - Sort Menu*****
Main Menu:
Please select one of the following options:
1. Valid Records
2. Invalid Records
3. Sort Inventory
4. Quit program
Selection: 3
Sort Menu:
Please select one of the following sorting options:
1. ID
2. Model
3. Quantity
4. Price
5. Return to Main Menu
Selection: 3
Sorting by Quantity
VALID ITEMS IN THE INVENTORY
------------------------------------------------------
Vehicle ID Model Quantity Price
Total Records: 0
------------------------------------------------------
Main Menu:
Please select one of the following options:
1. Valid Records
2. Invalid Records
3. Sort Inventory
4. Quit program
Selection: 3
Sort Menu:
Please select one of the following sorting options:
1. ID
2. Model
3. Quantity
4. Price
5. Return to Main Menu
Selection: 4
Sorting by Price
VALID ITEMS IN THE INVENTORY
------------------------------------------------------
Vehicle ID Model Quantity Price
Total Records: 0
------------------------------------------------------
Main Menu:
Please select one of the following options:
1. Valid Records
2. Invalid Records
3. Sort Inventory
4. Quit program
Selection:
*****Test Case #7: *****
*/