Question #4


Develop a deterministic simulation model of a TV repair shop in C or C++. There are three repairmen who are suppose to fix the TVs. There is also a Mr. Inspector who is suppose to check to make sure TVs are fixed.

Each repairman or Mr. Inspector can only fix or check one TV at a time, thus, it is possible for TVs to arrive and there be no repairman available to fix them. In such a case, the TV waits until a repairman becomes available (i.e. a repairman completes fixing another TV). Similarly, when a TV is fixed by a repairman, Mr. inspector may not be available to check the TV, and again a TV may have to wait until he becomes available.

A TV that has been checked by Mr. inspector may need to go back for re-repair. Such a TV has no priority over any other TV, thus, it may have to wait its turn when sent back for re-repair. Assume that a TV will be fixed correctly the second time around, but it still has to be inspected.

Each TV will be represented by an input line that will contain a TV#, Arrival time, Service Time, and Failure Indicator Flag. Arrival time identifies the time for a TV to arrive. The Service Time gives the amount of time it takes for a repairman to repair the TV. A zero for Failure Indicator Flag means that Mr. inspector will decide that the TV can leave the shop, a one means that the TV needs to go back to a repairman to be re-repaired. Mr. inspector spends 1/10 of the time it took to service the TV to figure out if it needs to be re-repaired. In a re-repaired case, it takes a repairman one half of a TV's initial service time, but the time needed to inspect remains the same, 1/10 of the initial service time.

For each TV you must output how long it was in the repair shop. The program ends when all data is processed.

Sample Input:

1234    230     400     0
2345    300     500     0
3234    301     300     1
3443    400     110     0
3231    500     100     0
1231    501     200     1
3212    610     500     0



Expected Output:

TV#      Time in Repair Shop
---      -------------------
1234     441
3443     322
3231     240
2345     550
3234     679
1231     550
3212     670