gatewiredemo.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 31 行

CPP
31
字号
#include <iostream>
using namespace std;

#include "gates.h"
#include "wires.h"

int main()
{
    Wire * in  =  new Wire();  // and-gate in
    Wire * in2 =  new Wire();  // and-gate in
    Wire * in3 =  new Wire();  // or-gate in 
    Wire * aout = new Wire();  // and-gate out
    Wire * oout = new Wire();  // or-gate out
    
    Gate * andg = new AndGate(in,in2,aout,"andgate");
    Gate * org  = new OrGate(in3,andg->OutWire(0),oout);
    cout << "attaching probes" << endl;
    Probe * p = new Probe(aout);       // attach to the and-out wire
    Probe * q = new Probe(oout);       // attach to the or-out wire

    cout << "set " << *in << " on" << endl;
    in->SetSignal(true);
    cout << "set " << *in2 << " on" << endl;
    in2->SetSignal(true);
    cout << "set " << *in << " off" << endl;
    in->SetSignal(false);
    cout << "set " << *in3 << " on" << endl;
    in3->SetSignal(true);
    return 0; 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?