Question

In: Computer Science

Develop an algorithm and implement Multilevel Queuing scheduling using C++.and using bubble sorting. Consider a set...

Develop an algorithm and implement Multilevel Queuing scheduling using C++.and using bubble sorting.
Consider a set of user and system processes and determine (i) turnaround time (ii) waiting time of each process (iii) Average Waiting Time (AWT) and (iv) Average Turnaround Time (ATAT) of all processes.

please write comment

Solutions

Expert Solution

Code:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define tprocess 4

// create a struct

struct process
{
int Process_no,arrivaltime,bursttime,pr;
};

process proc[50];

bool comp(process A,process B)
{
if(A.arrivaltime == B.arrivaltime)
{
return A.pr<B.pr;
}
else
{
return A.arrivaltime<B.arrivaltime;
}
}

void get_wt_time(int wt[])
{
// service array that contains cumulative burst time
int service[50];

// Initilising elements of the arrays
service[0] = proc[0].arrivaltime;
wt[0]=0;


for(int i=1;i<tprocess;i++)
{
service[i]=proc[i-1].bursttime+service[i-1];

wt[i]=service[i]-proc[i].arrivaltime;

   if(wt[i]<0)
   {
   wt[i]=0;
   }
}

}

void get_tat_time(int tat[],int wt[])
{

for(int i=0;i<tprocess;i++)
{
   tat[i]=proc[i].bursttime+wt[i];
}
  
}

void findtime()
{
//Declare array for waiting time and turnaround time
int wt[50],tat[50];

double wavg=0,tavg=0;

// Function call for waiting time array
get_wt_time(wt);
//Function call for turnaround time
get_tat_time(tat,wt);
  
int stime[50],ctime[50];

stime[0] = proc[0].arrivaltime;
ctime[0]=stime[0]+tat[0];

// calculating starting and ending time
for(int i=1;i<tprocess;i++)
   {
       stime[i]=ctime[i-1];
       ctime[i]=stime[i]+tat[i]-wt[i];
   }
  
cout<<"Process_no\tStart_time\tComplete_time\tTurn_Around_Time\tWaiting_Time"<<endl;
  
  
for(int i=0;i<tprocess;i++)
   {
       wavg += wt[i];
       tavg += tat[i];
      
       cout<<proc[i].Process_no<<"\t\t"<<
           stime[i]<<"\t\t"<<ctime[i]<<"\t\t"<<
           tat[i]<<"\t\t\t"<<wt[i]<<endl;
   }
  
// display the average waiting time and average turn around time
  
   cout<<"\nAverage waiting time : ";
   cout<<wavg/(float)tprocess<<endl;
   cout<<"\nAverage turnaround time : ";
   cout<<tavg/(float)tprocess<<endl;

}

int main()
{
int arrivaltime[] = { 1, 2, 3, 4 };
int bursttime[] = { 7, 1, 5, 3 };
int priority[] = { 3, 7, 4, 1 };
  
for(int i=0;i<tprocess;i++)
{
   proc[i].arrivaltime=arrivaltime[i];
   proc[i].bursttime=bursttime[i];
   proc[i].pr=priority[i];
   proc[i].Process_no=i+1;
   }
  
   //Using sort function
  
   sort(proc,proc+tprocess,comp);
  
   //Calling function findtime
  
   findtime();

   return 0;
}

Output:

Thank You!! Hope you like it.

If any doubt comes up, Please let me know.


Related Solutions

Implement the CPU scheduling algorithm MLFQ in python. Have the program answer the table. Multilevel Feedback...
Implement the CPU scheduling algorithm MLFQ in python. Have the program answer the table. Multilevel Feedback Queue (absolute priority in higher queues)             Queue 1 uses RR scheduling with Tq = 5             Queue 2 uses RR scheduling with Tq = 10             Queue 3 uses FCFS All processes enter first queue 1. If time quantum (Tq) expires before CPU burst is complete, the process is downgraded to next lower priority queue. Processes are not downgraded when preempted by a...
Develop an algorithm and implement Optimal Page Replacement algorithm using C++. Determine the number of page...
Develop an algorithm and implement Optimal Page Replacement algorithm using C++. Determine the number of page faults and page hits by considering the Frame size=4, ReferenceString:2 4 6 7 8 2 4 9 13 9 2 7 2 6 1 4 9 2
The purpose here is to implement the QuickSort sorting algorithm to sort integers. Write a C...
The purpose here is to implement the QuickSort sorting algorithm to sort integers. Write a C program which accepts 1 command-line argument: the name of a text file which contains integers, one-per line. Your C program must be named project3. Your C program needs to implement the QuickSort algorithm to sort the integers read from the file specified on the command-line. Your QuickSort implementation must utilize the median-of-three algorithm for choosing a pivot, and BubbleSort any sub arrays with less...
implementing linked list using c++ Develop an algorithm to implement an employee list with employee ID,...
implementing linked list using c++ Develop an algorithm to implement an employee list with employee ID, name, designation and department using linked list and perform the following operations on the list. Add employee details based on department Remove employee details based on ID if found, otherwise display appropriate message Display employee details Count the number of employees in each department
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ......
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ... n - 1]) if (n = 2) and A[0] > A[1] swap A[0] and A[1] else if n > 2 m = ceiling(2n/3) STOOGESORT(A[0 ... m - 1]) STOOGESORT(A[n - m ... n - 1]) STOOGESORT(A[0 ... m - 1])
It's time to write a sorting algorithm! In this lab, you'll be writing Bubble Sort. Much...
It's time to write a sorting algorithm! In this lab, you'll be writing Bubble Sort. Much like the previous lab, you will be tasked with prompting the user for a list of values until the user enters 0 (you may use the same initializeVector that you wrote in the last lab). You will then write bubblesort which sorts the vector from smallest to largest. You will then call a function displayVector which displays the vector to the screen. Keep everything...
Develop an algorithm to implement an employee list with employee ID ,name designation and department using...
Develop an algorithm to implement an employee list with employee ID ,name designation and department using link list and perform the following operation on the list i)add employee details based on department ii)remove employee details iv)count the number of employee in each department
An operating system uses the First-Come, First-Served (FCFS) CPU scheduling algorithm. Consider the following set of...
An operating system uses the First-Come, First-Served (FCFS) CPU scheduling algorithm. Consider the following set of processes in this OS, with the length of the CPU burst time given in milliseconds, and the shown priority. A larger priority number implies a higher priority. There is no pre-emption. The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. Process Burst Time Priority P1 2 2 P2 1 5 P3 4 1 P4...
Write a function in C that uses the Merge Sort sorting algorithm with arrays. The function...
Write a function in C that uses the Merge Sort sorting algorithm with arrays. The function must not be void and must output type int* i.e. it must take the form: int* merge_sort(int a[], int n) where a[ ] is the input matrix and n is the size of the matrix. You may use an auxiliary functions such as "merge." The returned array should be sorted using merge_sort and should not modify the array that was input (a[ ] ).
Implement the CPU scheduling algorithm SJF non-preemptive in python. Have the program answer the table. Simulate...
Implement the CPU scheduling algorithm SJF non-preemptive in python. Have the program answer the table. Simulate and evaluate with the set of eight processes below. Assumptions: All processes are activated at time 0 Assume that no process waits on I/O devices. After completing an I/O event, a process is transferred to the ready queue. Waiting time is accumulated while a process waits in the ready queue. Turnaround time is a total of (Waiting time) + (CPU burst time) + (I/O...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT