Problem with queues with a parking garage

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.

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
#include <iostream>
#include <fstream>
using namespace std;

void enter (int car);
void depart (int car, char choice);

const int maxqueue = 7;
class queue_type

{
public:
		void clear_queue();
		bool empty_queue();
		bool full_queue();
		void insert_queue(int car);
		void delete_queue(int& car);
		int queue[8];
		int front,rear;
};

//---------------------------------------------------------------------

queue_type bash, knock, street, temp;

int main()
{
	int car;
	char choice;
	
	bash.clear_queue();
	knock.clear_queue();
	street.clear_queue();
	temp.clear_queue();

	cout << "Enter an 'a' if your car is arriving or enter a 'd' if your car is departing. Enter q to quit: " << endl;
	cin >> choice;
	cout << "Enter license plate number: " << endl;
	cin >> car;
	
	while ((choice!='q')||(choice!='Q'))
	{
		if ((choice=='a')||(choice=='A'))
			enter (car);
		else if ((choice=='d')||(choice=='D'))
			depart (car, choice);
		cin >> choice;
		cin >> car;
	}
	return 0;
}

//----------------------------------------------------------------------

void enter(int car)
{
	if (!(bash.full_queue()))
	{	
		bash.insert_queue(car);
		cout << "Car " << car << " has been parked in the BASHEMUP parking garage. " << endl;
	}
	else if(!(knock.full_queue()))
	{	
		knock.insert_queue(car);
		cout << "BASHEMUP is full! Car " << car << " has been parked in the KNOCKEMDEAD parking garage. " << endl;
	}
	else if (!(street.full_queue()))
	{
		street.insert_queue(car);
		cout << "Both lots are full! Car " << car << " has been parked in the street until a spot opens up. " << endl;
	}
}

//----------------------------------------------------------------------

void depart(int car, char choice)
{
	int k=0, i=0, m;
	int c1[7], c2[7], c3[7];
	while(i<7)
	{
		c1[i]=1;
		c2[i]=1;
		c3[i]=1;
		i++;
	}
	
	while (!(bash.empty_queue()))
	{
		bash.delete_queue(car);
		if (choice != car)
		{
			if (k==0)
			{
				m=c1[i];
				m++;
				c1[i]=m;
				cout << "Car " << car << " departed and moved " << c1[i] << " times" << endl;
				i++;
				temp.insert_queue(car);
			}
		}
			else 
			{
				cout << "Car Deleted" << endl;
				k=1;
			}
	}
	while (!(knock.empty_queue()))
	{
		knock.delete_queue(car);
		if (choice != car)
		{
			if (k==0)
			{
				m=c2[i];
				m++;
				c2[i]=m;
				cout << "Car " << car << " departed and moved " << c2[i] << " times" << endl;
				i++;
				temp.insert_queue(car);
			}
		}
			else 
			{
				cout << "Car Deleted" << endl;
				k=1;
			}
	}
	while (!(street.empty_queue()))
	{
		street.delete_queue(car);
		if (choice != car)
		{
			if (k==0)
			{
				m=c3[i];
				m++;
				c3[i]=m;
				cout << "Car " << car << " departed and moved " << c3[i] << " times" << endl;
				i++;
				temp.insert_queue(car);
			}
		}
		else 
			{
				cout << "Car Deleted" << endl;
				k=1;
			}
	}
}

//----------------------------------------------------------------------

void queue_type::clear_queue()
{
	front = maxqueue;
	rear = maxqueue;
}

//----------------------------------------------------------------------

bool queue_type::empty_queue()
{
	if (rear == front)
		return true;
	else
		return false;
}

//----------------------------------------------------------------------

bool queue_type::full_queue()
{
	int querear;
	if (rear == maxqueue)
		querear = 0;
	else
		querear = rear +1;
	if (querear == front)
		return true;
	else
		return false;
}

//----------------------------------------------------------------------

void queue_type::insert_queue(int car)
{
	if (rear == maxqueue)
		rear =0;
	else
		rear = rear + 1;
	car = queue[rear];
}

//----------------------------------------------------------------------

void queue_type::delete_queue(int& car)
{
	if (front == maxqueue)
		front = 0;
	else
		front = front + 1;
	car = queue[front];
}
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 :
1
2
3
4
5
struct CarInfo
{
    int ID;
    int NumberOfMoves;
};


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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void depart(int car)
{
    if( bash.contains(car) )
    {
        NumberOfMoves = bash.GetNumberOfMoves(car);
        bash.delete_queue(car);
        if( !street.empty_queue() )
        {
            ID = street.GetFirstCar();
            street.delete_queue(ID);
            bash.insert_queue(ID);
        }
    }
    else if( knock.contains(car) )
    {
        // same as bash, but for knock
    }
    else
    {
        street.delete_queue(car);
    }
}



Hope that helps.
Topic archived. No new replies allowed.