Sunday, April 10, 2011

Basic Combinational Circuit Programming for 4-inputs

// Programming Environment: Microsoft Visual Studio 2010
// Program Description: 2.2 Program to tabulate the values of the 4-input variables and the output produced by it
// Date/Time: 3/29/2011  5:51:57 PM
//------------------------------------------------------------------------
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstring>
#include <fstream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <utility>
#include <windows.h>
#include <conio.h>
#include "extras.h"
#include "Generic_Class.h"
using namespace std;
//---------------------------------------------------------------------------
// Named Constants
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Structure Declarations
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Function Prototypes
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main (void) {

    cout.setf (ios::fixed, ios::floatfield);
    cout.setf (ios::showpoint);
    cout.precision (2);

// Variable Declaration
int a;
int b;
int c;
int d;
int p;
int q;
int r;
int s;
int t;
int u;

cout << endl << "       TRUTH TABLE" << endl;
cout << endl << " Input " << "      " << "   Output  " << endl;
cout << endl << "-------" << "      " << "-----------" << endl;
cout << "A" << " " << "B" << " " << "C" << " " << "D" << "      "<< "P" << " " << "Q"
<< " " << "R" << " " << "S" << " " << "T" << " " << "U" << endl;
cout << endl << "-------" << "      " << "-----------" << endl;
for(a = 0; a <= 1; ++a) {
for (b = 0; b <= 1; ++b) {
for (c = 0; c <= 1; ++c) {
for (d = 0; d <= 1; ++d) {
cout << a << " " << b << " " << c << " " << d  << "     ";
p = (b | ~c);
cout << " " << (p & 1);
q = (p & a);
cout << " " << (q & 1);
r = (c | ~d);
cout << " " << (r & 1);
s = (b & r);
cout << " " << (s & 1);
t = (b & d);
cout << " " << (t & 1);
u = (q | s | t);
cout << " " << (u & 1) << endl;
}
}
}
}


    //---------------------------------------------------------
    cout << endl << endl << "\aDepress Any Key to Continue...";
    _getch ();
    return 0;
}
//------------------------------------------------------------------------
// Function Definitions
//------------------------------------------------------------------------