In: Computer Science
Write in C++ and insert comments.
Input two values a and b
0 may be used for False
1 may be used for True
Write a program that will print the truth table for the logical operator and give the results for the specific input a, b. The following logical operators should be coded.
● conjunction (AND)
● disjunction (OR)
● conditional Statement (If a then b)
● exclusive OR (XOR)
● biconditional operation (p iff q)
Example for conjunction If the specific input is a=0, b=1, the output for a conjunction should look something like
Truth Table
For a logical conjunction
0 0 0
0 1 0
1 0 0
1 1 1
For the specific values a=1, b=1 the conjunction is true.
(Provide two output one for a,b true and one for a,b false)
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
int a,b,temp,i;
cout<<"\tA B Conj Disj Xor \tBicon \t\t Cond"<<endl;
for(i=0;i<4;i++){
temp=i;
a=i%2;
temp/=2;
b=temp%2;
int c=a&&b;
int d=a||b;
int e=a^b;
cout<<endl<<"\t"<<b<<" "<<a<<" "<<c<<" "<<d<<" "<<e;
if(a==b){
cout<<"\t\t"<<"2";
}
else
cout<<"\t\t"<<"1";
if(a==b){
cout<<"\t\t"<<"2";
}
else{
if(a==1 && b==0){
cout<<"\t\t"<<"1";
}
else{
cout<<"\t\t"<<"2";
}
}
}
}