Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Below includes header files which does not need to be modified plus all the diff

ID: 669204 • Letter: B

Question

Below includes header files which does not need to be modified plus all the different .cpp codes. Look thru it and help me figure out some errors.

*BELOW IS THE proclist.header*

#include <iostream>

using namespace std;

#ifndef PROCLIST

#define PROCLIST

// List of Process History Information

// This is a simple linked list, all of whose elements record

// information about a process in a simulated process scheduler.

// This list data structure will be used for three different purposes:

// -- a record of the past history of a particular process

// -- a collection for the job scheduler of processes currently wishing to run

// -- a task list for known future events for the simulation

//

class ProcIterator;       // forward type declarations

class ProcList;           // since they all interact

class ProcListElement

{

friend class ProcList;   // these elements only used by ProcList

friend class ProcIterator;   // its iterator, and an output function

friend ostream& operator<<( ostream &, ProcListElement & );

friend ostream& operator<<( ostream &, ProcList & );

private:

int procID;       // process this applies to

int time;       // time stamp for event

char state;       // process state at that time

ProcListElement *next;   // linked list link

ProcListElement *prev; // linked list link

   ProcListElement( int i, int t, char s ) :

      procID(i), time(t), state(s), next(NULL), prev(NULL) { }

};

class ProcList

{

friend class ProcIterator;

friend ostream& operator<<( ostream &, ProcList & );

private:

ProcListElement *head, *tail;   // endpoints of list

public:

   ProcList() : head(NULL), tail(NULL) { }

   ~ProcList()       // destructor

   {

      clear();  

   }

      

bool empty()       // identify whether list is empty

   {

      return head == NULL;

   }

int leadTime()       // identify time of first event in list

   {

      return head->time;

   }

int tailTime()       // identify time of last event in list

   {

      return tail->time;

   }

void clear()       // erase the list

   {

      int i; char c;   // just placeholders

      while (head != NULL)

       popFront( i, c );

   }

ProcIterator begin();

ProcIterator end();

void pushBack( int, int, char );   // add new element to end

void insert( int, int, char );       // add element in time order

void popFront( int&, char& );       // remove element from front

};

// and an iterator to help visit all the data

class ProcIterator

{

friend class ProcList;   // List can create Iterators

private:

ProcList *list;           // which list are we visiting?

ProcListElement *current;   // which element now?

ProcIterator( ProcList *l, ProcListElement *e ) :

       list(l), current(e) { }

public:

bool operator!=( ProcIterator other )   // to compare to end()

   {

      return list != other.list || current != other.current;

   }

int process() const   { return current->procID; };

int time() const   { return current->time;   };

int state() const   { return current->state; };

void advance()       { current = current->next; }

ProcIterator erase();   // EXTRA CREDIT function

};

#endif

*BELOW IS THE proclist.cpp*

#include <iostream>

using namespace std;

// List of Process ProcList Information

// This is a simple linked list, all of whose elements record

// information about a process in a simulated process scheduler.

// This list data structure will be used for three different purposes:

// -- a record of the past history of a particular process

// -- a collection for the job scheduler of processes currently wishing to run

// -- a task list for known future events for the simulation

#include "proclist.h"

// First, some helper functions to display the data

ostream &operator<<( ostream &stream, ProcListElement &ele )

{

   stream << "(" << ele.procID << "," << ele.state << ","

      << ele.time << ")";

   return stream;

}

ostream &operator<<( ostream &stream, ProcList &hist )

{

   for (ProcListElement *curr = hist.head; curr != NULL; curr = curr->next )

   stream << *curr;

   stream << endl;

   return stream;

}

// And some functionality for the list itself.

// First some easy iterator definitions:

ProcIterator ProcList::begin()

{

return ProcIterator( this, head );

}

ProcIterator ProcList::end()

{

return ProcIterator( this, NULL );

}

// push a new element to the back end of the list

// Primarily used for First-In, First-Out ordering

void ProcList::pushBack( int procId, int time, char state )

{

   ProcListElement *newEle = new ProcListElement( procId, time, state );

if(empty())

{

head = newEle;

return;

}

else

{

ProcListElement *temp = new ProcListElement( 0, 0, ' ' );

temp = head;

while(temp->next) temp = temp->next;

temp->next = newEle;

newEle->prev = temp;

}

}

// remove the element at the front end of the list

// Two reference parameters are provided to hold onto information

// from the removed element. The time index is considered unnecessary.

void ProcList::popFront( int &procId, char &state )

{

if(empty())

{

cout<<"List is empty. No element to be deleted ";

  

return;

}

else

{

ProcListElement *temp = new ProcListElement( 0, 0, ' ' );

temp = head->next;

/* Copying the values to the reference variables passed */

procId = head->procID; state = head->state;

delete head;

head = temp;

}

}

// adds a new element into a sorted linked list

// which is sorted in increasing order according to the 'time' argument

void ProcList::insert( int procId, int time, char state )

{

   ProcListElement *newEle = new ProcListElement( procId, time, state );

if(empty())

{

head = newEle;

return;

}

else

{

ProcListElement *temp = new ProcListElement( 0, 0, ' ' );

temp = head;

while(temp->next && temp->time<=time) temp = temp->next;

if(temp->next == NULL)

{

temp->next = newEle;

}

else

{

newEle->prev = temp->prev;

temp->prev->next = newEle;

newEle->next = temp;

temp->prev = newEle;

}

}

}

*BELOW IS THE process.header*

#include "proclist.h"

#include <stdlib.h>

// A description of a process, executed in the process scheduling simulation

class Process

{

private:

int myId;       // an identifier for the larger picture

// A description of the process's total CPU needs

int bursts;       // total number of CPU bursts (<= 10)

int usages[10];       // lengths of each burst

char nextState[10];   // what to do after each burst

// A desription of what this process is doing now

int currentCycle;   // which burst is next ro run or continue

int remainingTime;   // how much time left on current burst

// A desription of what this process has done so far

ProcList log;

public:

Process( int id );   // the constructor appears in the .cpp

void restart()       // start at the very beginning

   {

      currentCycle = 0;

      remainingTime = usages[0];

      log.clear();   // empty the log

   }

void addLog( int time, char state )   // record an event

   {

      log.pushBack( myId, time, state );

   }

ProcList &getLog()

   {

      return log;       // get summarized results at end

   }

// run for a little while (in .cpp file)

void run( int &clock, int allowance, char &next );

};

*BELOW IS THE process.cpp in which the void Process::run needs to be completed *

#include "process.h"

// Process Constructor

// Initalizes a process as a single burst of CPU usage,

// which may or may not be allowed to run all at once.

// When that CPU time is complete, so is the process.

Process::Process( int id ) // a constructor

{

myId = id;

bursts = 1; // one big CPU requirement now

usages[0] = 80 + rand() % 120;

nextState[0] = 'Q'; // all done!

}

// Run a Process for some time

// The process would like to complete its current CPU burst,

// but is currently only allowed what is granted to it.

// Parameters:

//    clock       (modified int)   time on simulation clock

//    allowance   (input int)   time allowed to run with

//   next       (output char)   the process next state after this

//       'Q' = process is complete; 'X' = process wishes to run more

// Post-Condition:

//    the clock will have advanced until either the allowed time

//    has been used up, or the current CPU burst is complete

//    (whichever happens earlier). There will be no idle CPU time.

// Also: The history log for this Process will record what is known

//    at this time

void Process::run( int &clock, int allowance, char &next )

{

  

}

*BELOW IS THE histo.header*

#include "process.h"

// History Displayer

// Produces an Ascii-graphic representation of the history of a process

// within a simulation of job scheduling. The history is recorded as a

// series of time stamps, represented here as integer time values and

// characters representing state.

// Paramaters:

// history input ProcList array   linked lists of events and times

// size   input int       number of elements in array

// start   input int       beginning of time frame of interest

// stop   input int       end of time frame of interest

// Pre-Conditions:

// 'history' concludes with an entry with state 'Q' for completion

// 'start' and 'stop' are both positive integers, with start < stop

// NOTE: either 'start' or 'stop' may exceed the largest value in 'when'

// Results:

// A display of between 20 and 50 printable characters representing

// the job history within the time range of interest, using the

// characters stored within 'what'. Events outside the actual range

// of the job history will be displayed with blanks.

void displayHistory( Process history[], int size, int start, int stop );

*BELOW IS THE histo.cpp*

// History Displayer

// Produces an Ascii-graphic representation of the history of a process

// within a simulation of job scheduling. The history is recorded as a

// series of time stamps, represented here as integer time values and

// characters representing state.

// Paramaters:

// when   input int array       when this job changed state

// what   input char array   what state this job changed to

// start   input int       beginning of time frame of interest

// stop   input int       end of time frame of interest

// Pre-Conditions:

// 'what' consists of printable characters, including 'Q' marking end of job

// The Q symbol is not at position 0 of the array

// 'when' consists of increasing positive integers

// the number of meaningful values in both arrays is equal (including 'Q')

// 'start' and 'stop' are both positive integers, with start < stop

// NOTE: either 'start' or 'stop' may exceed the largest value in 'when'

// Results:

// A display of between 20 and 50 printable characters representing

// the job history within the time range of interest, using the

// characters stored within 'what'. Events outside the actual range

// of the job history will be displayed with blanks.

#include <iostream>

#include <iomanip>

using namespace std;

void displayHistory( const int when[], const char what[], int start, int stop )

{

char display[50];           // to hold the output

int outpos;               // next output position to fill

int scan;               // next input data item to scan

char currentState;           // current process state in history

int time;               // current time examined

int range = stop - start;       // total time period

int increment = 1 + range / 50;   // round fractions upwards

for (int i=0; i<50; i++)       // clear display

   display[i] = ' ';

// Identify where to begin recording output data, and

// what time to begin analyzing at (tracking may start early)

if (when[0] > start)       // process has not yet started yet

{

   outpos = (when[0]-start) / increment;   // skip spaces

   time = when[0];           // and start here

}

else

{

   outpos = 0;           // start at beginning of display

   time = start;           // and take measurements here

}

// Identify where first applicable data appears

// (tracking may start in the middle)

scan = 0;              

while (time <= stop && time >= when[scan+1])

   scan++;

currentState = what[scan];

// when[scan] <= time < when[scan+1]

// currentState represents the process state at this

// particular instant in time

// collect relevant data into the output array

while ( time <= stop && currentState != 'Q' )

{

   // currentState (what[scan]) extends from when[scan] to when[scan+1]

   // when[scan] <= time

   // On first repetition, time < when[scan+1], so currentState

   // corresponds to this instant in time (and may be recorded)

   // To avoid excessive "scan+1"s, this will increment right here

   scan++;      

   // currentState extends to when[scan], so record it until

   // that time is reached. First outer loop guarantees an iteration

while (time <= stop && time < when[scan])

   {

   display[outpos] = currentState;

   outpos++;           // next output array position

   time += increment;       // next time instant

   }

   currentState = what[scan];   // next state

   // It is possible that "time+increment" has jumped over a state

   // and recording executions while be interesting to know

   // This X will be recorded on top of the very last entry stored

   // so it will not get overwritten on the next loop cycle

   // (and we know from above that outpos > 0)

   if ( currentState == 'X' && time >= when[scan+1] )

      display[outpos-1] = 'X';   // record very short CPU burst that we missed

}

// Terminate the character array with a null character for easy output

display[outpos] = '';

cout << "Time: " << setw(4) << start <<

   setw( range/increment ) << stop << endl;

cout << "History: " << display << endl;

}

*BELOW IS THE scheduler.h*

#include <iostream>

using namespace std;

#include "histo.h"

// Process Scheduler

// This represents the part of an operating system that manages processes,

// choosing which to assign the CPU (assuming a single-processor system).

// It will maintain a collection of processes that are currently ready

// to use the CPU, and then choose which to run next.

//

// The time on the system clock is not required for this object,

// so all of the time fields in the linked list objects are set to zero.

class Scheduler

