1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#include <iostream>
#include <fstream>
using namespace std;
class pnode
{
public:
int c;
pnode *pnext;
};
class PROCESS
{
public:
PROCESS(); //constructor
//~PROCESS(); //destructor
void setProcess(int data[], int);
void AdjustTime();
pnode *time;
PROCESS *next;
int process_number;
int current_burst;
int IOtime;
int responsetime;
int waitingtime;
int turnaroundtime;
};
class QUEUE : public PROCESS
{
public:
QUEUE();
// ~QUEUE();
void currentprocess(PROCESS *);
void IOprocess(PROCESS *, int);
void Dequeue(PROCESS *);
void run(int&, int&, QUEUE *);
void calculation(int&, int&);
void display(int, QUEUE *);
bool currentIsEmpty();
bool waitingIsEmpty();
private:
PROCESS *first;
};
PROCESS::PROCESS()
{
process_number = current_burst = IOtime = 0;
waitingtime = turnaroundtime = 0;
responsetime = -1;
}
//PROCESS::~PROCESS()
//{
// while (time != NULL)
// {
// AdjustTime();
// }
//}
void PROCESS::setProcess(int data[], int num)
{
process_number = num;
pnode *ptr = new pnode;
time = ptr;
current_burst = data[0];
for (int i = 0; i < 21; i++)
{
ptr->c = data[i];
if (data[i + 1] == 0)
{
ptr->pnext = NULL;
return;
}
ptr->pnext = new pnode;
ptr = ptr->pnext;
}
}
int main(int argc, const char * argv[]) {
PROCESS p1, p2, p3, p4, p5, p6, p7, p8;
QUEUE readyQueue, waitingQueue;
int timer = 0;
int idle = 0;
int stop = 100;
bool end = false;
int data1[14] = { 6, 17, 8, 19, 12, 31, 11, 18, 9, 22, 8, 26, 10, 0 };
p1.setProcess(data1, 1);
readyQueue.currentprocess(&p1);
int data2[18] = { 19, 38, 11, 24, 15, 21, 12, 27, 12, 34, 11, 34, 9, 29, 9, 31, 7, 0 };
p2.setProcess(data2, 2);
readyQueue.currentprocess(&p2);
int data3[18] = { 3, 37, 14, 41, 8, 30, 4, 19, 7, 33, 5, 18, 4, 26, 5, 31, 16, 0 };
p3.setProcess(data3, 3);
readyQueue.currentprocess(&p3);
int data4[16] = { 15, 35, 14, 41, 16, 45, 18, 51, 14, 61, 13, 54, 16, 61, 15, 0 };
p4.setProcess(data4, 4);
readyQueue.currentprocess(&p4);
int data5[18] = { 9, 24, 7, 21, 15, 31, 6, 26, 7, 31, 3, 18, 6, 21, 6, 33, 3, 0 };
p5.setProcess(data5, 5);
readyQueue.currentprocess(&p5);
int data6[18] = { 4, 38, 3, 41, 5, 29, 4, 26, 7, 32, 4, 22, 3, 26, 5, 22, 8, 0 };
p6.setProcess(data6, 6);
readyQueue.currentprocess(&p6);
int data7[16] = { 14, 36, 17, 31, 16, 32, 15, 41, 14, 42, 17, 39, 16, 33, 15, 0 };
p7.setProcess(data7, 7);
readyQueue.currentprocess(&p7);
int data8[18] = { 5, 14, 4, 33, 6, 31, 4, 31, 6, 27, 5, 21, 4, 19, 6, 11, 6, 0 };
p8.setProcess(data8, 8);
readyQueue.currentprocess(&p8);
while (end == false)
{
readyQueue.run(timer, idle, &waitingQueue);
if (readyQueue.currentIsEmpty() && waitingQueue.waitingIsEmpty())
{
end = true;
}
}
cout << "\n\t\t Processes are complete\n\n";
waitingQueue.calculation(timer, idle);
system("pause");
return 0;
}
|