1. The outcome of each logical operator given two inputs can be organized into a truth table. A truth table shows the conditions when the logical operator returns true (1) or false (0). The following truth table for the AND operator (&&) is given. Complete the table for the other operators.

    Input A Input B A && B A || B A ^ B !A

    0

    0

    0

    0

    0

    1

    0

    1

    0

    1

    1

    1

    1

    0

    0

    1

    1

    0

    1

    1

    1

    1

    0

    0

  2. Complete the following truth table.

    A B C A && B || C A && (B || C) !(A && B) !(A && B) ^ C (A && (B || C)) ^ !(A && B)

    0

    0

    0

    0

    0

    1

    1

    1

    0

    0

    1

    1

    0

    1

    0

    1

    0

    1

    0

    0

    0

    1

    1

    1

    0

    1

    1

    1

    0

    1

    0

    1

    1

    0

    0

    0

    0

    1

    1

    1

    1

    0

    1

    1

    1

    1

    0

    0

    1

    1

    0

    1

    1

    0

    0

    1

    1

    1

    1

    1

    1

    0

    1

    1

  3. Determine whether the following conditions return true or false:

    1. 1==2 true !false

    2. 6>6 true !false

    3. !true true !false

    4. +1+2==5||7⇐7+ !true false

    5. 0 true !false

    6. !false && true !true false

    7. 7%4%2==7/5 !true false

    8. 1 !true false

    9. +(1==24==3)(1<2^4<3)+ !true false

    10. !(6!=5) || !(5>8) && 7+8 >= 6+9 !true false

  4. Determine an If condition that can be used to solve the following scenarios.

    1. Sickle cell anemia is a genetic blood condition in which a person has a shortage of healthy red blood cells. All humans acquire either a normal hemoglobin gene or a hemoglobin S gene from each of their parents. A person suffering from sickle cell anemia obtained a hemoglobin S gene from both of his or her parents. Jimbob wants you to write an if condition that will help him determine if he has sickle cell anemia.

      1. Let F be a boolean variable that stores if the gene inherited by his father is the hemoglobin S gene.

      2. Let M be a boolean variable that stores if the gene inherited by his mother is the hemoglobin S gene.

    2. Naqvi and Wesley are playing Settlers of Catan. In order to determine the turn order, both of them roll two dice, and the values of the two dice are added. The player who rolls the higher sum goes first. If the two sums are the same, whoever rolled the highest number goes first. If both of them rolled the same values, Naqvi goes first. Write an if condition that will help them determine who goes first in Settlers of Catan.

      1. Let N1 and N2 be the values of the two dice that Naqvi rolled

      2. Let W1 and W2 be the values of the two dice Wesley rolled.

    3. Valerie asks her friend Terry if she can get a ride to Pacific Mall. Terry will only give Valerie a ride if he has room in his car. His unusual car can only fit two other people and he already promised to drive Chris, Hans, and Victor, assuming they need to go. Also, Terry, hating grade 11’s for some unexplained reason, will prioritize Chris, Hans, and Victor before giving Valerie a ride. Write an if condition that determines if Valerie will get a ride.

      1. Let B be a boolean variable that stores if Chris needs a ride.

      2. Let H be a boolean variable that stores if Hans needs a ride.

      3. Let V be a boolean variable that stores if Victor needs a ride.

  5. Write a program that compares three integers, a, b, and c. Have the program output the number that is neither the smallest nor the largest of the three. Assume all three inputs have different values.

    Input: a b c

    Output: The median of the three inputs

    Table 1. Sample Runs
    Input Output

    1 3 7

    3

    8 -9 10

    8

    -56 -58 -57

    -57

  6. Write a program that determines if a year is a leap year. Any year divisible by 4 is a leap year. However, if the year is also divisible by 100 and not divisible by 400, the year is not a leap year. Output "Y" if the input is a leap year; otherwise, output "N".

    Table 2. Sample Runs
    Input 2016 2005 2000 1900 576 1 500

    Output

    Y

    N

    Y

    N

    Y

    N

    N

  7. Write a program that accepts three integer side lengths of a triangle, a, b, and c. a,b,c > 0.

    • First and foremost, if the side lengths form a right angle triangle, output "Right Angle".

    • If the side lengths form an equilateral triangle, output "Equilateral".

    • If the side lengths form an isosceles triangle, output "Isosceles".

    • If the side lengths form a scalene triangle that is not a right angle triangle, output "Scalene".

    • If the side lengths cannot make a triangle, output "Triangle Not Possible".

    Table 3. Sample Runs
    Input Output

    7 7 7

    Equilateral

    6 5 6

    Isosceles

    4 5 6

    Scalene

    5 13 12

    Right Angle

    1 2 3

    Triangle Not Possible

    16 8 7

    Triangle Not Possible

  8. Mr. Chow is back and his code looks atrocious. Sure, his code works, but it is very hard to read and is filled with redundant comparisons. Your job is to change Mr. Chow’s if conditions so that it makes more sense.

