Important alert: (current site time 7/28/2014 8:01:40 AM EDT)
 

VB icon

FIRST COME FIRST SERVED SCHEDULING ALGORITHM

Email
Submitted on: 12/7/2007 8:49:23 AM
By: Sathya Priya 
Level: Intermediate
User Rating: Unrated
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++
Views: 37475
 
     This program explains the concept of First Come Firts Served Scheduling Algorithm. It calculates and diplays the average waiting and turn around time. Also it displays the Gantt Chart.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: FIRST COME FIRST SERVED SCHEDULING ALGORITHM
// Description:This program explains the concept of First Come Firts Served Scheduling Algorithm. It calculates and diplays the average waiting and turn around time. Also it displays the Gantt Chart.
// By: Sathya Priya
//
// Inputs:Number of processes and the process name, burst time and arrival time for each process.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=11826&lngWId=3//for details.//**************************************

/* FIRST COME FIRST SERVED SCHEDULING*/
//PREPROCESSOR DIRECTIVES
#include<stdio.h>
#include<conio.h>
#include<string.h>
//GLOBAL VARIABLES - DECLARATION
int n,Bu[20],Twt,Ttt,A[10],Wt[10],w;
float Awt,Att;
char pname[20][20],c[20][20];
//FUNCTION DECLARATIONS
void Getdata();
void Gantt_chart();
void Calculate();
void fcfs();
//GETTING THE NUMBER OF PROCESSES AND THE BURST TIME AND ARRIVAL TIME FOR EACH PROCESS
void Getdata()
{
	int i;
	printf("\n Enter the number of processes: ");
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		fflush(stdin);
		printf("\n\n Enter the process name: ");
		scanf("%s",&pname[i]);
		printf("\n Enter The BurstTime for Process %s =	",pname[i]);
		scanf("%d",&Bu[i]);
		printf("\n Enter the Arrival Time for Process %s =	",pname[i]);
		scanf("%d",&A[i]);
	}
}
//DISPLAYING THE GANTT CHART
void Gantt_chart()
{
	int i;
	printf("\n\n\t\t\tGANTT CHART\n");
	printf("\n-----------------------------------------------------------\n");
	for(i=1;i<=n;i++)
		printf("|\t%s\t",pname[i]);
	printf("|\t\n");
	printf("\n-----------------------------------------------------------\n");
	printf("\n");
	for(i=1;i<=n;i++)
		printf("%d\t\t",Wt[i]);
	printf("%d",Wt[n]+Bu[n]);
	printf("\n-----------------------------------------------------------\n");
	printf("\n");
 }
//CALCULATING AVERAGE WAITING TIME AND AVERAGE TURN AROUND TIME
void Calculate()
{
	int i;
	//For the 1st process
	Wt[1]=0;
	for(i=2;i<=n;i++)
	{
		Wt[i]=Bu[i-1]+Wt[i-1];
	}
	for(i=1;i<=n;i++)
	{
		Twt=Twt+(Wt[i]-A[i]);
		Ttt=Ttt+((Wt[i]+Bu[i])-A[i]);
	}
	Att=(float)Ttt/n;
	Awt=(float)Twt/n;
	printf("\n\n Average Turn around time=%3.2f ms ",Att); 
	printf("\n\n AverageWaiting Time=%3.2f ms",Awt);
}
//FCFS Algorithm
void fcfs()
{
	int i,j,temp, temp1;
	Twt=0;
	Ttt=0;
	Printf(\n\n FIRST COME FIRST SERVED ALGORITHM\n\n);
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(A[i]>A[j])
			{
				temp=Bu[i];
				temp1=A[i];
				Bu[i]=Bu[j];
				A[i]=A[j];
				Bu[j]=temp;
				A[j]=temp1;
				strcpy(c[i],pname[i]);
				strcpy(pname[i],pname[j]);
				strcpy(pname[j],c[i]);
			}
		}
	}
	Calculate();
	Gantt_chart();
}
void main()
{
	int ch;
	clrscr();
	Getdata();
	fcfs();
	getch();
}


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

8/25/2008 8:04:50 AMlie

what's the function of using multidimensional array( pname[20][20] and c[20][20])??? thnkz..it just really matter..
(If this comment was disrespectful, please report it.)

 
5/19/2010 10:57:09 AMmehwish butt

outstanding ,, !!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.