Question

In: Computer Science

Use the enum keyword or a C++ class to create a new type Boolean with the...

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.

Solutions

Expert Solution

#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


Related Solutions

1. Use the enum keyword or a C++ class to create a new type Boolean with...
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...
Create a class that has a method that uses the ‘this’ keyword as the return statement....
Create a class that has a method that uses the ‘this’ keyword as the return statement. This method (called increment( ) in the class that you have just created ) increments the private integer field (private i ) in the class.   In the main ( ) method, if you increment (using the ‘this’ with increment() call) four times, you should see the following display: i is = 4 Thank You
In the following class: public class Truth { private boolean yes_no; ... } Create constructor, setter...
In the following class: public class Truth { private boolean yes_no; ... } Create constructor, setter and getter methods, and toString method.
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
Use boolean algebra to prove that: (A^- *B*C^-) + (A^- *B*C) + (A* B^- *C) +...
Use boolean algebra to prove that: (A^- *B*C^-) + (A^- *B*C) + (A* B^- *C) + (A*B* C^-) + (A*B*C)= (A+B)*(B+C) A^- is same as "not A" please show steps to getting the left side to equal the right side, use boolean algebra properties such as distributive, absorption,etc
This assignment is For a C++ class , I am having difficulty with getting the boolean...
This assignment is For a C++ class , I am having difficulty with getting the boolean statements the most; getting them set up properly inside the int main() area. You have been asked to define a tip-calculating function named calcTip that could be integrated into a larger piece of software designed to improve guest service at a restaurant. As a result, you must conform to the function specification used throughout the rest of the project's code: double calcTip(double checkAmount, bool...
----------------------------------------------------------------------------------------------- Create a class called MathOperations that a teacher might use to represent the basic type...
----------------------------------------------------------------------------------------------- Create a class called MathOperations that a teacher might use to represent the basic type of mathematical operations that may be performed. The class should include the following: Three double private variables as instance variables, number1, number2, and result. Your class should have a default constructor that initializes the three instance variables to zero. Your class should also have a constructor that initializes the two instance variables (number1 and number2) to the value entered by the user from keyboard....
In C++ 1.Create a class Point which has a template parameter of the type of internal...
In C++ 1.Create a class Point which has a template parameter of the type of internal data, T, and a template parameter for the dimension of the Point(2D, 3D etc.). Store a statically allocated, internal array of type T with dimension n. Ensure to include any constructer(s),destructors, getters or setters you might need. (10 points) 2.Create a template function which computes the Euclidean distance between 2 points. (6 points) 3.Instantiate two Point<double, 3> and compute their distance. Instantiate two Point<int,...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
Create a C++ class with a static member item so that whenever a new object is...
Create a C++ class with a static member item so that whenever a new object is created, the total number of objects of the class can be reported.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT