In: Computer Science
1. Use the enum keyword or a C++ class to create a new type Boolean with the two values F and T defined. Use the C++ class/struct keyword and an array to create a list of pairs that cover all possible combinations of the 2 Boolean constants you defined.
2. Extend the same program and implement conjunction and disjunction functionality in a separate library (mylib.h/mylib.cpp). Use your implementation to print truth tables for both.
3. Further extend the same program by adding xdisjunction and negation functionality. Use your implementation to print truth table for both.
4. Use functions developed (conjunction, disjunction, negation ...) in above assignment and implement Example 1.8 (a) Construct the truth table of the proposition (p∧q)∨(∼ p∨∼ q). Determine if this proposition is a tautology. (b) Show that p∨∼ p is a tautology.
5. Use functions developed in mylib (mylib.h/mylib.cpp) separate library (conjunction, disjunction, negation ...) in previous assignments and implement Example 1.9
(a) Show that ∼ (p∨q) ≡∼ p∧∼ q.
(b) Show that ∼ (p∧q) ≡∼ p∨∼ q.
(c) Show that ∼ (∼ p) ≡ p.
Parts (a) and (b) are known as DeMorgan’s laws.
course = Discrete Structures.
Please let me know if anything is required.
answers for 1, 2, and 3 :
#include <iostream>
using namespace std;
void conjunction() //defining the conjuction function
{
cout<<"Truth Table for conjunction \n"; // printing the truth
table for the conjunction function
cout<<"\ta b (a AND b)\n";
cout<<"\t0 0 0\n";
cout<<"\t0 1 0\n";
cout<<"\t1 0 0\n";
cout<<"\t1 1 1\n";
}
void disjunction() //defining the disjunction function
{
cout<<"Truth Table for disjunction \n"; // printing the truth
table for the disjunction function
cout<<"\ta b (a OR b)\n";
cout<<"\t0 0 0\n";
cout<<"\t0 1 1\n";
cout<<"\t1 0 1\n";
cout<<"\t1 1 1\n";
}
void negation() //defining the negation function
{
cout<<"Truth Table for negation \n"; // printing the truth
table for the negation function
cout<<"\ta ~a\n";
cout<<"\t0 1 \n";
cout<<"\t1 0 \n";
}
int main()
{
conjunction(); //calling conjunction(AND) function
disjunction(); //calling disjunction(OR) function
negation(); //calling negation(~) function
return 0;
}
4.
#include <iostream>
using namespace std;
void conjunction() //defining the conjuction
function
{
cout<<"Truth Table for conjunction \n"; // printing the truth
table for the conjunction function
cout<<"\ta b (a AND b)\n";
cout<<"\t0 0 0\n";
cout<<"\t0 1 0\n";
cout<<"\t1 0 0\n";
cout<<"\t1 1 1\n";
}
void disjunction() //defining the disjunction
function
{
cout<<"Truth Table for disjunction \n"; // printing the truth
table for the disjunction function
cout<<"\ta b (a OR b)\n";
cout<<"\t0 0 0\n";
cout<<"\t0 1 1\n";
cout<<"\t1 0 1\n";
cout<<"\t1 1 1\n";
}
void negation() //defining the negation function
{
cout<<"Truth Table for negation \n"; // printing the truth
table for the negation function
cout<<"\ta ~a\n";
cout<<"\t0 1 \n";
cout<<"\t1 0 \n";
}
int main()
{
conjunction(); //calling conjunction(AND) function
disjunction(); //calling disjunction(OR) function
negation(); //calling negation(~) function
cout<<"Truth table for (p∧q)∨(∼ p∨∼ q)\n"; //Truth
table for (p∧q)∨(∼ p∨∼ q)
cout<<" (p ^ q) ∨ (∼p ∨ ∼q) result = (p∧q)∨(∼ p∨∼ q)
\n";
cout<<" (0 0 0) 1 (1 1 1) 1\n";
cout<<" (0 0 1) 1 (1 1 0) 1\n";
cout<<" (1 0 0) 1 (0 1 1) 1\n";
cout<<" (1 1 1) 1 (0 0 0) 1\n";
return 0;
}
4.b
#include <iostream>
using namespace std;
void conjunction() //defining the conjuction
function
{
cout<<"Truth Table for conjunction \n"; // printing the truth
table for the conjunction function
cout<<"\ta b (a AND b)\n";
cout<<"\t0 0 0\n";
cout<<"\t0 1 0\n";
cout<<"\t1 0 0\n";
cout<<"\t1 1 1\n";
}
void disjunction() //defining the disjunction
function
{
cout<<"Truth Table for disjunction \n"; // printing the truth
table for the disjunction function
cout<<"\ta b (a OR b)\n";
cout<<"\t0 0 0\n";
cout<<"\t0 1 1\n";
cout<<"\t1 0 1\n";
cout<<"\t1 1 1\n";
}
void negation() //defining the negation function
{
cout<<"Truth Table for negation \n"; // printing the truth
table for the negation function
cout<<"\ta ~a\n";
cout<<"\t0 1 \n";
cout<<"\t1 0 \n";
}
int main()
{
conjunction(); //calling conjunction(AND) function
disjunction(); //calling disjunction(OR) function
negation(); //calling negation(~) function
cout<<"Truth table for (p∧q)∨(∼ p∨∼ q)\n"; //Truth
table for (p∧q)∨(∼ p∨∼ q)
cout<<" (p ^ q) ∨ (∼p ∨ ∼q) result = (p∧q)∨(∼ p∨∼ q)
\n";
cout<<" (0 0 0) 1 (1 1 1) 1\n";
cout<<" (0 0 1) 1 (1 1 0) 1\n";
cout<<" (1 0 0) 1 (0 1 1) 1\n";
cout<<" (1 1 1) 1 (0 0 0) 1\n";
cout<<"Truth table for p∨∼ p \n";//Truth table for
p∨∼ p which is tautology.
cout<<" p ∨ ~p result=(p∨∼ p)\n";
cout<<" 0 1 1 1\n";
cout<<" 1 1 0 1\n";
return 0;
}
5.
#include <iostream>
using namespace std;
void conjunction() //defining the conjuction
function
{
cout<<"Truth Table for conjunction \n"; // printing the truth
table for the conjunction function
cout<<"\ta b (a AND b)\n";
cout<<"\t0 0 0\n";
cout<<"\t0 1 0\n";
cout<<"\t1 0 0\n";
cout<<"\t1 1 1\n";
}
void disjunction() //defining the disjunction
function
{
cout<<"Truth Table for disjunction \n"; // printing the truth
table for the disjunction function
cout<<"\ta b (a OR b)\n";
cout<<"\t0 0 0\n";
cout<<"\t0 1 1\n";
cout<<"\t1 0 1\n";
cout<<"\t1 1 1\n";
}
void negation() //defining the negation function
{
cout<<"Truth Table for negation \n"; // printing the truth
table for the negation function
cout<<"\ta ~a\n";
cout<<"\t0 1 \n";
cout<<"\t1 0 \n";
}
int main()
{
conjunction(); //calling conjunction(AND) function
disjunction(); //calling disjunction(OR) function
negation(); //calling negation(~) function
cout<<"Truth table for (p∧q)∨(∼ p∨∼ q)\n"; //Truth
table for (p∧q)∨(∼ p∨∼ q)
cout<<" (p ^ q) ∨ (∼p ∨ ∼q) result = (p∧q)∨(∼ p∨∼ q)
\n";
cout<<" (0 0 0) 1 (1 1 1) 1\n";
cout<<" (0 0 1) 1 (1 1 0) 1\n";
cout<<" (1 0 0) 1 (0 1 1) 1\n";
cout<<" (1 1 1) 1 (0 0 0) 1\n";
cout<<"Truth table for p∨∼ p \n";//Truth table for
p∨∼ p which is tautology.
cout<<" p ∨ ~p result=(p∨∼ p)\n";
cout<<" 0 1 1 1\n";
cout<<" 1 1 0 1\n";
cout<<"Truth table for ∼ (p∨q) ≡ ∼ p∧∼ q
\n";//Truth table for ∼ (p∨q) ≡ ∼ p∧∼ q
cout<<" ~ (p ∨ q) ≡ (∼p ∧ ∼q) result = ∼ (p∨q) ≡ ∼ p∧∼ q
\n";
cout<<" 1 (0 0 0) ≡ (1 1 1) 1\n";
cout<<" 0 (0 1 1) ≡ (1 0 0) 0\n";
cout<<" 0 (1 1 0) ≡ (0 0 1) 0\n";
cout<<" 0 (1 1 1) ≡ (0 0 0) 0\n";
cout<<"Truth table for ∼ (p∧q) ≡∼ p∨∼ q \n";//Truth table for
∼ (p∧q) ≡ ∼ p∨∼ q
cout<<" ~ (p ∧ q) ≡ (∼p ∨ ∼q) result = ∼ (p∧q) ≡∼ p∨∼ q
\n";
cout<<" 1 (0 0 0) ≡ (1 1 1) 1\n";
cout<<" 1 (0 0 1) ≡ (1 1 0) 1\n";
cout<<" 1 (1 0 0) ≡ (0 1 1) 1\n";
cout<<" 0 (1 1 1) ≡ (0 0 0) 0\n";
cout<<"Truth table for ∼ (∼ p) ≡ p. \n";//Truth table for ∼
(∼ p) ≡ p
cout<<" p ~p result= ∼ (∼ p) ≡ p\n";
cout<<" 0 1 0 ≡ 0\n";
cout<<" 1 0 1 ≡ 1\n";
return 0;
}