Question: C + + Please revise my code so it can produce the exact sample output results. It currently is not producing the exact results. Write

C++
Please revise my code so it can produce the exact sample output 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 090015
P 091015
B 091520
P 092025
B 093050
P 094520
P 095525
B 100530
B 101510
P 103025
B 103530
B 104530
Sample Output:
Time 0900.15 PEOPLE ARRIVE, 15 PEOPLE NOW IN LINE.
Time 0910.15 PEOPLE ARRIVE, 30 PEOPLE NOW IN LINE.
Time 0915. BUS ARRIVES, PICKS UP 20.10 REMAIN.
Time 0920.25 PEOPLE ARRIVE, 35 PEOPLE NOW IN LINE.
Time 0930. BUS ARRIVES, PICKS UP 50.0 REMAIN.
Time 0945.20 PEOPLE ARRIVE, 20 PEOPLE NOW IN LINE.
Time 0955.25 PEOPLE ARRIVE, 45 PEOPLE NOW IN LINE.
Time 1005. BUS ARRIVES, PICKS UP 30.15 REMAIN.
Time 1015. BUS ARRIVES, PICKS UP 10.5 REMAIN.
Time 1030.25 PEOPLE ARRIVE, 30 PEOPLE NOW IN LINE.
Time 1035. BUS ARRIVES, PICKS UP 30.0 REMAIN.
Bus stop records complete.
My code:
//BusStopQueue.h
#pragma once
#include
#include
#include
using namespace std;
struct BusStop {
char code;
int arrival_time;
int numPeople;
};
struct NodeType {
BusStop busStop;
NodeType* next;
};
void enqueue(queue& busQueue, char code, int time, int numPeople){
BusStop newBusStop;
newBusStop.code = code;
newBusStop.arrival_time = time;
newBusStop.numPeople = numPeople;
busQueue.push(newBusStop);
}
void dequeue(queue& busQueue, int numPeople){
while (numPeople >0 && !busQueue.empty()){
BusStop frontBusStop = busQueue.front();
busQueue.pop();
if (frontBusStop.numPeople > numPeople){
frontBusStop.numPeople -= numPeople;
cout << "TIME "<< setw(4)<< setfill('0')<< frontBusStop.arrival_time <<". BUS ARRIVES, PICKS UP "<< numPeople <<"."<< frontBusStop.numPeople <<" REMAIN." << endl;
numPeople =0;
busQueue.push(frontBusStop); // Return the remaining people to the queue
}
else {
numPeople -= frontBusStop.numPeople;
cout << "TIME "<< setw(4)<< setfill('0')<< frontBusStop.arrival_time <<". BUS ARRIVES, PICKS UP "<< frontBusStop.numPeople <<".0 REMAIN." << endl;
}
}
}
//Driver.cpp
#include
#include "BusStopQueue.h"
int main(){
ifstream inputFile("input.txt");
if (!inputFile){
cerr << "Error opening input file." << endl;
return 1;
}
queue busQueue;
char code;
int time, numPeople;
while (inputFile >> code >> time >> numPeople){
if (code =='B'){
dequeue(busQueue, numPeople);
}
else if (code =='P'){
enqueue(busQueue, code, time, numPeople);
cout << "TIME "<< setw(4)<< setfill('0')<< time <<"."<< numPeople <<" PEOPLE ARRIVE, "<< busQueue.back().numPeople <<" PEOPLE NOW IN LINE." << endl;
}
}
// Process remaining buses in the queue
while (!busQueue.empty()){
BusStop frontBusStop = busQueue.front();
busQueue.pop();
cout << "TIME "<< setw(4)<< setfill('0')<< frontBusStop.arrival_time <<". BUS ARRIVES, PICKS UP "<< frontBusStop.numPeople <<".0 REMAIN." << endl;
}
cout << "Bus stop records complete." << endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!