C++ Write a program that produces the truth table of the following logical opera
ID: 3782457 • Letter: C
Question
C++
Write a program that produces the truth table of the following logical operators. You can output
one table with all the operators (one column for each operator) or ve tables (one table for each
operator), you decide. Write the header(s) of the table(s)- this is the name of the columns-. Output
the result on the le prog1 output.txt. The table should contain the letters 'T' and 'F', it should
not print 1s and 0s. Show the results on the following order:
1. negation
2. disjunction (AND operator)
3. conjunction (OR operator)
4. exclusive or (or but not both)
5. implication (CONDITIONAL operator)
6. biconditional
Explanation / Answer
Answer:
#include<iostream.h>
#include<conio.h>
#include <fstream.h>
void main()
{
clrscr();
int a=0;
b=1,
c;
cout<<"enter value of a=(0/1)";
cin>>a; cout<<"enter value of b=(0/1)";
cin>>b; cout<<" enter 1 for negation";
cout<<" enter 2 for disjuction";
cout<<" enter 3 for conjuction";
cout<<" enter 4 for exclusive";
cout<<" enter your choice=";
int choice; cin>>choice;
switch(choice)
{
case 1: c=!a;
break;
case 2:
c=a&&b;
break;
case 3:
c=a||b;
break;
case 4:
c=a^b;
break;
}
Ofstream ofobj("output.txt");
Char ch[30];
if(c==1)
{
cout<<"true";
}
else if(c!=1)
{
cout<<"false";
}
Ofobj<<ch: Ofobj. Close();
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.