Back

Activity 1.27: Quarter 1 Review

divider

Activity 1.27

Quarter 1 Review

Key Concepts

Three Things Build Every Program

Two Bugs Stop the Program

Most Bugs Make No Noise

Where the Two Notations Disagree

Three Things Build Every Program

Twenty-six activities ago you printed one line. Since then you have written games, quizzes, and an invasion. Predict: every one of those programs was built from the same three things. What are they?

Three Things Build Every Program

Sequencing
Statements run one after another, top to bottom (Activity 1.4 on).
Selection
The program chooses a path with if and else (Activities 1.12 to 1.16).
Iteration
The program repeats with while and for (Activities 1.17 to 1.21).

Every algorithm on the AP exam is built from those three, and you have all of them. Arrays gave the loops something to walk; they are data, not a fourth building block. Quarter 2 adds ways to organize the three, not new ones.

Two Bugs Stop the Program

Some mistakes C# will not run past. The program stops with an exception, and the message names the line. Predict: which two have you met?

Two Bugs Stop the Program

  • int.Parse given text that is not a number stops with a FormatException (Activity 1.9).
  • An index below 0 or at .Length or above stops with an IndexOutOfRangeException (Activity 1.24).

These are the easy ones. A crash is loud, it happens every time, and it points at the line. The exam agrees on the second: an index outside the list ends the program there too.

Most Bugs Make No Noise

Here are seven bugs from this quarter. Predict: how many of them stop the program with an error?

Most Bugs Make No Noise

  • 47 / 6 is 7, not 7.83 (Activity 1.6)
  • A branch that never runs, because an earlier one catches its cases (1.13)
  • A loop that never ends, because nothing inside changes its test (1.17)
  • A maximum started above the data, so it never changes (1.20)
  • Two names for one array, so changing one changes the other (1.23)
  • A results loop starting at i = 1, skipping the first element (1.25)
  • A hit check without !hit[i], stopping shots on a ghost (1.26)

None of them. Every one runs to the end and prints a wrong answer, or never ends at all. That is the real lesson of the quarter: a program that runs is not a program that works.

A Silent Bug Is Caught by a Prediction

No error message will ever point at those seven. The only thing that catches them is knowing what the answer should be before you run the program, and noticing when it is not.

That is why the Break It on Purpose tasks kept asking for a prediction first. It is also how you will read code on the exam, where there is no computer to run it on.

Where the Two Notations Disagree

You have been learning two languages at once: C#, which you run, and the exam's notation, which you read. Predict: name one piece of code that gives a different answer in each.

Where the Two Notations Disagree

C#Exam
Dividing 17 by 533.4
A random 1 to 5Next(1, 6)RANDOM(1, 5)
The first elementa[0]aList[1]
One list into anotherOne array, two namesA copy
Showing a valueWriteLine ends the lineDISPLAY adds a space
A chain of choiceselse ifAn IF nested in the ELSE
A condition loopwhile runs while trueREPEAT UNTIL runs until true

Each row is worth points on the exam, every year. The checkpoint pairs several of them on purpose.

Today: Six Traces, Then the Checkpoint

Six short programs to work out on paper, then the Quarter 1 checkpoint.

Traces 3 and 4 are a pair, and so are 5 and 6. The same program in each notation, with a different answer. Get them wrong now rather than in the checkpoint, and definitely rather than in May.

Today's Objectives

  • Tracing programs in C# and in exam notation
  • Naming the three building blocks of every program
  • Telling a bug that crashes from a bug that is silent
  • Saying where the two notations give different answers

Key Terms

Sequencing
Statements running one after another, in order.
Selection
Choosing which statements run, based on a condition.
Iteration
Repeating statements, a set number of times or until a condition changes.

'F' → Fullscreen

divider

Warm-Up: Six Traces

Work each one out on paper. Do not run them. Write your answer on your sheet before you move to the next.

