152k views
3 votes
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

User Thinkdeep
by
5.1k points

1 Answer

3 votes

Answer:

a)

#include <iostream>

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<<c;

return 0;

}

b)

#include <iostream>

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<<d;

return 0;

}

Step-by-step 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.

User Delu
by
4.3k points