fcfs

You might also like

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

#include<iostream>

using namespace std;

class fcfs {
int a[10], k, b[10], c[10], d[10], n, i, j, sum, total;
float awt, atat;

public:
void getdata() {
k = total = sum = 0;
cout << "Enter the number of processes: ";
cin >> n;

// Input burst times for each process


for(i = 0; i < n; i++) {
cout << "Enter the burst time for process " << i+1 << ": ";
cin >> a[i];
d[i] = i+1; // Process number
}

b[0] = 0;

// Calculate completion times and total waiting time


for(i = 0; i < n; i++) {
k += a[i];
b[i+1] = k; // Burst time at which process i completes
}

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


c[i] = a[i] + b[i]; // Turnaround time for each process
sum += b[i]; // Total waiting time
total += c[i]; // Total turnaround time
}

awt = (float) sum / n; // Average waiting time


atat = (float) total / n; // Average turnaround time
}

void putdata() {
cout << "Process\tBurst time\tWaiting time\tTurnaround time\n";
for(i = 0; i < n; i++) {
cout << d[i] << "\t" << a[i] << "\t\t" << b[i] << "\t\t" << c[i] << "\
n";
}

cout << "Average waiting time: " << awt << "\n";
cout << "Average turnaround time: " << atat << "\n";
}
};

int main() {
fcfs obj;
obj.getdata();
obj.putdata();
return 0;
}

You might also like