Home » Algorithms

Implementation of Round Robin CPU Scheduling algorithm using C++

In this article, we are going to implement of Round Robin CPU Scheduling Algorithm (which is a preemptive version of FCFS algorithm) using C++ program.
Submitted by Aleesha Ali, on February 06, 2018

This algorithm is the preemptive version of FCFS algorithm.

Preemptive: If a process of higher priority comes then first CPU will be assign to the Process with higher priority first.

Scheduling criteria tells us that any algorithm is how much efficient, the main criteria of scheduling are given below:

  • Arrival time
  • Turnaround time
  • Waiting time
  • Burst time
  • Quantum time

* Ready Queue is a queue where all the processes wait to get CPU for its execution.

Arrival time: The time at which the process enters into ready queue.

Turnaround time: The interval between the times of submission of a process to the time of completion.

Waiting time: The total amount of the time a process spends in ready queue.

Burst time: The time needed by CPU to complete its execution.

Quantum time: The amount of the time a CPU is assign to be executed is known as the quantum time independent of the actual burst time, a process will get scheduled in quantum parts values or we can say in quantum chunks.

Round Robin Algorithm

This algorithm is known as preemptive version of FCFS as discussed earlier, it executes the process on the basis of first come first serve, and the only difference here is it works on the principle of quantum time.

C++ Program for the Round Robin Scheduling

//C++ Program to implement Round Robin 
//Scheduling CPU Algorithm

#include <iostream>
#include <vector>

/*at = Arrival time,
bt = Burst time,
time_quantum= Quantum time
tat = Turn around time,
wt = Waiting time*/

using namespace std;

int main(){
	int i,n,time,remain,temps=0,time_quantum;

	int wt=0,tat=0;

	cout<<"Enter the total number of process="<<endl;

	// assigning the number of process to remain variable

	//dynamic array declaration using vector method of (STL)
	//STL standard template library of C++

	cout<<"Enter the Arrival time, Burst time for All the processes"<<endl;

	cout<<"Enter the value of time QUANTUM:"<<endl;

	cout<<"\n\nProcess\t:Turnaround Time:Waiting Time\n\n";
		if(rt[i]<=time_quantum && rt[i]>0)
			time += rt[i];
			//Addition using shorthand operators

		else if(rt[i]>0)
			rt[i] -= time_quantum;
			//Subtraction using shorthand operators
			time += time_quantum;
			//Addition using shorthand operators

		if(rt[i]==0 && temps==1)
			//Desplaying the result of wating, turn around time:

			wt += time-at[i]-bt[i];
			tat += time-at[i];

		if(i == n-1)
		else if(at[i+1] <= time)

	cout<<"Average waiting time "<<wt*1.0/n<<endl;
	cout<<"Average turn around time "<<tat*1.0/n<<endl;;

	return 0;


Round Robin Algo Implementation using C++ program

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.