Three problems on lists in AP exam notation — Activities 1.23 and 1.24. This is where the two notations disagree most, and both disagreements are on this page: the exam counts from 1, and ← makes a copy where C# shares one array between two names.
Work these on paper. There is no computer on exam day. One is a translation and two are traces.
The reference sheet's list operations. Nothing else appears in these problems.
aList ← [value1, value2, value3]aList[i]LENGTH(aList)aList ← bListAPPEND(aList, value)INSERT(aList, i, value)REMOVE(aList, i)DISPLAY(expression)Four rules that catch people:
aList[1]. The last is aList[LENGTH(aList)], with no minus one.aList ← bList makes a copy. Changing one afterward does not change the other — the opposite of C#.INSERT and REMOVE shift everything after them. Write the whole list out again after every line.The last element, written both ways.
string[] crew = { "Ada", "Bo", "Cy" };
Console.WriteLine(crew[crew.Length - 1]);crew ← ["Ada", "Bo", "Cy"]
DISPLAY(crew[LENGTH(crew)])Both display Cy, and the minus one is the whole difference. C# counts 0, 1, 2, so the last of three is at 2. The exam counts 1, 2, 3, so the last of three is at 3 — which is its length.
Rewrite this C# in exam notation. Two things need to change, and neither is the array's contents.
string[] names = { "Avery", "Blake", "Casey" };
Console.WriteLine(names[0]);Console.WriteLine(names.Length);Your version must display the same two things: Avery, then 3.
Write out the whole list after each line, then give what the program displays.
aList ← [10, 20, 30]APPEND(aList, 40)INSERT(aList, 2, 15)REMOVE(aList, 1)DISPLAY(LENGTH(aList))DISPLAY(aList[1])DISPLAY puts a space after each value, so both values end up on one line.
What does this display?
first ← [1, 2, 3]second ← firstsecond[1] ← 99
DISPLAY(first[1])DISPLAY(second[1])Then answer this: here is the same program in C#. It displays something different. Say what, and why.
int[] first = { 1, 2, 3 };int[] second = first;second[0] = 99;
Console.WriteLine(first[0]);Console.WriteLine(second[0]);This is graded on completion, not accuracy.