answersLogoWhite

0


Best Answer

#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();

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

#include<stdio.h> void main() { int i,ex[20],tr[20],wt[20],n,ar[20]; int j,k,temp,od[20]; float b=0,c=0; printf("\n Enter the number of processes : "); scanf("%d",&n); for(i=0;i<n;i++) { printf(" P%d = ",i+1); printf("\n Excecution time : "); scanf(" %d",&ex[i]); printf("\n Arrival time : "); scanf("%d",&ar[i]); } for(i=0;i<n;i++) od[i]=ar[i]; for(i=0;i<n;i++) for(j=i+1;j<n;j++) { if(ar[i]>ar[j]) { temp=ar[i]; ar[i]=ar[j]; ar[j]=temp; } } for(j=0;j<n;j++) { for(i=0;i<n;i++) { if(ar[j]==od[i]) { if(j==0) { wt[i]=ar[j]; b=wt[i]; tr[i]=ex[i]; c=tr[i]; break; } wt[i]=temp-ar[j]+ar[j-1]; b=b+wt[i]; tr[i]=ex[i]+wt[i]; c=c+tr[i]; break; } } temp=tr[i]; } b=b/n; c=c/n; printf("\n ORDER NAME ARRIVAL-TIME EX.TIME WAITING-TIME TURN-AROUND-TIME \n"); for(j=0;j<n;j++) for(i=0;i<n;i++) { if(ar[j]==od[i]) { printf(" %d P%d\t %d %d\t %d\t\t %d ",j+1,i+1,ar[j],ex[i],wt[i],tr[i]); printf("\n"); break; } } printf("Average waiting time = %f \n Average turn around time = %f \n",b,c); }

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

#include<string.h>

main()

