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
|
#include<iostream>
#include<queue>
#include<list>
using namespace std;
struct JOB
{
int process_number;
int total_time_required;
int time_to_finish;
int slice_remaining;
int priority;
};
struct Job findNextJob(queue<Job>queue1&,queue<Job>queue2&) //function I'm trying to figure out
{
Job tempjob;
if(!queue1.empty())
{
tempjob = queue1.front();
queue1.pop();
return tempjob;
}
}
int main()
{
queue<JOB> queue1;
queue<JOB> queue2;
queue<JOB> queue3;
queue<JOB> queue4;
queue<JOB> queue5;
queue<JOB> queue6;
JOB * process1 = new JOB[1];
JOB * process2 = new JOB[1];
JOB * process3 = new JOB[1];
JOB * process4 = new JOB[1];
JOB * process5 = new JOB[1];
JOB job1,job2,job3,job4,job5,job6,job7,job8,job9,job10,job11,job12,job13,job14,job15, jtemp;
job1.process_number = 1; job1.total_time_required = 6; job1.time_to_finish = 6; job1.priority = 1; job1.slice_remaining = 4;
job2.process_number = 2; job2.total_time_required = 4; job2.time_to_finish = 4; job2.priority = 3; job2.slice_remaining = 4;
job3.process_number = 3; job3.total_time_required = 8; job3.time_to_finish = 8; job3.priority = 1; job3.slice_remaining = 4;
job4.process_number = 4; job4.total_time_required = 3; job4.time_to_finish = 3; job4.priority = 2; job4.slice_remaining = 3;
job5.process_number = 5; job4.total_time_required = 8; job5.time_to_finish = 8; job5.priority = 4; job5.slice_remaining = 4;
job6.process_number = 6; job6.total_time_required = 2; job6.time_to_finish = 2; job6.priority = 3; job6.slice_remaining = 2;
job7.process_number = 7; job7.total_time_required = 4; job7.time_to_finish = 4; job7.priority = 5; job7.slice_remaining = 4;
job8.process_number = 8; job8.total_time_required = 8; job8.time_to_finish = 8; job8.priority = 4; job8.slice_remaining = 4;
job9.process_number = 9; job9.total_time_required = 7; job9.time_to_finish = 7; job9.priority = 1; job9.slice_remaining = 4;
job10.process_number = 10; job10.total_time_required = 6; job10.time_to_finish = 6; job10.priority = 4; job10.slice_remaining = 4;
job11.process_number = 11; job11.total_time_required = 3; job11.time_to_finish = 3; job11.priority = 1; job11.slice_remaining = 3;
job12.process_number = 12; job12.total_time_required = 7; job12.time_to_finish = 7; job12.priority = 3; job12.slice_remaining = 4;
job13.process_number = 13; job13.total_time_required = 3; job13.time_to_finish = 3; job13.priority = 2; job13.slice_remaining = 3;
job14.process_number = 14; job14.total_time_required = 4; job14.time_to_finish = 4; job14.priority = 4; job14.slice_remaining = 4;
job15.process_number = 15; job15.total_time_required = 7; job15.time_to_finish = 7; job15.priority = 1; job15.slice_remaining = 4;
queue1.push(job1);queue1.push(job3);queue1.push(job9); queue1.push(job11); queue1.push(job15);
queue2.push(job4);queue2.push(job13);
queue3.push(job2);queue1.push(job6);queue1.push(job12);
queue4.push(job5);queue1.push(job8);queue1.push(job10);queue1.push(job14);
queue1.push(job7);
int pp = 1; // variable for the time slices that have taken place
while(pp<5)
{
cout<<"start of while "<<pp<<endl;
if(pp % 4 == 0)
{
cout<<"i is " <<pp<<endl;
pp = 0;
}
if(!queue1.empty())
{
process1[0] = queue1.front();
queue1.pop();
}
if(!queue1.empty())
{
process2[0] = queue1.front();
queue1.pop();
}
if(!queue1.empty())
{
process3[0] = queue1.front();
queue1.pop();
}
if(!queue1.empty())
{
process4[0] = queue1.front();
queue1.pop();
}
if(!queue1.empty())
{
process5[0] = queue1.front();
queue1.pop();
}
for(int i=0;i<4;i++)
{
process1[0].time_to_finish--;
process2[0].time_to_finish--;
process3[0].time_to_finish--;
process4[0].time_to_finish--;
process5[0].time_to_finish--;
cout<<"process1 time to finish "<<process1[0].time_to_finish<<endl;
}
pp++;
cout<<"end while "<<pp<<endl;
}
|