Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ problem, We are doing a round robin scheduler with a queue, these are the instructions for the main.cpp file. take in a batch filename

c++ problem, We are doing a round robin scheduler with a queue, these are the instructions for the main.cpp file.

take in a batch filename as a command line argument

check for correct command line arguments (basically, make sure one is provided)

buildQueue function - takes in a filename and reference param for the time slice; reads time slice and job info and enqueues each job

roundRobin function - takes in the job queue and time slice and implement the round robin algorithm above

Here is round robin algorithm,

While the queue is not empty: 1. dequeue the next job from the queue 2. run it for t time units or until finished (whichever is smaller) 3. if the job is not finished, enqueue it

Below is my code so far, but i am unable to read input from the batch file , my difficulty is with reading the file with ifstream infile, how do i fix it?

Here is an example batch input,

more jobs.batch 250 0 760 1 650 2 530 3 400 4 810 5 940 6 670 7 105 8 280 9 370

Here is example output,

g++ main.cpp $ ./a.out jobs.batch 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 8 9 0 1 2 4 5 6 0 4 5

#include

#include

#include

#include "quuu.h"

#include "job.h"

#include

using namespace std;

void buildqueue( string n, int lice){

string line;

int id, time;

QUEUE S;

ifstream infile(n);

infile >> timeslice;

while(getline(infile,line)) {

infile >> id;

infile >>time;

Job In(id,time) ;

S.enqueue(In);

}

infile.close();

}

void roundrobin( QUEUE job ,Job a, int time_slice){

while ((job.isEmpty())== false ){

job.dequeue();

int rtime;

a.run(time_slice, rtime) ;

}

if(a.id_method() < time_slice )

job.enqueue(a);

cout << a.id_method();

}

int main(int argc, char *argv[]) {

// check for the right number of cmd args

// and exit if not properly included

if (argc != 2) {

cout << "You must enter one string as an argument!" << endl;

exit(1);

}

int n =0;

QUEUE S;

Job list;

string fn = (argv[1]); //filename

buildqueue(fn,n ) ;

roundrobin(S,list,n);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions