-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcess.cpp
84 lines (62 loc) · 1.51 KB
/
Process.cpp
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
#include <vector>
#include <ostream>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
class Process{
private:
char id;
int frames;
vector<int> arrivals;
vector<int> usageTime;
public:
Process(char ID, int size) {
id = ID;
frames = size;
}
void pushbackArrivals(int t) {
for (unsigned int i=0; i<arrivals.size(); i++) {
arrivals[i] += t;
}
}
void pushInstance(int arr, int usage) {
arrivals.push_back(arr);
usageTime.push_back(usage);
}
int remainingInstances() const {
return (int)arrivals.size();
}
void popInstance() {
arrivals.erase(arrivals.begin());
usageTime.erase(usageTime.begin());
}
int getArrivalTime() const {
return arrivals[0];
}
char getID() const {
return id;
}
int getMemorySize() const {
return frames;
}
int getFinishTime() const {
return usageTime[0]+arrivals[0];
}
string toString() const {
char* firstLine = (char*)malloc(sizeof(char)*100);
char* secondLine = (char*)malloc(sizeof(char)*100);
sprintf(firstLine, "%c\t", id);
sprintf(secondLine, "(%d)\t", frames);
for (unsigned int i=0; i<arrivals.size(); i++) {
sprintf(firstLine+strlen(firstLine), "%d\t", arrivals[i]);
sprintf(secondLine+strlen(secondLine), "%d\t", usageTime[i]);
}
sprintf(firstLine+strlen(firstLine), "\n");
sprintf(secondLine+strlen(secondLine),"\n");
sprintf(firstLine+strlen(firstLine), "%s", secondLine);
string finalAnswer = string(firstLine);
return finalAnswer;
}
};