Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are creating a program that allows student to enter a Boolean expression and you will display the truth table with multiple variables and result.

You are creating a program that allows student to enter a Boolean expression and you will display the truth table with multiple variables and result.

Here are some steps for this program: 1. Prompt the user to enter total count of variables (restrict it to 1. Create a program using your choice of language (Python, Java, C#, C++, etc.) to perform the above tasks. Program output: 5 test cases 1st run: Enter total count of variables: 1 Enter the expression using variable Enter total count of variables: 3 Enter the expression using variable name(s) x,y,z : x and (not y or z) or x 4th run: Enter total count of variables: 4 Enter the expression using variable name(s) x,y,z,w: w and not (x 5th run: Enter total count of variables: 5 Error: Variable must be between 1 and 4: -10 Error: Variable must  

Here are some steps for this program: 1. Prompt the user to enter total count of variables (restrict it to 1-4 variables). 3. 2. Validate the count to make sure the program only allows 1, or 2 or 3 or 4 variables. Prompt the user to enter a Boolean expression (You will use and, or, not boolean operators). You will use the name x, y, z, w for variables, for example, if you have 2 variables, you use x, y. If you have 3 variables, you use x, y, z. For 4 variables, you use x, y, z, w. Some valid expression examples are displayed as follows: not x and not y and not z (equivalent to x'y'z') (equivalent to xy' + z) C. w and not (x or y) or x and not y and z and not w (equivalent to w(x+y)' + xyzw') 4. Validate the expression to make sure that if there are 2 variables, use x, y in the expression. If there are 3 variables, use x,y,z in the expression and if there are 4 variables, use x,y,z,w in the expression. 5. Print Truth Table based on number of variables. If you have 3 variables, you will have 2 = 8 rows. You will have 3 variable columns and 1 output column. See Program Output reference below. a. b. x and not y or z 6. If you use Python, use eval(expression) function to calculate the output for each row. 7. The simplest display is to use a loop for each variable to display each row. If you have 3 variables, you need 3 loops, and for 4 variables, you will have 4 loops. To Solve this problem, we can use the following functions. Function name Purpose of the function getTotal Variables getExpression displayHeader Display Truth Table main Prompt the user to enter total variables (1-4), validate user input and return total count of variables Pass in total count of variables and prompt user to enter expression and return expression. Validate the use of variables in the expression. For 1 variable, use x. For 2 variables, use x,y. For 3 variables, use x,y,z. For 4 variables use x,y,z,w. Use not, and, or boolean operators in the expression. Display header information, the heading of the truth table. (see output below) Display truth table with all variables and output columns main function as the entry of your code

Step by Step Solution

3.50 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

Sure I can help you with that Heres an example implementation in Python that addresses the problem r... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

What is the retrospective and prospective P / e ratio

Answered: 1 week ago