Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to malloc This program is related to the Clanguage. (It is expected to be written in C language.) input.txt and logic.txt; are files

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

I have to malloc
This program is related to the Clanguage. (It is expected to be written in C language.) input.txt and logic.txt; are files to read, end.txt; is the file to be created. A program must be written that simulates the logic circuit for a given set of inputs. According to the content in the logic.txt, the program dynamically creates the necessary structures for a logic circuit and evaluates the cases listed in input.txt. Your program will print the output as end.txt. Each output step should be on a separate line. logic.txt: Each line starts with a keyword. INPUT AND OR NOT FLIPFLOP -The first line specifies input labels. Labels are separated by spaces.Example: INPUT a input2 c3 k -Here there are 4 inputs are defined. Each has an identifier. a, input2, C3, k. -AND keyword specifies that there is an and gate defined. AND keyword follows the identifier for the gate and two other identifiers for the inputs. Example: AND gate_A c3 another_id -Here the and gate is identified by the string gate_A. Its inputs are identified c3 and another_id. These identifiers can be input identifiers or identifiers for other gates. -OR keyword specifies that there is an or gate defined. OR keyword follows the identifier for the gate and two other identifiers for the inputs. Example: OR gate_B ck id3 -Here the or gate is identified by the string gate_B. Its inputs are identified ck and id3. These identifiers can be input identifiers or identifiers for other gates. -NOT keyword specifies that there is an not gate defined. NOT keyword follows the identifier for the gate and one other identifier for its input. Example: NOT gate_C c51 -Here the not gate is identified by the string gate_C. It has only one input an it is identified by the string c5. -FLIPFLOP keyword specifies that there is an flip-flop gate defined. FLIPFLOP keyword follows the identifier for the gate and one other identifier for its input. Example: FLIPFLOP gate_FC6 -Here the flip-flop gate is identified by the string gate_F. Its input is identified by c6. input.txt: Each line is a list of 1 and 0. Example: 1 1 0 1 1 0 1 1 1 0 0 1 0 1 0 0 1 Example: Suppose that logic.txt is has the following content: INPUT a b c d AND and1 a b OR or 1 and1 c NOT ni d FLIPFLOP f1 n1 AND a2 ori f1 input.txt has the following content: 1 1 0 1 1 0 1 0 1 1 1 0 Assume that initially former out of any FLIPFLOP is 0. Any FLIPFLOPs should preserve the state throughout the evaluation of the whole input.txt. Each line in input.txt is assigned to identifiers a, b, c, d, defined in logic.txt. According to the truth tables, outputs of gates are calculated. For the input.txt given, the contents of end.txt should be: For the input.txt given, the contents of end.txt should be: 1 0 a and1 b or1 a2 output f1 d n1 Warning: -Write comment on your code !!! It's your job to find the exit pin. There will always be an output pin. -Each identifier is unique. The maximum length of each identifier is 10 characters. -Assume there won't be multiple spaces separating descriptors, keywords, or data. Encrypt it according to this assumption. -You have to use dynamic memory allocation and structure. You have to use struct to represent the gates of the circuit. -Do not send your code without testing it with several different scenarios. Try cases with multiple doors of the same type. Try single door cases. Try a thousand lines of input.txt file. Try cases with many gates. Try situations with lots of entries. - You can use C structures, unions, arrays, C strings, pointers, recursion. -Do not print anything to stdout and stderr

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions

Question

2. What efforts are countries making to reverse the brain drain?

Answered: 1 week ago