View the step-by-step solution to:

Question

Assignment:

Queues are often used to represent lists of things that are being processed

according to the order in which they arrived -- i.e. "first come, first served".  

Assignment

program that simulates the minute-by-minute operation of a checkout line, such as one you might find in a retail store. Use the following parameters:

1) Customers arrive at the checkout line and stand in line until the cashier is free.

2) When they reach the front of the line, they occupy the cashier for some period of time (referred to as ServiceTime) measured in minutes.

3) After the cashier is free, the next customer is served immediately.

4) Customers arrive at the checkout line at ArrivalRate per minute. Use the function included below (randomChance()) to return the number of customers arriving in a given minute, determined randomly.

5) The line can only hold so many people, MaxLineSize, until new arriving customers get frustrated and leave the store without purchasing anything.

6) ServiceTime is determined at the point the customer reaches the cashier, and should be taken from the random interval MinServiceTime and MaxServiceTime -- use the function randomInt() provided.

7) The overall time of the simulation is SimulationTime, measured in minutes.

The program should take 6 inputs (to be read from a text file named simulation.txt, as numbers only, one per line, in this order):

- SimulationTime - total number of minutes to run the simulation (whole number).

ArrivalRate - per-minute arrival rate of customers (a floating point number greater than 0 and less than 1). This number is the "percent chance" that a customer will arrive in a given minute. For example, if it is 0.4, there is a 40% chance a customer will arrive in that minute.

MinServiceTime - the minimum expected service time, in minutes (whole number).

MaxServiceTime - the maximum expected service time, in minutes (whole number).

MaxLineSize - the maximum size of the line. If a new customer arrives and the line has this many customers waiting, the new customer leaves the store unserviced.

IrateCustomerThreshold - nobody enjoys standing in line, right? This represents the number of minutes after which a customer becomes angry waiting in line (a whole number, at least 1). These customers do not leave, they only need to be counted.

At the end of each simulation, the program should output:

- The total number of customers serviced

- The total number of customers who found the line too long and left the store.

- The average time per customer spent in line

- The average number of customers in line

- The number of irate customers (those that had to wait at least IrateCustomerThreshold minutes)

You are free to use any STL templates as needed (queue or vector, for example).


I need help on determining how to know if a customer is done and how to process the next. We are told to have one large outer for loop that goes minute by minute and if a customer arrives put them in queue at that current index of the for loop.



#include <iostream>

#include <queue>

#include <cstdlib>

#include <ctime>

#include <cstring>

#include <fstream>


using namespace std;


bool randomChance(double);

int randomInt(intint);


int main()

{

  srand(time(0));

  queue<int> Line;

  ifstream infile("sim.txt");


//Inputs from simulation.txt

  int SimulationTime, MinServiceTime, MaxServiceTime, MaxLineSize, IrateCustomerThreshold;

  double ArrivalRate;


//Stats Tracked

  int numCustomers=0, leftCustomers=0, irateCustomers=0,ServiceTime=0, timeToOpen = 0;

  double avgWaitTime=0, avgLineLen =0;

  bool isDone = false;


  while(!infile.eof())

  {

    infile >> SimulationTime;

    infile >> ArrivalRate;

    infile >> MinServiceTime;

    infile >> MaxServiceTime;

    infile >> MaxLineSize;

    infile >> IrateCustomerThreshold;


    


    for(int i = 0; i < SimulationTime; i++)

    {

      if(randomChance(ArrivalRate))

      {

        if(Line.size() == MaxLineSize)

          leftCustomers++;

        else

          Line.push(i);

      }



    }

  }


  avgWaitTime = avgWaitTime / numCustomers;

  avgLineLen = avgLineLen / SimulationTime;



  cout << "n Average wait time: " << avgWaitTime << endl;

  cout<<"Customers serviced:tt"<< numCustomers<<endl;

  cout<<"Customers leaving:tt"<<leftCustomers<<endl;


  infile.close();


  system("pause");

  return 0;

}



bool randomChance(double prob) { 

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

    return (rv < prob); 


int randomInt(int minint max) { 

    return (rand() % (max - min) + min); 

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes