Question 1 and 2 requires you to create a program ( you need to submit the source code and screenshot for the output), and question 3 and 4 requires solving the problems (no programs needed for those two questions).
1.Write a C++ program to construct the truth table of P ∨¬(Q ∧ R)
2.Write a C++ program to verify that the proposition P ∨¬(P ∧Q) is a tautology.
Question 1:
Answer:
#include <iostream>
using namespace std;
int main()
{
//boolean variable declaration
bool p,q;
//display table header
cout << "P Q P^Q ~(P^Q) (p v ~(P^Q)) \n";
//display the table data
for ( int i = 0 ; i < 4 ; i++ )
{
p = ( i >> 0 ) & 0x01;
q = ( i >> 1 ) & 0x01;
//display p and q
cout<<p<<" ";
cout<<q<<" ";
cout<<(p&&q)<<"
"<<!(p&&q)<<"
"<<(p||!(p&&q))<<endl;
}
return 0;
}
OUTPUT:
Question 2:
A given boolean expression is a tautology if it is always true and doesn't depend upon the input.
The given boolean expression is:
P v ~(P^Q)
The above proposition is a tautology if the above proposition is true for all types of input values of P and Q.
The program source code to prove the tautology is given below:
#include <iostream>
using namespace std;
int main()
{
//boolean variable declaration
bool p,q;
//display table header
cout << "P Q P^Q ~(P^Q) (P v ~(P^Q)) \n";
//display the table data
for ( int i = 0 ; i < 4 ; i++ )
{
p = ( i >> 0 ) & 0x01;
q = ( i >> 1 ) & 0x01;
//display p and q
cout<<p<<" ";
cout<<q<<" ";
cout<<(p&&q)<<"
"<<!(p&&q)<<"
"<<(p||!(p&&q))<<endl;
}
return 0;
}
OUTPUT:
The given proposition is a tautology because it result true always.
Get Answers For Free
Most questions answered within 1 hours.