#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0

    C++ Queue Simulator


    Based on the question below, I have finished Part 1 of the Sales System. Going into Part 2, there are things that I don't really get.

    My ideas :

    First is, Save all records into a file so that two instances of the program can access the file. The thing is, it does not 'click 'with the requirement. We can't access a file by 2 programs simultaneously, can we?

    Second, create an "in-program" queue - where only an instance of the program is run and queue could be a simple array or LinkList. What I don't get is, when/how to create and store the customer on that queue? The program need to be interrupted to prompt for adding a customer into queue (while it is running)? it just does not make any sense to me...

    Any other ideas? or perhaps some comment in implementing my ideas? thanks

    Problem Statement

    You are hired to develop a sales system for cinema ticket and a simulator for queuing. The business
    rules are listed below:

    Code:
    Part 1 Sales System (13 marks):
    All tickets are priced at RM10 per person.
    There are 3 types of customers:
           Non-member: No annual fee, do not enjoy any discount or benefit.
           Gold member: RM10 annual fee, enjoy a 10% discount for every ticket purchased.
           Platinum member: RM50 annual fee, enjoy a 20% discount for every ticket purchased and
    get a free ticket for every 5 tickets purchased.
    
    Part 2 Queue Simulator (2 marks)
    There are 2 sale counters serving one queue. Your program may start (and loop) by asking the
    user to choose one of the following 3 options:
           A customer joins the queue.
           Counter 1 takes the next customer.
           Counter 2 takes the next customer.
    
    For every option selected, your simulator should list following:
           The queue.
           The customers already served by the counters.
           The customers currently being served by the counters.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    I don't think you need two programs or shared memory, although that scheme could work. I would maintain a queue of customers awaiting service. And a loop.
    At each iteration {
    Some probability for a new customer to joins the queue.
    If counter 1 is open it handles a customer*.
    If counter 2 is open it handles a customer.
    }

    The service time is sampled from a distribution.
    The probability for a customer to join the queue comes from some distribution.

    Does the employee at counter 2 get a 15 minute break?
    Do diners arrive faster at noon than at 2PM?
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0
    Originally Posted by b49P23TIvg
    I don't think you need two programs or shared memory, although that scheme could work. I would maintain a queue of customers awaiting service. And a loop.
    At each iteration {
    Some probability for a new customer to joins the queue.
    If counter 1 is open it handles a customer*.
    If counter 2 is open it handles a customer.
    }

    The service time is sampled from a distribution.
    The probability for a customer to join the queue comes from some distribution.

    Does the employee at counter 2 get a 15 minute break?
    Do diners arrive faster at noon than at 2PM?

    That sounds like implement-able. I will try working on it. Btw I will update the post with codes of my program to make it clearer how suitable it is to implement the "queue simulator"
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0
    hmmm, however I look at it, it make sense if I write another program to call the previously written program (part 1)...making the queue simulator now as the main program...is that what you have in mind?
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    I didn't know, for certain, the two problems were related.

    Here's a great thread that shows how to decompose a problem from the top down into little functions that you can reuse across multiple programs. It's written in java but the idea holds.
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,614
    Rep Power
    1945
    Originally Posted by b49P23TIvg
    I don't think you need two programs or shared memory, although that scheme could work. I would maintain a queue of customers awaiting service. And a loop.
    At each iteration {
    Some probability for a new customer to joins the queue.
    If counter 1 is open it handles a customer*.
    If counter 2 is open it handles a customer.
    }

    The service time is sampled from a distribution.
    The probability for a customer to join the queue comes from some distribution.

    Does the employee at counter 2 get a 15 minute break?
    Do diners arrive faster at noon than at 2PM?
    As far as i can read, it sounds more it is the user that decide when a new customer arrive and when a customer get to a counter.

    something like this:
    user action: join a customer to the queue -> 1 customer in queue, 0 customer currently served at counter, 0 customer already been served
    user action: join a customer to the queue -> 2 customer in queue, 0 customer currently served at counter, 0 customer already been served
    user action: counter 1 takes next customer -> 1 customer in queue, 1 customer currently served at counter, 0 customer already been served
    user action: counter 1 takes next customer -> 0 customer in queue, 1 customer currently served at counter, 1 customer already been served
    etc..
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0
    Hi guys,

    to be frank, it's not the algorithm for 'queue' that I am not sure of. It is 'how to implement it with the rest of the program (part 1)'
  14. #8
  15. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Since you know how to find items off queues, with a pop or look method, I thinking that you didn't read the entire link I provided at post 5. Click the underlined text.
    [code]Code tags[/code] are essential for python code and Makefiles!
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Since you know how to find items off queues, with a pop or look method, I thinking that you didn't read the entire link I provided at post 5. Click the underlined text.
    I did read and I think I understand the 'points' of the post. The 2nd page's were right on.

    However, it seems that I have mistakenly bring ups some wrong ideas here. In relation to my ideas in the first post, given some times, I think I would be able to tackle the question, of course with research and stuff.

    what I want is the 'right' way to tackle the question.....programming wise, from you all experts and much well knowledgeable than me.

    btw, at the end, I did implement some simple queue (just another array of class object) on top of the program, with 2 'simultaneous' users, within the same program.

    but to be frank, still doesnt 'feel' right to me.

IMN logo majestic logo threadwatch logo seochat tools logo