Professional Documents
Culture Documents
h>
#include<conio.h>
#include<stdio.h>
#include<alloc.h>
#include<string.h>
#include<process.h>
//node declaration
struct node0
{
int arrTime;
int procNo;
int burstTime;
int waitTime;
int cpuTime;
struct node0 *next;
};
node getnode()
{
node x=(node)malloc(sizeof(struct node0));
if(x==NULL)
{
printf("Memory not allocated\n");
return NULL;
}
x->next=NULL;
x->arrTime=0;
x->procNo=0;
x->burstTime=0;
x->waitTime=0;
x->cpuTime=0;
return x;
}
if(head==NULL)
{
head=obj;
return head;
}
node cur=head;
while(cur->next!=NULL)
cur=cur->next;
cur->next=obj;
return head;
}
node getCurrProcess(node head)
{
node cur=head;
while(cur->burstTime==0)
cur=cur->next;
return cur;
}
void main()
{
clrscr();
node head=getnode(),obj,currProcess;
int input,totalTime=0,currTime=0;
int arr[10];
int iarr=0;
obj=getnode();
if(input==1)
{
cout<<"\nArrival time is 0";
head->arrTime=0;
if(input==0)
{
currTime++;
cout<<"\nArrival Time is:->"<<currTime;
currProcess=getCurrProcess(head);
arr[iarr]=currProcess->procNo;
iarr++;
cout<<"\nProcess currently executing is:->"<<currProcess->procNo;
currProcess->burstTime--;
cout<<"\nTime left in completion of this process:-
>"<<currProcess->burstTime;
currProcess->cpuTime++;
incrementWaitTime(head,currProcess,currTime);
totalTime--;
}
else
{
if(input==1)
{
obj=getnode();
cout<<"\nArrival Time is:->"<<currTime;
obj->arrTime=currTime;
cout<<"\n\n";
clrscr();
cout<<endl<<"Gauntt Chart\n\n";
cout<<endl<<"0";
int d=1;
for(int k=0;k<iarr-1;k++)
{ textcolor(d);
cprintf("%c%c",char(219),char(219));
if(arr[k]!=arr[k+1]&&k!=iarr-1)
{
cout<<k+1;//<<arr[k+1];
d+=1;
}
}
cout<<endl;
d=1;
for( k=0;k<iarr-1;k++)
{ textcolor(d);
cprintf(" ");
if(arr[k]!=arr[k+1]&&k!=iarr-1)
{
cprintf("P%d",arr[k]);//<<arr[k+1];
d+=1;
}
}
cout<<endl;
/*
for( k=0;k<iarr-1;k++)
{
if(arr[k]!=arr[k+1])
cout<<"P"<<arr[k];//<<arr[k+1];
cout<<" ";
}
*/
cout<<endl<<endl<<endl;
node cur=head;
float count=0,avgwait=0,avgtat=0;
while(cur!=NULL)
{
cout<<"\nProcess no:->"<<cur->procNo<<"\t"<<"Waiting time:->"<<cur-
>waitTime<<"\t"<<"tat Time:->"<<cur->waitTime+cur->cpuTime;
cout<<"\n";
avgwait+=cur->waitTime;//-cur->arrTime;
avgtat+=cur->waitTime+cur->cpuTime;//-cur->arrTime;
count++;
cur=cur->next;
}
getch();
}