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
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...
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.
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
Using C++ code, write a program named q5.cpp to print the minimum of the sums x...
Using C++ code, write a program named q5.cpp to print the minimum of the sums x + y^3 and x^3 + y, where x and y are input by a user via the keyboard.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT