'F' → Fullscreen
Everything you have met, on one card. You get this sheet on exam day and it is collected afterward. Read it before the traces.
a ← expression assign a COPY of the resultaList ← bList assigns a COPY of the listDISPLAY(expression) show it, FOLLOWED BY A SPACE= ≠ > < ≥ ≤ comparison. = means EQUALS
aList[1] THE FIRST ELEMENTLENGTH(aList) how manyINSERT(aList, i, value) shift right, place at iAPPEND(aList, value) place at the endREMOVE(aList, i) remove and shift left
a MOD b remaindera / b TRUE division. 17 / 5 is 3.4 there is no rounding operator
REPEAT n TIMES { } no loop counter is providedREPEAT UNTIL(cond) { } repeats UNTIL it becomes trueFOR EACH item IN aList { }
IF(cond) { } ELSE { } the only two selection forms
PROCEDURE name(p1, p2){ RETURN(expression) hands back AND exits immediately}result ← name(a, b)Three things on that card cost more marks than the rest put together:
DISPLAY prints a space after every value, so two calls in a row give space-separated output on one line. Console.WriteLine starts a new line instead.aList ← bList makes a copy. In C#, int[] aList = bList; does not: both names point at the same array, and the same program gives different answers in the two notations.On paper. Do not run anything. Four are C# and two are exam notation, and they are not in the order you might expect. Check which one you are in before you answer.
What does this print?
int size = 10;
Console.WriteLine(Grow(size));Console.WriteLine(size);
int Grow(int size){ size = size * 2; return size;}Three numbers. Make a table of low, high, mid and checks for the first call before you answer.
int[] ids = { 3, 8, 15, 22, 30, 41, 56 };
Console.WriteLine(Find(22));Console.WriteLine(Find(3));Console.WriteLine(Find(7));
int Find(int target){ int low = 0; int high = ids.Length - 1; int checks = 0;
while (low <= high) { int mid = (low + high) / 2; checks = checks + 1;
if (ids[mid] == target) { return checks; }
if (ids[mid] < target) { low = mid + 1; } else { high = mid - 1; } }
return -1;}Then answer: one of these is found in a single check. Say why that value, without the word “luck.”
What does this display? Every character, including spaces.
PROCEDURE label(n){ IF(n MOD 2 = 0) { RETURN("even") } RETURN("odd")}
aList ← [4, 7, 10]
FOR EACH item IN aList{ DISPLAY(label(item))}Then answer: there is no ELSE, and the procedure still always returns exactly one value. Explain why.
What does this print?
int steps = 0;int n = 6;
for (int i = 0; i < n; i++){ for (int j = i + 1; j < n; j++) { steps = steps + 1; }}
Console.WriteLine(steps);Then answer: you met this number this quarter, attached to an algorithm on a list of the same length. Which one, and why is that not a coincidence?
What does this display?
bList ← [2, 4, 6]aList ← bList
aList[2] ← 99
FOR EACH item IN aList{ DISPLAY(item)}FOR EACH item IN bList{ DISPLAY(item)}Then answer: write the same thing in C# with int[] aList = bList; and aList[1] = 99;, and work out what it prints. The answers differ. Say which one the exam expects.
Two bytes stored back to back in one array, one bit per position. What does this print?
int[] bits = { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0 };
Console.WriteLine(ToDecimal(0));Console.WriteLine(ToDecimal(8));
int ToDecimal(int start){ int total = 0; int place = 1;
for (int i = start + 7; i >= start; i--) { if (bits[i] == 1) { total = total + place; }
place = place * 2; }
return total;}Then answer: the second number is a power of 2. Say how you can tell from the bits alone, without adding anything up.
Go down this list and mark anything you cannot do without looking it up. Whatever you mark is your revision, and nothing else is worth spending time on.
while loop into REPEAT UNTILDISPLAY calls in a row, spaces includedaList ← bList does, and what C#'s int[] aList = bList; does insteadSame session, straight after this. 30 minutes, on paper, closed notes.
Then the gallery walk. Everybody runs their Build 2 program. Bring it working, or bring it broken and be able to say what broke.
Answer the following questions before submitting your work.
Your six trace answers with the follow-up questions, your marked checklist, and your three reflection answers.