0% found this document useful (0 votes)
8 views

Lab 10 Out Put

The document describes a program that implements the First Come First Serve (FCFS) scheduling algorithm. The program takes the number of processes as input, along with each process's name, burst time, and arrival time. It sorts the processes by arrival time and calculates their waiting times, turnaround times, average waiting time, and average turnaround time. Finally, it prints a Gantt chart showing the schedule.

Uploaded by

Aliza Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lab 10 Out Put

The document describes a program that implements the First Come First Serve (FCFS) scheduling algorithm. The program takes the number of processes as input, along with each process's name, burst time, and arrival time. It sorts the processes by arrival time and calculates their waiting times, turnaround times, average waiting time, and average turnaround time. Finally, it prints a Gantt chart showing the schedule.

Uploaded by

Aliza Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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