Thread: Use a linked list queue to simulate customers waiting in line

  1. #1
    Registered User
    Join Date
    Sep 2020

    Question Use a linked list queue to simulate customers waiting in line

    This is my first program working with queues and I have no idea where to start. Fair warning this is a long program. My main question is with the functions in the main program near the bottom of this post. I posted this question in order so you know what everything means.
    I read from a "customerList.txt" file in the format of id<tab>arrivalTime<tab>serviceTime:
    1          0         7
    2          0         3
    3          1         2
    4          3         1
    5          3         4
    I have 3 header files and one main program. I have a Queue.h, with normal queue member functions. I have a Cashier.h structure:
    struct Cashier
        int custid;
        int endTime;
        bool busy;
        custid = 0;
        endTime = 0;
        busy = false;
    And I have a Customer.h structure:
    struct Customer
        int id;
        int arrivalTime;
        int serviceTime;
        id = 0;
        arrivalTime = 0;
        serviceTime = 0;
    Now I have the Simulation.cpp program. This is where I am lost. In the main() I read the customers from the "customers.txt" file into an array of Customers (no more than 50 customer records). I add the customer to the queue at the appropriate time. Each of the three cashiers will process customers from the same queue. I have to use 3 functions in the Simulation.cpp. I have a general idea what to do but I don't know how to implement it.

    fillCustomerQueue: this function reads the text file and fills the customer queue when a correct time comes. For example, all customers with an arriving time the same as the current time should be enqueued. the prototype is:
    void fillCustomerQueue(ifstream &custData, LLQueue<Customer> &custList, Customer &custIn, int currentTime);
    processCustomers: for all cashiers, if not busy, should serve a customer. If busy and time for a job to end, end it. This is the prototype:
    void processCustomers(LLQueue<Customer> &custList, Cashier serv[], const int currectTime);
    isDone: returns true if all cashiers are no longer busy with customers. Check the current job statuses of each cashier with the current time to determine if they should still be busy. The prototype is:
    bool testCashier(Cashier serv[], LLQueue<Customer> &custList);
    In main() I have the following. I'm still working on this, I'm just sharing it so you know what the declarations look like:
    int main()
       Customer carray[50];    //all customers
       LLQueue<Customer> custList;    //customer arrival time
       Cashier cashiers[3];
       ifstream file;"customerList.txt");
       if (
          cout << "Can not open file.\n";
          int i = 0;
          while (file >> carray[i].id >> carray[i].arrivalTime >> carray[i].serviceTime)
       return 0;
    The function are what I really need help with. This is what I have so far in fillCustomerQueue. I don't know where to go from here:
    void fillCustomerQueue(ifstream &custData, LLQueue<Customer> &custList, Customer &custIn, int currentTime)
       Customer tempArray[50];
       int i = 0;
       while (tempArray[i].arrivalTime == currentTime)
    For isDone I just have a pseudocode of what the function should return.
    bool isDone(Cashier serv[], LLQueue<Customer> &custList)
         all cashiers not busy and && queue is empty == true
    For processCustomers I also have a pseudocode:
    void processCustomers(LLQueue<Customer> &custList, Cashier serv[], const int currentTime)
       for(all cashiers)
            if(cashier is busy)
                 cout << still busy
            if(cashier is busy && endTime == currentTime)
                  cashier = not busy
            if(cashier not busy)
                  delete queue from custList
                  set cashier's info
            if(cashier not busy && custList is empty)
                  cout << all cashier are free
    Last edited by meagangramlin; 09-30-2020 at 10:41 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Queue
    By BretFlorida in forum C Programming
    Replies: 4
    Last Post: 04-16-2013, 10:19 AM
  2. Linked List Queue
    By BretFlorida in forum C Programming
    Replies: 9
    Last Post: 03-28-2013, 07:06 PM
  3. standard linked list or Queue in C??
    By dayalsoap in forum C Programming
    Replies: 1
    Last Post: 06-13-2011, 02:12 PM
  4. linked-list queue
    By the_winky_files in forum C Programming
    Replies: 17
    Last Post: 11-21-2005, 03:57 PM
  5. Linked List Queue Implementation help
    By Kenogu Labz in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2005, 10:14 AM

Tags for this Thread