Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ implementation: To simulate the flow of tasks through the queue during a time period of n minutes long using the following algorithm. Initialize the

C++ implementation: To simulate the flow of tasks through the queue during a time period of n minutes long using the following algorithm.

Initialize the queue to empty.

While the simulation is not done

Increment simulation is not done

Increment simulated time by one minute.

If the queue is not empty, then remove the task at the front of the queue.

Compute a random integer k between 0 and 3.

If k is 1, then add one task to the queue.

If k is 2, then add two tasks.

Otherwise (if k is 0 or 3), do not add any tasks to the queue.

Compute the priority of each task by generating a random value of 0 or 1.

(Please use a switch statement with 4 cases to implement the following information above, please include comments explaining, thank you!)

-------------------------------------------------------------------------

// Simulates an operating system's use of a priority queue to regulate

// access to a system resource (printer, disk, etc.).

#include

#include

#include "PriorityQueue.cpp"

#include

using namespace std;

//--------------------------------------------------------------------

//

// Declaration for the task data struct

//

struct TaskData

{

int getPriority () const

{ return priority; } // Returns the priority. Needed by the heap.

int priority, // Task's priority

arrived; // Time when task was enqueued

};

//--------------------------------------------------------------------

int main ()

{

PriorityQueue > taskPQ; // Priority queue of tasks

TaskData task; // Task

int simLength, // Length of simulation (minutes)

minute, // Current minute

numPtyLevels, // Number of priority levels

numArrivals, // Number of new tasks arriving

j; // Loop counter

// Seed the random number generator

srand( (unsigned int) time( NULL ) );

cout << endl << "Enter the number of priority levels : ";

cin >> numPtyLevels;

cout << "Enter the length of time to run the simulator : ";

cin >> simLength;

for ( minute = 0 ; minute < simLength ; minute++ )

{

// Dequeue the first task in the queue (if any).

// Your code here

int numberOfTasks = rand()%4;

// Determine the number of new tasks and add them to

// the queue.

// Your code here

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions