Question: C + + Please revise my code so it can produce the correct results. It currently is not producing the exact results. Write a program
C
Please revise my code so it can produce the correct results. It currently is not producing the exact results.
Write a program that simulates a waiting line at a bus stop using a queue data structure. Each input
record comprises three elements: code B for bus arrival, P for people arrival a time, and a
numPeople representing the number of people for buses. Buses pick up people in the order they arrive,
with each bus departing once it reaches its capacity. When a B record is processed, print: TIME xxx
BUS ARRIVES, PICKS UP yyy PEOPLE. zzz REMAIN. When a P record is processed, print: TIME xxx xxx
PEOPLE ARRIVE, xxx PEOPLE NOW IN LINE.
input text file:
P
P
B
P
B
P
P
B
B
P
B
B
Sample Output:
Time PEOPLE ARRIVE, PEOPLE NOW IN LINE.
Time PEOPLE ARRIVE, PEOPLE NOW IN LINE.
Time BUS ARRIVES, PICKS UP REMAIN.
Time PEOPLE ARRIVE, PEOPLE NOW IN LINE.
Time BUS ARRIVES, PICKS UP REMAIN.
Time PEOPLE ARRIVE, PEOPLE NOW IN LINE.
Time PEOPLE ARRIVE, PEOPLE NOW IN LINE.
Time BUS ARRIVES, PICKS UP REMAIN.
Time BUS ARRIVES, PICKS UP REMAIN.
Time PEOPLE ARRIVE, PEOPLE NOW IN LINE.
Time BUS ARRIVES, PICKS UP REMAIN.
Bus stop records complete.
My code:
BusStopQueueh
#pragma once
#include
#include
using namespace std;
struct BusStop
char code;
int arrivaltime;
int numPeople;
;
struct NodeType
BusStop busStop;
NodeType next;
;
void enqueuequeue& busQueue, char code, int time, int numPeople
BusStop newBusStop;
newBusStop.code code;
newBusStop.arrivaltime time;
newBusStop.numPeople numPeople;
busQueue.pushnewBusStop;
void dequeuequeue& busQueue, int numPeople
while numPeople && busQueue.empty
BusStop frontBusStop busQueue.front;
busQueue.pop;
if frontBusStopnumPeople numPeople
frontBusStop.numPeople numPeople;
cout "TIME frontBusStop.arrivaltime BUS ARRIVES, PICKS UP numPeople frontBusStop.numPeople REMAIN." endl;
numPeople ;
busQueue.pushfrontBusStop; Return the remaining people to the queue
else
numPeople frontBusStop.numPeople;
cout "TIME frontBusStop.arrivaltime BUS ARRIVES, PICKS UP frontBusStop.numPeople REMAIN." endl;
Drivercpp
#include
#include
#include "BusStopQueue.h
int main
ifstream inputFileinputtxt;
if inputFile
cerr "Error opening input file." endl;
return ;
queue busQueue;
char code;
int time, numPeople;
while inputFile code time numPeople
if code B
dequeuebusQueue numPeople;
else if code P
enqueuebusQueue code, time, numPeople;
cout "TIME setw setfill time numPeople PEOPLE ARRIVE, busQueue.backnumPeople PEOPLE NOW IN LINE." endl;
Process remaining buses in the queue
while busQueue.empty
BusStop frontBusStop busQueue.front;
busQueue.pop;
cout "TIME setw setfill frontBusStop.arrivaltime BUS ARRIVES, PICKS UP frontBusStop.numPeople REMAIN." endl;
cout "Bus stop records complete." endl;
return ;
My Results Incorrect:
TIME PEOPLE ARRIVE, PEOPLE NOW IN LINE.
TIME PEOPLE ARRIVE, PEOPLE NOW IN LINE.
TIME BUS ARRIVES, PICKS UP REMAIN.
TIME BUS ARRIVES, PICKS UP REMAIN.
TIME PEOPLE ARRIVE, PEOPLE NOW IN LINE.
TIME BUS ARRIVES, PICKS UP REMAIN.
TIME BUS ARRIVES, PICKS UP REMAIN.
TIME PEOPLE ARRIVE, PEOPLE NOW IN LINE.
TIME PEOPLE ARRIVE, PEOPLE NOW IN LINE.
TIME BUS ARRIVES, PICKS UP REMAIN.
TIME BUS ARRIVES, PICKS UP REMAIN.
TIME BUS ARRIVES, PICKS UP REMAIN.
TIME PEOPLE ARRIVE, PEOPLE NOW IN LINE.
TIME BUS ARRIVES, PICKS UP REMAIN.
TIME BUS ARRIVES, PICKS UP REMAIN.
Bus stop records complete.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
