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

    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Programming Problem, Help Greatly Appreciated


    I took a course in computers, and I have a slight background in PHP. I was not expecting programming to be apart of the actual class, and it has caught me off guard. I have spent the last weeks fighting with this, trying to understand how I can put it into code properly. Any ideas, code samples, or guidance would be GREATLY appreciated!


    Assume the following:
    a. Disk spooling is NOT being used.
    b. The printer does NOT have a hardware buffer to hold the output while the printer is printing

    (The theme music from Mission Impossible is playing faintly in the background).

    SIMULATE the following scenario
    A hypothetical program computes for three seconds then outputs a variable length record to be printed. The printer takes from 0.75 to 4.75 seconds (average time is 2.75 seconds) to print each output record. (Use a random number generator)

    The hypothetical program loops 500 times for each case of software buffers (0, 1, 2, 3, 4, 5, 10, 25, and 100 software output buffers). Calculate the AVERAGE time for the program to “virtually compute and print” a record from the 500 records, for EACH of the 9 choices of buffer.





    Thanks again!

    -Steve
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,543
    Rep Power
    595
    Since this is homework I don't want to give you the answer directly so please state where you are having difficulty. What have you done so far and what kind of result are you getting?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by gw1500se
    Since this is homework I don't want to give you the answer directly so please state where you are having difficulty. What have you done so far and what kind of result are you getting?
    Having some sort of example or outline is really all I need. From there, I can work it out. Apparently, the use of arrays is one way to get through this problem, although I'm not even sure where to begin. I keep imagining the program in my head, even put it on paper and wrote out quite a bit of code (Which I've scrapped every time, since I felt I was doing the problem entirely wrong).
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,543
    Rep Power
    595
    You don't need an array unless I am misunderstanding the task. Post what you think the algorithm would be in words.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    I'll give you some hints, which you might or might not already know:
    * You can't compute an accurate average by individually summing the print times of each record; this is because you will have some records computing while other records are printing simultaneously, and you don't want to count that time twice. Thus you need to keep a running counter of the amount of "time" that has passed since the start of the simulation (virtual time, not real time).
    * If all of your buffers are full, the software has to block after computation. For example, with 0 buffers if you get a print time of 4 seconds your software is going to compute for three seconds, transmit to the printer, compute for three seconds while the printer is simultaneously printing for three seconds, then block for one second while the printer finishing the previous print job, then it can transmit the job and start computing the next one.
    * Thus, each record will add exactly 3 seconds to the total time UNLESS the printer's buffers are all full; then it will add additional time (the time required for a buffer to become available).
    * You can use an array for this (probably with one element for each buffer), but it probably isn't necessary. It might be easier to understand since an array is conceptually closer to how a real buffer would work.
    * If you don't use an array, you will want to determine the print time for a record when you take it out of the buffer rather than when you insert it.
    * It might help to write out examples of a few iterations for 0, 1 and 2 buffers to see how it should work. The example for 2 buffers will generalize to 3+ easily enough.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo