Question

In: Computer Science

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 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.

Solutions

Expert Solution

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;
}


Related Solutions

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,...
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
----------------------------------------------------------------------------------------------- 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....
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.
android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called...
android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called DataBaseManager as in Lecture 5 and create a database table in SQLite, called StudentInfo. The fields for the StudentInfo table include StudentID, FirstName, LastName, YearOfBirth and Gender. Include functions for adding a row to the table and for retrieving all rows, similar to that shown in lecture 5. No user interface is required for this question, t -Continuing from , follow the example in...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
1. when you create a class by making it inherit from another class, the new class...
1. when you create a class by making it inherit from another class, the new class automatically, contains the data fields and _____ of the original class a. fonts b. methods c. class names d. arrays 2. if a programming language does not support ________, the language is not considered object oriented a. syntax b. applets c. loops d. polymorphism 3. when you create a class and do not provide a ______, java automatically supplies you with a default one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT