-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemory.cpp
executable file
·65 lines (45 loc) · 1.07 KB
/
Memory.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
#ifndef MEMORY_CPP
#define MEMORY_CPP
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Memory
{
public:
Memory(){ }
//initialize object with spesific memory capacity
Memory(int memorySize)
{
values.resize(memorySize);
}
//destructor
~Memory() { /**/ }
//increment memory capacity with value
void addIndex(int value)
{
values.push_back(value);
}
//get value after checking index boundary
int getValueByIndex(int index) const
{
if(values.size() > index)
return values[index];
else {
cout << "GET - Memory Index Out Of Bound index :" << index << endl;
}//exception is more convenient here
}
//set value after checking index boundary
void setValueByIndex(int index, int value)
{
if(values.size() > index)
values[index] = value;
else
cout << "SET - Memory Index Out Of Bound index : " << index << endl;
}
//get current memory capacity
int size() const { return values.size(); }
private:
vector<int> values; //memory vector
};
#endif