| dangles19 (5) | |||
|
Okay so I am having trouble with my depart function. When I output I keep getting 0 for the license plate number and the count for each time a car moves is not right. Any help would be great. Thank you. ____________________________________________ The BASHEMUP Parking Garage contains a single lane that holds up to 7 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 in BASHEMUP , the car then proceeds to the Knockemdead garage...which is similar to the BASHEMUP. There is room for 7 cars at the Knockemdead garage. Now...if both garages are filled up, cars wait in the street near the BASHEMUP garage for a space..and of course they are queued up in the street. The size of the street queue is also 7. I will not allow more than 21 cars total so don't worry about overflow on the street! So in summary...when a car arrives it tries to park in the BASHEMUP If no room it goes to the Knockemdead...a message indicates which garage it is in.....When a car departs a message indicates that a car has departed and also indicates which garage... Now here is the challenge... When a car departs, the message should 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 the car departs from the street queue. Also if both garages are full and a car departs from either garage, the car in front of the street queue moves into the garage and there MUST be a message indicating which car moved from the street and which garage it moved to. Try to use strings for license plate numbers. Also print out a summary of what is left in the garage(s) and street when the program ends.
| |||
|
|
|||
| toum (170) | |||||
|
The problem is that your queue and your depart function don't do what they are supposed to do. 1) The queue - You remove the cars from the front of the queue. This is not what is asked from you. Your remove method should take a car ID as argument, look for the car with this ID in the queue and remove it. Removing means moving up all the cars located after the removed car. - The number of time a car has moved can not be computed outside the queue. You have to store that information in your queue class. A simple way to do that would be to use a structure to store car related information :
2) The depart() function - It should have only 1 argument : the ID of the car that departs - Explaining what's wrong is complicated, so I wrote what you have to do in pseudo-code:
Hope that helps. | |||||
|
|
|||||