Help with Queues

There are two parking garages each have a maxqueue of 5. There is also a street that cars could wait until a spot opens up. When a spot opens up in one of the garages the first car in the street queue must be moved into that open spot. Also when the car exits the garage it must state which garage it came out of and the fee (if first spot in garage $10 second $20 and anything else $25). When I run the program it reads the fee if its in the first spot.

Here is my code:

#include <iostream>
#include <fstream>
using namespace std;

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

const int maxqueue = 5;
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, choice);
else if ((choice == 'd') || (choice == 'D'))
depart(car, choice);

}

/*return 0;*/
}

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

void enter(int car, char choice)
{


if (!(knock.full_queue()))
{
knock.insert_queue(car);
cout << "Car " << car << " has been parked in the Knockemdead Parking Garage. " << endl;
}
else if (!(bash.full_queue()))
{
bash.insert_queue(car);
cout << "Knockemdead is full! Car " << car << " has been parked in the Bashemup 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;
}
else
{
cout << "All lots are full! Go to Boston! " << endl;
}

cout << "Enter an 'a' OR 'A' if your car is arriving or enter a 'd' OR '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, choice);
else if ((choice == 'd') || (choice == 'D'))
depart(car, choice);

}

/*return choice;*/
}

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

void depart(int car, char choice)
{
int x = car;
int location = 1;

for (int i = 1; i < maxqueue; i++){
while (!(knock.empty_queue()))
{

if (knock.front != x)
{
knock.delete_queue(x);
temp.insert_queue(x);
}
else{
location = i;
knock.delete_queue(x);
cout << "Car " << car << " has been removed from KnockemDead garage " << endl;
temp.delete_queue(x);
knock.insert_queue(x);

if (location == 1)
{
cout << "Fee is $10" << endl;
}

if (location == 2)
{
cout << "Fee is $20" << endl;
}

else
{
cout << "Fee is $25" << endl;
}


}
}
location++;
}

}

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

void departB(int car, char choice)
{


}

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

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];
}
Last edited on
Topic archived. No new replies allowed.