rendered paste body
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main(int argc, _TCHAR* argv[])
{
// Declare the string Variables
string p;
string q;
string Conjunction, Disjunction, Exclusive;
string Implication;
string BiConditional;
string DeMorgan;
string Absorption;
string recurse;
// Declare the functions used to Assign the truth values to the associated variables
string getConjunction(string p,string q);
string getDisjunction(string p,string q);
string getExclusiveOr(string p,string q);
string getImplication(string p,string q);
string getBiConditional(string p,string q);
string getAbsorption(string p, string q);
string getDeMorgan(string p, string q);
string menu (string p, string q, string Conjunction, string Disjunction, string Exclusive, string Implication, string BiConditional, string Absorption, string DeMorgan);
// Do...While runs the program loop at least once
do
{
system("cls");
// Collect the truth values for p and q
cout << "Enter the First Truth Value p (1/0): ";
cin >> p;
cout << "Enter the Second Truth Value q (1/0): ";
cin >> q; cout << endl;
// Assign the Truth Values to the associated variables
Conjunction = getConjunction(p, q);
Disjunction = getDisjunction(p, q);
Exclusive = getExclusiveOr(p, q);
Implication = getImplication(p, q);
BiConditional = getBiConditional(p, q);
DeMorgan = getDeMorgan(p, q);
Absorption = getAbsorption(p, q);
// Run a recursive Menu function
// Causes the program to run until the user chooses to exit
recurse = menu(p,q,Conjunction,Disjunction,Exclusive,Implication, BiConditional, DeMorgan, Absorption);
}
while (recurse == "yes");
return 0;
}
// Returns the value of the Conjunction proposition, based on p & q
string getConjunction (string p, string q)
{
if (p == "true" && q == "true")
return "true";
else
return "false";
}
// Returns the value of the Disjunction proposition, based on p & q
string getDisjunction (string p, string q)
{
if (p == "true" || q == "true")
return "true";
else
return "false";
}
// Returns the value of the Exclusive Or proposition, based on p & q
string getExclusiveOr (string p, string q)
{
if ((p == "true" && q == "false") || (p == "false" && q == "true"))
return "true";
else
return "false";
}
// Returns the value of the Implication proposition, based on p & q
string getImplication (string p, string q)
{
if (p == "true" && q == "false")
return "false";
else
return "true";
}
// Returns the value of the BiConditional proposition, based on p & q
string getBiConditional (string p, string q)
{
if (p == q)
return "true";
else
return "false";
}
// Returns the value of Absorption proposition, based on p & q
string getAbsorption (string p, string q)
{
if ( p == "true" )
{
return "true";
}
else
return "false";
}
// Returns the value of DeMorgan's Law, based on p and q
string getDeMorgan(string p, string q)
{
if (( p == "false" ) && ( q == "false" ))
{
return "false";
}
else
{
return "true";
}
}
// A menu running in a function to keep the Main function tidy
string menu (string p, string q, string Conjunction, string Disjunction, string Exclusive, string Implication, string BiConditional, string DeMorgan, string Absorption)
{
int MenuChoice;
cout << "\nWhich Checks do you want to perform? \n1: Conjunction, Disjunction, Exclusive \n2: Implication, BiConditional \n3: Abosrption, DeMorgan, or Commutative";
cout << "\nOption: ";
cin >> MenuChoice;
// The first menu Option: Conjunction, Disjunction and ExclusiveOr
if (MenuChoice == 1)
{
cout << "\t*****************" << endl;
cout << "\t***p: " << p << " * q: " << q << "***" << endl;
cout << "\t*****************" << endl;
cout << "\t*Conjunction: " << Conjunction << "*" << endl;
cout << "\t*Disjunction: " << Disjunction << "*" << endl;
cout << "\t*Exclusive Or: " << Exclusive << "*" << endl;
cout << "\t*****************" << endl;
}
// The second menu option: Implication and biConditional
else if (MenuChoice == 2)
{
cout << "\t******************" << endl;
cout << "\t***p: " << p << " ** q: " << q << "***" << endl;
cout << "\t******************" << endl;
cout << "\t*Implication: " << Implication << "*" << endl;
cout << "\t*BiConditional: " << BiConditional << "*" << endl;
cout << "\t******************" << endl;
}
// The third menu choice shows Commutative, Absorption and DeMorgain
else if (MenuChoice == 3)
{
cout << "\t*******************************" << endl;
cout << "\t*********p: " << p << " ** q: " << q << "**********" << endl;
cout << "\t*******************************" << endl;
cout << "\t*DeMorgan: " << DeMorgan << "*" << endl;
cout << "\t*Absorption: " << Absorption << "*" << endl;
cout << "\t*Commutative: " << " *"<< endl;
cout << "\t****First Law(Conjunction): " << Conjunction << "*" << endl;
cout << "\t****Second Law(Disjunction): " << Disjunction << "*" << endl;
cout << "\t*******************************" << endl;
}
// If given an incorrect menu option, the function Recurses and
// shows the available options again
else
menu (p, q, Conjunction, Disjunction, Exclusive, Implication, BiConditional, DeMorgan, Absorption);
// The program checks if the user wants to quit or not
string Recurse;
cout << "\nRun Program Again? (yes/no)" << endl;
cin >> Recurse;
if (Recurse == "yes")
return true;
else
return false;
}