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.
Here is the program
#include<iostream>
using namespace std;
enum Boolean {
F=0, T=1
}; //default values of False is 0 and true is 1.
struct combination {
enum Boolean array[4];
};
void conjunction(struct combination &p, struct combination
&q , struct combination &result) {
cout<<"The Truth tabe for conjuction "<<endl;
cout<<"p q result"<<endl;
for(int i=0;i<4;i++){
result.array[i]=(p.array[i]&&q.array[i]==F?F:T);
cout<<p.array[i]<<" "<<q.array[i]<<"
"<<(p.array[i] && q.array[i])<<endl;
}
}
void disjunction(struct combination &p, struct combination
&q , struct combination &result) {
cout<<"The Truth tabe for disjuction "<<endl;
cout<<"p q result"<<endl;
for(int i=0;i<4;i++){
result.array[i]=(p.array[i]||q.array[i]==F?F:T);
cout<<p.array[i]<<" "<<q.array[i]<<"
"<<(p.array[i] || q.array[i])<<endl;
}
}
void negation(struct combination &p, struct combination
&result){
cout<<"The Truth tabe for negation"<<endl;
cout<<"p result"<<endl;
for(int i=0;i<4;i++)
{
result.array[i]=(p.array[i]==F?T:F);
result.array[i]=(p.array[i]==T?F:T);
cout<<p.array[i]<<"
"<<result.array[i]<<endl;
}
}
//To test the functions
int main(){
struct combination p,q,r;
p.array[0]=F;p.array[1]=F;p.array[2]=T;p.array[3]=T;
q.array[0]=F;q.array[1]=T;q.array[2]=F;q.array[3]=T;
conjunction(p,q,r);
disjunction(p,q,r);
negation(p,r);
negation(q,r);
}
The output of the program is as below
The Truth tabe for conjuction
p q result
0 0 0
0 1 0
1 0 0
1 1 1
The Truth tabe for disjuction
p q result
0 0 0
0 1 1
1 0 1
1 1 1
The Truth tabe for negation
p result
0 1
0 1
1 0
1 0
The Truth tabe for negation
p result
0 1
1 0
0 1
1 0