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