In: Computer Science
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!
#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;
}