Using C++ allow a user to input a compound propositional logic statement that co
ID: 3732349 • Letter: U
Question
Using C++ allow a user to input a compound propositional logic statement that contains no more than 3 unique variables and generates the following output:
a) A truth table for the expression starting from individual propositional logic statements and showing all intermediate steps.
b) A simplified version of the statement (ONLY if it is possible to simplify the expression using inference rules).
Example: Input: [DA (q r)] (q r) Output: a. Truth table with all intermediate steps: F T T b. Simplified Expression: T (the given expression is a Tautology)Explanation / Answer
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
char p,q,r, result1, result2, result3, result;
here: // for shifting loop to here in case user has not entered valid valuess
cout<<"Enter the value of p: (T/F) ";
cin>>p;
p=toupper(p); //converting to uppercase if user entered uppercase character
cout<<"Enter the value of q: (T/F) ";
cin>>q;
q=toupper(q); //converting to uppercase if user entered uppercase character
cout<<"Enter the value of r: (T/F) ";
cin>>r;
r=toupper(r); //converting to uppercase if user entered uppercase character
// to evaluate expression q->r
if(q == 'T'){
if(r == 'T')
result1 = 'T';
else if (r == 'F')
result1 = 'F';
else {
cout<<"You have entered invalid value for r (other than T/F) please recheck and eneter all values again!! ";
goto here;
}
}
else if (q=='F')
{
if (r=='T')
result1 = 'T';
else if (r == 'F')
result1 = 'T';
else{
cout<<"You have entered invalid value for r (other than T/F) please recheck and eneter all values again!! ";
goto here;
}
}
else {
cout<<"You have entered invalid value for q (other than T/F) please recheck and eneter all values again!! ";
goto here;
}
cout<<"The result of expression q->r: "<<result1<<endl;
// evaluate expression p^q (p and q)
if(p == 'T'){
if(q == 'T')
result2 = 'T';
else if (q == 'F')
result2 = 'F';
}
else if (p=='F')
{
if (q=='T')
result2 = 'F';
else if (q == 'F')
result2 = 'F';
}
else {
cout<<"You have entered invalid value for p (other than T/F) please recheck and eneter all values again!! ";
goto here;
}
cout<<"The result of expression p^q (p and q) is: "<<result2<<endl;
// evaluate expression p^(q->r)
if(p == 'T'){
if(result1 == 'T')
result3 = 'T';
else if (result1 == 'F')
result3 = 'F';
}
else if (p=='F') // if p is false statement will always be false so need not to check rest of the consitions
result3='F';
cout<<"The result of expression p^(q->r): "<<result3<<endl;
//To evaluate experession for [p^(q->r)]-> (q->r)
// it is always a tautology that means always its expression is T but then also checked al conditons
if(result3 == 'T'){
if(result1 == 'T')
result = 'T';
else if (result1 == 'F')
result = 'F';
}
else if (result3=='F')
{
if (result1=='T')
result = 'T';
else if (result1 == 'F')
result = 'T';
}
cout<<"The resultant experession for [p^(q->r)]-> (q->r) is: "<<result<<endl;
return 0;
}
OUTPUT OF THE CODE:
dps@machine:~/Documents/Chegg$ g++ propositional.cc -o propositional
dps@machine:~/Documents/Chegg$ ./propositional
Enter the value of p: (T/F) t
Enter the value of q: (T/F) f
Enter the value of r: (T/F) f
The result of expression q->r: T
The result of expression p^q (p and q) is: F
The result of expression p^(q->r): T
The resultant experession for [p^(q->r)]-> (q->r) is: T
dps@machine:~/Documents/Chegg$ ./propositional
Enter the value of p: (T/F) f
Enter the value of q: (T/F) f
Enter the value of r: (T/F) f
The result of expression q->r: T
The result of expression p^q (p and q) is: F
The result of expression p^(q->r): F
The resultant experession for [p^(q->r)]-> (q->r) is: T
dps@machine:~/Documents/Chegg$ ./propositional
Enter the value of p: (T/F) f
Enter the value of q: (T/F) t
Enter the value of r: (T/F) f
The result of expression q->r: F
The result of expression p^q (p and q) is: F
The result of expression p^(q->r): F
The resultant experession for [p^(q->r)]-> (q->r) is: T
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.