Monday, 1 February 2016

C++ Program For First Come First Served (FCFS) Scheduling Algorithm

Problem:- Program for FCFS Scheduling or C Program for First Come First Served (FCFS) Scheduling Algorithm or C program to implement the FCFS(FIRST COME FIRST SERVE or First Come First Served (FCFS) Scheduling Algorithm in c++ and c or C++ Program for First Come First Served (FCFS) Scheduling Algorithm or C Program For First Come First Serve Algorithm (FCFS) or c program for first come first serve Scheduling or C++ Program for First Come First Served (FCFS) Scheduling Algorithm or First Come First Serve Scheduling Algorithm in C with Gantt Chart or C code for First Come First Serve Scheduling(FCFS) or C program for First Come First Serve Algorithm or First come first served scheduling (FCFS) program in c/c++ or C Program to implement FCFS algorithm or UNIX C Program for First Come First Serve Scheduling Algorithm or Java Program for First Come First Serve (FCFS) Scheduling Algorithm or fcfs first come first serve scheduling algorithm in java or First Come First Serve(FCFS) Program in Java.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Explanation:- First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm. FCFS follow the FIFO (First In First Out) rules that means when a process comes to CPU for executing, CPU executes the process without checking anything like in primitive scheduling algorithm. In other words, we can say that the First process will be executed either the execution time of the first process is higher than other or until the first process executing another process should wait for their turn. Below is the Brief description or Q&A of FCFS Non-Preemptive scheduling algorithm.

1. What is First Come First Served (FCFS) Scheduling Algorithm?.
2. How to Calculate Turn Around Time?.
3. How to Calculate Waiting Time?.
4. Example.

What is First Come First Served (FCFS) Scheduling Algorithm?.

First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm for process execution in an operating system and easy to understand and poor performance (waiting time is higher), If the first process is taking time for execution than until finish first process rest of the process has to wait.

How to Calculate Turn Around Time?.

Turn Around Time = Completion Time – Arrival Time

With the help of this formula, we can calculate a Turn Around Time of all process in Queue.

How to Calculate Waiting Time?.

Waiting Time = Turn Around Time – Burst Time

This formula is used for calculating the waiting time for rest of process.


Example:- We are taking 5 process whose CBT, or Burst Time Is 4, 9, 8, 3, 7 respectively and the output is given below.

Enter The Total Number of Process: 5

Enter CBT of Process:
4
9
8
3
7

======================================================================
                        Gantt. Chart
======================================================================
[P1]    [P2]    [P3]    [P4]    [P5]
----------------------------------------------------------------------

0       4       13      21      24

======================================================================
Process     CBT   Waiting Time    Turn Around Time
======================================================================

[p1]          4           0               4
[p2]          9           4              13
[p3]          8          13              21
[p4]          3          21              24
[p5]          7          24              31


Average Awating Time: 12.4

Average Turn Around Time: 18.6


Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date


Solution:-

#include<stdio.h>
#include<string.h>

int strToint (char[]);

int main()
{
/*Visit - www.programmingwithbasics.com*/
   
    cout<<"=====================================";
    cout<<"\nVisit - www.programmingwithbasics.com";
    cout<<"\n=====================================";
    
    while(1)
    {
    char str[10];
    int intNum;

    printf("\n\nEnter Integer Number: ");
    scanf("%s",str);

    intNum = strToint(str);

if(intNum==0)
{
printf("\nEnter The Number Not String\n\n");
}
else
    {
    printf("\n\nEquivalent Integer Value: %d",intNum);
}
}
return 0;
}

int strToint (char str[])
{

    int i=0,sum=0;

    while(str[i] != '\0')
  {

        if(str[i] < 48 || str[i] > 57)
  {
            printf("\n\nCan't Convert Into Integer");
            return 0;
        }
        else
  {
            sum = sum*10 + (str[i] - 48);
            i++;
        }
    }

return sum;

}

return sum;

}

Output:-

C++ Program For First Come First Served (FCFS) Scheduling Algorithm

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

2 comments: