All pastes #433627 Raw Edit

Mine

public text v1 · immutable
·published 2007-04-10 22:20 UTC
rendered paste body
#include "stdafx.h"
#include <iostream>
using namespace std;


int main(int argc, _TCHAR* argv[])
{
	// Declare the boolean Variables
	bool p;
	bool q;
	bool Conjunction, Disjunction, Exclusive;
	bool Implication, BiConditional;
	bool DeMorgan;
	bool Absorption;
	bool recurse;
	
	// Declare the functions used to Assign the truth values to the associated variables
	bool getConjunction(bool p,bool q);
	bool getDisjunction(bool p,bool q);
	bool getExclusiveOr(bool p,bool q);
	bool getImplication(bool p,bool q);
	bool getBiConditional(bool p,bool q);
	bool getAbsorption(bool p, bool q);
	bool getDeMorgan(bool p, bool q);
	bool menu (bool p, bool q, bool Conjunction, bool Disjunction, bool Exclusive, bool Implication, bool BiConditional, bool Absorption, bool 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 == true);
	return 0;
}
// Returns the value of the Conjunction proposition, based on p & q
bool getConjunction (bool p, bool q)
{
	if (p == true && q == true)
		return true;
	else
		return false;
}
// Returns the value of the Disjunction proposition, based on p & q
bool getDisjunction (bool p, bool q)
{
	if (p == true || q == true)
		return true;
	else
		return false;
}
// Returns the value of the Exclusive Or proposition, based on p & q
bool getExclusiveOr (bool p, bool 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
bool getImplication (bool p, bool q)
{
	if (p == true && q == false)
		return false;
	else
		return true;
}
// Returns the value of the BiConditional proposition, based on p & q
bool getBiConditional (bool p, bool q)
{
	if (p == q)
		return true;
	else
		return false;
}

// Returns the value of Absorption proposition, based on p & q
bool getAbsorption (bool p, bool q)
{	
	if ( p == true )
	{
		return true;
	}
	else
		return false;
}

// Returns the value of DeMorgan's Law, based on p and q
bool getDeMorgan(bool p, bool q)
{
	if (( p == false ) && ( q == false ))
	{
		return false;
	}
	else
	{
		return true;
	}
}



// A menu running in a function to keep the Main function tidy
bool menu (bool p, bool q, bool Conjunction, bool Disjunction, bool Exclusive, bool Implication, bool BiConditional, bool DeMorgan, bool 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
	bool Recurse;
	cout << "\nRun Program Again? (1/0)" << endl;
	cin >> Recurse;
	if (Recurse == true)
		return true;
	else 
		return false;
}