Task 1 Task 2 Task 3

Task 1

Here is a program, written in pseudocode, which determines the biggest number in an array:

DECLARE biggest, i : INTEGER

DECLARE arr : ARRAY[1:10] OF INTEGER

 

arr ← [34,23,65,435,34,56,67,454,34,2]

#remember that in pseudocode the first index in an array is 1

biggest ← arr[1]

FOR i ← 2 TO 10

IF arr[i] > biggest

THEN

biggest ← arr[i]

END IF

END FOR

OUTPUT biggest

Resdesign the program so that a procedure called displayBiggest processes an array that is sent as a parameter.

The following computer program should work after your solution has been written and tested:

DECLARE nums : ARRAY[1:10] OF INTEGER

 

nums ← [34,23,65,435,34,56,67,454,34,2]

CALL getBiggest(nums)

Note: the function design should include 1 parameter

Task 2

A computer program stores an array of city names followed by a 2-digit continent code eg:

["london-eu", "madrid-eu", "new york-us", "sydney-au", "santiago-sa", "rome-eu", "bangkok-as", "tokyo-as"]

The program calls a procedure with the following header:

PROCEDURE countCountries(cities : ARRAY[0:n] OF STRING)

where n is the last index of the array.

The procedure produces a count of cities in Europe, USA and Asia and displays the result.

Implement this procedure.

Test your procedure with this test file:

bricks

Task 3

Here is part of a lottery computer program written in pseudocode. It is quite tricky! It uses a global variable.

The program draws 6 lottery numbers in the range 1-49. No two numbers are the same!

To solve this problem in Python, you will have to research how to change data stored in a global variable if you are accessing the variable from a procedure.

Talk to your teacher or classmates if you do not get this.

Here is the pseudocode of the main program:

#array to store 6 lottery numbers, global variable

lottery ← [-1,-1,-1,-1,-1,-1]

drawNums()

FOR i ← 1 TO LENGTH(lottery):

OUTPUT lottery[i]

END FOR

Here is the pseudocode for the procedure drawNums()

PROCEDURE drawNums():

index ← 1

WHILE index<6 DO

x ← RAND(1,49)

alreadyDrawn ← FALSE

FOR i ← 1 TO LENGTH(lottery):

IF x = lottery[i] THEN

alreadyDrawn ← TRUE

END IF

END FOR

IF alreadyDrawn = FALSE THEN

lottery[index]←x

index←index+1

END IF

END WHILE

Code this program in Python.

Note: array indexes in pseudocode start with 1, and in Python they start with 0.