XOR truth table

This is a discussion on XOR truth table within the C++ Programming forums, part of the General Programming Boards category; I created an XOR true table using some of my old C language knowledge, I showed my tutor and he ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475

    XOR truth table

    I created an XOR true table using some of my old C language knowledge,

    I showed my tutor and he said that creating such a table is considered redundent, but others argue it can be used to inplement C++'s flexability.

    Here is the coce... What do you guys think about my tutors comment and the argument in general?

    Personally, I think it is rather helpful.

    Code:
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    // main function
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	bool p, q;
    
    	p = true;
    	q = true;
    
    	cout << p << " XOR " << q << " is " <<
    		 ( ( p || q ) && !( p && q ) ) << "\n";
    
    	p = false;
    	q = true;
    
    	cout << p << " XOR " << q << " is " <<
    		 ( ( p || q ) && !( p && q ) ) << "\n";
    
    	p = true;
    	q = false;
    
    	cout << p << " XOR " << q << " is " <<
    		 ( ( p || q ) && !( p && q ) ) << "\n";
    
    	p = false;
    	q = false;
    
    	cout << p << " XOR " << q << " is " <<
    		 ( ( p || q ) && !( p && q ) ) << "\n";
    
    	getchar();	// freeze output
    
    	return 0;	// indicatres sucsessful termination
    }

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Since C/C++ has the ^ operator, doing it your way can be considered redundant.
    Kurt

  3. #3
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    but then students more often than not get assignments that amount to implementing something that's available in the standard library (like lists, stacks, queues, etc.)

    But get rid of those compiler specific things in there. Anything starting with an underscore is suspect by definition

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >What do you guys think about my tutors comment and the argument in general?
    I like the code because it demonstrates how you'd implement xor if your language didn't have such an operator.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    If the input type were int rather than bool, it also shows how you could do a logical xor rather than a bitwise xor. Of course, it can be more simply written as p != q.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  2. progarm doesnt compile
    By kashifk in forum Linux Programming
    Replies: 2
    Last Post: 10-25-2003, 05:54 PM
  3. extra word printing
    By kashifk in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2003, 04:03 PM
  4. inputting words from a file
    By kashifk in forum C++ Programming
    Replies: 5
    Last Post: 10-24-2003, 07:18 AM
  5. help with operator <
    By kashifk in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2003, 03:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21