继承-数电逻辑门-逻辑抽象
使用c++实现数字电路继承体系,这里是基本逻辑抽象,用于描述逻辑门的基本特征和实现的基本结构
.h
复制代码
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/* 作者:断水客 功能: 数电逻辑门抽象,定义高低电平符号 1:_HIGH(true),0: _LOW(false) 文件:logic_gates 时间:2019/11/18 结构:logic_gates.h包含所有类型门的头文件,具体抽象数电元件在各自源文件中实现 */ ///2019/11/20 完成与门库的基类设计. 下一步,完成门的基类头文件布局 ///2019/11/21 完成基类布局 ///2019/11/20 重构继承体系,减少冗余代码(除input外的的<function member>和<data member>均从基类调用) ///2019/11/26 完成或门-意识到与非门默认输入的区别(底部建议第6条) #ifndef LOGIC_GATES_H #define LOGIC_GATES_H const bool _HIGH=true;///高电平 const bool _LOW=false;///低电平 ///逻辑门基本抽象类 /* 说明: 类中处理的变量为bool型逻辑变量 - 对应高低电平的0-low/1-high 基本结构: 输入处理:input() - 将输入值写入<data member>: _inputA、B、C... 逻辑处理:connection() - 根据逻辑门功能对输入进行处理,把处理结果写到<data member>: _output中 输出处理: output() - 输出逻辑结果_output */ class logic_gates { public: logic_gates(); virtual ~logic_gates(); virtual void input(bool& inputs)=0;///逻辑输入 virtual void connection()=0;///逻辑运算 virtual bool output()=0;///逻辑输出 protected: private: bool _inputs;///多个输入逻辑值 bool _output;///输出逻辑值-通过connection函数对输入逻辑值的系列运算获得 }; #endif // LOGIC_GATES_H /* 建议: 1、构造函数使用委托以简化初始值列表 2、输入处理函数使用const bool& 类型的参数 3、使用_HIGH和_LOW 初始化<data member> 4、使用_HIGH和_LOW 描述高低电平 5、派生类委托基类构造函数初始化继承成员 6、逻辑门留置默认输入项,为无输入的端口赋值(与门_HIGH,或门_LOW) */
.c
复制代码
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#include "logic_gates.h" logic_gates::logic_gates() :_inputs(_HIGH),_output(_HIGH) { //ctor //输入输出变量都置为高电平 } logic_gates::~logic_gates() { //dtor } void logic_gates::input(bool& inputs) { _inputs = inputs; } void logic_gates::connection() { _output = (_inputs);//逻辑运算结果写入_output } bool logic_gates::output() { return _output; }
与门实现:https://blog.csdn.net/qq_33904382/article/details/103321057
最后
以上就是等待身影最近收集整理的关于继承-数电逻辑门-逻辑抽象的全部内容,更多相关继承-数电逻辑门-逻辑抽象内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复