0% found this document useful (0 votes)
15 views1 page

2

The document contains multiple C++ programs for different scheduling algorithms: FCFS (First-Come, First-Served), SJF (Shortest Job First), and Priority scheduling. Each program prompts the user to enter the number of processes and their respective arrival and burst times, then calculates completion, turnaround, and waiting times. Additionally, there are sections for indexed, linked, and sequential memory management, showcasing file handling and memory allocation techniques.

Uploaded by

Tech Ishant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

2

The document contains multiple C++ programs for different scheduling algorithms: FCFS (First-Come, First-Served), SJF (Shortest Job First), and Priority scheduling. Each program prompts the user to enter the number of processes and their respective arrival and burst times, then calculates completion, turnaround, and waiting times. Additionally, there are sections for indexed, linked, and sequential memory management, showcasing file handling and memory allocation techniques.

Uploaded by

Tech Ishant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

FCFS PROGRAM SJF PROGRAM PRIORITY PROGRAM

#include <iostream> #include <iostream>


#include <iostream>
using namespace std; using namespace std;
using namespace std;
int main() { struct Process {
int main() {
int n; int pid; int arrival; int burst;
int n;
cout << "Enter number of processes: "; int completion; int turnaround; int waiting;
cout << "Enter the number of processes: ";
cin >> n; }; int main() {
cin >> n;
int pid[n], arrival[n], burst[n], completion[n], turnaround[n], int n; cout << "Enter number of processes: ";
int bt[10], prior[10], pno[10], wt[10], tat[10];
waiting[n]; cin >> n; Process p[n]; for (int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
float totalTAT = 0, totalWT = 0; p[i].pid = i + 1;
pno[i] = i + 1;
for (int i = 0; i < n; i++) { cout << "Enter arrival time and burst time for process P" <<
cout << "Process " << pno[i] << ":\n";
pid[i] = i + 1; p[i].pid << ": ";
cout << "Enter burst time: ";
cout << "Enter arrival time and burst time for process " << cin >> p[i].arrival >> p[i].burst;
cin >> bt[i];
pid[i] << ": "; } for (int i = 0; i < n - 1; i++) {
cout << "Enter priority: ";
cin >> arrival[i] >> burst[i]; for (int j = i + 1; j < n; j++) {
cin >> prior[i];
} for (int i = 0; i < n-1; i++) { if (p[i].arrival > p[j].arrival ||
}
for (int j = 0; j < n-i-1; j++) { (p[i].arrival == p[j].arrival && p[i].burst > p[j].burst)) {
for (int i = 0; i < n - 1; i++) {
if (arrival[j] > arrival[j+1]) { swap(p[i], p[j]);
for (int j = i + 1; j < n; j++) {
swap(arrival[j], arrival[j+1]); } } }
if (prior[i] > prior[j]) {
swap(burst[j], burst[j+1]); int time = 0, completed = 0;
swap(prior[i], prior[j]);
swap(pid[j], pid[j+1]); bool done[n] = {false};
swap(bt[i], bt[j]);
} } } completion[0] = arrival[0] + burst[0]; while (completed < n) {
swap(pno[i], pno[j]);
for (int i = 1; i < n; i++) { int idx = -1, minBurst = 9999;
} } } wt[0] = 0;
if (arrival[i] > completion[i-1]) for (int i = 0; i < n; i++) {
tat[0] = bt[0];
completion[i] = arrival[i] + burst[i]; if (!done[i] && p[i].arrival <= time && p[i].burst < minBurst)
int totalWT = wt[0], totalTAT = tat[0];
else { minBurst = p[i].burst;
for (int i = 1; i < n; i++) {
completion[i] = completion[i-1] + burst[i]; idx = i; }
wt[i] = wt[i - 1] + bt[i - 1];
} for (int i = 0; i < n; i++) { } if (idx != -1) {
tat[i] = wt[i] + bt[i];
turnaround[i] = completion[i] - arrival[i]; time += p[idx].burst;
totalWT += wt[i];
waiting[i] = turnaround[i] - burst[i]; p[idx].completion = time;
totalTAT += tat[i];
totalTAT += turnaround[i]; p[idx].turnaround = p[idx].completion - p[idx].arrival;
}
totalWT += waiting[i]; p[idx].waiting = p[idx].turnaround - p[idx].burst;
float avgWT = (float)totalWT / n;
} cout << "\nPID\tArrival\tBurst\tCompletion\tTurnaround\ done[idx] = true;
float avgTAT = (float)totalTAT / n;
tWaiting\n"; completed++;
cout << "\nJob\tBT\tWT\tTAT\tPriority\n";
for (int i = 0; i < n; i++) { } else { time++; } }
for (int i = 0; i < n; i++) {
cout << "P" << pid[i] << "\t" float totalTAT = 0, totalWT = 0;
cout << "P" << pno[i] << "\t" << bt[i] << "\t" << wt[i] << "\t" <<
<< arrival[i] << "\t" cout << "\nPID\tArrival\tBurst\tCompletion\tTurnaround\
tat[i] << "\t" << prior[i] << endl;
<< burst[i] << "\t" tWaiting\n";
}
<< completion[i] << "\t\t" for (int i = 0; i < n; i++) {
cout << "\nAverage Waiting Time: " << avgWT;
<< turnaround[i] << "\t\t" cout << "P" << p[i].pid << "\t"
cout << "\nAverage Turnaround Time: " << avgTAT << endl;
<< waiting[i] << endl; << p[i].arrival << "\t"
return 0;
} cout << "\nAverage Turnaround Time = " << totalTAT / n; << p[i].burst << "\t"
}
cout << "\nAverage Waiting Time = " << totalWT / n << endl; << p[i].completion << "\t\t"
return 0; } << p[i].turnaround << "\t\t"
<< p[i].waiting << endl;
totalTAT += p[i].turnaround;
INDEXED PROGRAM LINKEDtotalWT PROGRAM += p[i].waiting; SEQUENTIAL PROGRAM
#include <iostream> #include <iostream>
} cout << "\nAverage Turnaround Time: " << totalTAT / n; #include <iostream>
using namespace std; usingcoutnamespace std; Waiting Time: " << totalWT / n << endl;
<< "\nAverage using namespace std;
int main() { int main()
return{ 0; } int main() {
int files, i, j; int i, j, n; int n, i, j;
int index[10], size[10], data[10][10]; string name[10]; int blocks[20], startBlock[20], tempStart[20], memory[20][20];
cout << "Enter number of files: "; int start[10], total[10], block[10][10]; cout << "Enter number of files: ";
cin >> files; cout << "Enter number of files: "; cin >> n;
for (i = 0; i < files; i++) { cin >> n; for (i = 0; i < n; i++) {
cout << "\nFile " << i + 1 << ":\n"; for (i = 0; i < n; i++) { cout << "Enter number of blocks occupied by file " << i + 1 << ":
cout << "Enter index block: "; cout << "\nEnter file name: "; ";
cin >> index[i]; cin >> name[i]; cin >> blocks[i];
cout << "Enter number of blocks: "; cout << "Enter start block: "; cout << "Enter the starting block of file " << i + 1 << ": ";
cin >> size[i]; cin >> start[i]; cin >> startBlock[i];
cout << "Enter block numbers: "; cout << "Enter number of blocks: "; tempStart[i] = startBlock[i]; // Save original starting block
for (j = 0; j < size[i]; j++) { cin >> total[i]; for (j = 0; j < blocks[i]; j++) {
cin >> data[i][j]; cout << "Enter block numbers: "; memory[i][j] = startBlock[i]++;
} for (j = 0; j < total[i]; j++) { }
} cin >> block[i][j]; }
cout << "\nFile\tIndex\tSize\tBlocks\n"; } cout << "\nFilename\tStart Block\tLength\n";
for (i = 0; i < files; i++) { } cout << "\nFile\tStart\tSize\tBlocks\n"; for (i = 0; i < n; i++) {
cout << i + 1 << "\t" << index[i] << "\t" << size[i] << "\t"; for (i = 0; i < n; i++) { cout << i + 1 << "\t\t" << tempStart[i] << "\t\t" << blocks[i] <<
for (j = 0; j < size[i]; j++) { cout << name[i] << "\t" << start[i] << "\t" << total[i] << "\t"; "\n";
cout << data[i][j] << " "; for (j = 0; j < total[i]; j++) { }
} cout << block[i][j]; cout << "\nBlocks occupied are:\n";
cout << endl; if (j != total[i] - 1) for (i = 0; i < n; i++) {
} cout << " -> "; cout << "File " << i + 1 << ": ";
return 0; } cout << endl; for (j = 0; j < blocks[i]; j++) {
} } return 0; cout << memory[i][j] << " "; }
} cout << "\n"; }
return 0;
}

You might also like