plz ineed help (very important) (program for print queue)

Discussion in 'Mac Programming' started by nnose, Apr 24, 2008.

  1. nnose macrumors newbie

    Joined:
    Apr 3, 2008
    #1
    asingle printer might be shared by all users of network.many users can send print jobs to the printer ,even when the printer is already busey.these print jobs are placed in a queue until the printer becomes available.then the print job with the highest priority is sent to printer first.
    write a c++ programme that implement the previous queue using linked list.assume this queue has two priorities 0 and 1,each job has an id and priority.
    1-load initial list of jobs from auser specified input file into queue.
    2-view queue contents of waiting jobs.
    3-perform serve and append operation on queue.
    plz any one help me or give somthing to help me pleeeeeez?
     
  2. GoCubsGo macrumors Nehalem

    GoCubsGo

    Joined:
    Feb 19, 2005
    #2
    This reads like a riddle...or a math problem.
    I pick #3. Let me know if I'm right.
     
  3. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    This is *your* homework. You should at least take a crack at it before asking for help.

    I don't know how "object-oriented" this needs to be. It's C++ so each print job could be an object, and probably should be (If it was just C, it would be a struct). It would need fields to hold that particular job's priority and its ID. It should have accessors for each of these fields, but probably not mutators as they should not change after they are created (that isn't in the scope given above, at least). The constructor should take a job ID and priority. If you need to generate the job ids instead of taking fixed IDs you would need a static member of the class that can be incremented each time a job is created and that can be used in the constructor to generate the job ID instead of accepting one. Then the constructor would only take a single argument for the priority.

    I think the point of the assignment is to use your own linked list class instead of using existing classes, so you'd need a linked list class that has a current position field, and a field to hold the starting node. If it's doubly-linked you could have a field for the last node if you wanted to be able to iterate backwards. Even if it is singly linked, it might be best to have a field for the last node for easy addition of a new node. You should also have a node class that has a field for the next node, the previous node if it is doubly-linked, and a field that holds the instance of the print job class defined above.

    Since this takes priority into account you can approach it in different ways. You can have two linked lists in a new queue class, one for priority 0 jobs, one for priority 1 jobs. You only schedule a priority 1 job if there are no priority 0 jobs. You could keep a single linked list, but on insertion you could place the new node in the right place in the list to keep it "sorted" by priority. Another way would be to keep the list itself unsorted, only insert at the end, and when you go to schedule a job you look through the list trying to find a priority 0 job to schedule. if none are found, you can just grab the first item in the list (which must be priority 1) and schedule that.

    Your queue class would need a few fields based on the decision you make above, plus, if desired, a currently running job field that holds one job object. You would then have a few member functions to do things like display the current queue (needing to do this would push me towards the implementation above in which you insert based on priority into a single linked list), schedule a new job, etc.

    I will encourage anyone else reading this thread to make design suggestions, but abstain from writing any code. I hesitated to even make design suggestions, but decided that leaving room for decisions and still having to implement them was enough that the OP would still have to really do the assignment themselves.

    -Lee
     
  4. Muncher macrumors 65816

    Muncher

    Joined:
    Apr 19, 2007
    Location:
    California
    #4
    This is about as helpful as we're going to get, take it or leave it.
     
  5. sushi Moderator emeritus

    sushi

    Joined:
    Jul 19, 2002
    Location:
    キャンプスワ&#
    #5
    Thanks to lee1210, I now understand what the OP was trying to say. That (the OP's post) was a hard read.
     

Share This Page