Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++: Do a program that will simulate a drive-in for a new fast-food place, Taco

ID: 3765645 • Letter: C

Question

c++:

Do a program that will simulate a drive-in for a new fast-food place, Taco Fry, where you get good greasy food, Mexican style. Translate the pseudocode found in chapter 13. You may use a linked list for the eventList. Find the average wait for people going through the drive-in. Read the input from a sample file like:

20 5

22 4

23 2

30 3

The output would be:

Taco Fry drive-in

new event A 20 5

new event A 22 4

new event A 23 2

new event D 25

Customer at time 22 had to wait 3

new event D 29

Customer at time 23 had to wait 6

new event A 30 3

new event D 31

Customer at time 30 had to wait 1

new event D 34

Average wait time was 2.5

final psuedocode:

Explanation / Answer

#include "simulation.h"
#include <iostream>
#include <fstream>
using namespace std;
SimulateClass::SimulateClass():arrivalCount(-1),waitingTime(0),departureCalls(0),newEvent(0)
{
}
void SimulateClass::simulateBank()
{
bankQueue bQueue;
eventList eList;
ifstream inFile;
inFile.open("");
if (!inFile) cout << "error opening file. "; // will add exceptions later on
else
{
int arrivalTime;
inFile >> arrivalTime;
eList.push_front(arrivalTime);
newEvent = eList.front();
while (!eList.empty() )
{
newEvent = eList.front();
if ( (newEvent == eList.back() )
{
processArrival(newEvent, inFile, eList, bQueue );
++arrivalCount;
}
else
{
processDeparture(newEvent, eList, bQueue );
++departureCalls;
}
}
displaySimulation();
}
inFile.close();
}
void SimulateClass::processArrival( int arrivalEvent, ifstream &inFile , eventList &eList, bankQueue &bQueue )
{
int transactionTime, arrivalTime;
bool BoolFrontBQueue = bQueue.empty();
bQueue.push(arrivalEvent);
eList.remove(arrivalEvent);
if ( BoolFrontBQueue )
{
inFile >> transactionTime;
waitingTime = arrivalEvent + transactionTime;
eList.push_back(waitingTime);
}
if ( !inFile.eof() )
{
inFile >> arrivalTime;
++arrivalCount;
if ( arrivalTime <= eList.front() )
{
eList.push_front( arrivalTime );
}
else
{
// arrivalTime > eList.front()
eList.push_back(arrivalTime);
}
}
}
void SimulateClass::processDeparture(int departureEvent, eventList &eList, bankQueue &bQueue )
{
int transactionTime;
bQueue.pop();
eList.pop_front();
if (!bQueue.empty() )
{
transactionTime = eList.front();
waitingTime = departureEvent + transactionTime;
if ( waitingTime <= eList.front() )
{
eList.push_front( waitingTime );
}
else
{
// arrivalTime > eList.front()
eList.push_back(waitingTime);
}
}
}
void SimulateClass::displaySimulation()
{
cout << arrivalCount << " ";
double testCase = static_cast<double>(5.6)*10;
cout << testCase << " ";
cout << departureCalls;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote