CODE> #include #include #include #include using namespace std; struct process { int pid; int arrival_time; int burst_time; int priority; int start_time; int completion_time; int turnaround_time; int waiting_time; int response_time; }; int main() { int n; struct process p[100]; declare all the variables required memset(is_completed,0,sizeof(is_comple ted)); cout<<"Enter the number of processes: "; cin>>n; for(int i = 0; i < n; i++) { cout<<"Enter processId of process "<>p[i].pid; } for(int i = 0; i < n; i++) { cout<<"Enter arrival time of process "<>p[i].arrival_time; } for(int i = 0; i < n; i++) { cout<<"Enter burst time of process "<>p[i].burst_time; burst_remaining[i] = p[i].burst_time; } for(int i = 0; i < n; i++) { cout<<"Enter priority of the process "<>p[i].priority; } cout<<"Pid\t"<<"AT\t"<<"BT\t"<<"P RI\t"<<"\n"< mx) { mx = p[i].priority; idx = i; } if(p[i].priority == mx) { if(p[i].arrival_time < p[idx].arrival_time) { mx = p[i].priority; idx = i; } } } } if(idx != -1) { if(burst_remaining[idx] == p[idx].burst_time) { p[idx].start_time = current_time; } // Write code to calculate burst time, arrival time, turn around time, waiting time, average time } else { current_time++; } } avg_turnaround_time = (float) //find out turn around time //declare total waiting  time //declare total waiting  time //declare average time total_response_time / n; cout<

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter2: Basic Elements Of C++
Section: Chapter Questions
Problem 1TF: 1. Mark the following statements as true or false. a. An identifier must start with a letter and can...
icon
Related questions
Question
100%

CODE>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string.h>
using namespace std;
struct process {
int pid;
int arrival_time;
int burst_time;

int priority;
int start_time;
int completion_time;
int turnaround_time;
int waiting_time;
int response_time;
};
int main() {
int n;
struct process p[100];
declare all the variables required
memset(is_completed,0,sizeof(is_comple
ted));
cout<<"Enter the number of
processes: ";
cin>>n;
for(int i = 0; i < n; i++) {
cout<<"Enter processId of process
"<<i+1<<": ";
cin>>p[i].pid;

}
for(int i = 0; i < n; i++) {
cout<<"Enter arrival time of
process "<<i+1<<": ";
cin>>p[i].arrival_time;
}
for(int i = 0; i < n; i++) {
cout<<"Enter burst time of process
"<<i+1<<": ";
cin>>p[i].burst_time;
burst_remaining[i] =
p[i].burst_time;

}
for(int i = 0; i < n; i++) {
cout<<"Enter priority of the
process "<<i+1<<": ";
cin>>p[i].priority;
}
cout<<"Pid\t"<<"AT\t"<<"BT\t"<<"P
RI\t"<<"\n"<<endl;
for(int i = 0; i < n; i++) {
cout<<p[i].pid<<"\t"<<p[i].arrival_time
<<"\t"<<p[i].burst_time<<"\t"<<p[i].pr
iority<<"\t"<<endl;
}

int current_time = 0;
int completed = 0;
int prev = 0;
while(completed != n) {
int idx = -1;
int mx = -1;
for(int i = 0; i < n; i++) {
if(p[i].arrival_time <=
current_time && is_completed[i] == 0)
{
if(p[i].priority > mx) {
mx = p[i].priority;
idx = i;
}
if(p[i].priority == mx) {

if(p[i].arrival_time <
p[idx].arrival_time) {
mx = p[i].priority;
idx = i;
}
}
}
}
if(idx != -1) {
if(burst_remaining[idx] ==
p[idx].burst_time) {
p[idx].start_time =
current_time;
}
// Write code to calculate burst time, arrival time, turn around time, waiting time, average time
}
else {
current_time++;
}
}
avg_turnaround_time = (float)
//find out turn around time

//declare total waiting  time
//declare total waiting  time
//declare average time
total_response_time / n;
cout<<endl<<endl;
cout<<"Pid\t"<<"AT\t"<<"BT\t"<<"P
RI\t"<<"ST\t"<<"CT\t"<<"TAT\t"<<"
WT\t"<<"RT\t"<<"\n"<<endl;
for(int i = 0; i < n; i++) {
cout<<p[i].pid<<"\t"<<p[i].arrival_time
<<"\t"<<p[i].burst_time<<"\t"<<p[i].pr
iority<<"\t"<<p[i].start_time<<"\t"<<p
[i].completion_time<<"\t"<<p[i].turnar
ound_time<<"\t"<<p[i].waiting_time<<
"\t"<<p[i].response_time<<"\t"<<"\n"
<<endl;
}
//print all the times
return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning