-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcess.cpp
More file actions
120 lines (104 loc) · 2.32 KB
/
Copy pathProcess.cpp
File metadata and controls
120 lines (104 loc) · 2.32 KB
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
/*
* Name: Kabir Bhakta Student Number: 7900098
* Purpose: This class has each and every detail of the process.
*/
#include "Process.h"
#include "Bursts.h"
#include "Queue.h"
#include <iostream>
using namespace std;
//constructor
Process::Process(int id, int arrivalTime, Queue *cpuQ, Queue *ioQ)
{
this->id = id;
this->arrivalTime = arrivalTime;
this->cpuQ = cpuQ;
this->ioQ = ioQ;
this->waitTime = 0;
this->exitTime = 0;
}
//sum of all the bursts
int Process::getTotalBurst()
{
return totalBurst;
}
//sets the sum of all the bursts
void Process::setTotalBurst(int newTotal)
{
totalBurst = newTotal;
}
//returns the id of the process
int Process::getId()
{
return id;
}
//checks if the process has more bursts to process or not
bool Process::noMoreBursts()
{
if (this->getIOBurst() == nullptr && this->getCPUBurst() == nullptr)
{
return true;
}
else
return false;
}
//returns the top burst from the cpu bursts
Bursts *Process::getCPUBurst()
{
return dynamic_cast<Bursts *>(cpuQ->getTop());
}
//returns the top burst from the io bursts
Bursts *Process::getIOBurst()
{
return dynamic_cast<Bursts *>(ioQ->getTop());
}
//sets the current cpu burst a new value
void Process::setCPUBurst(int newBurst)
{
dynamic_cast<Bursts *>(cpuQ->getTop())->setBurst(newBurst);
}
//removes the top burst of the CPu burst
Bursts *Process::removeFromCPU()
{
return dynamic_cast<Bursts *>(this->cpuQ->dequeue());
}
//removes the top burst of the io burst
Bursts *Process::removeFromIO()
{
return dynamic_cast<Bursts *>(this->ioQ->dequeue());
}
int Process::getArrTime()
{
return arrivalTime;
}
int Process::getExitTime()
{
return exitTime;
}
int Process::getWaitTime()
{
return waitTime;
}
void Process::setExitTime(int exit)
{
exitTime = exit;
}
void Process::setWaitTime()
{
waitTime = exitTime - arrivalTime - getTotalBurst();
}
//compares with other process based on the id number
int Process::compareTo(ListItem *other)
{
int boolean = 0;
Process *otherProcess = dynamic_cast<Process *>(other);
if (this->getId() < otherProcess->getId())
{
boolean = 1;
}
return boolean;
}
void Process::print()
{
cout << "" << this->getId() << "\t" << this->getArrTime() << "\t" << this->getExitTime() << "\t" << this->getWaitTime() << endl;
}