-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDISKSHED_FCFS1.cpp
More file actions
60 lines (45 loc) · 1.67 KB
/
DISKSHED_FCFS1.cpp
File metadata and controls
60 lines (45 loc) · 1.67 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
int headPosition, totalRequests;
cout << "Enter the current head position: ";
cin >> headPosition;
cout << "Enter the total number of disk requests: ";
cin >> totalRequests;
int* requests = new int[totalRequests];
cout << "Enter the disk request positions:\n";
for (int i = 0; i < totalRequests; i++) {
cout << "Request " << (i + 1) << ": ";
cin >> requests[i];
}
// Calculate the total head movement and build the seek sequence
int totalHeadMovement = 0;
vector<int> seekSequence;
// Process each request in the order of arrival
for (int i = 0; i < totalRequests; i++) {
// Calculate the absolute difference between head position and current request
int headMovement = abs(requests[i] - headPosition);
// Update the head position
headPosition = requests[i];
// Accumulate the head movement
totalHeadMovement += headMovement;
// Add the current request position to the seek sequence
seekSequence.push_back(requests[i]);
}
cout << "\nTotal head movement: " << totalHeadMovement << endl;
// Display the seek sequence
cout << "Seek Sequence: ";
for (int i = 0; i < seekSequence.size(); i++) {
cout << seekSequence[i];
if (i != seekSequence.size() - 1) {
cout << " -> ";
}
}
cout << endl;
cout<<"Throughput:"<<(float)totalRequests/totalHeadMovement;
// Deallocate the dynamically allocated memory
delete[] requests;
return 0;
}