Important alert: (current site time 11/1/2014 2:21:34 AM EDT)
 

VB icon

FCFS (First Come First Serve) CPU Scheduling

Email
Submitted on: 6/7/2008 5:07:20 PM
By: Blueorange Tekknologee  
Level: Intermediate
User Rating: By 2 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 22040
author picture
(About the author)
 
     This Describes the principle of a queue processing technique or servicing conflicting demands by ordering process or also known as CPU scheduling. The program displays the list of process and their burst and waiting time and the total waiting and burst time.
 
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: FCFS (First Come First Serve) CPU Scheduling
// Description:This Describes the principle of a queue processing technique or servicing conflicting demands by ordering process or also known as CPU scheduling. The program displays the list of process and their burst and waiting time and the total waiting and burst time.
// By: Blueorange Tekknologee
//
// Inputs:any integer from 1 to 20
//
// Returns:the list of process and their burst and waiting time and the total waiting and burst time.
//
// Assumes:CPU scheduling
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=12179&lngWId=3//for details.//**************************************

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct Process //structure for processes
{
 int burst;
 int time;
};
//--------functions------------------------
//a function that displays the processes and their burst time
int validate(int processInput)
{
	if(processInput == 0 || processInput>20)
		return 0;
	else
		return 1;
}
void heading()
{
	gotoxy(18,3);
	printf(" ---------------------------------------\n");
	gotoxy(18,4);
	printf("| FIRST COME FIRST SERVE CPU SCHEDULING |\n");
	gotoxy(18,5);
	printf(" ---------------------------------------\n");
	gotoxy(18,6);
	printf("| 1 - Use this program |\n");
	gotoxy(18,7);
	printf("| 2 - CREDITS |\n");
	gotoxy(18,8);
	printf("| 3 - Exit |\n");
	gotoxy(18,9);
	printf(" ---------------------------------------\n");
	gotoxy(18,10);
printf("Enter your choice(1-4):");
}
void displayProcess(Process p[], int processInput, int sum, float &awt)
{
int i,index=1,yAxis=12;
	gotoxy(18,12);
	printf("Processes\tBurst Time\tWaiting Time\n");
 for(i=0;i<processInput;i++)
 {
	gotoxy(18,yAxis+=1);
 printf("\tP%d\t%5d\t%15d\n", index, p[i].burst, p[i].time);
 index++;
 }
 gotoxy(18,yAxis+2);
 printf("Total Waiting Time = %d\n",sum);
 gotoxy(18,yAxis+3);
 printf("Average Waiting Time = %.2f",awt);
}
//a function that generates random burst for each processes
void randomBurst(Process p[], int processInput)
{
int i,burstTime;
	randomize();//call randomize function
 for(i=0;i<processInput;i++)
 {
	burstTime=rand()%10; //generate random number
p[i].burst=burstTime; //assign the random number to each process' burst time
 }
}
//a function that computes the waiting time of each process, sum and average of waiting time
void waitingTime(Process p[],int processInput,int &sum, float &awt)
{
int i;
	p[0].time = 0; //always assign zero waiting time for process 1
	p[1].time=p[0].burst; //assign the burst time of process 1 to process 2
sum=p[1].time; //sum stores the waiting time of process 2
 for(i=2;i<processInput;i++)//assign waiting time for the succeeding processes
 {//process1 burstTime + process1 waiting time
	p[i].time=(p[i-1].burst + p[i-1].time);
	sum += p[i].time; 
 }
 
}
main()
{
 Process p[20];
 int processInput,burstTime,i,j,sum=0,choice;
 float awt=0.00;
 do
 {
 heading();
 scanf("%d",&choice);
	if(choice == 1)
	{
		clrscr();
		gotoxy(18,10);
		printf("Enter the Number of processes(1-20):");
		scanf("%d",&processInput);
			if(validate(processInput) == 1)
			{
				randomBurst(p,processInput);
				waitingTime(p,processInput,sum,awt);
				awt = (sum/processInput);
				displayProcess(p,processInput,sum,awt);
				getch();
				clrscr();
				fflush(stdin);
			}
			else
			{
			clrscr();
 }
	}
	else if(choice == 2)
	{
	clrscr();
	gotoxy(18,10);
	printf("\tCreated by:\n");
	gotoxy(18,11);
	printf("Created By:\n");
	gotoxy(18,12);
	printf("Blueorange Tekknologee\n");
	getch();
	clrscr();
	}
 }
 while(choice!=3);
 clrscr();
 gotoxy(32,10);
 printf("GOoDByE!");
}


Other 4 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


 There are no comments on this submission.
 

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.