Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ help! Hey! I'm having trouble executing my while loop for reading a file. It doesn't end and my getline isn't reading the next 5

C++ help!

Hey! I'm having trouble executing my while loop for reading a file. It doesn't end and my getline isn't reading the next 5 increments. Here is my code, input file, and error below. Thank you so much!!

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

//

// Returns 'true' if a customer arrived during this minute, using

// a random number.

//

bool customerArrived(double prob) {

double rv = rand() / (double(RAND_MAX) + 1);

return (rv

}

struct Customer {

int arrivalTime; // time customer arrived

int serviceTime; // time required for service

};

/* Main program */

int main() {

string simName;

int simTime;

int serviceTime;

int maxLineSize;

double arrivalRate; // per-minute arrival rate of customers

ifstream f("simtest.txt");

if (!f){

cout

return 1;

}

// seed random number generator

srand(time(0));

//simulation loop

getline(f, simName);

f >> simTime >> arrivalRate >> serviceTime >> maxLineSize;

while (!f.eof()){

//simulation variables

int totalCustomers = 0;

int totalDropped = 0;

int currentTime = 0;

int currentLineLength = 0;

int totalWait = 0;

queue line;

while (currentTime

// check if customer arrives

if (customerArrived(arrivalRate)){

if(currentLineLength

Customer c = {currentTime, serviceTime};

c.arrivalTime = currentTime;

line.push(c);

currentLineLength++;

} else {

totalDropped++;

}

}

// checks if the cashier is free, serve the next person

if(!line.empty()){

Customer c = line.back();

if((currentTime - c.arrivalTime) >= c.serviceTime){

totalCustomers++;

totalWait += (currentTime + c.serviceTime) - c.arrivalTime;

line.pop();

currentLineLength--;

}

}

currentTime++;

//totalWait++;

}

//output simulation results

// Left-justify everything

cout

// Print a table

cout

cout

cout

cout

cout

cout

cout

cout

cout static_castdouble>(totalWait)/totalCustomers

cout

double(totalWait)/simTime

cout

cout

getline(f, simName);

f >> simTime >> arrivalRate >> serviceTime >> maxLineSize;

}

return 0;

}

input file:

Short Lines 2000 0.1 15 5 Long Lines 2000 0.5 15 10 Mixed 2000 0.25 8 7 here's what i got:

image text in transcribedhere's what it's supposed to look like for one simulation (w/o the loop):

Simulation name: Short Lines -------------------------------------- Simulation time: 2000 Arrival rate: 0.1 Service time: 15 Max line size: 5 Customers served: 125 Average wait time: 66.688 Average line length: 4.246 Total dropped customers: 97

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

Defi ne grievance and identify the stages in a grievance procedure.

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago