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

Develop an algorithm and implement a Preemptive Priority scheduling algorithm using C++ and using bubble sorting...
Develop an algorithm and implement a Preemptive Priority scheduling algorithm using C++ and using bubble sorting .Arrival time, burst time and priority values.The code should also display: (i) Gantt chart and determine the following: (ii) Determine the Turnaround time(TAT), waiting time(WT) of each process (iii) Determine the Average Waiting Time (AWT) and Average Turnaround Time (ATAT) of all processes. please write the comments
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...
Import a data set (txt file) then do the sorting algorithm using bubble sort, radix sort,...
Import a data set (txt file) then do the sorting algorithm using bubble sort, radix sort, insertion sort, and merge sort, It must show how long it took and how many movements occurred. Please write codes in C++ Here's data set (should be stored in txt file) 7426 4524 4737 9436 3997 2757 6288 5414 9590 5968 6638 3199 9514 1541 9866 2144 6731 911 2171 6135 6437 912 9417 2662 6606 6349 707 2890 5386 9718 3492 5068 9674...
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])
C++ Write a program for sorting a list of integers in ascending order using the bubble...
C++ Write a program for sorting a list of integers in ascending order using the bubble sort algorithm Requirements Implement the following functions: Implement a function called readData int readData( int **arr) arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers from a file call data.txt into the array arr. The first integer number in the file is the number of intergers. After the first number,...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT