Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<string.h>
- #include <conio.h>
- using namespace std;
- #define MAX 100
- /* DECLARATIONS */
- char choice, choiceA, IU;
- int a=1, b = 0, d=0,c = 2, e=0, procs, x, y, ans, ans1, ansA, ansB, ansC, batangPasaway, ansD, ansE;
- int AT[MAX];
- int BT[MAX];
- int ANS[MAX];
- int PROCS[MAX];
- int PRI[MAX];
- /* VOIDS */
- void input();
- void FCFS();
- void SJF();
- void priority();
- void inputPriority();
- /* MAIN PROGRAM */
- int main(int argc, char** argv) {
- IU:
- cout << "\nChoose Your Program:";
- cout << "\nA - FIRST COME FIRST SERVE";
- cout << "\nB - SHORTEST JOB FIRST";
- cout << "\nC - PRIORITY SCHEDULING";
- cout << "\nYour choice: ";
- cin >> choice;
- choiceA = choice;
- system("CLS");
- if (choiceA == 'A' || choiceA =='a'){
- input();
- FCFS();
- }
- if (choiceA == 'B' || choiceA =='b'){
- input();
- SJF();
- }
- else if (choiceA == 'C' || choiceA =='c'){
- inputPriority();
- priority();
- }
- }
- /* ENTER PROCESSES */
- void input(){
- cout << "Enter Number of Processes: ";
- cin >> procs;
- PROCS[MAX] = procs;
- for(int i=0; i<procs; i++){
- PROCS[i] = i;
- cout << "\nProcess " << i+1;
- cout << "\nArrival Time: ";
- cin >> AT[i];
- cout << "Burst Time: ";
- cin >> BT[i];
- x++;
- }
- }
- void inputPriority(){
- cout << "Enter Number of Processes: ";
- cin >> procs;
- PROCS[MAX] = procs;
- for(int i=0; i<procs; i++){
- PROCS[i] = i;
- cout << "\nProcess " << i+1;
- cout << "\nArrival Time: ";
- cin >> AT[i];
- while(AT[0]!= 0 && AT[0]!= 1 && x == 0) {
- cout << "The arrival time of Process 1 must be 1 or 0.";
- cout << "\nRe enter: ";
- cin >> AT[i];}
- cout << "Burst Time: ";
- cin >> BT[i];
- cout << "Priority: ";
- cin >> PRI[i];
- x++;
- }
- }
- /* ITS THE GANT CHART NAAA AAA AAAA */
- void gantChart(){
- cout << "\t\tITS THE GANT CHART \n";
- cout << "\nNOTE: if it has dash it is idle\n\n";
- cout << "|";
- for(int i=0; i<procs; i++){
- cout << " P" << PROCS[i]+1 << " |";
- }
- }
- /* FIRST COME FIRST SERVE */
- void FCFS(){
- cout << "\nPROCESS" << "\t ARRIVAL TIME" << "\t BURST TIME";
- for(int i=0; i<procs; i++){
- for(int j=1; j<procs-i-1; j++){
- if(AT[j] > AT[j+1] ){
- int temp = AT[j];
- AT[j] = AT[j+1];
- AT[j+1] = temp;
- temp = PROCS[j];
- PROCS[j] = PROCS[j+1];
- PROCS[j+1] = temp;
- temp = BT[j];
- BT[j] = BT[j+1];
- BT[j+1] = temp;
- }
- }
- }
- for(int i=0; i<procs; i++){
- cout << "\n " << PROCS[i] + 1 << "\t " << AT[i] << "\t\t "<< BT[i];
- }
- cout << "\n\n";
- system("pause");
- system("CLS");
- gantChart();
- ans = BT[0] + BT[b+1];
- ANS[d] = ans;
- if (AT[0] == 0)
- cout << "\n" << AT[0] << " " << BT[0] << " " << ANS[d];
- else
- cout << "\n 0-" << AT[0] << " " << BT[0] << "- " << ANS[d];
- for(int i=0; i<procs-2; i++){
- ANS[i] = ANS[d] + BT[c];
- cout << "\t " << ANS[i];
- ANS[i] = ANS[i];
- c++;
- }
- /* ITS TURNAROUNDD TIMEEEE */
- cout << "\n\nTURN-AROUND TIME";
- ansB = BT[0] - AT[0];
- ansC = ans - AT[1];
- for(int i=0; i<procs-3; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << BT[i] << " - " << AT[i] << "= " << ansB ;
- }
- for(int i=1; i<procs-2; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[1] << "= " << ansC ;
- }
- for(int i=2; i<procs; i++){
- ansD = ANS[(i-2)] - AT[i];
- cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-2)] << " - " << AT[i] << "= " << ansD ;
- }
- /* ITS WAITINGGGGGG TIMEEEE */
- cout << "\n\nWAITING TIME";
- ansB = AT[0] - AT[0];
- ansC = BT[0] - AT[1];
- ansE = ans - AT[2];
- for(int i=0; i<procs-3; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << AT[i] << " - " << AT[i] << "= " << ansB ;
- }
- for(int i=1; i<procs-2; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << BT[0] << " - " << AT[1] << "= " << ansC ;
- }
- for(int i=2; i<procs-1; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[2] << "= " << ansE ;
- }
- for(int i=3; i<procs; i++){
- ansD = ANS[(i-3)] - AT[i];
- cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-3)] << " - " << AT[i] << "= " << ansD ;
- }
- }
- /*SHORTEST JOB FIRST */
- void SJF(){
- cout << "\nPROCESS" << "\t ARRIVAL TIME" << "\t BURST TIME";
- for(int i=0; i<procs; i++){
- for(int j=1; j<procs-i-1; j++){
- if(BT[j] > BT[j+1] ){
- int temp = AT[j];
- AT[j] = AT[j+1];
- AT[j+1] = temp;
- temp = PROCS[j];
- PROCS[j] = PROCS[j+1];
- PROCS[j+1] = temp;
- temp = BT[j];
- BT[j] = BT[j+1];
- BT[j+1] = temp;
- }
- }
- }
- for(int i=0; i<procs; i++){
- cout << "\n " << PROCS[i] + 1 << "\t " << AT[i] << "\t\t "<< BT[i];
- }
- cout << "\n\n";
- system("pause");
- system("CLS");
- gantChart();
- ans = BT[0] + BT[b+1];
- ANS[d] = ans;
- if (AT[0] == 0)
- cout << "\n" << AT[0] << " " << BT[0] << " " << ANS[d];
- else
- cout << "\n 0-" << AT[0] << " " << BT[0] << "- " << ANS[d];
- for(int i=0; i<procs-2; i++){
- ANS[i] = ANS[d] + BT[c];
- cout << "\t " << ANS[i];
- ANS[i] = ANS[i];
- c++;
- }
- /* ITS TURNAROUNDD TIMEEEE */
- cout << "\n\nTURN-AROUND TIME";
- ansB = BT[0] - AT[0];
- ansC = ans - AT[1];
- for(int i=0; i<procs-3; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << BT[i] << " - " << AT[i] << "= " << ansB ;
- }
- for(int i=1; i<procs-2; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[1] << "= " << ansC ;
- }
- for(int i=2; i<procs; i++){
- ansD = ANS[(i-2)] - AT[i];
- cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-2)] << " - " << AT[i] << "= " << ansD ;
- }
- /* ITS WAITINGGGGGG TIMEEEE */
- cout << "\n\nWAITING TIME";
- ansB = AT[0] - AT[0];
- ansC = BT[0] - AT[1];
- ansE = ans - AT[2];
- for(int i=0; i<procs-3; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << AT[i] << " - " << AT[i] << "= " << ansB ;
- }
- for(int i=1; i<procs-2; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << BT[0] << " - " << AT[1] << "= " << ansC ;
- }
- for(int i=2; i<procs-1; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[2] << "= " << ansE ;
- }
- for(int i=3; i<procs; i++){
- ansD = ANS[(i-3)] - AT[i];
- cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-3)] << " - " << AT[i] << "= " << ansD ;
- }
- }
- /* PRIORITY SCHEDULING */
- void priority(){
- cout << "\nPROCESS" << "\t ARRIVAL TIME" << "\t BURST TIME" << "\t PRIORITY";
- for(int i=0; i<procs; i++){
- for(int j=1; j<procs-i-1; j++){
- if(PRI[j] > PRI[j+1] ){
- int temp = AT[j];
- AT[j] = AT[j+1];
- AT[j+1] = temp;
- temp = PROCS[j];
- PROCS[j] = PROCS[j+1];
- PROCS[j+1] = temp;
- temp = BT[j];
- BT[j] = BT[j+1];
- BT[j+1] = temp;
- temp = PRI[j];
- PRI[j] = PRI[j+1];
- PRI[j+1] = temp;
- }
- }
- }
- for(int i=0; i<procs; i++){
- cout << "\n " << PROCS[i] + 1 << "\t " << AT[i] << "\t\t "<< BT[i] << "\t\t "<< PRI[i];
- }
- cout << "\n\n";
- system("pause");
- system("CLS");
- gantChart();
- ans = BT[0] + BT[b+1];
- ANS[d] = ans;
- if (AT[0] == 0)
- cout << "\n" << AT[0] << " " << BT[0] << " " << ANS[d];
- else
- cout << "\n 0-" << AT[0] << " " << BT[0] << "- " << ANS[d];
- for(int i=0; i<procs-2; i++){
- ANS[i] = ANS[d] + BT[c];
- cout << "\t " << ANS[i];
- ANS[i] = ANS[i];
- c++;
- }
- /* ITS TURNAROUNDD TIMEEEE */
- cout << "\n\nTURN-AROUND TIME";
- ansB = BT[0] - AT[0];
- ansC = ans - AT[1];
- for(int i=0; i<procs-3; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << BT[i] << " - " << AT[i] << "= " << ansB ;
- }
- for(int i=1; i<procs-2; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[1] << "= " << ansC ;
- }
- for(int i=2; i<procs; i++){
- ansD = ANS[(i-2)] - AT[i];
- cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-2)] << " - " << AT[i] << "= " << ansD ;
- }
- /* ITS WAITINGGGGGG TIMEEEE */
- cout << "\n\nWAITING TIME";
- ansB = AT[0] - AT[0];
- ansC = BT[0] - AT[1];
- ansE = ans - AT[2];
- for(int i=0; i<procs-3; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << AT[i] << " - " << AT[i] << "= " << ansB ;
- }
- for(int i=1; i<procs-2; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << BT[0] << " - " << AT[1] << "= " << ansC ;
- }
- for(int i=2; i<procs-1; i++){
- cout << "\nP" << PROCS[i]+1 << "= " << ans << " - " << AT[2] << "= " << ansE ;
- }
- for(int i=3; i<procs; i++){
- ansD = ANS[(i-3)] - AT[i];
- cout << "\nP" << PROCS[i]+1 << "= " << ANS[(i-3)] << " - " << AT[i] << "= " << ansD ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement