问题
I have this assignment that requires me to turn a premise statement into code. The idea is that i need to print out the truth table for a premise statement. This is the premise: (((P v Q) ^ (Q -> R)) XOR (P v R)) <-> (R ^ Q)
I can create a manual Truth table Truth Table for the above premise
I just dont understand how to transform that into code? How would i approach that using the typical basic libraries such as iostream, string, math, etc. I can't utilize anything else like vectors, sets, etc.
You don't have to write literal code but perhaps some pseudocode might help or even justs tips.
I understand that "^" is &&, "v" is ||, "->" is "if-else" but i'm not sure about "<->" and "XOR" or simply how to put that in code.
Thanks in advance.
UPDATE: As per the assistance of my fellow stackoverflow peers, we've managed to obtain the literal meaning of each logical operator statement into a c++ approach.
(P v Q) = P OR Q = (P || Q)
(P ^ Q) = P AND Q = (P && Q)
(P XOR Q) = P ^ Q = (P ^ Q)
(P -> Q) = if P then Q = (!P || Q)
(p <-> Q) = Only If P then Q = !(P ^ Q)
回答1:
You can (and should) use Boolean variables:
// declare variables and initialize.
bool p = true;
bool q = true;
bool r = true;
// Input values (from user or file)
//...
// Output some columns:
cout << p << " | " << q << " | " << r << " | ";
cout << (p || q) << " | ";
//...
cout << endl;
来源:https://stackoverflow.com/questions/46720065/turning-a-premise-into-code