32
Assignment 6 Sample problems

Assignment 6 Sample problems

  • Upload
    aimon

  • View
    71

  • Download
    0

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: Assignment  6  Sample problems

Assignment 6 Sample problems

Page 2: Assignment  6  Sample problems

Consider the following scratch program:

Page 3: Assignment  6  Sample problems

When the flag is clicked, how many times will the meow sound happen before everything stops?

Page 4: Assignment  6  Sample problems

When the flag is clicked, how many times will the meow sound happen before everything stops?

The answer is 11

Page 5: Assignment  6  Sample problems

What value will num have at the end?

Page 6: Assignment  6  Sample problems

What value will num have at the end?

The answer is 7

Page 7: Assignment  6  Sample problems

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.

Page 8: Assignment  6  Sample problems

Consider the following Scratch program:

Page 9: Assignment  6  Sample problems

How many times does the meow sound play?

Page 10: Assignment  6  Sample problems

How many times does the meow sound play?

The answer is 3

Page 11: Assignment  6  Sample problems

How many times does the sprite say "Hello!"?

Page 12: Assignment  6  Sample problems

How many times does the sprite say "Hello!"?

The answer is 2

Page 13: Assignment  6  Sample problems

What is the value of the variable num when everything stops?

Page 14: Assignment  6  Sample problems

What is the value of the variable num when everything stops?

The answer is 3

Page 15: Assignment  6  Sample problems

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

Page 16: Assignment  6  Sample problems

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,………..

Page 17: Assignment  6  Sample problems

Which of the following statements below expresses a base case?

1: C₀=12: C₁=13: C₂=2

Page 18: Assignment  6  Sample problems

Which of the following statements below expresses a base case?

1: C₀=12: C₁=13: C₂=2

Page 19: Assignment  6  Sample problems

Which of the following statements expresses the recursive step (i.e. dividing the problem into smaller subproblems)?

1: C₀=12: Cₓ₊₁=(4x+2)Cₓ/(x+2)3: Cₓ₊₁= C₀+(4x+2)Cₓ/(x+2)

Page 20: Assignment  6  Sample problems

Which of the following statements expresses the recursive step (i.e. dividing the problem into smaller subproblems)?

1: C₀=12: Cₓ₊₁=(4x+2)Cₓ/(x+2)3: Cₓ₊₁= C₀+(4x+2)Cₓ/(x+2)

Page 21: Assignment  6  Sample problems

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

Page 22: Assignment  6  Sample problems

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

Page 23: Assignment  6  Sample problems

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

Page 24: Assignment  6  Sample problems

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

Page 25: Assignment  6  Sample problems

How can we get ?

1. B and A or C

so False and True or True=> True

Page 26: Assignment  6  Sample problems

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

Page 27: Assignment  6  Sample problems

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 CThe answer is True

Page 28: Assignment  6  Sample problems

How can we get ?

1. not B or (acc and B)

so True or( True and False)=> True

Page 29: Assignment  6  Sample problems

What will E be after each of these short machine-language programs are executed?

acc = not B E=accacc= A E = acc or E

Page 30: Assignment  6  Sample problems

What will E be after each of these short machine-language programs are executed?

acc = not B E=accacc= A E = acc or E

The answer is E=A or (not B)

Page 31: Assignment  6  Sample problems

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

Page 32: Assignment  6  Sample problems

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

The answer is E=not B and (A or B )