Answered step by step
Verified Expert Solution
Link Copied!

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 1
Logic Evaluating Logical Expressions
Total 100 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 1.2 for details.
Input
Your program should take as input the following information:
number of variables in an expression, between 1 and 5
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 3-way nested loop.
Satisfy all the requirements specified in this document.
COSC 314 Project 12
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: 4
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: 2
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
1. Variables (4): a = true, b = false, c = true, d = false
Expression: c /\ ~d \/ a \/ b
2. Variables (3): a = false, b = false, c = true
Expression: ~a /\ ~b /\ c
3. Variables (5): 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

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

Students also viewed these Databases questions