Using C++ IN NEW YORK CITY home of the winningest sports franchise ever The Scra
ID: 661577 • Letter: U
Question
Using C++
IN NEW YORK CITY
home of the winningest sports franchise ever
The Scratchemup Parking Garage contains a single lane that holds up to six cars. Cars arrive at the south end of the garage and leave from the north end. If a customer arrives to pick up a car that is not the northernmost, all cars to the north of his car are moved out, his car is driven out, and the other cars are restored in the same order that they were in originally. Whenever a car leaves, all cars to the south are moved forward so that at all times all the empty spaces are in
the south part of the garage.
Write a program that reads a group of input lines. Each line contains an 'a' for arrival or a d' for departure and a license plate number. Cars are assumed to arrive and depart in the order
specified by the input. The program should print a message each time that a car arrives or departs. When a car arrives, the message should specify whether or not there is room in the garage for the car. If there is no room for a car, the car then proceeds to the Bashemup garage...which is similar to the Scratchemup.
There is room for 6 cars at the Bashemup Garage. Now...if both garages are filled up, cars wait in the street near the Scratchemup garage for a space..and of course they are queued up in the street as well. The street can hold only 6 cars. If more than 6 cars try to wait in the street the cars are told to go to BOSTON.
So in summary...when a car arrives it tries to park in the Scratchemup
If no room it goes to the Bashemup...If still no room it tries to park in the street
When a car departs a message should indicate where it departed from (i.e. which garage or the street).
If there is a car waiting to get in the garage (because both are full) then the first car in the street queue must be moved into the garage that now has room and a message stating this must appear.
A message must appear every time a car enters or leaves a garage OR the street.must be interactive
When a car exits the garage (but NOT the street) the parking fee must be also be displayed as follows:
Cars at front of queue : $40
Cars next in line: $40 + $2 for each place behind front of queue
(i.e. , if a car is third in queue it would cost $ 40 + 2* $ 2 =$ 44
The possibility also exists that the car you are looking for is not there!!
Hey this is the BIG APPLE!
First try it with integers then try strings
When we exit the program it should indicate how many cars are in each garage and the street
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
const int maxqueue = 5;
class queue_type
{
public:
void clear_queue();
bool empty_queue();
bool full_queue();
void insert_queue(string numb, int move);
void delete_queue(string& numb, int& move);
string queue[6];
int moved[6];
int front,rear;
};
int main() {
queue_type scratch;
queue_type knock;
queue_type street;
char input = '*';
string license;
string license2;
bool found = false;
int move;
scratch.clear_queue();
knock.clear_queue();
street.clear_queue();
while (input != 'q') {
cout << " Enter vehicle's license plate: ";
cin >> license;
cout << "Is license plate " << license << " arriving or departing? ";
cin >> input;
if (input == 'a')
{
if (! scratch.full_queue())
{ scratch.insert_queue(license, 0);
cout << " There is room in Scratchemup Garage for license plate number " << license << endl;
if (scratch.full_queue()) {
cout << " The Scratchemup Garage is now full! " << endl;
cout << "All other vehicle's will now be brought to Knockemdead Garage " << endl;
} }
else
{ if (! knock.full_queue())
{knock.insert_queue(license, 0);
cout << " There is room in Knockemdead Garage for license plate number " << license << endl;
if (knock.full_queue()) {
cout << " The Knockemdead Garage is now full! " << endl;
cout << "All other vehicle's will now be brought to the street " << endl;
}
}
if (! street.full_queue())
else
{
street.insert_queue(license, 0);
cout << " There is room in the street for license plate number " << license << endl;
if (street.full_queue()) {
cout << "The street is now full! " << endl;
cout << "No more cars are allowed to arrive " << endl;
}
}
else cout << " There is no room in the street for license plate number " << license << endl;
}
}
if (input == 'd')
{
for (int i =0; i < maxqueue; i++)
{
if (! scratch.empty_queue()) { scratch.delete_queue(license2, move);
131 if (license == license2) {
133 found = true;
134 move = move + 1;
136 cout << "License plate number " << license << " has been moved "<< move << " times " << endl;
137 cout << " License plate number " << license << " has departed from Scratchemup Garage " << endl;
138 }
140 else
141 {
142 if (found&& !scratch.empty_queue())
143 move = move + 1;
145 scratch.insert_queue(license2, move);
147 }
148 }
150 }
152 if (! found) {
154 for (int i = 0; i < maxqueue; i++)
156 {
158 if (! knock.empty_queue()) {
160 knock.delete_queue(license2, move);
162 if (license == license2) { found = true;
165 move = move + 1;
167 cout << "License plate number " << license << " has been moved "<< move << " times " << endl;
168 cout << " License plate number " << license << " has departed from Knockemdead Garage " << endl;
169 }
else
172 {
if (found&& !knock.empty_queue())
175 move = move + 1;
knock.insert_queue(license2, move);
}
180 }
181
182 }
183
184 }
185
186 if (! found) {
187
188 for (int i = 0; i < maxqueue; i++)
189
190 {
191
192 if (! street.empty_queue()) {
193
194 street.delete_queue(license2, move);
195
196 if (license == license2) {
197
198 found = true;
199
200 cout << "License plate number " << license << " has been moved 0 times " << endl;
201 cout << " License plate number " << license << " has departed from the street " << endl;
202 }
203
204 else
205 street.insert_queue(license2, 0);
206
207 }
208
209 }
210
211 }
212
213 found = false;
214
215 }
216
217
218 }
219
220 }
221
222
223 void queue_type::clear_queue()
224 {
225
226 front = maxqueue;
227
228 rear = maxqueue;
229
230 }
231
232 bool queue_type::empty_queue()
233
234 {
235
236 if (rear == front)
237
238 return true;
239
240 else
241
242 return false;
243
244 }
245
246 bool queue_type::full_queue()
247
248 {
249
250 int querear;
251
252 if (rear == maxqueue)
253
254 querear = 0;
255
256 else
257
258 querear = rear + 1;
259
260 if (querear == front)
261
262 return true;
263
264 else
265
266 return false;
}
void queue_type::insert_queue(string numb, int move)
{
if (rear == maxqueue)
rear = 0;
else
rear = rear + 1;
queue[rear] = numb;
moved[rear] = move;
}
void queue_type::delete_queue(string& numb, int& move)
{
if (front == maxqueue)
front = 0;
else
front = front + 1;
numb = queue[front];
move = moved[front];
moved[front] = 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.