C++ Given the symbol definitions: Meaning Symbol: NOT A ==> ~A A AND B ==> A * B
ID: 3804195 • Letter: C
Question
C++
Given the symbol definitions:
Meaning Symbol:
NOT A ==> ~A
A AND B ==> A * B
A OR B ==> A + B
A XOR B ==> A % B
A IMPLY B ==> A > B
A IF AND ONLY IF B ==> A ^ B
Write a program to find out the truth table of an expression. The number of
variable is less than or equal to 10. The precedence of the operators and
also the brackets should be ignored in this question.
Input:
3
r s t
r*s+t>~r
Output:
r s t | r*s+t>~r
--------------------
T T T | F
T T F | F
T F T | F
T F F | T
F T T | T
F T F | T
F F T | T
F F F | T
Input:
2
a b
~~a%b
Output:
a b | ~~a%b
--------------
T T | F
T F | T
F T | T
F F | F
Explanation / Answer
The program for this question is below :
#include<iostream>
using namespace std;
int main()
{
int x,y,z;
cout<<"X Y Z XY+Z";
for(x=0;x<=10;++x)
for(y=0;y<=10;++y)
for(z=0;z<=10;++z)
{
if(x*y+z==2)
cout<<" "<<x<<" "<<y<<" "<<z<<" 1";
else
cout<<" "<<x<<" "<<y<<" "<<z<<" "<<x*y+z;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.