In: Computer Science
(1) What are the advantages and disadvantages to using the int data type rather than the bool data type to manipulate Boolean expressions? Why do students think the int data type is still used for Boolean expressions?
(2) Discuss how C++ provides two-way selection through the if…else statement. Explain the syntax of this statement. Also, explain how the bool data type is used in C++ to manipulate Boolean expressions.
Answer 1
The data type int is used over boolean
1) It results
boolean true for a non-zero integer value.
2) It results boolean
false for a zero integer value.
Advantages
1) The counting can be
operated along with boolean execution
For example -
int count = 10;
if (count)
cout << count;
else
cout << "zero";
Gives the number as a result, and when it is zero it prints zero.
2) Arithmetic operation too can be performed over int.
Answer 2
A two-way selection is -
if (true)
then
//
do something
else
//
do something else
Here, two choices are available to the user,
whether it will be true or false.
For every choice, there is a selection