<span id="L1" class="line"><span class="cp">#include &lt;iostream&gt;</span></span>
<span id="L2" class="line"><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span></span>
<span id="L3" class="line"><span class="c1">// This program takes a student's marks and outputs a letter grade</span></span>
<span id="L4" class="line"><span class="c1">// The input will ALWAYS be an integer between 0 and 100 inclusive</span></span>
<span id="L5" class="line"><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span></span>
<span id="L6" class="line">    <span class="kt">int</span> <span class="n">mark</span><span class="p">;</span></span>
<span id="L7" class="line">    <span class="n">cin</span> <span class="o">&gt;&gt;</span> <span class="n">mark</span><span class="p">;</span></span>
<span id="L8" class="line">    <span class="k">if</span> <span class="p">(</span><span class="n">mark</span> <span class="o">&gt;=</span> <span class="mi">80</span><span class="p">)</span> <span class="p">{</span></span>
<span id="L9" class="line">        <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">"You get an A!"</span><span class="p">;</span></span>
<span id="L10" class="line">    <span class="p">}</span></span>
<span id="L11" class="line">    <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="n">mark</span> <span class="o">&gt;=</span> <span class="mi">60</span> <span class="o">&amp;&amp;</span> <span class="n">mark</span> <span class="o">&lt;</span> <span class="mi">70</span><span class="p">){</span></span>
<span id="L12" class="line">        <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">"You get a C!"</span><span class="p">;</span></span>
<span id="L13" class="line">    <span class="p">}</span></span>
<span id="L14" class="line">    <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="n">mark</span> <span class="o">&gt;=</span> <span class="mi">70</span> <span class="o">&amp;&amp;</span> <span class="n">mark</span> <span class="o">&lt;</span> <span class="mi">80</span><span class="p">){</span></span>
<span id="L15" class="line">        <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">"You get a B!"</span><span class="p">;</span></span>
<span id="L16" class="line">    <span class="p">}</span></span>
<span id="L17" class="line">    <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="n">mark</span> <span class="o">&gt;=</span> <span class="mi">50</span> <span class="o">&amp;&amp;</span> <span class="n">mark</span> <span class="o">&lt;</span> <span class="mi">60</span><span class="p">){</span></span>
<span id="L18" class="line">        <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">"You get a D!"</span><span class="p">;</span></span>
<span id="L19" class="line">    <span class="p">}</span></span>
<span id="L20" class="line">    <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="n">mark</span> <span class="o">&lt;</span> <span class="mi">50</span><span class="p">){</span></span>
<span id="L21" class="line">        <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">"You get to TRY AGAIN! :D"</span><span class="p">;</span></span>
<span id="L22" class="line">    <span class="p">}</span></span>
<span id="L23" class="line"><span class="p">}</span></span>