Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

March 28, 2017 Name: 6. The can be automatically used e of a truth table is part

ID: 3806666 • Letter: M

Question

March 28, 2017 Name: 6. The can be automatically used e of a truth table is part of the language or function is somethir in because it for theOR function. The For instance, A rue and B False then OR B is True OR A function above was shown for an example of how a truth table works. A logical xOR (Exclusive OR) operation is defined by the following truth table. write the types in the for a function to compare two Boolean values. Include the appropriate variable declaration line (25 points) Input output A XOR B For instance, True and B False then A xOR B is True (Next Page is setup for the code)

Explanation / Answer

The XOR (eXclusive OR) operator returns a True value if and only if the values of both its (Boolean) operands are different. In this example of implementing an XOR function, the said function takes two parameters, both of type Boolean (which means that they can take one of only two values:- True and False) The XOR function also returns a Boolean value (True/False)

This function returns a True if and only if one of the parameters is True and the other is False. In case both the parameters have the same value, either True or False, the function returns a False.

The pseudocode shown below, takes two Boolean parameters A and B and itself returns a Boolean value based on the values of both these parameters.

First we check the value of A and then we check whether or not B has the same value. If both A and B have the same value, the function returns a False but if A and B have different values, the XOR function returns a True.

The Pseudocode:-

Function XOR(A as Boolean, B as Boolean) as Boolean

If A = True Then   'if A is True
   If B=True Then   'if A and B are both True, then A XOR B is False, so return False
       return False
   Else           'if A is True but B is False then A XOR B becomes True, so return True
       return True
   Endif
Else               'if A is False
   If B = False Then   'if A and B are both False then A XOR B is False, so return False
       return False
   Else               'If A is False and B is True then A XOR B becomes True, so return True
       return True
   Endif
Endif
End Function

In summary the XOR function takes two Boolean values, A and B as input and returns a Boolean value, True if and only if the values of A and B are different. But if the value of A and B is the same (either True or False, doesn't matter as long as they are both the same), it returns a Boolean value, False.