Discrete Mathematics Write a program in C++ that takes two propositions \'p\' an
ID: 3663264 • Letter: D
Question
Discrete Mathematics
Write a program in C++ that takes two propositions 'p' and 'q' as input where the two propositions are either True or False. The program produces the truth table of the input combinations of 'p' and 'q' for all the following logical operations. For Example: When the inputs are True and True for 'p' and 'q' and the logical operation is a conjunciton, then, your program must produce the result True.
1. negation
2. conjunction
3. disjunction
4. exclusive or
5. implication
6. biconditional
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
char p, q;
cout <<"Enter T or F for p='A is truthful': " ;
cin >> p;
cout <<"Enter T or F for q='B is truthful': " ;
cin >> q;
if((p == 'T' || 't') && (q == 'T' || 't'))
{
cout <<"A says 'We are both telling the truth' is TRUE" << endl;
cout <<"B says 'A is lying' is FALSE" << endl;
system("PAUSE");
return 0;
}
if((p == 'F' || 'f') && (q == 'T' || 't'))
{
cout <<"A says 'We are both telling the truth' is FALSE" << endl;
cout <<"B says 'A is lying' is TRUE" << endl;
system("PAUSE");
return 0;
}
if((p == 'T' || 't') && (q == 'F' || 'f'))
{
cout <<"A says 'We are both telling the truth' is FALSE" << endl;
cout <<"B says 'A is lying' is FALSE" << endl;
system("PAUSE");
return 0;
}
if(p == 'F' && q == 'F')
{
cout <<"A says 'We are both telling the truth' is FALSE" << endl;
cout <<"B says 'A is lying' is TRUE" << endl;
system("PAUSE");
return 0;
}
else
{
cout <<"Please use only 'T' or 'F' next time." << endl;
system("PAUSE");
return 0;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.