320 likes | 425 Views
Assignment 6 Sample problems. Consider the following scratch program :. When the flag is clicked, how many times will the meow sound happen before everything stops? . When the flag is clicked, how many times will the meow sound happen before everything stops ? The answer is 11.
E N D
When the flag is clicked, how many times will the meow sound happen before everything stops?
When the flag is clicked, how many times will the meow sound happen before everything stops? The answer is11
What value will num have at the end? The answer is 7
How can we get ? In the beginning, num=5. Broadcast alpha actives receive alpha block, so keep broadcasting beta then active receive beta block, repeat 5 times. After repeat 5 times, change number by 1, so num=5+1=6, then continue broadcasting second alpha, do the same thing like before. so the number of meow sound is 5+6=11, num=6+1=7.
How many times does the meow sound play? The answer is 3
How many times does the sprite say "Hello!"? The answer is 2
What is the value of the variable num when everything stops?
What is the value of the variable num when everything stops? The answer is 3
How can we get ? 1: Before broadcast, meow 1 time. In the first broadcasting, num increases from 1 to 3 without meowing. In the second of broadcasting, since num=3, meow twice. Therefore, the total number of meowing is 1+2=3. 2: whenever active receive block, say hello once. There are two broadcasts, say hello twice. 3: num=3
The Catalan sequence is a series of numbers where the first number is C₀=1, and each subsequent number is Cₓ₊₁=(4x+2)Cₓ/(x+2). Thus, the sequence is 1, 1, 2, 5,………..
Which of the following statements below expresses a base case? 1: C₀=1 2: C₁=1 3: C₂=2
Which of the following statements below expresses a base case? 1: C₀=1 2: C₁=1 3: C₂=2
Which of the following statements expresses the recursive step (i.e. dividing the problem into smaller subproblems)? 1: C₀=1 2: Cₓ₊₁=(4x+2)Cₓ/(x+2) 3: Cₓ₊₁= C₀+(4x+2)Cₓ/(x+2)
Which of the following statements expresses the recursive step (i.e. dividing the problem into smaller subproblems)? 1: C₀=1 2: Cₓ₊₁=(4x+2)Cₓ/(x+2) 3: Cₓ₊₁= C₀+(4x+2)Cₓ/(x+2)
Recall the Instruction Set and Processor we used in class: Translate the following machine language program into the list of binary instructions used by the computer: acc =acc and A acc=acc or D acc= not E
Recall the Instruction Set and Processor we used in class: Translate the following machine language program into the list of binary instructions used by the computer: acc =acc and A 1010000 acc=acc or D 1000011 acc= not E 0110100
Let the values of the variables be A=True, B=False, C= True and acc=True. What will be in the accumulator after each of the following programs are executed? acc = Bacc = acc and Aacc = acc or C
Let the values of the variables be A=True, B=False, C= True and acc=True. What will be in the accumulator after each of the following programs are executed? acc = Bacc = acc and A acc = acc or C The answer is True
How can we get ? • B and A or C so False and True or True=> True
Let the values of the variables be A=True, B=False, C= True and acc=True. What will be in the accumulator after each of the following programs are executed? acc = acc and BC=accacc=not B acc= acc or C
Let the values of the variables be A=True, B=False, C= True and acc=True. What will be in the accumulator after each of the following programs are executed? acc = acc and BC=accacc=not B acc= acc or C The answer is True
How can we get ? • not B or (acc and B) so True or( True and False)=> True
What will E be after each of these short machine-language programs are executed? acc = not BE=accacc= AE = acc or E
What will E be after each of these short machine-language programs are executed? acc = not BE=accacc= AE = acc or E The answer is E=A or (not B)
What will E be after each of these short machine-language programs are executed? acc = A acc= acc or B E = acc acc= not BE = acc and E
What will E be after each of these short machine-language programs are executed? acc = Aacc= acc or BE= acc acc= not BE = acc and E The answer is E=not B and (A or B )