{

float avgwt,avgtt;

char pname[10][10],c[10][10];

int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;

printf("\n\nEnter the number of processes:");

scanf("%d",&n);

printf("\n\n Enter the NAME, BURST TIME and ARRIVAL TIME of thr process");

for(i=0;i<n;i++)

{

printf("\n\nNAME : ");

scanf("%s",&pname[i]);

printf("\n\nBURST TIME : ");

scanf("%d",&bt[i]);

printf("\n\n ARRIVAL TIME :");

scanf("%d",&at[i]);

}

for(i=0;i<n;i++)

for(j=i+1;j<n;j++)

{

if(at[i]>at[j])

{

t=at[i];

at[i]=at[j];

at[j]=t;

q=bt[i];

bt[i]=bt[j];

bt[j]=q;

strcpy(c[i],pname[i]);

strcpy(pname[i],pname[j]);

strcpy(pname[j],c[i]);

}

}

wt[0]=0;

for(i=0;i<n;i++)

{

wt[i+1]=wt[i]+bt[i];

sum=sum+(wt[i+1]-at[i]);

tt[i]=wt[i]+bt[i];

ss=ss+bt[i];

}

avgwt=(float) sum/n;

avgtt=(float) sbt/n;

printf("\n\nAverage waiting time=%f",avgwt);

printf("\n\nAverage turn-around time=%f",avgtt);

printf("\n\n GANTT CHART\n");

for(i=0;i<n;i++)

{printf("|\t%s\t",pname[i]);

}

printf("\n");

for(i=0;i<n;i++)

{

printf("%d\t\t",wt[i]);

}

printf("%d\n",ss);

printf("\n");

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

The First Come First Served algorithm services the first recognized requestor without regard to priority or to length of time required to service that request.

A simple way to do this (there are many ways to do this, some better than others) would be setup an array of flags for a related set of functions. Whenever someone wanted a particular function to run, they would set the corresponding flag. If that is the first flag set, they could just invoke the function. If it is not the first flag set, they must wait. Each function must reset its flag, and then check to see if other flags are set before going to sleep.

You can use a queue construct to make it.The first in,the first out,means you can do FCFS.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago
#includemain(){int n,a[10],b[10],t[10],w[10],g[10],i,m;float att=0,awt=0; for(i=0;i<10;i++) { a[i]=0; b[i]=0; w[i]=0; g[i]=0; }printf("enter the number of process"); scanf("%d",&n);printf("enter the burst times"); for(i=0;i scanf("%d",&b[i]); printf("\nenter the arrival times"); for(i=0;i scanf("%d",&a[i]); g[0]=0; for(i=0;i<10;i++) g[i+1]=g[i]+b[i]; for(i=0;i { w[i]=g[i]-a[i]; t[i]=g[i+1]-a[i]; awt=awt+w[i]; att=att+t[i]; } awt =awt/n; att=att/n; printf("\n\tprocess\twaiting time\tturn arround time\n"); for(i=0;i { printf("\tp%d\t\t%d\t\t%d\n",i,w[i],t[i]); }printf("the average waiting time is %f\n",awt);printf("the average turn around time is %f\n",att);}
This answer is:
User Avatar

User Avatar

Wiki User

11y ago

tiger and got

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you give a C plus plus program about FCFS algorithm?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is c plus plus program use to convert algorithm in to c plus plus program?

You can't convert an algorithm into code. That is the job of the programmer, not the language. Algorithm's are expressed in plain-English and typically use pseudocode to broadly demonstrate the implementation of the algorithm. However, it is the programmer's job to convert these algorithms into working code. Pseudocode isn't a programming language as such, but it uses structures and statements that are familiar to any programmer and can be easily translated into any language. However, pseudocode is not a standard so there are many different ways to present pseudocode to the programmer. Moreover, pseudocode is generalised and is far too generic to be converted directly into any one language, never mind C++, which can take advantage of the underlying hardware to produce more efficient algorithms than would otherwise be implied by the pseudocode alone. Hence the need for plain-English algorithms in conjunction with the pseudocode. Programmer's can process all this information far more easily than any computer can. Even if you could program a converter for one algorithm, there's no guarantee it would work for any other algorithm. The time spent programming an algorithm converter would be far better spent simply translating the algorithm yourself.


Algorithm of push and pop in c plus plus?

pop push c++ programming


Is there an answer book for the A plus program?

The A Plus Program is an initiative, not a test. So no, there is no answer book.


What is the only function all C plus plus programs must contain?

Every C plus plus program that is a main program must have the function 'main'.


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999

Related questions

How does algorithm and c plus plus program get along?

They are bosom-friends.


How do you write an Algorithm for a C plus plus Program?

You don't write an algorithm for a C++ program, unless you are documenting the C++ program after-the-fact. The normal procedure is to write the algorithm first, in a language independent fashion, and then translate that stated algorithm into C++ code, or into whatever language you wish.


Algorithms to the given c plus plus programs?

The question is impossible to answer. You cannot determine an algorithm from a given program if the program is not actually given in the question. Please place the program in the discussion section.


How can i write pseudo code for C plus plus if i haven't even wrote the program yet?

You are going about this backwards. First, define the program. Second, describe its algorithm. Third, if needed, write pseudo code. (Sometime, algorithm and pseudo code is the same process.) Fourth, or third, write real code.


What is c plus plus program use to convert algorithm in to c plus plus program?

You can't convert an algorithm into code. That is the job of the programmer, not the language. Algorithm's are expressed in plain-English and typically use pseudocode to broadly demonstrate the implementation of the algorithm. However, it is the programmer's job to convert these algorithms into working code. Pseudocode isn't a programming language as such, but it uses structures and statements that are familiar to any programmer and can be easily translated into any language. However, pseudocode is not a standard so there are many different ways to present pseudocode to the programmer. Moreover, pseudocode is generalised and is far too generic to be converted directly into any one language, never mind C++, which can take advantage of the underlying hardware to produce more efficient algorithms than would otherwise be implied by the pseudocode alone. Hence the need for plain-English algorithms in conjunction with the pseudocode. Programmer's can process all this information far more easily than any computer can. Even if you could program a converter for one algorithm, there's no guarantee it would work for any other algorithm. The time spent programming an algorithm converter would be far better spent simply translating the algorithm yourself.


Algorithm of push and pop in c plus plus?

pop push c++ programming


What is dry run in c plus plus terminology?

A manual check of the algorithm to ensure its correctness.


How do you check a user's text input in C plus plus?

Use an SLR parser algorithm.


How do you find a largest algorithm in c plus plus?

#define max (a, b) ((a) &gt;= (b)) ? (a) : (b)


Sample program of c plus plus by using an algorithm union?

The union of two data sequences is the combined set of both sequences. To create a union, copy the first data sequence then append the second to the copy. Both sequences must be of the same type.


What is GCD in C Plus Plus?

A C++ implementation of the Binary GCD (Stern's) algorithm is shown in the Related Link below.


How to restart c plus plus program?

Exit the program and relaunch it.