Question

The Parking Garage Problem

The Scratchemup parking garage contains a single lane that holds up to 10 cars. Cars arrive at the south end of the garage and leave from the north end. If a customerarrives to pick up a car that is not the northernmost, all cars to the north of his car are moved out, her car is driven out, and the other cars are restored in thesame 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 partof the garage.
Write a program that reads a group of input lines. Each line contains an a for arrival and d for departure and a license plate number (example: 979WJC). Cars areassumed 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 car arrives, themessage 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 Knockemdead garage...whichis similar to the Scratchemup. There is room for 8 cars at the Knockemdead garage. If both garages are full, cars wait in the street near the Scratchemup garage for aspace...and of course they are queued up in the street. The size of the street queue is also 8.
So in summary, when a car arrives it tries to park in the Scratchemup garage. If there is no room, it goes to the Knockemdead garage. If there is no room there, itwaits in the street. A message indicates which garage it is in (or the street). When room becomes available, and a car moves from the street to one of the garages,another message should be printed. When a car departs, a message indicates that a car has departed and also indicates which garage (or the street). This departuremessage should also include the number of times the car was moved within the garage (including the departure itself, but not the arrival). This number is zero if thecar departs from the street and not from one of the garages.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include

#include

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 << "\nEnter 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 << "\nThere is room in Scratchemup Garage for license plate number " << license << endl;
if (scratch.full_queue()) {
cout << "\nThe 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 << "\nThere is room in Knockemdead Garage for license plate number " << license << endl;
if (knock.full_queue()) {
cout << "\nThe 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 << "\nThere 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 << "\nThere 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 << "\nLicense 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 << "\nLicense 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 << "\nLicense 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;
}

Add a comment
Know the answer?
Add Answer to:
The Parking Garage Problem
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The laughs parking garage contains a single lane that hold up to ten cars. Cars arrive...

    The laughs parking garage contains a single lane that hold up to ten 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 northernmost, all the cars to the north of his car are moved out, his car is driven out, and the others cars are restored in the same order that they were in originally. Whenever a car leaves, all the...

  • The CSC326 parking garage contains 2 lanes, each capable of holding up to 10 cars. There...

    The CSC326 parking garage contains 2 lanes, each capable of holding up to 10 cars. There is only a single entrace/exit to the garage at one end of the lanes. If a customer arrives to pick up a car which is not nearest the exit, all cars blocking the car's path are moved into the other lane. If more cars still must be moved out of the way, they go into the street. When the customer's car is driven out,...

  • PLease, I need help with this Code. PLease create correctly documentations comments for better understanding. This...

    PLease, I need help with this Code. PLease create correctly documentations comments for better understanding. This is the input: JAV001 ARRIVE JAV002 ARRIVE JAV003 ARRIVE JAV004 ARRIVE JAV005 ARRIVE JAV001 DEPART JAV004 DEPART JAV006 ARRIVE JAV007 ARRIVE JAV008 ARRIVE JAV009 ARRIVE JAV010 ARRIVE JAV011 ARRIVE JAV012 ARRIVE JAV013 ARRIVE JAV014 ARRIVE JAV006 DEPART JAV014 DEPART JAV013 DEPART JAV005 DEPART JAV015 ARRIVE JAV010 DEPART JAV002 DEPART JAV015 DEPART JAV014 DEPART JAV009 DEPART JAV003 DEPART JAV008 DEPART JAV007 DEPART JAV012 DEPART JAV011...

  • Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from...

    Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from the previous assignment and modify it so that it uses an array of Car objects as the principal data structure instead of an ArrayList-of-Car. This is an example of the OOP principle of information hiding as your Car and test classes will not have to be modified at all. Unless you broke encapsulationon the previous assignment, that is   II. Specifications Specifications for all 3...

  • Objective: To implement the programming languages features discussed in class and to develop a program that...

    Objective: To implement the programming languages features discussed in class and to develop a program that uses Graphical User Interfaces (GUI) that provides a friendly environment for users. Project Assignment Design and implement a Hotel Reservation System. The hotel has two types of rooms. One is regular room that has two beds. Another is deluxe room that has two beds and a safe. The regular room price is $120 per night. The deluxe room is $130 per night. A safe...

  • Can someone help me get started on this question? I am not sure where to begin...

    Can someone help me get started on this question? I am not sure where to begin here. Thank you! Question B: Car traffic arrives at a large toll plaza at different rates depending on the time of day. The rate (in cars-per-hour) at time "t" is r(t) = 5000*(1 - 0.8cos(2 pit/24)) for t measured in hours between 0 and 24. i) Define A(T) = the # of cars that have arrived by time "T". Find a formula for A(T)....

  • Alpine-Himalayan Ocean Paoiño Ocean Ocean Deep eartho EXERCISE 16.2 Locating Earthquake Epicenters Name: Course Section: Date:...

    Alpine-Himalayan Ocean Paoiño Ocean Ocean Deep eartho EXERCISE 16.2 Locating Earthquake Epicenters Name: Course Section: Date: This exercise leads you through the reasoning used to calculate the distance from a seismic station to epicenter. But instead of two different seismic waves, let's see first how this works with two cars that start along a road at exactly the same time (see the figure on the next page). Both use cruise control set at 1 mile per minute (60 miles per...

  • What rates should be charged? Downtown Parking Authority In January a meeting was held in the office of the mayor of Oa...

    What rates should be charged? Downtown Parking Authority In January a meeting was held in the office of the mayor of Oakmont to discuss a unicipal parking facility. The participants included the mayor, the traffic proposca the administrator of Oakmont's Downtown Parking Authority, the city planner, and the finance director. The purpose of the meeting was to consider a report Richard Stockton, executive assistant to the Parking Authority's administrator, concerning estimated costs and revenues for the proposed facility. Mr. Stockton's...

  • What additional information, if any, should be obtained before making a final decision? Downtown Parking Authority In J...

    What additional information, if any, should be obtained before making a final decision? Downtown Parking Authority In January a meeting was held in the office of the mayor of Oakmont to discuss a unicipal parking facility. The participants included the mayor, the traffic proposca the administrator of Oakmont's Downtown Parking Authority, the city planner, and the finance director. The purpose of the meeting was to consider a report Richard Stockton, executive assistant to the Parking Authority's administrator, concerning estimated costs...

  • I need help in C++ . Project 3 – Parking Deck Ticketing System Objectives: Use if,...

    I need help in C++ . Project 3 – Parking Deck Ticketing System Objectives: Use if, switch, and loop statements to solve a problem. Use input and output statements to model a real world application Incorporate functions to divide the program into smaller segments Instructions: Your task is to write a program that simulates a parking meter within the parking deck. The program will start by reading in the time a car arrives in the parking deck. It will then...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT