class Scheduler{ //SuperClass for inheritance private: public: // the following is for overridden in all of 4 schedulers. // all are abstract base classes. virtual void insertReady(Event Ready) = 0; virtual bool QEmpty() = 0; // check whether the deque is empty virtual Event toProcess() = 0; }; class FCFS : public Scheduler{ private: public: FCFS(); //constructor deque<Event> modeReady; // Initialize the deque /* the following is first come first serve. when calling, always pop the first element in the deque of modeReady */ void insertReady(Event newEvent){ modeReady.push_back(newEvent); } bool QEmpty(){ if (modeReady.size() == 0){ return true; } else{ return false; } } Event toProcess(){ // the first element go processing, and remove it from the deque container Event newProcess = modeReady.front(); // the first ready goes to processing, log it. modeReady.pop_front(); // pop up the current first element from deque. return newProcess; } }; class LCFS : public Scheduler{ private: public: LCFS(); // constructor deque<Event> modeReady; // Initializae the queue void insertReady(Event newEvent){ modeReady.push_back(newEvent); } bool QEmpty(){ if (modeReady.size() == 0){ return true; } else{ return false; } } Event toProcess(){ // return the Event newProcess = modeReady.back(); // the last element go processing, and remove it from the deque container modeReady.pop_back(); // pop up the current last element from deque. return newProcess; } }; class RR : public Scheduler{ /* // Concept: // queue Q while(true) { w = Q.front() w = work(w) if(hasProcess()) Q.push(nextPorcess()) if(w != null) Q.push(w) time++ } */ private: public: RR(int timeQuantum); // constructor: as requirement in the document, we need to accept time quantum for RoundRobin // the format is similar to FCFS, we deal the remain details in the main function deque<Event> modeReady; void insertReady(Event newEvent){ modeReady.push_back(newEvent); } bool QEmpty(){ if (modeReady.size() == 0){ return true; } else{ return false; } } Event toProcess(){ Event newProcess = modeReady.front(); // the first ready goes to processing, log it. modeReady.pop_front(); // pop up the current first element from deque. return newProcess; } }; class PRIO : public Scheduler{ private: public: PRIO(int timeQuantum); // constructor: as requirement in the document, we need to accept time quantum for RoundRobin // the format is similar to FCFS, we deal the remain details in the main function deque<Event> modeReady; void insertReady(Event newEvent){ modeReady.push_back(newEvent); } bool QEmpty(){ if (modeReady.size() == 0){ return true; } else{ return false; } } Event toProcess(){ Event newProcess = modeReady.front(); // the first ready goes to processing, log it. modeReady.pop_front(); // pop up the current first element from deque. return newProcess; } }; class ShortJobFirst : public Scheduler{ private: public: ShortJobFirst(); // Constructor deque<Event> modeReady; // Initialize deque void insertReady(Event newEvent){ deque<Event>::iterator it; for (it = modeReady.begin() ; it != modeReady.end() ; ++it){ if (newEvent.timeEXE < (*it).timeEXE){ // choose the current shortest one break; } } modeReady.insert(it , newEvent); } bool QEmpty(){ if (modeReady.size() == 0){ return true; } else{ return false; } } // now, the prior element in container deque is the shortest, it shoud be pushed to process first. Event toProcess(){ Event newProcess = modeReady.front(); deque<Event>::iterator it; /* // test // std::cout << "mydeque contains:"; for (std::deque<int>::iterator it = mydeque.begin(); it!=mydeque.end(); ++it){ std::cout << ' ' << *it; std::cout << '\n'; } */ modeReady.erase(modeReady.begin()); return newProcess; } }; Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD) string sCMD = "F"; // Default: 'F':= FCFS. double cpuTimeSum = 0; // total time of CPU running. Initialization: 0. int quantum = 2147483647; // Default: the max integer. int main(int argc , char* argv[]){ string schAlgo; Scheduler* scheduler; // since the scheduler is abstract, so we need to set a pointer for it. scheduler = SchInitial(schAlgo , quantum , sCMD); } Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD){ if (sCMD == "F"){ schAlgo = "FCFS"; return new FCFS(); } else if (sCMD == "L"){ schAlgo = "LCFS"; return new LCFS(); } else if (sCMD == "S"){ schAlgo = "ShortJobFirst"; return new ShortJobFirst(); } else if (sCMD == "R10"){ schAlgo = "RR"; quantum = atoi(sCMD.substr(1).c_str()); return new RR(quantum); } else { schAlgo = "PRIO"; quantum = atoi(sCMD.substr(1).c_str()); return new PRIO(quantum); } }
Standard input is empty
prog.cpp:8:28: error: ‘Event’ has not been declared
virtual void insertReady(Event Ready) = 0;
^~~~~
prog.cpp:12:11: error: ‘Event’ does not name a type
virtual Event toProcess() = 0;
^~~~~
prog.cpp:21:3: error: ‘deque’ does not name a type
deque<Event> modeReady; // Initialize the deque
^~~~~
prog.cpp:29:20: error: ‘Event’ has not been declared
void insertReady(Event newEvent){
^~~~~
prog.cpp:42:3: error: ‘Event’ does not name a type
Event toProcess(){ // the first element go processing, and remove it from the deque container
^~~~~
prog.cpp: In member function ‘virtual void FCFS::insertReady(int)’:
prog.cpp:30:4: error: ‘modeReady’ was not declared in this scope
modeReady.push_back(newEvent);
^~~~~~~~~
prog.cpp: In member function ‘virtual bool FCFS::QEmpty()’:
prog.cpp:34:8: error: ‘modeReady’ was not declared in this scope
if (modeReady.size() == 0){
^~~~~~~~~
prog.cpp: At global scope:
prog.cpp:55:3: error: ‘deque’ does not name a type
deque<Event> modeReady; // Initializae the queue
^~~~~
prog.cpp:57:20: error: ‘Event’ has not been declared
void insertReady(Event newEvent){
^~~~~
prog.cpp:70:3: error: ‘Event’ does not name a type
Event toProcess(){ // return the
^~~~~
prog.cpp: In member function ‘virtual void LCFS::insertReady(int)’:
prog.cpp:58:4: error: ‘modeReady’ was not declared in this scope
modeReady.push_back(newEvent);
^~~~~~~~~
prog.cpp: In member function ‘virtual bool LCFS::QEmpty()’:
prog.cpp:62:8: error: ‘modeReady’ was not declared in this scope
if (modeReady.size() == 0){
^~~~~~~~~
prog.cpp: At global scope:
prog.cpp:102:3: error: ‘deque’ does not name a type
deque<Event> modeReady;
^~~~~
prog.cpp:104:20: error: ‘Event’ has not been declared
void insertReady(Event newEvent){
^~~~~
prog.cpp:117:3: error: ‘Event’ does not name a type
Event toProcess(){
^~~~~
prog.cpp: In member function ‘virtual void RR::insertReady(int)’:
prog.cpp:105:4: error: ‘modeReady’ was not declared in this scope
modeReady.push_back(newEvent);
^~~~~~~~~
prog.cpp: In member function ‘virtual bool RR::QEmpty()’:
prog.cpp:109:8: error: ‘modeReady’ was not declared in this scope
if (modeReady.size() == 0){
^~~~~~~~~
prog.cpp: At global scope:
prog.cpp:134:3: error: ‘deque’ does not name a type
deque<Event> modeReady;
^~~~~
prog.cpp:136:20: error: ‘Event’ has not been declared
void insertReady(Event newEvent){
^~~~~
prog.cpp:149:3: error: ‘Event’ does not name a type
Event toProcess(){
^~~~~
prog.cpp: In member function ‘virtual void PRIO::insertReady(int)’:
prog.cpp:137:4: error: ‘modeReady’ was not declared in this scope
modeReady.push_back(newEvent);
^~~~~~~~~
prog.cpp: In member function ‘virtual bool PRIO::QEmpty()’:
prog.cpp:141:8: error: ‘modeReady’ was not declared in this scope
if (modeReady.size() == 0){
^~~~~~~~~
prog.cpp: At global scope:
prog.cpp:165:3: error: ‘deque’ does not name a type
deque<Event> modeReady; // Initialize deque
^~~~~
prog.cpp:169:20: error: ‘Event’ has not been declared
void insertReady(Event newEvent){
^~~~~
prog.cpp:192:3: error: ‘Event’ does not name a type
Event toProcess(){
^~~~~
prog.cpp: In member function ‘virtual void ShortJobFirst::insertReady(int)’:
prog.cpp:170:4: error: ‘deque’ was not declared in this scope
deque<Event>::iterator it;
^~~~~
prog.cpp:170:10: error: ‘Event’ was not declared in this scope
deque<Event>::iterator it;
^~~~~
prog.cpp:170:16: error: ‘::iterator’ has not been declared
deque<Event>::iterator it;
^~
prog.cpp:171:9: error: ‘it’ was not declared in this scope
for (it = modeReady.begin() ; it != modeReady.end() ; ++it){
^~
prog.cpp:171:14: error: ‘modeReady’ was not declared in this scope
for (it = modeReady.begin() ; it != modeReady.end() ; ++it){
^~~~~~~~~
prog.cpp:172:18: error: request for member ‘timeEXE’ in ‘newEvent’, which is of non-class type ‘int’
if (newEvent.timeEXE < (*it).timeEXE){ // choose the current shortest one
^~~~~~~
prog.cpp:177:4: error: ‘modeReady’ was not declared in this scope
modeReady.insert(it , newEvent);
^~~~~~~~~
prog.cpp:177:21: error: ‘it’ was not declared in this scope
modeReady.insert(it , newEvent);
^~
prog.cpp: In member function ‘virtual bool ShortJobFirst::QEmpty()’:
prog.cpp:183:8: error: ‘modeReady’ was not declared in this scope
if (modeReady.size() == 0){
^~~~~~~~~
prog.cpp: At global scope:
prog.cpp:209:23: error: ‘string’ was not declared in this scope
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD)
^~~~~~
prog.cpp:209:31: error: ‘schAlgo’ was not declared in this scope
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD)
^~~~~~~
prog.cpp:209:41: error: expected primary-expression before ‘int’
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD)
^~~
prog.cpp:209:56: error: ‘string’ was not declared in this scope
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD)
^~~~~~
prog.cpp:209:64: error: ‘sCMD’ was not declared in this scope
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD)
^~~~
prog.cpp:209:68: error: expression list treated as compound expression in initializer [-fpermissive]
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD)
^
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:215:2: error: ‘string’ was not declared in this scope
string schAlgo;
^~~~~~
prog.cpp:218:25: error: ‘schAlgo’ was not declared in this scope
scheduler = SchInitial(schAlgo , quantum , sCMD);
^~~~~~~
prog.cpp:218:45: error: ‘sCMD’ was not declared in this scope
scheduler = SchInitial(schAlgo , quantum , sCMD);
^~~~
prog.cpp:218:49: error: ‘SchInitial’ cannot be used as a function
scheduler = SchInitial(schAlgo , quantum , sCMD);
^
prog.cpp: At global scope:
prog.cpp:222:23: error: redefinition of ‘Scheduler* SchInitial’
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD){
^~~~~~
prog.cpp:209:12: note: ‘Scheduler* SchInitial’ previously defined here
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD)
^~~~~~~~~~
prog.cpp:222:23: error: ‘string’ was not declared in this scope
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD){
^~~~~~
prog.cpp:222:31: error: ‘schAlgo’ was not declared in this scope
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD){
^~~~~~~
prog.cpp:222:41: error: expected primary-expression before ‘int’
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD){
^~~
prog.cpp:222:56: error: ‘string’ was not declared in this scope
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD){
^~~~~~
prog.cpp:222:64: error: ‘sCMD’ was not declared in this scope
Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD){
^~~~
Standard output is empty