Question

In: Computer Science

In c++ use bool functions to create and print a truth table for disconjunction and negation...

In c++ use bool functions to create and print a truth table for disconjunction and negation functionality and use it to print the truth table for equation pv~p.

Solutions

Expert Solution

#include <iostream>
using namespace std;

int disjunction(bool a, bool b)
{

//This function returns the value of a∨b
if(a==true||b==true)
return 1;
else
return 0;

}

int negation(bool a)
{

//This function returns the value of ~a
if(a==true)
return 0;
else
return 1;
}

int main() {
// declare the bool
bool a = true;
bool b= true;

//Print the disjunction function
printf("Disjunction Truth Table");
printf("\n\nA\tB\tO/P");
printf("\n%d\t%d\t%d",a,b,disjunction(a,b));
printf("\n%d\t%d\t%d",a,!b,disjunction(a,!b));
printf("\n%d\t%d\t%d",!a,b,disjunction(!a,b));
printf("\n%d\t%d\t%d",!a,!b,disjunction(!a,!b));

//Print the negation function
printf("\n\nNegation Truth Table");
printf("\n\nA\t~A");
printf("\n%d\t%d",a,negation(a));
printf("\n%d\t%d",!a,negation(!a));

//Printing the P ∨ ~P equation
printf("\n\nTruth Table for P ∨ ~P");
printf("\n\nP\t~P\tP∨~P");
printf("\n%d\t%d\t%d",a,negation(a),disjunction(a,negation(a)));
printf("\n%d\t%d\t%d",!a,negation(!a),disjunction(a,negation(!a)));


return 0;
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Snapshot of Output:


Related Solutions

write a program that will print a truth table for p ^ ~q. Using C++ please.
write a program that will print a truth table for p ^ ~q. Using C++ please.
Use Python: # Problem Set 01: - Develop neurons and print truth table of the following...
Use Python: # Problem Set 01: - Develop neurons and print truth table of the following 2-input logic gates: AND, OR, NAND, NOR, XOR, XNOR and 1-input NOT gate (Notice: use Markdown to explain how you developed a neuron, and to insert images showing the truth table of logic gates before coding) # Problem Set 02: - Develop neuron and print truth table of XOR gate using only NAND gates - Develop neuron and print truth table of XOR gate...
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR,...
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR, NAND, NOR, XOR, XNOR and 1-input NOT gate (Notice: use Markdown to explain how you developed a neuron, and to insert images showing the truth table of logic gates before coding)
Create an Employee class having the following functions and print the final salary in c++ program....
Create an Employee class having the following functions and print the final salary in c++ program. - getInfo; which takes the salary, number of hours of work per day of employee as parameters - AddSal; which adds $10 to the salary of the employee if it is less than $500. - AddWork; which adds $5 to the salary of the employee if the number of hours of work per day is more than 6 hours.
create a table of data for two different linear functions. The table should use the same...
create a table of data for two different linear functions. The table should use the same values of X for both functions. Based on your table will the graph of these two functions intersect explain your answer
create a table of data for two different linear functions. The table should use the same...
create a table of data for two different linear functions. The table should use the same values of X for both functions. Based on your table will the graph of these two functions intersect explain your answer
In C++, please check for memory leaks Recursive Functions Goals Create and use recursive functions In...
In C++, please check for memory leaks Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character. Example: Input of “Hello,...
Write a program in C++ that will output the truth table for a simple wff. There...
Write a program in C++ that will output the truth table for a simple wff. There will only be Ps and Qs, so you can hard code the P truth table and the Q truth table into arrays. The user will use A for ^ , O for V, N for ' , & I for -> . Hint: Read the first character, load the appropriate truth table into the first working array. Read the next character. If it is...
create a VHDL program for the Truth Table below. Please make sure to create your code...
create a VHDL program for the Truth Table below. Please make sure to create your code for the simplified circuit. A B C Z 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 0
Problem 3: Obtain the truth table for the following functions and express each function in sum...
Problem 3: Obtain the truth table for the following functions and express each function in sum of minterms and product of maxterms form: [20 Points] A. X = (B+CD)(C+BD) B. Y = BD’ + ACD’ + AB’C + A’C’ Problem 4: [15 Points] A. Write the following Boolean expression in SOP form : (B+D)(A’+B’+C) B. Write the following Boolean expression in POS form : AB’ + A’C’+ABC
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT