Ask Question

Write the proghrams for the following:

1. Given values for two Boolean variables a and b, the expression evaluates to True if just one of a or b is True, but not if both are True or both or False i. (Note: this is also called an "exclusive or" between a and b.)

2. Given values for three Boolean variables a, b, and c, the expression evaluates to True if an odd number (i. e. exactly 1 or 3) of the variables a, b, and c is True, and is False otherwise. a. Note: Use only Boolean expressions. Do not use if-elif-else blocks

+3
Answers (1)
  1. 11 March, 23:18
    0
    a)

    #include

    using namespace std;

    int main () {

    bool a, b, c;

    cin>>a>>b;

    if (a^b) / /X-OR operator in C++.

    c=true;

    else

    c=false;

    cout<
    return 0;

    }

    b)

    #include

    using namespace std;

    int main () {

    bool a, b, c, d;

    cin>>a>>b>>c;

    if ((a^b) ^c) / /X-OR operator in C++.

    d=true;

    else

    d=false;

    cout<
    return 0;

    }

    Explanation:

    The above written programs are in C++. There is an operator (^) called X-OR operator in C++. It returns true if the number of 1's are odd and returns false if the number of 1's are even.

    In the if statement I have user X-OR operator (^) to find the result and storing the result in another boolean variable in both the questions.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write the proghrams for the following: 1. Given values for two Boolean variables a and b, the expression evaluates to True if just one of a ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers