Lab 1: Dealing with Complexity

from Lab 1, Page 3
AAP-3.B.5
Imagine you are using a procedure calculate_area(length, width) to find the area of rectangles. Which action demonstrates the benefit of using parameters in this procedure?
You can use the same procedure with different length and width values to calculate the area of various rectangles.
The parameters length and width can now be used as variable names everywhere in your program.
You can allow the user to change the name of the variables length and width.
You can use the same length and width values for every rectangle in the program.
from Lab 1, Page 4
AAP-3.B.1
Imagine you are developing a program that calculates the total cost of a shopping cart after applying a discount and taxes. Your team has created a function below that performs one step of this task. Which of the following demonstrates procedural abstraction in this scenario?
PROCEDURE calculate_tax(cart, tax_rate)
Using the
calculate_tax
function without knowing the specific math operations inside it.
Reading through the function code to determine how it works so you can write your own version.
Declaring
cart
and
tax_rate
variables outside of the function and using those variables when calling the function.
This is not a good example of procedural abstraction. Your team should not be writing a procedure to perform just one step of the task.
from Lab 1, Page 4
AAP-1.A.2
You are reviewing the following two snippets of code written by a classmate:
Code 1:
x ← 5
y ← 3
z ← x * y  
DISPLAY(z)
Code 2:
length ← 5  
width ← 3  
area ← length * width  
DISPLAY(area) 
Which statement best explains why Code 2 is preferable?
It runs faster than Code 1.
It uses meaningful variable names, making it easier to understand.
It uses more variables, making the program more generalizable.
There is nothing to make Code 2 preferable to Code 1.

Lab 2: Contact List

from Lab 2, Page 1
AAP-1.D.3.C
Why are abstract data types (ADTs) used in programming? Choose all that apply.
To make the code run faster.
To hide complexity and provide a custom interface for managing data.
To eliminate the need for conditional statements.
To eliminate the need for debugging.
from Lab 2, Page 2
CRD-2.C.3.A, CRD-2.D.3.A
This question is about identifying inputs and outputs.
Imagine you are working on a program for a smart home thermostat. The thermostat uses a temperature sensor to monitor the current room temperature and sends a message to a heating system to adjust the temperature. Below is a flow diagram of the logic of the program code that controls the thermostat.
start -> read current_temp -> read desired_temp -> current_temp < desired_temp? {true -> report turn heating system ON} {false -> report turn heating system OFF} Based on the thermostat program described in the flowchart, determine whether the following statements are true or false.
  1. The current room temperature is an input to the program.
  2. The desired temperature set by the user is an output from the program.
  3. A message sent to the heating system to turn ON or turn OFF is an output of the program.
  4. The room temperature increasing or decreasing is an output of the program.
True, True, True, False
True, False, True, False
True, False, False, True
False, False, True, False
from Lab 2, Page 5
Which of the following statements are true about this list?
set (words and numbers) to {rabbit, 5, benefit, is, 34, kite, 2, 305, the, 61}
map (letter (1) of ()) over (words and numbers) reports the list {r, 5, b, i, 3, k, 2, 3, t, 6}.
map (item (1) of ()) over (words and numbers) reports the list {rabbit}.
Both of the above.
None of the above.
from Lab 2, Page 5
Which of the following statements are true about this list?
set (capitals) to {{Augusta, Maine}, {Boise, Idaho}, {Columbia, South Carolina}, {Des Moines, Iowa}}
Choose all that apply.
Why not use an ADT?

The list inside a list shown above makes it clearest to you now as you answer this self-check item what the structure is, but you're right, in an actual program it would be better to use an abstract data type:
state: (Augusta) capital: (Maine)

map (item (1) of ()) over (capitals) reports the list {Augusta, Boise, Columbia, Des Moines}.
map (item (1) of ()) over (capitals) reports the list {Augusta, Maine}.
map (letter (1) of ()) over (capitals) reports the list {A, B, C, D}.
map (all but first of ()) over (capitals) reports the list {Maine, Idaho, South Carolina, Iowa}.
map (all but first of ()) over (capitals) reports the list {{Boise, Idaho}, {Columbia, South Carolina}, {Des Moines, Iowa}}.
from Lab 2, Page 5

Consider this list of squares:
set (squares) to {1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225}
Which of the following expressions will report a list? Choose all that apply.

map (sqrt of()) over (squares)
keep items (()mod(2)=0) from (squares)
combine (squares) using (()+())
keep items (letter (length of ()) of () = 1) from (squares)
combine (squares) using (join ()()) items of
map ((0)-()) over (squares)