+ 2
Computing logic gates.
The input pin of a logic gate has pin1 = string A. pin 2 = string G4O A has the value 1 so thats not a problem. G4O however stands for Gate 4 output. Which means this input pin is conected to Gate 4 output pin. How do I code so that whenever a Gate's input is another Gate's output, it will try to run the previous Gate's output. All gates is their own object as this is an OOP question.
1 Odpowiedź
+ 2
The gates should have a method to calculate the output.
If you set the input for a new gate and want to use the output of the previous gate you set the input with the output method of the previous gate.
Assuming you named the methods
void setInput(bool in);
bool getOutput();
And created the gates named gate1 and gate2 with type GateAND. (just an example)
-------------------------
GateAND gate1;
GateAND gate2;
gate1.setInput(1); //assuming indefinite numbers
gate1.setInput(1); //of inputs stored in vector
gate2.setInput(1);
gate2.setInput(gate1.getOutput());
-------------------------
Now one of the inputs of gate 2 is the output of gate 1.
I hope this helps.
Here is an example. https://code.sololearn.com/cQ1DLjfjXBkB/?ref=app
Note that this just works with 2 inputs in this code. To get multiple inputs working the getOutput method would need to be changed. But it's possible if you create an algorithm for it ^^