Project outline

Hi.

I need to make an application that simulates a circuit with logic gates (AND, OR, NOT, NAND, NOR, XOR). Can someone help me figure out the "skeleton" of such an application?

I'm not asking for code on a silver platter. Just an outline of what classes I would need to implement and some general advice.

Thanks.

To solve/create something you need to define the problem. For example:

- assume that each gate is black box with input/s and output/s. For now assume each box has always 2 input, 1 output
- each input/output can has only one state at given time: low, high or hi-z
- boxes can be connected, ie: input to output, output to input

Now that you know what to do, you must create interfaces, for example:

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
enum ePinState
{
    LOW = 0,
    HIGH,
    HI_Z
};

class CPin
{
protected:
    ePinState = m_state; // pin can be in 1 of 3 states
    CPin * m_pOtherPin; // pin can be connected to other pin
public:
    CPin() : m_state(HI_Z), m_pOtherPin(NULL) // assume pin is not connected when created
    {}
    virtual ~CPin() {}
    
    virtual void SetState(ePinState a_newState) = 0;
};

class COutputPin : public CPin
{
public:
    void SetState(ePinState a_newState) 
    {
        // when output change, and if it is connected to other input
        // that input state should be changed accordingly
    }
};

class CInputPin : public CPin
{
        // when input change, it should somehow indicate to owned CGate,
        // that output should change according to gate type
};

// here you must think of, how to change output when one of inputs state changes
class CGate
{
public:
CInputPin input1;
CInputPin input2;
COutputPin ouput;
};

class CNANDGate : public CGate
{
// specific nand gate calculation, when input/s state change
};


and so on.
Topic archived. No new replies allowed.