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

Scheduling Algorithm (FCFS)

This C++ program calculates the average waiting time and average turnaround time for processes using different scheduling algorithms. It takes the process IDs, burst times, and arrival times as input. It calls functions to calculate the waiting times, turnaround times, and prints the results along with the average waiting and turnaround times.

Uploaded by

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

Scheduling Algorithm (FCFS)

This C++ program calculates the average waiting time and average turnaround time for processes using different scheduling algorithms. It takes the process IDs, burst times, and arrival times as input. It calls functions to calculate the waiting times, turnaround times, and prints the results along with the average waiting and turnaround times.

Uploaded by

Haseeb Saeed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Submitted by: Muhammad Haseeb Saeed

#include<iostream>
using namespace std;

void wTime(int Pr[], int num, int burst[], int wait[], int arr[]);
void TTime(int Pr[], int num, int burst[], int wait[], int tat[]);
void AvgT(int Pr[], int num, int burst[], int arr[]);
int main()
{

int Pr[] = {3, 1, 2};


int num = sizeof Pr / sizeof Pr[0];

int bTime[] = {6, 5, 3};

int aTime[] = {1, 0, 4};

AvgT(Pr, num, bTime, aTime);

return 0;
}

void AvgT(int Pr[], int num, int burst[], int arr[])


{
int wait[num], tat[num];

wTime(Pr, num, burst, wait, arr);


TTime(Pr, num, burst, wait, tat);

cout << "Process List: " << " BTime: " << " ATime: " << " WTime: " << " TTime " << " Completion \n";
int tWait = 0, tTat = 0;
for (int i = 0 ; i < num ; i++)
{
tWait = tWait + wait[i];
tTat = tTat + tat[i];
int cTime = tat[i] + arr[i];
cout << " " << i+1 << "\t\t" << burst[i] << "\t\t" << arr[i] << "\t\t" << wait[i] << "\t\t " << tat[i] << "\t\t " << cTime <<
endl;
}

cout << "Average wait Time: " << (float)tWait / (float)num;


cout << "\nAverage Turn-Around Time: " << (float)tTat / (float)num;
}

void wTime(int Pr[], int num, int burst[], int wait[], int arr[])
{
int serviceT[num];
serviceT[0] = 0;
wait[0] = 0;
for (int i = 1; i < num ; i++)
{
serviceT[i] = serviceT[i-1] + burst[i-1];
Submitted by: Muhammad Haseeb Saeed

wait[i] = serviceT[i] - arr[i];

if (wait[i] < 0)
wait[i] = 0;
}
}

void TTime(int Pr[], int num, int burst[], int wait[], int tat[])
{
for (int i = 0; i < num ; i++)
tat[i] = burst[i] + wait[i];
}

You might also like