Three are C# and three are exam notation. Traces 3 and 4 are the same program in each notation, and so are 5 and 6 — and in each pair the answers are different.


Trace 1 — C#

Trace 1
int a = 3;
int b = 4;
int c = a + b * 2;
Console.WriteLine(c);

Trace 2 — C#

Trace 2
int total = 0;
for (int i = 1; i <= 4; i++)
{
if (i % 2 == 0)
{
total = total + i;
}
}
Console.WriteLine(total);

Trace 3 — C#

Trace 3
int boxes = 17;
int perCrate = 5;
Console.WriteLine(boxes / perCrate);

Trace 4 — Exam Notation

Trace 3, in exam notation.

Trace 4
boxes ← 17
perCrate ← 5
DISPLAY(boxes / perCrate)

Trace 5 — C#

Trace 5
int[] a = { 1, 2, 3 };
int[] b = a;
b[0] = 99;
Console.WriteLine(a[0]);

Trace 6 — Exam Notation

Trace 5, in exam notation. If you get the same value for both, reread Activity 1.23.

Trace 6
list ← [1, 2, 3]
copy ← list
copy[1] ← 99
DISPLAY(list[1])
divider

Before the Checkpoint

You should be able to do every one of these without looking anything up. If one is shaky, that is where to spend your review — and Question Set 8's unsure marks are a good place to start.

Data

  • Declare a variable with its type, and change it later
  • Tell an int, a double, a string, and a bool apart
  • Turn typed input into a number with int.Parse or double.Parse, and say what happens when the text is not a number
  • Predict what dividing two ints gives, and avoid it when you need the decimal
  • Show a number to two decimal places with :F2

Decisions

  • Write if, else if, and else
  • Order a chain so no branch is unreachable
  • Combine conditions with &&, ||, and !
  • Say which numbers Random.Shared.Next(a, b) can give

Repetition

  • Write a while loop and a for loop
  • Name the setup, the test, and the change in either one
  • Explain what makes a loop infinite
  • Use a counter, an accumulator, and a running maximum
  • Predict how many times a nested loop's inside runs

Arrays

  • Create an array, and read or change one element
  • Reach the last element with .Length - 1
  • Walk an array with the standard for loop, and say why its test is <
  • Check that an index is valid before using it
  • Explain why two names can share one array

Exam Notation

  • Read ← as assignment and = as equals
  • Rewrite an else if chain as nested IF and ELSE
  • Turn a while condition into a REPEAT UNTIL one
  • Keep your own counter inside REPEAT n TIMES, and walk a list with FOR EACH
  • Index a list from 1, and know that ← copies it
  • Know that / does not cut off decimals, RANDOM includes both ends, and DISPLAY adds a space
divider

The Checkpoint

The Quarter 1 checkpoint is 40 minutes, on paper, in exam format: sixteen multiple-choice questions, then one written question about a broken program.

  • Everything from Activity 1.1 through 1.26 is fair game
  • C# and exam notation are mixed together, with no warning about which is which — the way the exam does it
  • Two questions ask you to select all that apply
  • No computer. Work on paper, as you did with the traces

Pace yourself. The multiple choice is about 28 minutes, which is exam pace, and the written question gets the rest. If a question is taking too long, mark it, move on, and come back. Leaving one blank to answer three others is the right trade, and it is a skill worth practicing now.

divider

Reflection

Answer these after the checkpoint, honestly. They are not graded on being flattering.

  1. Which of the seven silent bugs from the slides have you written yourself this quarter? Describe the one that took you longest to find, and how you found it.
  2. Explain why a bug that stops the program is easier to fix than one that runs and prints a wrong answer. Use one example of each from this quarter.
  3. Which difference between C# and exam notation still catches you most, and what will you do about it before the exam in May?
divider

Submit

Submit two things to the dropbox:

  1. Your answers to the six traces.
  2. Your three reflection answers.

Quarter 1 Complete