Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following program and fill in the blanks in lines 5 with appropriat

ID: 3735001 • Letter: C

Question

Consider the following program and fill in the blanks in lines 5 with appropriate code. What will be the output in line 16 if random(1,2) returned 1 at line 13?

1 FUNCTION String coinToss(Integer rValue)

2 IF rValue == 1 THEN

3 RETURN "head"

4 ELSE

5 RETURN "________"

6 END IF

7 END FUNCTION

8

9 MODULE main()

10 DECLARE Integer rand

11 DECLARE String value = ""

12

13 SET rand = random(1,2) //generate a random number

14

15 SET value = coinToss(rand)

16 DISPLAY "You got ", value

17 END MODULE

tail; You got head

rValue; You got tail

head; You got tail

rand, You got head

Explanation / Answer

Answer: rand, You got head

1 FUNCTION String coinToss(Integer rValue)

2 IF rValue == 1 THEN

3 RETURN "head"

4 ELSE

5 RETURN "__coinToss(rValue - 1)______"

6 END IF

7 END FUNCTION

8

9 MODULE main()

10 DECLARE Integer rand

11 DECLARE String value = ""

12

13 SET rand = random(1,2) //generate a random number

14

15 SET value = coinToss(rand)

16 DISPLAY "You got ", value

17 END MODULE