Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Project 1 Logic Evaluating Logical Expressions Total 1 0 0 pts . Write a program that will evaluate a logical expression ( compound proposition )
Project
Logic Evaluating Logical Expressions
Total pts
Write a program that will evaluate a logical expression compound proposition based on the
given truth values of individual propositional variables. A logical expression may include the
logical AND logical OR and logical NOT ~ operators.
Here is an example of a logical expression using proper notation:
a b c d
This expression will need to be input as the following in this program to accommodate simple
keyboard input:
a b ~c or d
Note that the logical AND and logical OR operators are input using the keys and on your
keyboard. These symbols use two keys on your keyboard with no space in between. Also note
that there is no space between the logical NOT operator and the variable that it is attached to
There needs to be a space included between a variable and the other operators.
The logical operators will be evaluated left to right in the order of precedence of the operators.
Parentheses will not be included. Check Zybook section for details.
Input
Your program should take as input the following information:
number of variables in an expression, between and
the truth values of each of these variables
a logical expression involving these variables and logical operators
Code
Your program should allow the user to interact via the keyboard. There is no need for any file
input. Your program should guide the user if they provide incorrect input instead of stopping or
crashing.
Your program should adhere to the following programming guidelines:
Use proper naming conventions, such as upper case for constants, lower case for
variables, and title case for classes.
Use proper formatting, such as tabs spaces, line breaks, and curly braces.
Display good documentation, such as a header block for each file and and inline
comments, as needed.
Display good design, such as decomposition of tasks and modular code.
Should be no more complex than necessary, for example, if a task can be accomplished
by a single loop, it should not be programmed with a way nested loop.
Satisfy all the requirements specified in this document.
COSC Project
Output
A sample program output is given below. User input is displayed in green font.
Logical Expressions Evaluator
Enter the number of variables in the expression:
Enter the values of variables true or false:
a: true
b: false
c: true
d: false
Enter the logical expression:
c ~d a b
The value of the given logical expression is true.
Below is a program output including errors in user input. Your program should not crash.
Logical Expressions Evaluator
Enter the number of variables in the expression:
Enter the values of variables true or false:
a: one
Invalid value. Enter true of false.
true
b: false
Enter the logical expression:
a d
Invalid expression. Enter again.
a b
The value of the given logical expression is false.
Test cases
Variables : a true, b false, c true, d false
Expression: c ~d a b
Variables : a false, b false, c true
Expression: ~a ~b c
Variables : a false, b false, c true, d true, e false
Expression: c e b ~a d
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started