Procedures and functions Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the first step to doing a 2D array with a procedure and function?

A

Declare the array lists

DECLARE rainfall: ARRAY [1:3, 1:4] OF REAL
DECLARE months: ARRAY [1:3] OF STRING

DECLARE ..:.. ARRAY [..:.. , ..:..] OF …
DECLARE ..:.. ARRAY [..:..] OF …

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the second step to doing a 2D array with a procedure and function?

A

Initialise the arrays and constants

Months <- [“January”,”February”,”March”]
Rainfall <- [[0.0,0.0,0.0,0.0], [0.0,0.0,0.0,0.0], [0.0,0.0,0.0,0.0]]

CONSTANT numberofmonths <- 3
CONSTANT numberofweeks <- 4

… <- [”..”,”..”,”..”]
… <- [[..,..,..,..] [..,..,..,..] [..,..,..,..]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the third step to doing a 2D array with a procedure and function?

A

Create a procedure for inputting the rainfall values

-PROCEDURE inputrainfall(months: STRING, rainfall: REAL)
-FOR r <- 1 TO 3
-FOR c <- 1 TO 4
-OUTPUT “Enter a new rainfall value”
-INPUT Newrainfall
-WHILE Newrainfall < 0 AND Newrainfall < 150 DO
-OUTPUT “Error, enter a new value between 0 and 150”
-INPUT Newrainfall
-ENDWHILE
- Rainfall [c][r] <- Newrainfall
- NEXT C
- NEXT R
-ENDPROCEDURE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the fourth step to doing a 2D array with a procedure and function?

A

Procedure to print monthly rainfall

-PROCEDURE printrainfall(Months: STRING, Rainfall: REAL)
-FOR r <- 1 TO 3
-Monthyrainfall <- 0
-FOR c <- 1 TO 4
-monthlyrainfall <- monthyrainfall + rainfall[r][c]
-NEXT c
-OUTPUT “The total rainfall for”, months[r], “is”, monthlyrainfall
-NEXT r
-ENDPROCEDURE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the fifth step to doing a 2D array with a procedure and function?

A

A function to work out the total

-FUNCTION Totalrainfall(months: STRING, Rainfall: REAL) RETURN INTEGER
-Total <- 0
-FOR r <- 1 TO 3
-Monthlyrainfall <- 0
-FOR c <- 1 TO 4
-Monthlyrainfall <- Monthlyrainfall + rainfall[r][c]
-Total <- Total + Monthlyrainfall
-NEXT C
-NEXT R
-RETURN Total
-ENDUNCTION

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the sixth step to doing a 2D array with a procedure and function?

A

A function to work out average rainfall

-FUNCTION Average(Months: STRING, Rainfall: REAL) RETURNS REAL
-Average <- Total / numberofmonths
-RETURN “The average rainfall is”, Average
-ENDFUNCTION

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the seventh step to doing a 2D array with a procedure and function?

A

-FUNCTION Weeklyaverage(Months: STRING, Rainfall REAL) RETURNS REAL
-Weeklyaverage <- Average/numberofweeks
-RETURN “the weekly average is”, Weeklyaverage
-ENDFUNCTION

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the eigth step to doing a 2D array with a procedure and function?

A

Procedure to work out months above average

-PROCEDURE aboveaverage(Months: STRING, Rainfall: REAL)
-monthsaboveaverage <- 0
-FOR r <- 1 TO 3
-FOR c <- 1 TO 4
-IF rainfall[r][c] > Average THEN
-monthsaboveaverage <- monthsaboveaverage + 1
-NEXT c
-NEXT r
-OUTPUT “The number of months above average are”, monthsaboveaverage
-ENDPROCEDURE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the ninth step to doing a 2D array with a procedure and function?

A

Case statement to allow the user to select a subroutine

-OUTPUT “1 Input rainfall”
-OUTPUT “2 Print rainfall”
-OUTPUT “3 Total rainfall”
-OUTPUT “4 Average rainfall”
-OUTPUT “5 Weekly average rainfall”
-OUTPUT “6 “Months above average”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the tenth step to doing a 2D array with a procedure and function?

A

Calling the procedures and functions using a case statement

CASE OF KeyPress
-“1” CALL inputrainfall (months, rainfall)
-“2” CALL printrainfall (months, rainfall)
-“3” OUTPUT totalrainfall (months, rainfall)
-“4” OUTPUT Average (months, rainfall)
-“5” OUTPUT Weeklyaverage (months, rainfall)
-“6” CALL monthsaboveaverage(months, rainfall)
-OTHERWISE OUTPUT “Not a valid option”
ENDCASE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly