Question: //please follow comments in the code for instructions and finish the question using c++ #include #include using namespace std; enum class logic { False, True
//please follow comments in the code for instructions and finish the question using c++
#include
#include
using namespace std;
enum class logic { False, True };
enum class gate { AND, OR, NOR, NAND };
string logicToString(logic l) {
// return a string for a given logical value (false,true) switch (l) { case (logic::False): return "False"; case (logic::True): return "True";
}
}
gate stringToGate(string gateStr) {
// converts a string representing a logical operation to a gate variable if (gateStr == "nor") { return gate::NOR; } if (gateStr == "or") { return gate::OR; } if (gateStr == "nand") { return gate::NAND; } if (gateStr == "and") { return gate::AND; }
}
logic OP(gate g, logic x, logic y) {
// this function returns the result of applying the logical operation (g)
// on the logical inputs x and y.
if (g == gate::AND) { cout if (x == logic::True && y == logic::True) { return logic::True; } else if (x == logic::True && y == logic::False) { return logic:: False; } else if (x == logic::False && y == logic::True) { return logic::False; } else if (x == logic::False && y == logic::False) { return logic::False; }
} else if (g == gate::NAND) { if (x == logic::True && y == logic::True) { return logic::False; } else if (x == logic::True && y == logic::False) { return logic::True; } else if (x == logic::False && y == logic::True) { return logic::True; } else if (x == logic::False && y == logic::False) { return logic::True; } }
else if (g == gate::OR) { if (x == logic::True && y == logic::True) { return logic::True; } else if (x == logic::True && y == logic::False) { return logic::True; } else if (x == logic::False && y == logic::True) { return logic::True; } else if (x == logic::False && y == logic::False) { return logic::False; } }
else if (g == gate::NOR) { if (x == logic::True && y == logic::True) { return logic::False; } else if (x == logic::True && y == logic::False) { return logic::False; } else if (x == logic::False && y == logic::True) { return logic::False; } else if (x == logic::False && y == logic::False) { return logic::True; } }
}
int main() {
logic x[] = { logic::False, logic::True };
logic y[] = { logic::False, logic::True };
string operation;
cin >> operation;
gate op = stringToGate(operation);
for (int i = 0; i
for (int j = 0; j
// Write the necessary code to display the truth table for the
//gate entered by the user
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
