-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBoolVariable.cpp
More file actions
80 lines (70 loc) · 1.47 KB
/
BoolVariable.cpp
File metadata and controls
80 lines (70 loc) · 1.47 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
#include <iostream>
#include "BoolVariable.h"
using namespace std;
/*
* constructor of new bool variable.
* value - the given value of the variable.
* name - the given name of the variable.
* type - the type of the variable
*/
BoolVariable::BoolVariable(bool value, string name, string type) : Variable(name,type)
{
m_value = value;
}
/*
*destructor of the variable.
*/
BoolVariable::~BoolVariable() {}
/*
* sets new value of the current variable.
* value - the new value of the variable.
*/
void BoolVariable::setValue(bool value)
{
m_value = value;
}
/*
* return the value of the variable.
*/
bool BoolVariable::getValue() const
{
return m_value;
}
/*
* copying a given bool variable into te current variable.
* b1 - the given variable.
*/
BoolVariable& BoolVariable::operator=(const BoolVariable& b1)
{
bool a = b1.getValue();
setValue(a);
return *this;
}
/*
* returns true or false is the value of the current variable is identical to the value of
* the given variable.
* b1 - the given variable
*/
bool BoolVariable::operator==(const BoolVariable& b1)const
{
bool a = b1.getValue();
bool b = getValue();
return a == b;
}
/*
* A private function to print the variable.
*/
ostream & BoolVariable::Show(ostream & out)const
{
if(m_value)
cout<<"true";
else
cout<<"false";
}
/*
* printing a given variable with the right format
*/
ostream & operator<<(ostream& out,const BoolVariable & b)
{
b.Show(out);
}