-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOR2.cpp
More file actions
95 lines (79 loc) · 1.73 KB
/
Copy pathOR2.cpp
File metadata and controls
95 lines (79 loc) · 1.73 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
#include "OR2.h"
#include <fstream>
OR2::OR2(const GraphicsInfo& r_GfxInfo, int r_FanOut) :Gate(2, r_FanOut)
{
Set_noOfConnectedPins(2);
m_GfxInfo.x1 = r_GfxInfo.x1;
m_GfxInfo.y1 = r_GfxInfo.y1;
m_GfxInfo.x2 = r_GfxInfo.x2;
m_GfxInfo.y2 = r_GfxInfo.y2;
m_InputPins[0].SetConnected(false);
m_InputPins[1].SetConnected(false);
m_Label = "ignore";
}
void OR2::Operate()
{
//caclulate the output status as the ANDing of the two input pins
for (int i = 0; i < 2; i++)
{
if (m_InputPins[i].getStatus() == HIGH)
{
m_OutputPin.setStatus(HIGH);
break;
}
else {
m_OutputPin.setStatus(LOW);
}
}
//Add you code here
}
// Function Draw
// Draws 2-input AND gate
void OR2::Draw(Output* pOut)
{
//Call output class and pass gate drawing info to it.
pOut->DrawOR2(m_GfxInfo ,m_Selected);
}
void OR2::Draw(GraphicsInfo GInfo, bool m_selected, Output* pOut)
{
pOut->DrawOR2(GInfo, m_Selected);
}
OutputPin& OR2::Get_OutputPin()
{
return m_OutputPin;
}
InputPin *OR2::Get_InputPin()
{
return m_InputPins;
}
int OR2::GetInputs()
{
return m_Inputs;
}
//returns status of outputpin
int OR2::GetOutPinStatus()
{
return m_OutputPin.getStatus();
}
//returns status of Inputpin #n
int OR2::GetInputPinStatus(int n)
{
return m_InputPins[n - 1].getStatus(); //n starts from 1 but array index starts from 0.
}
//Set status of an input pin ot HIGH or LOW
void OR2::setInputPinStatus(int n, STATUS s)
{
m_InputPins[n - 1].setStatus(s);
}
int OR2::no()
{
return m_ConnectedPins;
}
void OR2::Set_noOfConnectedPins(int x)
{
m_ConnectedPins = (x <= 2) ? x : m_ConnectedPins;
}
void OR2::save(ofstream &file)
{
file << "OR2" << " " << ( m_GfxInfo.x1 + m_GfxInfo.x2 ) / 2 << " " << ( m_GfxInfo.y1 + m_GfxInfo.y2 ) / 2 << endl << m_Label << endl;
}