11,480,847 members (63,540 online)
Rate this:
See more:
I was proposed a project that sounds like this.

Consider a set of logical gates like AND, OR, XOR or NOT. Allow for building any logical circuit by connecting such gates.
Provide input (0/1) to a number of gates and collect the results at the output of some of the gates.
Be able to read the description of the circuit from a file.

Additional information that I was given: I have to build some classes/interfaces allowing to model such circuits.After that, you have to simulate the flow of the input signals to the end nodes and eventually to collect the results on some output connectors.It is not about writing a program to evaluate logical propositions like p&q|r&!p or to write truth tables. Rather you have some signals flowing through connectors and processed at the level of each logical gate.

I was suggested an idea like the one below, for a single AND gate, 2 inputs and a single output. Is this a good approach?

01 public class LogicAnd extends Gate
02 {
03 public LogicAnd(int a, int b, int q) {
04 a_ = a; b_ =b; q_ = q;
05 }
06
07 public void Evaluate(int[] signals) {
08 signals[q_] = signals[a_]&signals[b_];
09 }
10 }

Has anyone done anything of this kind? What would you do, how would you start/shape this problem? I am looking for any help as much as possible, open to hints and solutions, anything is helpful.
Posted 5-Feb-13 3:06am
Fredrik Bornander at 5-Feb-13 8:15am

Is this homework?
Maxbummer at 5-Feb-13 8:17am

It's a project

Rate this:

## Solution 1

When I was at uni back in the late 1980's we had an introductory course where we were taught Scheme (a LISP dialect). The book that was used throughout the course was Structure and Interpretation of Computer Programs[^] by H. Abelson and G.J. Sussman.
One of the things that was engraved indelibly in my mind was an expression simulator written completely in Scheme. One of the principles that was used to solve this was called Propagation of Constraints[^] in Chapter 3 about Modularity, Objects, and State[^].
Please read this! Even though you'll not be implementing this in Scheme, there's still a lot to be learned from that book, especially how signals\states propagate through the network. The Celsius-Fahrenheit calculator works both ways for instance without you having to rewrite anything. It merely depends which pin is assigned a value the correct counterpart will be calculated. Back then I was really amazed at this principle.

This chapter is a bit closer to what you are looking for while I still think that above mentioned principle will be helpful in more general expression evaluators: 3.3.4 A Simulator for Digital Circuits[^][/Edit]

If you have any doubts, leave me a comment.

Cheers,

—Manfred
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

 0 Sergey Alexandrovich Kryukov 294 1 Richard MacCutchan 160 2 OriginalGriff 135 3 CHill60 130 4 CPallini 125
 0 Sergey Alexandrovich Kryukov 8,184 1 OriginalGriff 7,586 2 Sascha Lefèvre 3,114 3 Maciej Los 2,491 4 Richard Deeming 2,335

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 5 Feb 2013