Question

In: Computer Science

Write a C++ program to construct the truth table of P ∨¬(Q ∧ R) If you...

Write a C++ program to construct the truth table of P ∨¬(Q ∧ R)

If you could include comments to explain the code that would be much appreciated!!! :)

Thank you so much!

Solutions

Expert Solution


#include <iostream>

using namespace std;


int main()
{
int x,y,z;//x,y,z are p,q,r variables
cout<<"P\tQ\tR\tPV~(Q∧R)";//displays header of the table

for(x=0;x<=1;++x)//proposition p value can be 0 or 1. x takes 0 or 1
for(y=0;y<=1;++y)//proposition q value can be 0 or 1
for(z=0;z<=1;++z)//proposition r value can be 0 or 1
{
/*PV~(Q∧R) formula can be written as p+~(qr)in formal language
in programmaing language can be written as p+!(q*r)
*/
if(x+!(y*z)==2) //2 is not present in the proposition logic hence it is considered as 1
cout<<"\n"<<x<<"\t"<<y<<"\t"<<z<<"\t1";
else
cout<<"\n"<<x<<"\t"<<y<<"\t"<<z<<"\t"<<(x+(!(y*z)));//formula calculates and displays
}

return 0;
}


Related Solutions

Construct a truth table for the statement [q∨(~r∧p)]→~p. Complete the truth table below by filling in...
Construct a truth table for the statement [q∨(~r∧p)]→~p. Complete the truth table below by filling in the blanks. (T or F) p q r ~r ~r∧p q∨(~r∧p) ~p [q∨(~r∧p)]→~p T T T T T F T F T T F F
write a program that will print a truth table for p ^ ~q. Using C++ please.
write a program that will print a truth table for p ^ ~q. Using C++ please.
Write a truth table for the proposition: ¬(q ∧ r) → (¬p ∨ ¬r). Consider a “1” to be true and a “0” to be false.
Write a truth table for the proposition: ¬(q ∧ r) → (¬p ∨ ¬r). Consider a “1” to be true and a “0” to be false.
Discrete math question Prove that ¬(q→p)∧(p∧q∧s→r)∧p is a contradiction without using truth table
Discrete math question Prove that ¬(q→p)∧(p∧q∧s→r)∧p is a contradiction without using truth table
C++ Write a program that produces the truth table of the following logical operators. You aresupposed...
C++ Write a program that produces the truth table of the following logical operators. You aresupposed to output one table with all the operators (one column for each operator). Write theheader of the table - this is the name of the columns-. Output the result on the file prog1 output.txt. The table should contain the letters T and F, it should NOT print 1s and 0s. Show theresults on the following order: 1. negation (!) 2. disjunction (AND operator, &)...
Prove or disprove using a Truth Table( De Morgan's Law) ¬(p∧q) ≡ ¬p∨¬q
Prove or disprove using a Truth Table( De Morgan's Law) ¬(p∧q) ≡ ¬p∨¬q Show the Truth Table for (p∨r) (r→¬q)
Using a truth table determine whether the argument form is valid or invalid p ∧ q...
Using a truth table determine whether the argument form is valid or invalid p ∧ q →∼ r p∨∼q ∼q→p ∴∼ r
Q2) (a) construct a truth table for the following function: ?(?, ?, ?) = (?? +...
Q2) (a) construct a truth table for the following function: ?(?, ?, ?) = (?? + ?̅?) ̅̅̅ + ?? (b) Use the truth table of (a) to write the function F in sum of minterms form. (c) Expand the function ?(?, ?, ?) = ? + ?̅? to product of Maxterms form. (d) Simplify the following function using K-Map. ?(?, , ?, ?, ?) = ?̅? + ?? + ?̅? + ??̅?
Show that if P;Q are projections such that R(P) = R(Q) and N(P) = N(Q), then...
Show that if P;Q are projections such that R(P) = R(Q) and N(P) = N(Q), then P = Q.
Prove p → (q ∨ r), q → s, r → s ⊢ p → s
Prove p → (q ∨ r), q → s, r → s ⊢ p → s
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT