Task 1 Task 2 Task 3
Task 1 Task 2 Task 3

Task 1

A city has a name eg "New York", a population eg 12000000 and a pollution index eg 5.7

Design this record structure as a new type in pseudocode.

Task 2

Two City records need to be declared, c1 and c2

Then the records need the following data to be assigned to them:

c1

San Francisco

8000000

3.2

 

c2

Boston

12000000

3.7

Finally, some code needs to be written to determine which City record has the highest polution index. The name of that city will be displayed.

Solve this problem in PSEUDOCODE.

Task 3

An array of City records has been declared as follows:

DECLARE cities : ARRAY[1:10] OF City

10 City records are then assigned to the array as follows:

FOR i ← 1 To 10

DECLARE c : City

INPUT cityName

INPUT cityPopulation

INPUT cityPIndex

//assign data to record

c.name ← cityName

c.population ← cityPopulation

c.pIndex ← cityPIndex

//assign record to next element in array

cities[i] ← c

END FOR

A function, processRecords will process the array. It will count all cities that have a population greater than 10000000 and a pollution index greater than 5.0

The function header is:

FUNCTION processRecords(BYREF cityList : ARRAY[1:100] OF City) RETURNS INTEGER

Write this function in pseudocode.

Task 4

For the City problem above, investigate how to design a record structure using classes in Python.

Design a class called City with the 3 properties: Name, Population, cityPIndex

Write a computer program to construct 5 city records and append them to an array, cities.

In Python, code the function processRecords as in Task 3.

The function header is the same as Task 3:

FUNCTION processRecords(BYREF cityList : ARRAY[1:5] OF City) RETURNS INTEGER

Write this function in pseudocode.