Question: Write a program , in C, that reads a circuit description and prints a truth table showing all combinations of input variables. In all three

Write a program , in C, that reads a circuit description and prints a truth table showing all combinations of input variables.

In all three parts, the program may be given the name of a file containing a circuit description as an argument. If a fille name is not given, the program will read from standard input (stdin). Part 1 (40 points) For this part, the circuit descriptions will be sorted so that each temporary variable appears as an output parameter before any appearances as an input variable. Part 2 (20 points) For this part, the circuit descriptions will not be sorted, meaning that a temporary variable may be used as an input parameter before its use as an output parameter.

Input - The input to your program will be a single circuit description using the language described in section 1. This circuit description may be provided as a ?le speci?ed as an argument to truthtable, or it may be provided to truthtable through standard input (stdin). You MAY assume that the input is correctly formatted and that no variable depends on its own output.

Output - The output of truthtable is a truth table showing each combination of inputs and the corresponding output for the speci?ed circuit. Each column in the table corresponds to a speci?c input or output variable, which are given in the same order as their declaration in the INPUT and OUTPUT directives. Columns are separated by a single space, and a vertical bar (|) occurs between the input and output variables.

Usage -

$ cat circuit1.txt INPUT 3 : IN1 IN3 IN4 OUTPUT 1 : OUT1 MULTIPLEXER 2 : 1 0 1 0 : IN3 IN4 : temp1 MULTIPLEXER 1 : temp1 1 : IN1 : OUT1 $ ./truthtable circuit1.txt 0 0 0 | 1 0 0 1 | 0 0 1 0 | 1 0 1 1 | 0 1 0 0 | 1 1 0 1 | 1 1 1 0 | 1 1 1 1 | 1 $ cat circuit2.txt INPUT 2 X Y OUTPUT 2 Z W XOR X Y T PASS T Z NOT T W $ cat circuit2.txt | ./truthtable 0 0 | 0 1 0 1 | 1 0 1 0 | 1 0 1 1 | 0 1

For part 2, truthtable must handle unsorted circuit descriptions:

$ cat circuit3.txt INPUT 4 A B C D OUTPUT 1 Z AND A B E MULTIPLEXER 2 0 1 1 0 E F Z OR C D F $ ./truthtable circuit3.txt 0 0 0 0 | 0 0 0 0 1 | 1 0 0 1 0 | 1 0 0 1 1 | 1 0 1 0 0 | 0 0 1 0 1 | 1 0 1 1 0 | 1 0 1 1 1 | 1 1 0 0 0 | 0 1 0 0 1 | 1 1 0 1 0 | 1 1 0 1 1 | 1 1 1 0 0 | 1 1 1 0 1 | 0 1 1 1 0 | 0 1 1 1 1 | 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!