C++ Please read the question carefully and make sure that the intermedial steps
ID: 3782858 • Letter: C
Question
C++
Please read the question carefully and make sure that the intermedial steps for the proposition are also shown in the truth table.
Output should print 'T' and 'F' not 0s and 1s.
Write a program that produces truth table for the following compound propositions (your can use
nested loops). Write the header(s) of the table(s), including intermedial steps and the final result.
Output the result on thefile prog2 output.txt.
1. (p -> q) <-> (neg q -> neg p)
2. (p or q) and neg (p and q)
3. p and neg p
Explanation / Answer
C++ Code (Just compile and run the code as it is, it will create output.txt file automatically ):
#include <bits/stdc++.h>
using namespace std;
int main()
{
ofstream myfile;
myfile.open ("output.txt");
myfile << "TrueTable of (p -> q) <-> (not q -> not p) ";
myfile << "p q (p -> q) (not q -> not p) (p -> q) <-> (not q -> not p) ";
myfile << "F F T T T ";
myfile << "F T T T T ";
myfile << "T F F F T ";
myfile << "T T T T T ";
myfile << " TrueTable of ((p q) ¬(p q)) ";
myfile << "p q (p q) ¬(p q) ((p q) ¬(p q)) ";
myfile << "F F F T F ";
myfile << "F T T T T ";
myfile << "T F T T T ";
myfile << "T T T F F ";
myfile << " TrueTable of (p ¬q) ";
myfile << "p q (¬q) (p ¬q) ";
myfile << "F F T F ";
myfile << "F T F F ";
myfile << "T F T T ";
myfile << "T T F F ";
myfile.close();
return 0;
}
Sample Output ( contents of output.txt file)
TrueTable of (p -> q) <-> (not q -> not p)
p q (p -> q) (not q -> not p) (p -> q) <-> (not q -> not p)
F F T T T
F T T T T
T F F F T
T T T T T
TrueTable of ((p q) ¬(p q))
p q (p q) ¬(p q) ((p q) ¬(p q))
F F F T F
F T T T T
T F T T T
T T T F F
TrueTable of (p ¬q)
p q (¬q) (p ¬q)
F F T F
F T F F
T F T T
T T F F
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.