25.3. Set #3¶
The following questions make up Set #3 of the Untimed Practice Exam Questions. The questions resemble, both in format and substance, what you might see on the AP CS Principles exam. You should finish these questions within 17 minutes to satisfy the time constraints of the AP exam. You may refer to the AP CS Reference Sheet, which can be found here.
You will not be able to change your answers after you hit the “Finish Exam” button.
A grocery store uses a database to store important statistics. The prices of all items are stored in a list called itemList, which is indexed from 1 to x. The company uses the following program to assign the index of the item in the store that has the highest price to the variable max.
i ← 0 max ← i + 1 x ← LENGTH(itemList) REPEAT x times { i ← i + 1 <MISSING CODE> }Which of the following code segments can replace <MISSING CODE> so that the program works as intended?
(A)
IF(itemList[i] > max) { max ← itemList[i] }(B)
IF(itemList[i] > itemList[max]) { max ← i }(C)
IF(itemList[i] < itemList[max]) { max ← i }(D)
IF(itemList[i] > itemList[max]) { max ← itemList[i] }- Incorrect. This does not compare two prices -- the variable 'max' is not a price, it is the index of the current max value.
- Correct. This updates the value of max with 'i' if it is greater than the previous maximum price.
- Incorrect. This will not update the value of max with the highest price value.
- Incorrect. This assigns the price value to the variable max rather than the index value of the list itemList.
What does iteration with computer science loops mean?
- Executing code once
- Incorrect. Iteration with a loop involves repetition, so executing code once is not iteration.
- Repeating a block of code until a condition is met
- Correct. Iteration repeats one or more statements until a condition is met.
- Duplicating a section of code multiple times in a program
- Incorrect. Iterating with loops is a way of preventing you from having to duplicate a section of code multiple times.
- Debugging code multiple times until it passes testing
- Incorrect. Debugging involves a person finding errors or "bugs" in their code. Iteration with loops runs a set of code until a condition is met.
Refer to the following code:
weight ← 0.5 IF weight < 1 { price ← 1.45 } IF weight >= 1 { price ← 1.15 } total ← weight * price DISPLAY(weight) DISPLAY(price)What will be printed?
- 0.5 1.45
- Correct. Since 'weight' < 1 is True, 'price' equals 1.45. Both 'weight' and 'price' are being displayed.
- 0.5 0.75
- Incorrect. Although 0.75 is the value of 'total,' it is never displayed.
- 0
- Incorrect. Neither the value of weight nor price -- the two variables being displayed -- are equal to 0.
- 1.45
- Incorrect. Although price is equal to 1.45, the value of weight is also being displayed by this code.
Refer to the following code:
numItems ← 1 IF numItems ← 1 { message ← "You ordered 1 item” } IF numItems > 1 { message ← "You ordered " + numItems + " items" } DISPLAY(message)What will print if numItems ← -2?
- “You ordered -2 items”
- Incorrect. There is no code to make "You ordered -2 items" the value of 'message.'
- “You ordered 1 item”
- Incorrect. This would be the value of 'message' if numItems equaled 1.
- Nothing will be printed.
- Incorrect. Variable 'message' was never assigned a value, so this would result in an error and the code would not run completely.
- You will get an error message.
- Correct. Variable 'message' was never assigned a value, so this would result in an error.
Refer to the following code:
numbers ← [-1,0,1] FOR EACH item IN numbers: IF item > 0: DISPLAY("positive") ELIF item < 0: DISPLAY(“negative”) ELSE: DISPLAY(“neither”)What will print when this code is run?
- negative neither positive
- Correct. The loop iterates through the three integers in 'numbers' and displays the proper strings when the IF statements are true.
- positive
- Incorrect. 'Positive' is displayed for the final item in the list, but there are two other items in the list.
- negative positive
- Incorrect. This does not account for the 0 in the list.
- Nothing will print
- Incorrect. The if and else clauses are satisfied in this code, so there would be an output.
What is the default direction a turtle object is facing?
- North
- Incorrect. Though it may seem like a turtle should start by facing north, it starts facing a different direction.
- South
- Incorrect. The default direction of a turtle is facing east.
- East
- Correct. The default direction of a turtle is facing east.
- West
- Incorrect. Think about in which direction you read and write.
What will print when the following code is run?
myLst ← [0,5,10,15,20,25] FOR EACH item IN myLst[:3] : { y ← x*2 myLst.APPEND(y) } DISPLAY(myLst[4:])- [0, 5, 10, 20, 25, 0, 10, 20, 30]
- Incorrect. Look again at which elements are modified in the FOR loop and which items in myLst are displayed in the last line of code.
- [20, 25, 0, 10, 20]
- Correct. The first three items in 'myLst' iterate through the loop, are multiplied by 2 and appended to the back of 'myLst.' Then the list is displayed from the fifth item until the end of the list.
- [25, 0, 10, 20]
- Incorrect. This would be correct if myLst[5:] were displayed.
- [0, 5, 10, 15]
- Incorrect. This would be correct if you wanted to display myLst[:4] instead of myLst[4:].
New data is available to add to a company’s existing data. The IT director wants to store the new data on the cloud. What is a concern that needs to be addressed before implementing the plan?
- The redundancy of the Internet increasing costs
- Incorrect. This is not a concern when moving data to the cloud.
- The cost the ISP will charge to access the cloud
- Incorrect. An internet service provider will not charge more to access a data cloud.
- The security of the data being transmitted back and forth
- Correct. One of the main concerns with implementing new data systems for large companies is security.
- Determining who has access to the data.
- Incorrect. This is not a main concern and would be up to the discretion of the IT director.
Which of the following will evaluate to true?
I. True AND FalseII. False or TrueIII. False AND (True or False)- I
- Incorrect. This evaluates to False - a statement cannot be True AND False.
- II
- Correct. The statement can be either True or False which evaluates to True.
- I and II
- Incorrect. I evaluates to False.
- II and III
- Incorrect. III evaluates to False because a statement cannot be False AND True.
A student purchases a single-user license of an online textbook and wants to share the textbook with their classmates. Under what conditions is it acceptable for the student to share this textbook?
- If the student shares only three chapters of the textbook with their classmates.
- Incorrect. A single-user license does not allow you to distribute the text, regardless of how many chapters you share.
- If the student gets permission from textbook’s editor
- Incorrect. The editor does not own the rights to the text.
- If the student gets permission from the textbook’s copyright owner
- Correct. The copyright owner owns the rights to the text.
- If the textbook is only shared with one other classmate
- Incorrect. Single-user license implies that the text cannot be shared.
Which of the following would be considered a subdomain of umich.edu according to the guidelines of the Domain Name System (DNS)?
- umich.edu/help
- Incorrect. This links to a different url in the same web address; it is not a subdomain of umich.edu.
- umich.edu.subdomain
- Incorrect. A subdomain does not come after umich.edu in the web address.
- students.umich.edu
- Correct. A subdomain modifies a domain and comes before the domain in the web address.
- umich.edu
- Incorrect. Nothing is modifying the domain umich.edu.
A weatherman record atmospheric data to predict future weather conditions. Suppose that his lab in Detroit takes hourly measurements of air temperature and precipitation in the city for a total period of 12 months. The lab also records the exact time and date for each measurement.
Which of the following questions about the Detroit’s weather could NOT be accurately answered using only the data collected by the lab?
- How does temperature fluctuate in Detroit from day to night?
- Incorrect. This data could be recorded since air temperature and time are both measured.
- What is the average annual precipitation?
- Correct. Data for only one year is recorded, so there is no way to measure average annual precipitation.
- Is there a correlation between air temperature and precipitation?
- Incorrect. Since both air temperature and precipitation are recorded, this can be measured.
- What is the average daily temperature?
- Incorrect. This can be recorded since the temperature is recorded every day for 12 months.
A weatherman record atmospheric data to predict future weather conditions. Suppose that his lab in Detroit takes hourly measurements of air temperature and precipitation in the city for a total period of 12 months. The lab also records the exact time and date for each measurement.
Which of the following questions about the Detroit’s weather could be accurately answered using only the data collected by the lab?
- What is the average time the sun is out each day?
- Incorrect. Sunrise and sunset times are not recorded.
- Is there a correlation between precipitation in Detroit and Kalamazoo?
- Incorrect. Only data from Detroit is recorded.
- Is there a correlation between daily air temperature and sunrise time?
- Incorrect. Time of sunrise is not measured by the data.
- During which hour of the day does it rain most on average?
- Correct. Precipitation and time are recorded, so this could be measured.
A programmer is writing code to swap two user-input values. The program will ask the user for two inputs and stores them in value1 and value2, then switch the two values. Which of the following correctly does this?
(A)
value1 ← INPUT() value2 ← INPUT() value2 ← value1 value1 ← value2(B)
value1 ← INPUT() value2 ← INPUT() temp ← value1 value2 ← temp value1 ← temp(C)
value1 ← INPUT() value2 ← INPUT() temp ← value1 value1 ← value2 value 2 ← temp(D)
value1 ← INPUT() value2 ← INPUT()- Incorrect. This will result in value1 and value2 being the same.
- Incorrect. Close! You DO need a temporary variable, but value1 and value2 will still be the same in this case.
- Correct. By using the variable "temp" you can swap the values of value1 and value2 by storing the original value of value1 in temp.
- Incorrect. The values are only being assigned here, not being swapped.
Which of the following algorithms, given a list of integers, require both selection and iteration?
- An algorithm that returns the number of elements that are positive.
- Correct. The algorithm will have to iterate through the list and select the positive integers.
- An algorithm that returns true if the first element equals the last.
- Incorrect. The algorithm will only need to select the first and last integers and compare the values.
- An algorithm that calculates the average of the elements in the list.
- Incorrect. This only requires iteration since no individual values are selected.
- An algorithm that swaps the first and second elements in the list.
- Incorrect. This does not require iteration.