-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshravan_karande_carInfo.cpp
194 lines (153 loc) · 5.01 KB
/
shravan_karande_carInfo.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
// ASU CSE310 Spring 2024 Assignment #1
// Name: Shravan Karande
// ASU ID: 1225888172
// Description: This program displays a menu of choices to a user
// and performs the chosen task. It will keep asking a user to
// enter the next choice until the choice of 'Q' (Quit) is entered.
#include <iostream>
#include <string>
#include "LinkedList.h"
using namespace std;
void printMenu();
int main()
{
// local variables, can be accessed anywhere from the main method
char input1 = 'Z';
string inputInfo;
string model, make, oldModelAndMake, newModelAndMake;
int vin;
double price;
string line;
bool success = false;
// instantiate a Linked List object
LinkedList *list1 = new LinkedList();
printMenu();
do // ask for user input
{
cout << "\nWhat action would you like to perform?\n";
cin.get(input1);
input1 = toupper(input1); // change it to upper case
cin.ignore(20, '\n'); // flush the buffer
// matches one of the following cases
switch (input1)
{
case 'A': // Add the Car
cout << "Please enter the Car information:\n";
cout << "Enter Car Model:\n";
getline(cin, model);
cout << "Enter Car Make:\n";
getline(cin, make);
cout << "Enter Car Vin:\n";
cin >> vin;
cout << "Enter Car Price:\n";
cin >> price;
cin.ignore(20, '\n'); // flush the buffer
success = list1->addCar(model, make, vin, price);
if (success == true)
cout << "Car \"" << model << " " << make << "\" is added\n";
else
cout << "Car \"" << model << " " << make << "\" is NOT added\n";
break;
case 'C': // Change Car model and make
cout << "Please enter the Car vin which you want to change the model and make:\n";
cin >> vin;
cout << "\nPlease enter the new model and make: \n";
cin.ignore(20, '\n'); // flush the buffer
getline(cin, newModelAndMake);
list1->changeCarInfo(vin, newModelAndMake);
break;
case 'D': // Display all Cars
list1->printCarList();
break;
case 'E': // Display Cars by make
cout << "\nPlease enter Car make which you want to display:\n";
cin >> make;
cin.ignore(20, '\n');
list1->printCarListByMake(make);
break;
case 'F': // Find a Car
cout << "\nPlease enter the car VIN you want to search:\n";
cin >> vin;
cin.ignore(20, '\n'); // flush the buffer
if (list1->findCar(vin) == true)
{
cout << "Car with VIN #: " << vin << " was found" << endl;
}
else
{
cout << "Car with VIN #: " << vin << " was NOT found" << endl;
}
break;
case 'P': // Update a Car price
cout << "\nPlease enter the Car VIN you want to update the price:\n";
cin >> vin;
cin.ignore(20, '\n');
if(list1->findCar(vin) == true)
{
cout << "\nPlease enter the new price:\n";
cin >> price;
cin.ignore(20, '\n');
list1->updateCarPrice(vin, price);
}
else {
cout<<"Car with VIN #: " << vin << " does NOT exist";
}
break;
case 'R': // Remove a Car from the list by VIN
cout << "\nPlease enter the Car VIN to remove:\n";
cin >> vin;
cin.ignore(20, '\n'); // flush the buffer
if (list1->removeByVin(vin) == true)
{
cout << "\nCar with VIN #: " << vin << " was removed" << endl;
}
else
{
cout << "\nCar with VIN #: " << vin << " does NOT exist" << endl;
}
break;
case 'S': // Remove a Car from the list by model and make
cout << "Please enter Car model you want to remove:\n";
getline(cin, model);
cout << "Please enter Car make you want to remove:\n";
getline(cin, make);
if(list1->removeByModelAndMake(model, make)==true) {
cout << "\nCar: " << make << " " << model << " was removed" << endl;
}
// {
// cout << "request granted" << endl;
// }ddd
// else
// {
// cout << "..I." << endl;
// }
break;
case 'Q': // Quit
delete list1;
break;
case '?': // Display Menu
printMenu();
break;
default:
cout << "Unknown action\n";
break;
}
} while (input1 != 'Q');
return 0;
}
/** The method printMenu displays the menu to a user**/
void printMenu()
{
cout << "Choice\t\tAction\n";
cout << "------\t\t------\n";
cout << "A\t\tAdd A Car\n";
cout << "C\t\tChange A Car Model and Make\n";
cout << "D\t\tDisplay All Cars\n";
cout << "E\t\tDisplay Cars by Make\n";
cout << "F\t\tFind A Car\n";
cout << "P\t\tUpdate Car price\n";
cout << "R\t\tRemove Car by VIN\n";
cout << "S\t\tRemove Car by Model and Make\n";
cout << "Q\t\tQuit\n";
cout << "?\t\tDisplay Help\n\n";
}