forked from shalevf6/AP-scriptRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntVariable.cpp
More file actions
99 lines (85 loc) · 1.96 KB
/
IntVariable.cpp
File metadata and controls
99 lines (85 loc) · 1.96 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
#include "IntVariable.h"
#include <iostream>
using namespace std;
/*
* constructor of new int variable.
* value - the given value of the variable.
* name - the given name of the variable.
* type - the type of the variable
*/
IntVariable::IntVariable(int newVal, string name, string type) : Variable(name,type)
{
m_intValue = newVal;
}
/*
*destructor of the variable.
*/
IntVariable::~IntVariable() {}
/*
* return the value of the variable.
*/
int IntVariable::getVal()const
{
return m_intValue;
}
/*
* sets new value of the current variable.
*/
void IntVariable::setVal(int newVal)
{
m_intValue = newVal;
}
/*
* return the sum of the values current variable and a given one.
* addTo - the given variable that need to be added.
*/
IntVariable& IntVariable::operator+(const IntVariable& addTo)
{
IntVariable *newInt = new IntVariable(0,"noName","int");
int tmp1 = addTo.getVal();
int tmp2 = getVal();
newInt->setVal(tmp1 + tmp2);
return *newInt;
}
/*
*return a given value to the current value.
* addToPlusOne - the given variable that added.
*/
IntVariable& IntVariable::operator+=(const IntVariable& addToPlusOne)
{
int tmp = addToPlusOne.getVal();
setVal(tmp + m_intValue);
return *this;
}
/*
* copying a value of a given variable into te current variable.
* newVal - the given variable.
*/
IntVariable& IntVariable::operator=(const IntVariable& newVal)
{
int tmp = newVal.getVal();
setVal(tmp);
return *this;
}
/*
* returns true or false is the current variable's value is identical the given variable's value.
* equalTo - the given var
*/
bool IntVariable::operator==(const IntVariable& equalTo)const
{
return m_intValue == equalTo.getVal();
}
/*
* A private function to print the variable.
*/
ostream & IntVariable::Show(ostream & out)const
{
cout<<m_intValue;
}
/*
* printing a given variable with the right format
*/
ostream & operator<<(ostream& out,const IntVariable & i)
{
i.Show(out);
}