Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

write a computer program that produces the desired output from the given input.

Input: Truth values for two statement letters A and B
Output: Corresponding truth values (appropriately
labeled, of course) for
                                          A Λ B, AB, AB, AB, A

Expert Solution
Check Mark
Step 1

Objective: This program prints the truth table of certain logic gates.

Programming language: since no language is mentioned, C++ is used.

Step 2

Answer:

#include <iostream> 
#include <stdlib.h> 
using namespace std;
void printAND(int A[],int B[])
{
    int Z;
    printf("AND gate\n");
    printf("A |\t |B\tZ=A AND B");
    for(int i = 0; i <4;i++) { 
        //computing AND gate values
        Z = A[i] & B[i]; 
        printf("\n %d |\t %d|\t%d",A[i],B[i],Z); 
    } 
}

void printOR(int A[],int B[])
{
    int Z;
    printf("OR gate\n");
    printf("A |\t |B\t|Z=A OR B");
    for(int i = 0; i <4;i++) { 
        //computing AND gate values
        Z = A[i] | B[i]; 
        printf("\n %d |\t %d|\t%d",A[i],B[i],Z); 
    } 
}

void printNOT(int B[])
{
    int Z;
    printf("NOT gate\n");
    printf("B\t|Z=NOT B");
    for(int i = 0; i <2;i++) { 
        //computing NOT gate values
        Z = !B[i]; 
        printf("\n%d|\t%d",B[i],Z); 
    } 
}

void printIMPLY(int A[],int B[])
{
    int Z;
    printf("IMPLES THAT\n");
    printf("A |\t |B\t|Z=A -> B");
    for(int i = 0; i <4;i++) { 
        //computing IMPLIES THAT
        if(A[i]==1 && B[i]==0)
            Z = 0; 
        else
            Z = 1;
        printf("\n %d |\t %d|\t%d",A[i],B[i],Z); 
    } 
}

void printEQUI(int A[],int B[])
{
    int Z;
    printf("EQUIVALENCE\n");
    printf("A |\t |B\t|Z=A <-> B");
    for(int i = 0; i <4;i++) { 
        //computing IMPLIES THAT
        if(A[i]==B[i])
            Z = 1; 
        else
            Z = 0;
        printf("\n %d |\t %d|\t%d",A[i],B[i],Z); 
    } 
}
int main() 

    int A[5] = { 0, 0, 1, 1}; 
    int B[5] = { 0, 1, 0, 1}; 
    int Z; 
    printAND(A,B);
    cout<<"\n";
    printOR(A,B);
    cout<<"\n";
    printNOT(B);
    cout<<"\n";
    printIMPLY(A,B);
    cout<<"\n";
    printEQUI(A,B);

bartleby

Step by stepSolved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education