Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Input - p4Input.txt lWidgetNr iStep1tu iStep2tu iArrivalDelta iWhichServer %ld %

ID: 3821618 • Letter: I

Question

Input - p4Input.txt

lWidgetNr iStep1tu iStep2tu iArrivalDelta iWhichServer

   %ld       %d       %d         %d           %d

lWidgetNr - identifies a widget going through the system

iStep1tu - time units for step 1 for this widget

iStep2tu - time units for step 2 for this widget

iArrivalDelta - delta time units before next widget arrives

iWhichServer - determines which server to use when given an option:

For alternative A : iWhichServer isn't used

For alternative B (extra credit): 1= server X, 2 = server Y

For current, iWhichServer isn't used.

Points

Part A

Provide a simulation of alternative A.

Include a command argument switch (-v) which has no corresponding argument. If -v is specified, this is verbose mode. This causes your program to print all clock times and events as they happen:   Arrival, Enter Queue X, Leave Queue X, Seize Server X, Release Server X, Enter Queue W, Leave Queue W, Seize Server W, Release Server W, Exit System. For some of those events, you should print additional information (time in queue, time in system). See the sample output below. We can invoke p4 with or without that switch

./p4 -v <p4Input.txt

./p4 <p4Input.txt

Show the statistics specified above.

Run the simulation for 50 widgets. Allow all of the widgets to complete both steps and exit the system.

/*******************************************

input:

Current ueueW Alt A ueuex Alt B Server W Step 1 Step 2 Server X ueueW Step 1 Server X ueuex Step 1 Server Y queue Step 1 Server W (modified) Step 2. Server W (modified) queue W Step 2

Explanation / Answer

#define REACHED_EOF 1 typedef struct { long lWidgetNr; int iStep1tu; int iStep2tu; int iArrivalTime; int iWhichServer; } Widget; // Event typedef typedef struct { int iEventType; int iTime; Widget widget; } Event; typedef struct NodeLL { Event event; struct NodeLL *pNext; } NodeLL; typedef struct { NodeLL *pHead; } LinkedListImp; typedef LinkedListImp *LinkedList; // typedefs for the queues typedef struct { Widget widget; int iEnterQTime; } QElement; typedef struct NodeQ { QElement element; struct NodeQ *pNext; } NodeQ; typedef struct { NodeQ *pHead; NodeQ *pFoot; long lQueueWaitSum; long lQueueWidgetTotalCount; char szQName[12]; } QueueImp; typedef QueueImp *Queue; // typedefs for server typedef struct { char szServerName[12]; int bBusy; Widget widget; long lWidgetCount; long lLastServerBeginTime; long lServerTimeSum; } ServerImp; typedef ServerImp *Server; // typedefs for the Simulation typedef struct { int iClock; int bVerbose; long lSystemTimeSum; long lWidgetCount; char cRunType; LinkedList eventList; } SimulationImp; typedef SimulationImp *Simulation;