Advertisement
BSIT_21

GERONIMO [SCHEDULING] [MAY MALI ATA HAHA]

Aug 5th, 2019
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.39 KB | None | 0 0
  1. #include <iostream>
  2. #include<string.h>
  3. #include <conio.h>
  4. using namespace std;
  5. #define MAX 100
  6.  
  7. /* DECLARATIONS */
  8. char choice, choiceA, IU;
  9. int a=1, b = 0, d=0,c = 2, e=0, procs, x, y, ans, ans1, ansA, ansB, ansC,  batangPasaway, ansD, ansE;
  10. int AT[MAX];
  11. int BT[MAX];
  12. int ANS[MAX];
  13. int PROCS[MAX];
  14. int PRI[MAX];
  15. /* VOIDS */
  16. void input();
  17. void FCFS();
  18. void SJF();
  19. void priority();
  20. void inputPriority();
  21.  
  22. /* MAIN PROGRAM */
  23. int main(int argc, char** argv) {
  24.    
  25.     IU:
  26.     cout << "\nChoose Your Program:";
  27.     cout << "\nA - FIRST COME FIRST SERVE";
  28.     cout << "\nB - SHORTEST JOB FIRST";
  29.     cout << "\nC - PRIORITY SCHEDULING";
  30.     cout << "\nYour choice: ";
  31.     cin >> choice;
  32.     choiceA = choice;
  33.     system("CLS");
  34.    
  35.     if (choiceA == 'A' || choiceA =='a'){
  36.         input();
  37.         FCFS();
  38.     }
  39.     if (choiceA == 'B' || choiceA =='b'){
  40.         input();
  41.         SJF();
  42.     }
  43.     else if (choiceA == 'C' || choiceA =='c'){
  44.         inputPriority();
  45.         priority();
  46.     }
  47. }
  48.  
  49. /* ENTER PROCESSES */
  50.     void input(){
  51.         cout << "Enter Number of Processes: ";
  52.         cin >> procs;
  53.         PROCS[MAX] = procs;
  54.        
  55.    
  56.        
  57.         for(int i=0; i<procs; i++){
  58.             PROCS[i] = i;
  59.            
  60.             cout << "\nProcess " << i+1;
  61.             cout << "\nArrival Time: ";
  62.             cin >> AT[i];
  63.            
  64.        
  65.             cout << "Burst Time: ";
  66.             cin >> BT[i];
  67.            
  68.             x++;
  69.         }
  70.         }
  71.    
  72.         void inputPriority(){
  73.         cout << "Enter Number of Processes: ";
  74.         cin >> procs;
  75.         PROCS[MAX] = procs;
  76.        
  77.    
  78.        
  79.         for(int i=0; i<procs; i++){
  80.             PROCS[i] = i;
  81.            
  82.             cout << "\nProcess " << i+1;
  83.             cout << "\nArrival Time: ";
  84.             cin >> AT[i];
  85.            
  86.              while(AT[0]!= 0 && AT[0]!= 1 && x == 0) {
  87.             cout << "The arrival time of Process 1 must be 1 or 0.";
  88.             cout << "\nRe enter: ";
  89.             cin >> AT[i];}
  90.        
  91.             cout << "Burst Time: ";
  92.             cin >> BT[i];
  93.            
  94.             cout << "Priority: ";
  95.             cin >> PRI[i];
  96.            
  97.             x++;
  98.         }
  99.         }
  100.        
  101.        
  102.     /* ITS THE GANT CHART NAAA AAA AAAA */
  103.     void gantChart(){
  104.         cout << "\t\tITS THE GANT CHART    \n";
  105.         cout << "\nNOTE: if it has dash it is idle\n\n";
  106.         cout << "|";
  107.             for(int i=0; i<procs; i++){
  108.                 cout << "   P" << PROCS[i]+1  << "  |";
  109.             }
  110.     }
  111.    
  112.     /* FIRST COME FIRST SERVE */
  113.     void FCFS(){
  114.     cout << "\nPROCESS" << "\t   ARRIVAL TIME" << "\t  BURST TIME";
  115.     for(int i=0; i<procs; i++){
  116.     for(int j=1; j<procs-i-1; j++){
  117.         if(AT[j] > AT[j+1] ){
  118.             int temp = AT[j];
  119.             AT[j] = AT[j+1];
  120.             AT[j+1] = temp;
  121.            
  122.             temp = PROCS[j];
  123.             PROCS[j] = PROCS[j+1];
  124.             PROCS[j+1] = temp;
  125.            
  126.             temp = BT[j];
  127.             BT[j] = BT[j+1];
  128.             BT[j+1] = temp;
  129.             }
  130. }
  131. }
  132.  
  133.     for(int i=0; i<procs; i++){
  134.             cout << "\n  " << PROCS[i] + 1 << "\t     " << AT[i]  << "\t\t   "<< BT[i];
  135.     }
  136.    
  137.     cout << "\n\n";
  138.     system("pause");
  139.     system("CLS");
  140.    
  141.     gantChart();
  142.    
  143.     ans = BT[0] + BT[b+1];
  144.     ANS[d] = ans;
  145.     if (AT[0] == 0)
  146.     cout << "\n" << AT[0] << "      "  << BT[0] << "      "  <<  ANS[d];
  147.     else
  148.     cout << "\n  0-" << AT[0] << "  " << BT[0] << "-     " << ANS[d];
  149.    
  150.     for(int i=0; i<procs-2; i++){
  151.     ANS[i] = ANS[d] + BT[c];
  152.     cout << "\t   " << ANS[i];
  153.     ANS[i] = ANS[i];
  154.     c++;
  155.     }
  156.    
  157.     /* ITS TURNAROUNDD TIMEEEE */
  158.     cout  << "\n\nTURN-AROUND TIME";
  159.     ansB = BT[0] - AT[0];
  160.     ansC = ans - AT[1];
  161.     for(int i=0; i<procs-3; i++){
  162.             cout << "\nP" << PROCS[i]+1 << "= " << BT[i] << " - " << AT[i] << "= " << ansB ;
  163.     }
  164.         for(int i=1; i<procs-2; i++){
  165.             cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[1] << "= " << ansC ; 
  166.     }
  167.     for(int i=2; i<procs; i++){
  168.         ansD = ANS[(i-2)] - AT[i];
  169.             cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-2)] << " - " << AT[i] << "= " << ansD ;  
  170.     }
  171.    
  172.     /* ITS WAITINGGGGGG TIMEEEE */
  173.     cout  << "\n\nWAITING TIME";
  174.     ansB = AT[0] - AT[0];
  175.     ansC = BT[0] - AT[1];
  176.     ansE = ans - AT[2];
  177.     for(int i=0; i<procs-3; i++){
  178.             cout << "\nP" << PROCS[i]+1 << "= " << AT[i] << " - " << AT[i] << "= " << ansB ;
  179.     }
  180.         for(int i=1; i<procs-2; i++){
  181.             cout << "\nP" << PROCS[i]+1 << "= " << BT[0] << " - " << AT[1] << "= " << ansC ;   
  182.     }
  183.         for(int i=2; i<procs-1; i++){
  184.             cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[2] << "= " << ansE ; 
  185.     }
  186.     for(int i=3; i<procs; i++){
  187.     ansD = ANS[(i-3)] - AT[i];
  188.             cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-3)] << " - " << AT[i] << "= " << ansD ;  
  189.     }
  190. }
  191.  
  192. /*SHORTEST JOB FIRST */
  193. void SJF(){
  194.     cout << "\nPROCESS" << "\t   ARRIVAL TIME" << "\t  BURST TIME";
  195.     for(int i=0; i<procs; i++){
  196.     for(int j=1; j<procs-i-1; j++){
  197.         if(BT[j] > BT[j+1] ){
  198.             int temp = AT[j];
  199.             AT[j] = AT[j+1];
  200.             AT[j+1] = temp;
  201.            
  202.             temp = PROCS[j];
  203.             PROCS[j] = PROCS[j+1];
  204.             PROCS[j+1] = temp;
  205.            
  206.             temp = BT[j];
  207.             BT[j] = BT[j+1];
  208.             BT[j+1] = temp;
  209.            
  210.         }
  211.     }
  212. }
  213.  
  214.     for(int i=0; i<procs; i++){
  215.             cout << "\n  " << PROCS[i] + 1 << "\t     " << AT[i]  << "\t\t   "<< BT[i];
  216.     }
  217.    
  218.     cout << "\n\n";
  219.     system("pause");
  220.     system("CLS");
  221.    
  222.     gantChart();
  223.    
  224.     ans = BT[0] + BT[b+1];
  225.     ANS[d] = ans;
  226.     if (AT[0] == 0)
  227.     cout << "\n" << AT[0] << "      "  << BT[0] << "      "  <<  ANS[d];
  228.     else
  229.     cout << "\n  0-" << AT[0] << "  " << BT[0] << "-     " << ANS[d];
  230.    
  231.     for(int i=0; i<procs-2; i++){
  232.     ANS[i] = ANS[d] + BT[c];
  233.     cout << "\t   " << ANS[i];
  234.     ANS[i] = ANS[i];
  235.     c++;
  236.     }
  237.        
  238.     /* ITS TURNAROUNDD TIMEEEE */
  239.     cout  << "\n\nTURN-AROUND TIME";
  240.     ansB = BT[0] - AT[0];
  241.     ansC = ans - AT[1];
  242.     for(int i=0; i<procs-3; i++){
  243.             cout << "\nP" << PROCS[i]+1 << "= " << BT[i] << " - " << AT[i] << "= " << ansB ;
  244.     }
  245.         for(int i=1; i<procs-2; i++){
  246.             cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[1] << "= " << ansC ; 
  247.     }
  248.     for(int i=2; i<procs; i++){
  249.         ansD = ANS[(i-2)] - AT[i];
  250.             cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-2)] << " - " << AT[i] << "= " << ansD ;  
  251.     }
  252.    
  253.     /* ITS WAITINGGGGGG TIMEEEE */
  254.     cout  << "\n\nWAITING TIME";
  255.     ansB = AT[0] - AT[0];
  256.     ansC = BT[0] - AT[1];
  257.     ansE = ans - AT[2];
  258.     for(int i=0; i<procs-3; i++){
  259.             cout << "\nP" << PROCS[i]+1 << "= " << AT[i] << " - " << AT[i] << "= " << ansB ;
  260.     }
  261.         for(int i=1; i<procs-2; i++){
  262.             cout << "\nP" << PROCS[i]+1 << "= " << BT[0] << " - " << AT[1] << "= " << ansC ;   
  263.     }
  264.         for(int i=2; i<procs-1; i++){
  265.             cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[2] << "= " << ansE ; 
  266.     }
  267.     for(int i=3; i<procs; i++){
  268.     ansD = ANS[(i-3)] - AT[i];
  269.             cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-3)] << " - " << AT[i] << "= " << ansD ;  
  270.     }
  271. }
  272.  
  273. /* PRIORITY SCHEDULING */
  274. void priority(){
  275.         cout << "\nPROCESS" << "\t   ARRIVAL TIME" << "\t  BURST TIME" << "\t  PRIORITY";
  276.     for(int i=0; i<procs; i++){
  277.     for(int j=1; j<procs-i-1; j++){
  278.         if(PRI[j] > PRI[j+1] ){
  279.             int temp = AT[j];
  280.             AT[j] = AT[j+1];
  281.             AT[j+1] = temp;
  282.            
  283.             temp = PROCS[j];
  284.             PROCS[j] = PROCS[j+1];
  285.             PROCS[j+1] = temp;
  286.            
  287.             temp = BT[j];
  288.             BT[j] = BT[j+1];
  289.             BT[j+1] = temp;
  290.            
  291.             temp = PRI[j];
  292.             PRI[j] = PRI[j+1];
  293.             PRI[j+1] = temp;
  294.            
  295.            
  296.            
  297.            
  298.            
  299.             }
  300. }
  301. }
  302.  
  303.     for(int i=0; i<procs; i++){
  304.             cout << "\n  " << PROCS[i] + 1 << "\t     " << AT[i]  << "\t\t   "<< BT[i] << "\t\t   "<< PRI[i];
  305.     }
  306.    
  307.     cout << "\n\n";
  308.     system("pause");
  309.     system("CLS");
  310.    
  311.     gantChart();
  312.    
  313.     ans = BT[0] + BT[b+1];
  314.     ANS[d] = ans;
  315.     if (AT[0] == 0)
  316.     cout << "\n" << AT[0] << "      "  << BT[0] << "      "  <<  ANS[d];
  317.     else
  318.     cout << "\n  0-" << AT[0] << "  " << BT[0] << "-     " << ANS[d];
  319.    
  320.     for(int i=0; i<procs-2; i++){
  321.     ANS[i] = ANS[d] + BT[c];
  322.     cout << "\t   " << ANS[i];
  323.     ANS[i] = ANS[i];
  324.     c++;
  325.     }
  326.    
  327.         /* ITS TURNAROUNDD TIMEEEE */
  328.     cout  << "\n\nTURN-AROUND TIME";
  329.     ansB = BT[0] - AT[0];
  330.     ansC = ans - AT[1];
  331.     for(int i=0; i<procs-3; i++){
  332.             cout << "\nP" << PROCS[i]+1 << "= " << BT[i] << " - " << AT[i] << "= " << ansB ;
  333.     }
  334.         for(int i=1; i<procs-2; i++){
  335.             cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[1] << "= " << ansC ; 
  336.     }
  337.     for(int i=2; i<procs; i++){
  338.         ansD = ANS[(i-2)] - AT[i];
  339.             cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-2)] << " - " << AT[i] << "= " << ansD ;  
  340.     }
  341.    
  342.     /* ITS WAITINGGGGGG TIMEEEE */
  343.     cout  << "\n\nWAITING TIME";
  344.     ansB = AT[0] - AT[0];
  345.     ansC = BT[0] - AT[1];
  346.     ansE = ans - AT[2];
  347.     for(int i=0; i<procs-3; i++){
  348.             cout << "\nP" << PROCS[i]+1 << "= " << AT[i] << " - " << AT[i] << "= " << ansB ;
  349.     }
  350.         for(int i=1; i<procs-2; i++){
  351.             cout << "\nP" << PROCS[i]+1 << "= " << BT[0] << " - " << AT[1] << "= " << ansC ;   
  352.     }
  353.         for(int i=2; i<procs-1; i++){
  354.             cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[2] << "= " << ansE ; 
  355.     }
  356.     for(int i=3; i<procs; i++){
  357.     ansD = ANS[(i-3)] - AT[i];
  358.             cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-3)] << " - " << AT[i] << "= " << ansD ;  
  359.     }
  360. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement