-
Notifications
You must be signed in to change notification settings - Fork 1
/
FCFS-DSP.cpp
41 lines (37 loc) · 1013 Bytes
/
FCFS-DSP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<bits/stdc++.h>
using namespace std;
int reqNum, head, currentHead, sum=0, x, i;
vector<int> requestQueue;
void processInput(){
cout<<"Enter the number of requests : ";
cin>>reqNum;
cout<<"Enter the request queue : ";
for(i=0; i<reqNum; i++){
cin>>x;
requestQueue.push_back(x);
}
cout<<"Enter Head position : ";
cin>>head;
}
void FCFS(){
x=0, currentHead=head;
cout<<"\n\tIteration\tCurrent Head\tDisk Movement\tTotal Disk Movement\n";
for(auto i : requestQueue){
sum += abs(currentHead-i);
cout<<"\t"<<x+1<<"\t\t"<<i<<"\t\t"<<abs(currentHead-i)<<"\t\t"<<sum<<endl;
currentHead = i;
++x;
}
cout<<"\nTotal Head Movement = "<<sum<<endl;
cout<<"Average Seek Time = "<<double(sum)/double(reqNum)<<endl;
cout<<"Order : ";
for(auto i : requestQueue){
if(i == requestQueue[reqNum-1]){cout<<i;break;}
cout<<i<<" -> ";
}
}
int main(){
processInput();
FCFS();
return 0;
}