繼承-數電邏輯門-或門
數電邏輯門-邏輯抽象:https://blog.csdn.net/qq_33904382/article/details/103320875
.h
/*
作者:斷水客
功能: 邏輯門-或門 (或門抽象和兩輸入、三輸入的或)
文件:gate_or.h
時間:2019/11/26
注:默認輸入爲_LOW低電平
*/
#ifndef GATE_OR_H
#define GATE_OR_H
#include "logic_gates.h"
class Gate_Or
{
public:
Gate_Or();
Gate_Or(const bool& A,const bool& B,const bool& C,const bool& D);
virtual void input(const bool& input);
virtual void connection();
virtual bool output();
virtual ~Gate_Or();
protected:
bool _inputA;
bool _inputB;
bool _inputC;
bool _inputD;
bool _output;
private:
bool _inputs;
};
class Gate_Or2IN:public Gate_Or
{
public:
Gate_Or2IN();
Gate_Or2IN(const bool&A,const bool& B);
virtual ~Gate_Or2IN();
void input(const bool& A,const bool& B);
};
#endif // GATE_OR_H
.c
#include "gate_or.h"
Gate_Or::Gate_Or(const bool& A,const bool& B,const bool& C,const bool& D)
:_inputA(A),_inputB(B),_inputC(C),_inputD(D),_output(_HIGH),_inputs(_HIGH)
{
//ctor
}
Gate_Or::Gate_Or()
:Gate_Or(_HIGH,_HIGH,_HIGH,_HIGH)
{
//ctor
}
Gate_Or::~Gate_Or()
{
//dtor
}
void Gate_Or::input(const bool& input)
{
_inputs = input;
}
void Gate_Or::connection()
{
_output = _inputA||_inputB||_inputC||_inputD;
}
bool Gate_Or::output()
{
connection();
return _output;
}
Gate_Or2IN::Gate_Or2IN(const bool& A,const bool& B)
:Gate_Or(A,B,_LOW,_LOW)
{
}
Gate_Or2IN::Gate_Or2IN()
:Gate_Or2IN(_LOW,_LOW)
{
}
Gate_Or2IN::~Gate_Or2IN()
{
}
void Gate_Or2IN::input(const bool& A,const bool& B)
{
_inputA = A;
_inputB = B;
}