Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This lab introduces logical comparisons and Boolean operators. These operators are used to create the conditions that govern whether a loop will be repeated, whether
This lab introduces logical comparisons and Boolean operators. These operators are used to create the conditions that govern whether a loop will be repeated, whether the code within an if statement will be executed, and which branch of an ifelse statement will be executed.
Comparison operators compare two values and evaluate to false actually the value if the comparison is false, and evaluate to true the value if the comparison is true. For example, the expression has the value whereas the expression has the value
The common comparison operators are:
less than Example: A B is true if A is less than B and is false otherwise
greater than Example: A B is true if A is greater than B and is false otherwise
less than or equal to Example: A B is true if A is less than or equal to B and is false otherwise
greater than or equal to Example: A B is true if A is equal to or greater than B and is false otherwise
equalnote the double equal signs Example: A B is true if A is equal to B and is false otherwise
not equal Example: A B is true if A is not equal to B and is false otherwise
Boolean operators named after the mathematician and logician George Boole make it possible to create more complex logical tests. If you want to determine if two things, A and B are true, or if either of two things, A or B are true, then you need to use Boolean operators. For example, the expression:
x y && x z
is true if the value held by variable x is less than the value held by variable y and the symbol && means and the value held by variable x is less than the value held by variable z
The common Boolean operators are:
OR example: A B is true if A is true or B is true or both are true and is false otherwise. The vertical line is usually above the key on the keyboard.
&& AND example: A && B is true only if A is true and B is true, otherwise it is false.
NOT example: A is true if A is false and is false otherwise
This lab consists of three parts.
Part I: Hypothesize whether each of the Boolean statements and mathematical expressions given below is true or false. Write your hypotheses in a file named hypotheses.txt that can be uploaded to Canvas. You will not be graded on whether you get these right or wrong, but you do need to turn them in
Consider which expressions were the most difficult to understand. Create more of your own expressions to try to clarify how Boolean and Mathematical expressions are evaluated in CC Add these expressions along with your hypotheses about their values to the list given below for a total of expressions
Part II: Write a program to determine whether the Boolean statements and mathematical expressions given below, plus the three that you created, are true or false. This program will be used to test your hypotheses. Remember that Cand C use a for false and for true. Therefore, to determine the validity of a Boolean statement you only need to embed it in a cout statement. For example, the command:
cout endl;
will print if the statement is false and if the statement is true.
To determine if a mathematical expression is treated as true or false an ifelse statement can be used. For example, to determine whether the expression: is treated as true or false you can use the code:
if
cout "It's true
;
else
cout "It's false
;
Make sure you can turn in the results from your program as well as the program itself. Remember to use the script command to create an output file. The command script laboutput.txt will create a file called laboutput.txt that you can submit.
Part III: Use the results of your program to mark in your original file containing your hypotheses which hypotheses were correct and which ones were incorrect.
Boolean and Mathematical Expressions to Test:
&&
&&
&& This one is tricky.
Also tricky.
Still more trickiness.
Turn in: Your file of hypotheses in hypotheses.txt regarding the expressions, with the correct answers as determined by your program. The source code of the program or programs that you used to test your hypotheses and the output of the programs All of these items should be submitted to your instructor via Canvas.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started