*** SIMPLE C PROGRAM WILL RATE GOOD****
PLEASE LEAVE COMMENTS THROUGHOUT THE CODE SO I CAN SEE WHAT IS HAPPENING AND LEARN, THANK YOU!
Write a program that implements the following disk-scheduling algorithms:
a. FCFS
b. SSTF
c. SCAN
d. C-SCAN
e. LOOK
f. C-LOOK
Your program will service a disk with 5,000 cylinders numbered 0 to
4,999. The program will generate a random series of 1,000 cylinder
requests and service them according to each of the algorithms listed
above. The program will be passed the initial position of the disk head
(as a parameter on the command line) and report the total amount of
head movement required by each algorithm.
#include <iostream> #include <cstdlib> #include <conio.h> #include <math.h> using namespace std; int compare (const void * a, const void * b) { if ( *(int*)a < *(int*)b ) return -1; if ( *(int*)a == *(int*)b ) return 0; if ( *(int*)a > *(int*)b ) return 1; } void shift(int a[],const int size) { for(int i=1;i<=size;i++) a[i-1]=a[i]; } class disk { private : int request[101]; int sorted_request[101]; int number_of_request; int max; int direction; public : disk() { cout<<"\nEnter maximum disk limit : "; cin>>max; } void receive_request() { enter_request_number: cout<<"\nEnter number of requests (max. 100): "; cin>>number_of_request; if(number_of_request>100) goto enter_request_number; current_location: cout<<"\nEnter current location : "; cin>>request[0]; sorted_request[0]=request[0]; if(request[0]>max||request[0]<0) goto current_location; current_direction: cout<<"\nEnter current direction(0:left / 1:right) : "; cin>>direction; if(direction!=0&&direction!=1) goto current_direction; for(int i=1;i<=number_of_request;i++) { cout<<"\nEnter request number "<<i<<" : "; cin>>request[i]; sorted_request[i]=request[i]; if(request[i]>max||request[i]<0) { cout<<"\nInvalid request !! Enter again!!"; i--; } } qsort(sorted_request+1,number_of_request,sizeof(int),compare); } int fcfs() { int head_movement=0; for(int i=1;i<=number_of_request;i++) head_movement+=abs(request[i]-request[i-1]); return head_movement; } int sstf() { int head_movement=0,flag=0,nor=number_of_request; int request[101]; request[0]=sorted_request[0]; for(int i=1;i<=number_of_request;i++) { if(sorted_request[i]>sorted_request[0]&&flag==0) flag=i; request[i]=sorted_request[i]; } while(nor) { if(flag==0) { head_movement+=request[0]-request[nor]; request[0]=request[nor]; } else if(flag==1) { head_movement+=abs(request[nor]-request[0]); break; } else if((request[flag]-request[0])>(request[0]-request[flag-1])) { head_movement+=request[0]-request[flag-1]; request[0]=request[flag-1]; flag--; shift(request+flag,nor-flag); } else { head_movement+=request[flag]-request[0]; request[0]=request[flag]; shift(request+flag,nor-flag); } nor--; } return head_movement; } int SCAN() { int head_movement=0,flag=0; for(int i=1;i<=number_of_request;i++) if(sorted_request[i]>sorted_request[0]&&flag==0) flag=i; if(direction==1) { if(flag==1) head_movement+=sorted_request[number_of_request]-sorted_request[0]; else { head_movement+=max-sorted_request[0]; head_movement+=max-sorted_request[1]; } } else { if(flag==0) head_movement+=abs(sorted_request[number_of_request]-sorted_request[0]); else { head_movement+=sorted_request[0]; head_movement+=sorted_request[number_of_request]; } } return head_movement; } int CSCAN() { int head_movement=0,flag=0; for(int i=1;i<=number_of_request;i++) if(sorted_request[i]>sorted_request[0]&&flag==0) flag=i; if(flag==1) head_movement+=sorted_request[number_of_request]-sorted_request[0]; else { head_movement+=max-sorted_request[0]; head_movement+=max; head_movement+=max-sorted_request[flag-1]; } return head_movement; } int LOOK() { int head_movement=0,flag=0; for(int i=1;i<=number_of_request;i++) if(sorted_request[i]>sorted_request[0]&&flag==0) flag=i; if(direction==1) { if(flag==1) head_movement+=sorted_request[number_of_request]-sorted_request[0]; else { head_movement+=sorted_request[number_of_request]-sorted_request[0]; head_movement+=sorted_request[number_of_request]-sorted_request[1]; } } else { if(flag==0) head_movement+=abs(sorted_request[number_of_request]-sorted_request[0]); else { head_movement+=sorted_request[1]; head_movement+=sorted_request[number_of_request]-sorted_request[1]; } } return head_movement; } int CLOOK() { int head_movement=0,flag=0; for(int i=1;i<=number_of_request;i++) if(sorted_request[i]>sorted_request[0]&&flag==0) flag=i; if(flag==1) head_movement+=sorted_request[number_of_request]-sorted_request[0]; else { head_movement+=sorted_request[number_of_request]-sorted_request[0]; head_movement+=sorted_request[number_of_request]-sorted_request[1]; head_movement+=sorted_request[flag-1]-sorted_request[1]; } return head_movement; } ~disk(){} }; int main() { disk hdd; hdd.receive_request(); cout<<"Total head movement in "; cout<<"FCFS is "<<hdd.fcfs()<<endl; cout<<"Total head movement in "; cout<<"SSTF is "<<hdd.sstf()<<endl; cout<<"Total head movement in "; cout<<"SCAN is "<<hdd.SCAN()<<endl; cout<<"Total head movement in "; cout<<"CSCAN is "<<hdd.CSCAN()<<endl; cout<<"Total head movement in "; cout<<"LOOK is "<<hdd.LOOK()<<endl; cout<<"Total head movement in "; cout<<"CLOOK is "<<hdd.CLOOK()<<endl; _getche(); }
*** SIMPLE C PROGRAM WILL RATE GOOD**** PLEASE LEAVE COMMENTS THROUGHOUT THE CODE SO I CAN...
Write a program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN d. C-SCAN Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will be passed the initial position of the disk head (as a parameter on the command line) and report the total amount of head movement and total number of change of direction required by each algorithm under each of the following cases: a)The program will generate a random...
Use any language Task two Write a program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN d. C-SCAN e.LOOK f. C-LOOK Your program will service a disk with 500 cylinders numbered 0 to 499. The program will generate a random series of 20 cylinder requests and service them according to each of the algorithms listed above. The proram will be passed the initial position of the disk head (as a parameter on the command line) and...
Write a java program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN Your program will service a disk with 5000 cylinders numbered 0 to 4999. The program will generate a random series of 1,000 cylinder requests and service them according to each of nth algorithms listed above. The program will be passed the initial position of the disk head and report the total amount of head movement required by the algorithm.
1. Suppose that a disk drive has 5,000 cylinders, numbered 0 to 4,999. The drive is currently serving a request at cylinder 2,150, and the previous request was at cylinder 1,805. The queue of pending requests, in FIFO order, is: 2,069 1,212 2,296 2,800 544 1,618 356 1,523 4,956 3,681 Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending requests for each of the following disk-scheduling...
I/O Scheduling Algorithms a) For each of the following scheduling algorithms, give a 1-2 sentence description of how it works. The description should be precise enough to distinguish each algorithm from the others. Algorithms: FCFS, SSTF, SCAN, C-SCAN, C-LOOK. (1 point) b) Given a hard disk with 200 cylinders and a queue with jobs having the following cylinder requests: 80, 190, 70, 130, 30, draw a diagram of the movements of the head for each of the algorithms listed in...
Suppose that a disk drive has 10,000 cylinders, numbered 0 to 10,000. The drive is currently serving a request at cylinder 7,423 and the previous request was at cylinder 8213. The queue of pending requests, in FIFO order, is: 9324, 6324, 7232, 1304, 5621, 105, 5382, 3241, 2425, 9891. Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending requests for each of the following disk-scheduling algorithms?...
Suppose that a disk drive has 6,000 cylinders, numbered 0 to 5999. The drive is currently serving a request at cylinder 3150, and the previous request was at cylinder 1805 (Hint: this indicates the reading head’s moving direction). The queue of pending requests, in FIFO order, is: 3511, 2332, 2800, 3192, 658, 1296, 1918, 1356, 5936, 2527 Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending...
8.) [12 pts.] Suppose that a disk drive is currently serving a request at cylinder 1010, the previous red cylinder 1000. The queue of pending requests, in FIFO order, is: drive has 2,000 cylinders, numbered O to 1,999. The 1010, 1310, 1950, 800, 200, 750, 1000 Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisty all the pending requests for each of the following disk scheduling algorithms a.) FCFS...
I need a full solution to this question. ( Operating Systems ) First Image: Second Image: Third Image: Fourth Image: thank you. Suppose that a disk has 5000 cylinders, numbered 0 to 1999. The drive is currently serving a request at cylinder 143, and the previous request was at cylinder 152. The queue of pending requests is as follows: 130, 1750 1022, 1509, 948, 1774, 913, 1470, 86 Starting from the current head position, what is total "seek time" for...
Please help me with 6 questions in 2 pictures below! The question is very clear. Please help me is the Of the three components of access time in a movable-head Disk Arm Scheduling Algorithms, longest. Select one: a. delay time b. seek time c. transfer time d. search time DMA can operate in mode Select one: a. Word-at-time, Fly-by, Block mode b. Word-at-time, response, Block mode O c. Word-at-time, Fly-by, request d. Word-at-time, Fly-by The requirements for long-term information storage...