PDA

View Full Version : fcfs



amita27
جمعه 14 اسفند 1388, 17:25 عصر
سلام لطفا به من بگید من چطور الگوریتم fcfs با زبان c بنویسم

saed2006
جمعه 14 اسفند 1388, 18:02 عصر
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
#include<stdio.h>
struct node
{
char name[10];
int bt;
int wt;
int tat;
struct node*next;
};
typedef struct node n;
n *start=NULL;
void main()
{
int i,m;
n *p,*temp,*t;
clrscr();
cout<<"\nEnter the number of Process:";
cin>>m;
for(i=0;i<m;i++)
{
p=(n*)malloc(sizeof (n));
cout<<"\n\tEnter the Process Name:";
cin>>p->name;
cout<<"\n\tEnter the Burst Time:";
cin>>p->bt;
if(start==NULL)
{
start=p;
start->next=NULL;
start->wt=0;
start->tat=start->bt;
}
else
{
temp=start;
while(temp!=NULL)
{
t=temp;
temp=temp->next;
}
t->next=p;
temp=p;
temp->wt=t->tat;
temp->tat=t->tat+temp->bt;
temp->next=NULL;
}
}
temp=start;
cout<<"\nProcesses\t\tBT\t\tWT\t\tTAT";
while(temp!=NULL)
{
cout<<"\n\t"<<temp->name;
cout<<"\t\t"<<temp->bt;
cout<<"\t\t"<<temp->wt;
cout<<"\t\t"<<temp->tat;
temp=temp->next;

}
cout<<"\n\n Created By:\n\tSanjog";
getch();
}

amita27
یک شنبه 16 اسفند 1388, 09:03 صبح
مرسي .فقط بگيد من اين برنامه رو تو چه محيطي اجرا كنم .من داخل محيط ++turbo c نوشتم error مي ده.

giootin_tiz
شنبه 20 آذر 1389, 23:35 عصر
مرسي .فقط بگيد من اين برنامه رو تو چه محيطي اجرا كنم .من داخل محيط ++turbo c نوشتم error مي ده.


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

int n,Bu[20],Twt,Ttt,A[10],Wt[10],w;
float Awt,Att;
char pname[20][20],c[20][20];

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("?FIRST COME FIRST SERVED ALGORITHM?");
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();
}

rohab2012
چهارشنبه 26 مهر 1391, 20:23 عصر
سلام میشه سورس کد الگوریتم های زمانبندی رو بذارین