C Please read the question carefully and make sure that the
C++
Please read the question carefully and make sure that the intermedial steps for the proposition are also shown in the truth table.
Output for thruth table should print \'T\' and \'F\' not 0s and 1s.
NOTE: Do not hard code truth tables. The program must use binary or bitwase operators to compute the results.
Part A
Write a program that produces the bitwise OR, bitwise AND, and bitwise XOR of the bit strings
1001 0011 1011 and 1111 1010 0000.
Part B
Write a program that produces truth table for the following compound proposition and decide if
it is a Tautology or Contradiction.
1. (p q) (¬p ¬q)
2. (p <-> q) <-> r
Part C
Write a program that produces truth table for the following compound proposition and decide if
it is a Satisfiable or Unsatisfiable
1. ( p r ) ( q r ) (¬p ¬q ¬r )
2. (p q) (¬p ¬q)
Thank you in advance!
Solution
Answer Part A:
#include<iostream>
//Define maximum number of binary bits
#define MAXBIT 12
using namespace std;
//To store first binary number
int first [MAXBIT];
//To store second binary number
int second[MAXBIT];
//To store result binary number
char resultBit[MAXBIT];
//Accept binary numbers
void accept()
{
cout<<\"\ Enter first 8 bit binary number\";
for(int x = 0; x < MAXBIT; x++ )
cin>>first[x];
cout<<\"\ Enter second 8 bit binary number\";
for(int x = 0; x < MAXBIT; x++ )
cin>>second[x];
}
//Display result
void display()
{
cout<<\"First\"<<\"\\tSecond\"<<\"\\tResult\ \";
for(int x = 0; x < MAXBIT; x++)
cout<<first[x]<<\"\\t\"<<second[x]<<\"\\t\"<<resultBit[x]<<endl;
}
//Bitwise OR operation
void bitwiseOR()
{
//Loops from zero to maximum number of bits
for(int x = 0; x < MAXBIT; x++)
{
//If binary bit of the first number and second number is zero then set the result to F
if(first[x] == 0 && second[x] == 0)
resultBit[x] = \'F\';
//Rest all cases set the result to T
else
resultBit[x] = \'T\';
}
}
//Bitwise AND operation
void bitwiseAND()
{
//Loops from zero to maximum number of bits
for(int x = 0; x < MAXBIT; x++)
{
//If binary bit of the first number and second number is one then set the result to T
if(first[x] == 1 && second[x] == 1)
resultBit[x] = \'T\';
//Rest all cases set the result to F
else
resultBit[x] = \'F\';
}
}
//Bitwise XOR operation
void bitwiseXOR()
{
//Loops from zero to maximum number of bits
for(int x = 0; x < MAXBIT; x++)
{
//If either binary bit of the first number and second number is one or
//binary bit of the first number and second number is zero then set the result to F
if((first[x] == 1 && second[x] == 1) || (first[x] == 0 && second[x] == 0))
resultBit[x] = \'F\';
//Rest all cases set the result to T
else
resultBit[x] = \'T\';
}
}
//Main method
int main()
{
accept();
bitwiseOR();
cout<<\"\ Bit wise OR operation\ \";
display();
bitwiseAND();
cout<<\"\ Bit wise AND operation\ \";
display();
bitwiseXOR();
cout<<\"\ Bit wise XOR operation\ \";
display();
}
Output:
Enter first 8 bit binary number1 0 0 1 0 0 1 1 1 0 1 1
Enter second 8 bit binary number1 1 1 1 1 0 1 0 0 0 0 0
Bit wise OR operation
First Second Result
1 1 T
0 1 T
0 1 T
1 1 T
0 1 T
0 0 F
1 1 T
1 0 T
1 0 T
0 0 F
1 0 T
1 0 T
Bit wise AND operation
First Second Result
1 1 T
0 1 F
0 1 F
1 1 T
0 1 F
0 0 F
1 1 T
1 0 F
1 0 F
0 0 F
1 0 F
1 0 F
Bit wise XOR operation
First Second Result
1 1 F
0 1 T
0 1 T
1 1 F
0 1 T
0 0 F
1 1 F
1 0 T
1 0 T
0 0 F
1 0 T
1 0 T


