fork download
  1. class Scheduler{ //SuperClass for inheritance
  2. private:
  3.  
  4. public:
  5.  
  6. // the following is for overridden in all of 4 schedulers.
  7. // all are abstract base classes.
  8. virtual void insertReady(Event Ready) = 0;
  9.  
  10. virtual bool QEmpty() = 0; // check whether the deque is empty
  11.  
  12. virtual Event toProcess() = 0;
  13.  
  14. };
  15.  
  16. class FCFS : public Scheduler{
  17. private:
  18.  
  19. public:
  20. FCFS(); //constructor
  21. deque<Event> modeReady; // Initialize the deque
  22.  
  23. /*
  24. the following is first come first serve.
  25. when calling, always pop the first element in the deque of modeReady
  26. */
  27.  
  28.  
  29. void insertReady(Event newEvent){
  30. modeReady.push_back(newEvent);
  31. }
  32.  
  33. bool QEmpty(){
  34. if (modeReady.size() == 0){
  35. return true;
  36. }
  37. else{
  38. return false;
  39. }
  40. }
  41.  
  42. Event toProcess(){ // the first element go processing, and remove it from the deque container
  43. Event newProcess = modeReady.front(); // the first ready goes to processing, log it.
  44. modeReady.pop_front(); // pop up the current first element from deque.
  45. return newProcess;
  46. }
  47.  
  48. };
  49.  
  50. class LCFS : public Scheduler{
  51. private:
  52.  
  53. public:
  54. LCFS(); // constructor
  55. deque<Event> modeReady; // Initializae the queue
  56.  
  57. void insertReady(Event newEvent){
  58. modeReady.push_back(newEvent);
  59. }
  60.  
  61. bool QEmpty(){
  62. if (modeReady.size() == 0){
  63. return true;
  64. }
  65. else{
  66. return false;
  67. }
  68. }
  69.  
  70. Event toProcess(){ // return the
  71. Event newProcess = modeReady.back(); // the last element go processing, and remove it from the deque container
  72. modeReady.pop_back(); // pop up the current last element from deque.
  73. return newProcess;
  74. }
  75.  
  76.  
  77.  
  78. };
  79.  
  80. class RR : public Scheduler{
  81. /*
  82. // Concept: //
  83. queue Q
  84. while(true) {
  85.   w = Q.front()
  86.   w = work(w)
  87.   if(hasProcess())
  88.   Q.push(nextPorcess())
  89.   if(w != null)
  90.   Q.push(w)
  91.   time++
  92. }
  93. */
  94.  
  95. private:
  96.  
  97. public:
  98. RR(int timeQuantum); // constructor: as requirement in the document, we need to accept time quantum for RoundRobin
  99.  
  100.  
  101. // the format is similar to FCFS, we deal the remain details in the main function
  102. deque<Event> modeReady;
  103.  
  104. void insertReady(Event newEvent){
  105. modeReady.push_back(newEvent);
  106. }
  107.  
  108. bool QEmpty(){
  109. if (modeReady.size() == 0){
  110. return true;
  111. }
  112. else{
  113. return false;
  114. }
  115. }
  116.  
  117. Event toProcess(){
  118. Event newProcess = modeReady.front(); // the first ready goes to processing, log it.
  119. modeReady.pop_front(); // pop up the current first element from deque.
  120. return newProcess;
  121. }
  122.  
  123. };
  124.  
  125.  
  126. class PRIO : public Scheduler{
  127. private:
  128.  
  129. public:
  130. PRIO(int timeQuantum); // constructor: as requirement in the document, we need to accept time quantum for RoundRobin
  131.  
  132.  
  133. // the format is similar to FCFS, we deal the remain details in the main function
  134. deque<Event> modeReady;
  135.  
  136. void insertReady(Event newEvent){
  137. modeReady.push_back(newEvent);
  138. }
  139.  
  140. bool QEmpty(){
  141. if (modeReady.size() == 0){
  142. return true;
  143. }
  144. else{
  145. return false;
  146. }
  147. }
  148.  
  149. Event toProcess(){
  150. Event newProcess = modeReady.front(); // the first ready goes to processing, log it.
  151. modeReady.pop_front(); // pop up the current first element from deque.
  152. return newProcess;
  153. }
  154.  
  155.  
  156.  
  157. };
  158.  
  159. class ShortJobFirst : public Scheduler{
  160. private:
  161.  
  162. public:
  163.  
  164. ShortJobFirst(); // Constructor
  165. deque<Event> modeReady; // Initialize deque
  166.  
  167.  
  168.  
  169. void insertReady(Event newEvent){
  170. deque<Event>::iterator it;
  171. for (it = modeReady.begin() ; it != modeReady.end() ; ++it){
  172. if (newEvent.timeEXE < (*it).timeEXE){ // choose the current shortest one
  173. break;
  174. }
  175. }
  176.  
  177. modeReady.insert(it , newEvent);
  178. }
  179.  
  180.  
  181.  
  182. bool QEmpty(){
  183. if (modeReady.size() == 0){
  184. return true;
  185. }
  186. else{
  187. return false;
  188. }
  189. }
  190.  
  191. // now, the prior element in container deque is the shortest, it shoud be pushed to process first.
  192. Event toProcess(){
  193. Event newProcess = modeReady.front();
  194. deque<Event>::iterator it;
  195. /*
  196. // test //
  197. std::cout << "mydeque contains:";
  198.   for (std::deque<int>::iterator it = mydeque.begin(); it!=mydeque.end(); ++it){
  199.   std::cout << ' ' << *it;
  200.   std::cout << '\n';
  201.   }
  202. */
  203. modeReady.erase(modeReady.begin());
  204. return newProcess;
  205. }
  206.  
  207. };
  208.  
  209. Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD)
  210. string sCMD = "F"; // Default: 'F':= FCFS.
  211. double cpuTimeSum = 0; // total time of CPU running. Initialization: 0.
  212. int quantum = 2147483647; // Default: the max integer.
  213.  
  214. int main(int argc , char* argv[]){
  215. string schAlgo;
  216.  
  217. Scheduler* scheduler; // since the scheduler is abstract, so we need to set a pointer for it.
  218. scheduler = SchInitial(schAlgo , quantum , sCMD);
  219.  
  220. }
  221.  
  222. Scheduler* SchInitial(string& schAlgo , int& quantum , string& sCMD){
  223. if (sCMD == "F"){
  224. schAlgo = "FCFS";
  225. return new FCFS();
  226. }
  227.  
  228. else if (sCMD == "L"){
  229. schAlgo = "LCFS";
  230. return new LCFS();
  231. }
  232.  
  233. else if (sCMD == "S"){
  234. schAlgo = "ShortJobFirst";
  235. return new ShortJobFirst();
  236. }
  237.  
  238. else if (sCMD == "R10"){
  239. schAlgo = "RR";
  240. quantum = atoi(sCMD.substr(1).c_str());
  241. return new RR(quantum);
  242. }
  243.  
  244. else {
  245. schAlgo = "PRIO";
  246. quantum = atoi(sCMD.substr(1).c_str());
  247. return new PRIO(quantum);
  248. }
  249.  
  250. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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){
                                                                ^~~~
stdout
Standard output is empty