In addition to the arithmetic operators, C++ provides a variety of
other operators including six relational operators. A relational
operator allows two values to be compared, and it produces a boolean
value indicating their relationship. A boolean value is either
false indicating if the claim or relationship
is true or false.
||equality, returns true if and only if its operands are equal|
||inequality, returns true if and only if its operands are different|
||less-than, returns true if and only if its left operand is less-than its right operand|
||greater-than, returns true if and only if its left operand is greater-than its right operand|
||less-than-or-equal-to, returns true if and only if its left operand is not greater than its right operand|
||greater-than-or-equal-to, returns true if and only if its left operand is not less than its right operand|
In C++, a boolean value is represented by the
bool type, so
these operators produce a
bool value. They are called the
relational operators because they are used to identify the
relationship between two values.
Add a line to your program that prints out these boolean values:
cout << "true is " << true << "\n" << "false is " << false << endl;Compile and execute your program.
Question #3.4.1: What does your program display for this output statement?
Depending on your compiler, you may actually get the boolean values
false to print out as words on the screen.
More likely, you will get integer values, probably
false. In C++,
taken to be false, and strictly speaking, any non-zero value is
true (although most compilers like to use the value
reading and reporting the results of this experiment, translate any
Modify your program so that it
jfrom the keyboard.
jusing each of the relational operators listed above.
Compile and execute your program.
Question #3.4.2: Find values for
jin each row to make the indicated relationship true:
i < j
i <= j
i == j
i != j
i >= j
i > j
Use your program to find and confirm your values.