COT_A1

COT_A1 - simply { // use 2^(boolean inputs) a = (abcd...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//Discreet Programming assignment 1 //Programmed in C++ for educational purposes // the only c++ - specific syntax used is the i/o. // By David Callies // 1/9/08 / #include<iostream> using namespace std; u #define BIT_A ((unsigned int) (1 << 3)) //0x08 #define BIT_B ((unsigned int) (1 << 2)) //0x04 #define BIT_C ((unsigned int) (1 << 1)) //0x02 #define BIT_D ((unsigned int) (1 << 0)) //0x01 # // A single statement of (a op1 b) op2 (c op3 d) // --> (p op q) int dologic(int p, int q, int type); i int main(void) { unsigned int abcd = 0; //a char should work here, but I am // wary of the type. int a, b, c, d, op1, op2, op3; cout << "Please enter op1(and=1,or=2,xor=3,nor=4,nand=5)\n"; cin >> op1; cout << "Please enter op2(and=1,or=2,xor=3,nor=4,nand=5)\n"; cin >> op2; cout << "Please enter op3(and=1,or=2,xor=3,nor=4,nand=5)\n"; cin >> op3; cout << "\nHere is your truth table:\n\na b c d answer\n"; while(abcd < 16) //if you were to change this program to have more inputs,
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: simply { // use 2^(boolean inputs) a = (abcd &amp; BIT_A)/8; //else it would display 8 b = (abcd &amp; BIT_B)/4; //else it would display 4 c = (abcd &amp; BIT_C)/2; //else it would display 2 d = (abcd &amp; BIT_D); //Ultra-simple formatting, only 1 character displayed cout &lt;&lt; a &lt;&lt; &quot; &quot; &lt;&lt; b &lt;&lt; &quot; &quot; &lt;&lt; c &lt;&lt; &quot; &quot; &lt;&lt; d &lt;&lt; &quot; &quot;; //a.k.a.: (a op1 b) op2 (c op3 d) cout &lt;&lt; dologic(dologic(a,b,op1), dologic(c,d,op3), op2) &lt;&lt; &quot;\n&quot;; abcd++; //incriment the bit source, creating a new pattern of abcd; } system(&quot;Pause&quot;); //For lazy file openers } int dologic(int p, int q, int type) { switch(type) //no breaks needed due to return { case 1: return (p &amp;&amp; q); //A AND B case 2: return (p || q); //A OR B case 3: return (p != q); //A XOR B case 4: return !(p || q); //A NOR B case 5: return !(p &amp;&amp; q); //A NAND B default: cout &lt;&lt; &quot;LOGIC ERROR!\n&quot;; //hasn't gone off yet . . . } }...
View Full Document

Page1 / 2

COT_A1 - simply { // use 2^(boolean inputs) a = (abcd...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online