Question

In: Computer Science

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.

Solutions

Expert Solution

  • Below is the detailed implementation of the above problem in C++ with code and output shown.
  • For better understanding please read the comments mentioned in the code.
  • In the code below the truth table is printed for p ^~q where ^ is xor of both operands and ~ is negation of the bit i.e, if q =0 then ~q=1, so using setwidth() for spacing below is the code for printing.
  • xor(^) of (1 and 0) or (0 and 1) is 1 and of (0 and 0) or (1 and 1) is 0.
  • CODE:

//include headers
#include <iostream>
#include <iomanip>
using namespace std;

//driver function
int main()
{
//printing heading
cout<<"Truth table\n\n";
//printing the table headings i.e, column names
cout<<"p"<<setw(5)<<"q"<<setw(5)<<"~q"<<setw(8)<<"p^~q"<<endl;
//for each possible pair (p,q) where p,q belongs to [0,1]
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
//print the row
cout<<i<<setw(5)<<j<<setw(5)<<(!j)<<setw(6)<<(i^(!j))<<endl;
}
}
return 0;
}

  • OUTPUT:

Truth table

p q ~q p^~q
0 0 1 1
0 1 0 0
1 0 1 0
1 1 0 1

  • Below are the screenshot attached for the code and output for better clarity and understanding.

CODE

OUTPUT

So if you still have any doubt regarding this solution please feel free to ask it in the comment section below and if it is helpful then please upvote this solution, THANK YOU.


Related Solutions

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!
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)
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 in C++ that will output the truth table for a simple wff. There...
Write a program in C++ that will output the truth table for a simple wff. There will only be Ps and Qs, so you can hard code the P truth table and the Q truth table into arrays. The user will use A for ^ , O for V, N for ' , & I for -> . Hint: Read the first character, load the appropriate truth table into the first working array. Read the next character. If it is...
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
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
1. write a truth table using this symbol: --> 2. write the inputs for the truth...
1. write a truth table using this symbol: --> 2. write the inputs for the truth table to the left of the --> and write the outputs for the truth table to the right of the --> 3. write the compliment, or NOT using ' As an example: The truth table for AND is written this way: A B --> A AND B 0 0 --> 0 0 1 --> 0 1 0 --> 0 1 1 --> 1 or...
1. write a truth table using this symbol: --> 2. write the inputs for the truth...
1. write a truth table using this symbol: --> 2. write the inputs for the truth table to the left of the --> and write the outputs for the truth table to the right of the --> 3. write the compliment, or NOT using ' As an example: The truth table for AND is written this way: A B --> A AND B 0 0 --> 0 0 1 --> 0 1 0 --> 0 1 1 --> 1 or...
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.
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, &)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT