Skip to content

Commit bb1c93f

Browse files
author
saksham1908
authored
Add files via upload
1 parent 595c841 commit bb1c93f

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

FCFS.cpp.txt

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
// C++ program for implementation of FCFS
3+
// scheduling
4+
#include<iostream>
5+
using namespace std;
6+
7+
// Function to find the waiting time for all
8+
// processes
9+
void findWaitingTime(int processes[], int n,
10+
int bt[], int wt[])
11+
{
12+
// waiting time for first process is 0
13+
wt[0] = 0;
14+
15+
// calculating waiting time
16+
for (int i = 1; i < n ; i++ )
17+
wt[i] = bt[i-1] + wt[i-1] ;
18+
}
19+
20+
// Function to calculate turn around time
21+
void findTurnAroundTime( int processes[], int n,
22+
int bt[], int wt[], int tat[])
23+
{
24+
// calculating turnaround time by adding
25+
// bt[i] + wt[i]
26+
for (int i = 0; i < n ; i++)
27+
tat[i] = bt[i] + wt[i];
28+
}
29+
30+
//Function to calculate average time
31+
void findavgTime( int processes[], int n, int bt[])
32+
{
33+
int wt[n], tat[n], total_wt = 0, total_tat = 0;
34+
35+
//Function to find waiting time of all processes
36+
findWaitingTime(processes, n, bt, wt);
37+
38+
//Function to find turn around time for all processes
39+
findTurnAroundTime(processes, n, bt, wt, tat);
40+
41+
//Display processes along with all details
42+
cout << "Processes "<< " Burst time "
43+
<< " Waiting time " << " Turn around time\n";
44+
45+
// Calculate total waiting time and total turn
46+
// around time
47+
for (int i=0; i<n; i++)
48+
{
49+
total_wt = total_wt + wt[i];
50+
total_tat = total_tat + tat[i];
51+
cout << " " << i+1 << "\t\t" << bt[i] <<"\t "
52+
<< wt[i] <<"\t\t " << tat[i] <<endl;
53+
}
54+
55+
cout << "Average waiting time = "
56+
<< (float)total_wt / (float)n;
57+
cout << "\nAverage turn around time = "
58+
<< (float)total_tat / (float)n;
59+
}
60+
61+
// Driver code
62+
int main()
63+
{
64+
//process id's
65+
int processes[] = { 1, 2, 3};
66+
int n = sizeof processes / sizeof processes[0];
67+
68+
//Burst time of all processes
69+
int burst_time[] = {10, 5, 8};
70+
71+
findavgTime(processes, n, burst_time);
72+
return 0;
73+
}

0 commit comments

Comments
 (0)