Four problems in AP exam notation, covering AND, OR, NOT, and RANDOM — Activities 1.15 and 1.16.
Work these on paper. There is no computer on exam day. Three are traces and one is a translation.
Everything from the exam reference sheet that we have covered so far. Nothing else appears in these problems.
a ← expressionDISPLAY(expression)NOT aa AND ba OR bRANDOM(a, b)a = b a ≠ ba > b a < ba ≥ b a ≤ bIF(condition){ ...}ELSE{ ...}Three rules that catch people:
RANDOM(a, b) includes both ends. RANDOM(1, 6) can give a 1 and it can give a 6 — which is not how Random.Shared.Next counts, and Problem 4 is about exactly that.The same decision, written both ways.
int day = 6;bool onDuty = false;
if (day >= 6 && !onDuty){ Console.WriteLine("Rest");}day ← 6onDuty ← false
IF(day ≥ 6 AND NOT onDuty){ DISPLAY("Rest")}&& becomes AND, ! becomes NOT, and the ! that was jammed against its variable becomes a word with a space after it. That is why the exam notation is easier to read aloud — and why a ! is so easy to miss going the other way.
What does this display?
age ← 16hasPass ← false
IF(age ≥ 18 OR hasPass){ DISPLAY("Enter")}ELSE{ DISPLAY("Denied")}What does this display, and in what order?
x ← 12y ← 5
IF(NOT (x < y)){ DISPLAY("first")}IF(x > 10 AND y > 10){ DISPLAY("second")}IF(x > 10 OR y > 10){ DISPLAY("third")}Careful: these are three separate IF statements, not a chain. More than one of them can run. Activity 1.13 made this distinction and it is still the most common way to lose a point here.
This program is run many times. List every value it could possibly display.
n ← RANDOM(1, 4)DISPLAY(n * 2)There are four of them, and getting three means you dropped an end off the range.
Rewrite this C# in exam notation. One of the numbers has to change, and it is the whole point of the problem.
int roll = Random.Shared.Next(1, 7);
if (roll == 6){ Console.WriteLine("Six!");}else{ Console.WriteLine("Not six.");}Both versions must roll the same six faces. Write one sentence saying which number you changed and why.
This is graded on completion, not accuracy.