In: Computer Science
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.
#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 &a, struct combination
&b , struct combination &r) //r is for results
{
cout<<"Truth tabe for conjuction "<<endl;
cout<<"p q"<<endl;
for(int i=0;i<4;i++)
{
r.array[i]=(a.array[i]&&b.array[i]==F?F:T);
cout<<a.array[i]<<"
"<<b.array[i]<<" "<<(a.array[i] &&
b.array[i])<<endl;
}
}
void disjunction(struct combination &a, struct combination
&b , struct combination &r)
{
cout<<"Truth tabe for disjuction
"<<endl;
cout<<"p q"<<endl;
for(int i=0;i<4;i++)
{
r.array[i]=(a.array[i]||b.array[i]==F?F:T);
cout<<a.array[i]<<"
"<<b.array[i]<<" "<<(a.array[i] ||
b.array[i])<<endl;
}
}
void negotiation(struct combination &a, struct combination
&r)
{
cout<<"Truth tabe for negotiation"<<endl;
cout<<"p"<<endl;
for(int i=0;i<4;i++)
{
r.array[i]=(a.array[i]==F?T:F);
r.array[i]=(a.array[i]==T?F:T);
cout<<a.array[i]<<"
"<<r.array[i]<<endl;
}
}
int main()
{
struct combination p;
struct combination q;
struct combination 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);
negotiation(p,r);
negotiation(q,r);
}
Truth tabe for conjuction
p q
0 0 0
0 1 0
1 0 0
1 1 1
Truth tabe for disjuction
p q
0 0 0
0 1 1
1 0 1
1 1 1
Truth tabe for negotiation
p
0 1
0 1
1 0
1 0
Truth tabe for negotiation
p
0 1
1 0
0 1
1 0