In: Computer Science
C++
This assignment will have you designing a program which can test multiple combinations of the Boolean variables A, B, and C, and determine which combinations of them will yield true values. However the statement is designed in the style of a Logical Circuit.You are asked to create three truth tables for the three problems.First, convert the diagram to boolean algebra equations.Then evaluate their values step by step based on the values of A, B and C.
Finally, print the truth table on the screen with detailed computational steps and boolean algebra symbols. Your headers will be the boolean algebra expressions.You are asked to submit source file and screen prints only.
CODE:
#include<iostream>
using namespace std;
int main()
{
// define the variables A,B and C
int A,B,C;
// print the header section with A,B,C and then the
result of boolean combination
cout<<"A\tB\tC\tAB+C\tA+BC\tB+AC";
//run a loop for A , B and C for all possible curcuit
combinations of 0 & 1
for(A=0;A<=1;++A)
for(B=0;B<=1;++B)
for(C=0;C<=1;++C)
{
// bounday
condition where the sum is leading to 2 rather than usual 1
if(A*B+C==2||A+B*C==2||B+A*C==2)
cout<<"\n\n"<<A<<"\t"<<B<<"\t"<<C<<"\t1"<<"\t1"<<"\t1";
else
cout<<"\n\n"<<A<<"\t"<<B<<"\t"<<C<<"\t"<<A*B+C<<"\t"<<A+B*C<<"\t"<<B+A*C;
}
return 0;
}
RESULT: