Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lab 10 Out Put

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Lab 10: Write a program for implementing the FCFS Scheduling algorithm

AIM:

To write a program for implementing FCFS scheduling algorithm.

ALGORITHM:

1. Start the process.


2. Declare the array size.
3. Get the number of elements to be inserted.
4. Select the process that first arrived in the ready queue
5. Make the average waiting the length of next process.
6. Start with the first process from it’s selection as above and let other process to
be in queue.
7. Calculate the total number of burst time.
8. Display the values.
9. Stop the process.

PROGRAM:
int main() {
float avgwt, avgtt;
string pname[10], c[10];
int wt[10], tt[10], bt[10], at[10], t,
q, i, n, sum = 0, sbt = 0, ttime, j, ss =
0;

cout << "\n\n Enter the number of


processes: ";
cin >> n;

cout << "\n\n Enter the NAME ,


BURST TIME and ARRIVAL TIME
of the process";
for (i = 0; i < n; i++) {
cout << "\n\n NAME : ";
cin >> pname[i];
cout << " BURST TIME : ";
cin >> bt[i];
cout << " ARRIVAL TIME : ";
cin >> at[i];
}

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


for (j = i + 1; j < n; j++) {
if (at[i] > at[j]) {
swap(at[i], at[j]);
swap(bt[i], bt[j]);
swap(pname[i], pname[j]);
}
}

wt[0] = 0;
for (i = 0; i < n; i++) {
wt[i + 1] = wt[i] + bt[i];
tt[i] = wt[i] + bt[i];
sum = sum + (tt[i] - bt[i]);
sbt = sbt + (wt[i + 1] - at[i]);
// tt[i] = wt[i] + bt[i];
ss = ss + bt[i];
}

avgwt = (float)sum / n;
avgtt = (float)sbt / n;

cout << "\n\n Average waiting time


= " << avgwt;
cout << "\n\n Average turn-around
time = " << avgtt;
cout << "\n\n GANTT
CHART\n\n";
for (i = 0; i < n; i++)
cout << "|\t" << pname[i] << "\t";
cout << "\n";
for (i = 0; i < n; i++)
cout << wt[i] << "\t\t";
cout << ss << "\n\n";

return 0;
}
OUTPUT:
Enter the number of processes: 2

Enter the NAME , BURST TIME and ARRIVAL TIME of the process

NAME : P1
BURST TIME : 6
ARRIVAL TIME : 0

NAME : P2
BURST TIME : 3
ARRIVAL TIME : 1

Average waiting time = 3


Average turn-around time = 7

GANTT CHART

| P1 | P2
0 6 9

You might also like