{

private:

ProcList readySet;   // set of processes ready to run

ProcList future;   // list of future events

int clock;       // current clock time for simulation

public:

void addProcess( int procId )

   {

      readySet.pushBack( procId, 0, 'X');

   }

void chooseProcess( int &procId )

   {

      char hold;

      readySet.popFront( procId, hold );

   }

bool noneReady()

   {

      return readySet.empty();

   }

void runScheduler( Process[], int[], int, int );

};

*BELOW IS THE scheduler.cpp*

#include "scheduler.h"

// Scheduler Simulation

// Simulates a process scheduler for a collecdtion of tasks

// Parameters:

//    tasks       (modified process array)description of tasks to run

//    arrival       (input int array)   arrival in simulation time

//    size       (input int)       number of elements in arrays

//    allowance   (input int)       maximal CPU allowance

//       (a large 'allowance' simulates First Come First Served)

// Each Process includes a history of its activity which is

// pupulated during the simulation and displayed afterwards.

//

// The scheduler includes a readySet of processes that are currently

// wishing to use the CPU, and a future list of events t hat will

// occur later in the simulation. A simulation clock advances to

// identify which events occur in which order.

void Scheduler::runScheduler( Process tasks[], int arrival[], int size, int allowance )

{

int pid;           // process wanting action

char nextAct;       // and the action it wants

for (int i=0; i < size; i++)

{

future.insert( i, arrival[i], 'X'); // all want to run

   tasks[i].restart(); // and start at beginning

   tasks[i].addLog( arrival[i], '-'); // might have to wait

}

clock = 0;           // initialize simulation clock

// repeat while anything is ready to run now or later

for(int i=0;i<size;i++) //repeat this scheduling for each process i

{

while ( !noneReady() || !future.empty() ) //repeat until every process is ready to run

{

if(clock==arrival[i]) //if arrival time is equal to clock time

tasks->insert(i,arrival[i],'X'); //run the i-th process and update status to X-completed[Here gives me an error with “No member named ‘insert’ in ‘Process’”]

}

clock++; //increment clock value

}

}

*BELOW IS THE driver.cpp*

// A quick driver to test the History Display routine

// It just fabricates a single job history to see what it does

//

#include <iostream>

using namespace std;

#include "scheduler.h"

int main()

{

   Scheduler sched;          // make a process scheduler

   Process tasks[] =           // 3 processes

   { Process(0), Process(1), Process(2) };  

   int arrival[] = {0, 40, 80}; // arrive at these times

   cout << "First Come First Served" << endl;

   sched.runScheduler( tasks, arrival, 3, 500000 );   // FIFO

   displayHistory( tasks, 3, 0, 500 );

   cout << endl << "Quanta of 70" << endl;

   sched.runScheduler( tasks, arrival, 3, 70 );   // RR generous

   displayHistory( tasks, 3, 0, 500 );

   cout << endl << "Quanta of 10" << endl;

   sched.runScheduler( tasks, arrival, 3, 10 );   // RR stingy

   displayHistory( tasks, 3, 0, 500 );

}

THANK YOU. theres not much coding you have to do just help me peace it together and check if this codes makes sense plus if you do modify the codes plz put it in bold.

Explanation / Answer

All you have done is looking perfect though i have not complied it, but check it manually drawing each class.
one Function which did not implement

is void Process::run( int &clock, int allowance, char &next );

so here is the implementation of that

// Run a Process for some time
// The process would like to complete its current CPU burst,
// but is currently only allowed what is granted to it.
// Parameters:
// clock (modified int) time on simulation clock
// allowance (input int) time allowed to run with
// next (output char) the process next state after this
// 'Q' = process is complete; 'X' = process wishes to run more
// Post-Condition:
// the clock will have advanced until either the allowed time
// has been used up, or the current CPU burst is complete
// (whichever happens earlier). There will be no idle CPU time.
// Also: The history log for this Process will record what is known
// at this time
void Process::run( int &clock, int allowance, char &next ){
addLog(clock,next);
nextState[bursts] = next;
remainingTime = allowance;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote