Search Header Logo
practical 3

practical 3

Assessment

Presentation

Information Technology (IT)

9th - 12th Grade

Practice Problem

Hard

Created by

Jovani Rose

Used 1+ times

FREE Resource

9 Slides • 0 Questions

1

​p4 revision

By Jovani Rose

2

​(i) Write program code to declare the global array DataArray

3

​The procedure PrintArray() takes an integer array as a parameter and outputs the contents of the array in the order they are stored.

4

​(c) The function LinearSearch(): • takes an integer array and integer search value as parameters • counts and returns the number of times the search value is found in the array. Write program code for the function LinearSearch()

5

​(d) (i) Amend the main program to: • prompt the user to input a whole number between 0 and 100 inclusive • read and validate the input from the user • call LinearSearch() with DataArray and the validated input value • output the result in the format: The number 7 is found 2 times.

6

​2 Study the following pseudocode for a recursive function. FUNCTION Unknown(BYVAL X, BYVAL Y : INTEGER) RETURNS INTEGER IF X < Y THEN OUTPUT X + Y RETURN (Unknown(X + 1, Y) * 2) ELSE IF X = Y THEN RETURN 1 ELSE OUTPUT X + Y RETURN (Unknown(X - 1, Y) DIV 2) ENDIF ENDIF ENDFUNCTION The operator DIV returns the integer value after division e.g. 13 DIV 2 would give 6 (a) Write program code to declare the function Unknown().

7

​2 Study the following pseudocode for a recursive function. FUNCTION Unknown(BYVAL X, BYVAL Y : INTEGER) RETURNS INTEGER IF X < Y THEN OUTPUT X + Y RETURN (Unknown(X + 1, Y) * 2) ELSE IF X = Y THEN RETURN 1 ELSE OUTPUT X + Y RETURN (Unknown(X - 1, Y) DIV 2) ENDIF ENDIF ENDFUNCTION The operator DIV returns the integer value after division e.g. 13 DIV 2 would give 6 (a) Write program code to declare the function Unknown().

8

media

9

​p4 revision

By Jovani Rose

Show answer

Auto Play

Slide 1 / 9

SLIDE

Discover more resources for Information Technology (IT)