#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();
}
#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");
}
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.
tiger and got
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.
pop push c++ programming
The A Plus Program is an initiative, not a test. So no, there is no answer book.
Every C plus plus program that is a main program must have the function 'main'.
how to write a program that counts automorphic number from 1 to 999
They are bosom-friends.
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.
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.
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.
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.
pop push c++ programming
A manual check of the algorithm to ensure its correctness.
Use an SLR parser algorithm.
#define max (a, b) ((a) >= (b)) ? (a) : (b)
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.
A C++ implementation of the Binary GCD (Stern's) algorithm is shown in the Related Link below.
Exit the program and relaunch it.