UNIT 6 PRACTICE PROBLEMS Flashcards
The following algorithm is followed by a person every morning when they get up from bed to go to school:
1. Wake up
2. Brush teeth
3. Put on shirt
4. Put on pants
5. Put on socks
6. Put on shoes
7. Tie shoes
Which concept does this algorithm best demonstrate?
Sequencing.
Which of the following is true of algorithms?
Every algorithm can be constructed using combinations of sequencing, selection, and iteration.
The algorithm below is used to find the largest element in a list of numbers.
By modifying one of the lines in the program it is possible to make the algorithm find the smallest element. Which line would need to be modified and how?
01 target <- list[1]
02 FOR EACH num IN list
03 {
04 IF(num > target)
05 {
06 target <- num
07 }
08 }
09 DISPLAY(target)
Line 04 becomes IF (num < target).
Find the bug. When Button1 is clicked, Label1 is supposed to be set to a name that is selected from the names list by the displayName procedure. But the label’s Text never changes. Why?
a) The displayName procedure is not being called when the button is clicked.
b) The list is not properly set up.
c) The displayName procedure has a bug in it.
d) The displayName procedure was never defined.
e) Maybe Label1 is not enabled.
a) The displayName procedure is not being called when the button is clicked.
What value will the global variable name have after Button1 is clicked?
Abe
How many elements are there in the names list
two elements
What is the length of the following list?
5
What value would the global variable name have after the blocks shown here are executed?
Mary
What name would be you get if you selected the item at index 2 of the item at index 2 of the names list?
Bush
What name occurs at index 3 in the following list?
Barack
What will the following code output read? [song, book, video, book]
A. [“song”, “book”, “read”, “book”]
В. [“song”, “read”, “book”, “video”, “read”, “book”]
C. [“song”, “book”, “read”, “video”, book”, “read”]
D. [‘song”, “readbook”, “video”, “readbook”]
B. [“song”, “read”, “book”, “video”, “read”, “book”]
What will be displayed once the code is ran?
unusual, bold, away
People were surveyed whether they preferred cats or dogs.
Preferences were stored in the list animals as strings, with the string “cat” representing a preference for cats and the string
“dog” representing a preference for dogs.
The following code segment is intended to traverse the list and display the number people who prefer cats and the number of people who prefer dogs.
A.
#1: IF (animals = “cats”)
#2: ELSE
B.
#1: IF (response = “cats”)
#2: ELSE
C.
#1: IF (animals = “cats”)
#2: IF (animals = “dogs”)
D. #1: IF (response = “cats”)
#2: IF (response = “dogs”)
B. #1: IF (response = “cats”)
#2: ELSE
D. #1: IF (response = “cats”)
#2: IF (response = “dogs”)
Names of students who signed up for a club are stored in a list called newMembers. The code segment below is intended to look for a member with a given name stored in a variable called
keyName. The code segment is meant to output the index of the position of the student with keyName. If the name is not in the list, -1 should be displayed.
A. FOR EACH i IN newMembers
B. FOR EACH indexOfName IN newMembers
C. REPEAT n TIMES
D. REPEAT indexOfName TIMES
C. REPEAT n TIMES
How many times will the loop be printed? “nom nom”
5 times out of