COT_A1 - simply use 2^(boolean inputs a =(abcd&...

Info icon This 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,
Image of page 1

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

View Full Document Right Arrow Icon
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 & BIT_A)/8; //else it would display 8 b = (abcd & BIT_B)/4; //else it would display 4 c = (abcd & BIT_C)/2; //else it would display 2 d = (abcd & BIT_D); //Ultra-simple formatting, only 1 character displayed cout << a << " " << b << " " << c << " " << d << " "; //a.k.a.: (a op1 b) op2 (c op3 d) cout << dologic(dologic(a,b,op1), dologic(c,d,op3), op2) << "\n"; abcd++; //incriment the bit source, creating a new pattern of abcd; } system("Pause"); //For lazy file openers } int dologic(int p, int q, int type) { switch(type) //no breaks needed due to return { case 1: return (p && 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 && q); //A NAND B default: cout << "LOGIC ERROR!\n"; //hasn't gone off yet . . . } }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern