In the unit page, the array represents the number of radio calls made by a driver from Monday to Friday during the three daily driving tests.
A function, countCalls, takes the array as a parameter, along with an integer, searchItem.
The function will return the number of times searchItem is found in the array.
Implement the function, countCalls, in pseudocode.
Test your design by converting your pseudocode to program code.
Submit both your program code and pseudocode.
Here is the function header:
FUNCTION countCalls(calls : ARRAY[1:5, 1:3] OF INTEGER, searchItem : INETEGER) RETURNS INTEGER
Here is a test program in pseudocode:
DECLARE radioCalls : ARRAY[1:5, 1:3] OF INTEGER
DECLARE result : INTEGER
radioCalls ← [[1,6,5],[1,4,5],[5,4,6],[2,2,4],[2,5,0]]
result ← countCalls(radioCalls, 3)
OUTPUT result
Translate this pseudocode into program code:
DECLARE nums : ARRAY[1:3, 1:3] OF INTEGER
DECLARE searchItem : INTEGER
nums ← [[2,5,4],[1,4,5],[1,2,9]]
searchItem ← RAND[1,10]
CALL processArray(nums,searchItem)
OUTPUT "END OF PROGRAM"
PROCEDURE processArray(BYREF arr : ARRAY[1:3, 1:3] OF INTEGER, BYVAL replace : INTEGER)
DECLARE count : INTEGER
count ← 0
FOR i ← 1 TO 3
FOR j ← 1 TO 3
IF arr[i][j] < 0 THEN
arr[i][j] ← replace
END IF
END FOR
END FOR
OUTPUT "END OF PROCEDURE"
END PROCEDURE
A 2D array of 10 rows and 5 columns stores either * or -
For example:
| - | * | - | - | - |
| * | - | - | * | - |
| * | * | - | * | * |
| - | - | * | * | * |
| - | * | - | - | * |
| - | * | - | - | * |
| - | * | * | - | * |
| - | * | - | * | * |
| - | * | - | - | * |
| * | - | - | - | * |
A function, countSymbol, takes a STRING as a parameter. If the parameter STRING is a "*" or a "-", the function will return a count of how many of the parameter STRING are in the array; other wise the function returns -1.
For example, using the above array, the following function call will return 20
result ← countSymbol("*");
The following function call will return -1:
result ← countSymbol("---");
Write pseudocode to implement the function, countSymbol.
Assume the array is a global variable - passit into the function ByRef.
Use the pseudocode cheatsheet if you need help.
A STRING array, dailySamples, stores information about daily noise pollution samples. Samples are taken twice a day.
| "10:23" | "1.2" |
| "13:01" | "1.7" |
| "13:27" | "1.9" |
| "11:20" | "2.2" |
| "13:45" | "0.9" |
| "14:17" | "1.4" |
The first number in a row is the time the sample was taken. The second number in a row is the noise level sample.
If the noise level sample is greater than 1.0, the data is appended to a file, samples.txt in the following format:
sample time: 14.22; level: 1.2
A procedure, appendToFile processes the array and updates the file.
Implement the procedure in pseudocode.