Project 3 write a c++ program.... IN BOSTON……… The city of champions! The Fenway
ID: 3669669 • Letter: P
Question
Project 3
write a c++ program....
IN BOSTON………
The city of champions!
The Fenway Parking Garage contains a single lane thatholds up to 5cars. Cars arrive at the south end of the garage and leave from the north end. If a customer arrives topick 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 inoriginally. Whenever a car leaves, all cars to the south are moved forward so that at all times all the empty spaces are inthe south part of the garage.
Write a program that will read an 'a' for arrival or a d' for departure or ‘q’ for quit. When then ask for a license plate number (must be a string). The program should print a message eachtime that a car arrives or departs. When a car arrives, themessage should specify whether or not there is room in thegarage for the car. If there is no room for a car, the car then proceeds to the Garden garage...which is similar to theFenway.
There is room for 6cars at the Garden Garage.Now...if both garages are filled up, cars wait in the streetnear the Fenwaygarage for a space...and of course they are linedup in the street as well. The street can hold only 4 cars. If more than 4 cars try to wait in the street the cars are told to go to New York City.
So in summary...when a car arrives it tries to park in Fenway
If there is no room it goes to the Garden...If still no room it tries to park in the street
INDICATE BY MESSAGE WHERE A CAR GOES WHEN IT ARRIVES
When a car departs a message should indicate where it departed from (i.e. whichgarage 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 must be moved into the garage that now has room and a message stating this must appear.
When a car exits either garage (but NOT the street) the parking fee must be also be displayed as follows:
If the car is at the front of the queue when about to depart fee is $ 10
If the car is second in the queue the fee is $15
If the car is 3rd the fee is $ 20
…and so on
No fee for departing from street
The possibility also exists that the car you are looking for is not there!!
Hey this is the Bean Town!
When we exit the program it should indicate how many cars are in each garage and the street and the total of the fees collected!
Explanation / Answer
#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];
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.