programming concepts (paper 2) Flashcards

1
Q

what happens to data used in a program

A

it is stored in memory locations while the program is running

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

what is a variable

A

a data item held in memory which may change value during program execution

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

what is a variable referred to by

A

its identifier

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

what are the different types of data variable can be

A
  • integer (5, -297)
  • real (3.12, 9.999)
  • char (A, @, $, 4)
  • string (Yes, Hello world)
  • boolean (TRUE, FALSE)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a constant

A

a value that cannot change during the execution of hte program (CONSTANT VAT <- 0.2)

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

what is the diifference between a variable and a constant

A

a variable can change during the program execution, a constant does not

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

what is an input

A

when the user inputs data or a request into the program to get an output (INPUT Name)

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

what is an output

A

it is used to output data on the screen after information has been processed by the user (OUTPUT “Area = “, Length * Width)

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

what is a boolean expression

A

something which uss one or more logical operators and evalutes to either TRUE or FALSE

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

what is a sequence control structure

A

when two or more statements are written and executed one after the other in sequence

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

what is a selectrion control structure

A

comprises an IF or CASE statement and a logical expression (CASE OF… OTHERWISE… ENDCASE…, IF… THEN…)

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

give an example of a nested if statement

A

IF Num1 >= Num2 AND Num1 >= Num3
THEN
OUTPUT Num1
ELSE
IF Num2 >= Num1 AND Num2 >= Num3
THEN
OUTPUT Num2
ELSE
OUTPUT Num3
ENDIF
ENDIF

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

what does a case statement actually allow to happen

A

one of several brances of code to be executed depending on what data has been inputed by the user

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

give me an example of a case statement

A

INPUT MemberType
CASE OF MemberType
“Junior” : EntryFee <- 2.0
“Senior” : EntryFee <- 3.0
“Special” : EntryFee <- 0.0
OTHERWISE OUTPUT “Invalid member type”
ENDCASE

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

what does iteration mean

A

repetition

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

what loop is count-controlled

A

FOR… NEXT

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

give an example of a FOR.. NEXT loop nested

A

FOR Table <- 2 TO 10
FOR N <- 1 TO 10
Answer <- Table * N
OUTPUT Answer
NEXT N
NEXT Table

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

what loop is condition controlled

A

WHILE… DO … ENDWHILE (pre-condition - checked at the start)
REPEAT… UNTIL (post-condition - checked at the end)

19
Q

Give an example of a WHILE… DO… ENDWHILE loop

A

Total <- 0
Days <- 0
INPUT Visitors
WHILE Visitors <> -1 DO
Total <- Total + Visitors
Days <- Days + 1
INPUT Visitors
ENDWHILE
Average <- Total / Days
OUTPUT “Average daily number of visitors:”
OUTPUT Average

20
Q

how is a string defined

A

as zero or more characters enclosed in quote marks (“”)

21
Q

what are the different string functions and what do that do

A
  • LENGTH(“ “) = returns the number of characters (including spaces)
  • LCASE(“ “) = makes everything in parameter lower case
  • UCASE(“ “) = makes everything in parameter upper case
  • SUBSTRING(“ “, Num, Num) = makes everything in the quote marks outputed between the two numbers
22
Q

what is a procedure

A

a named block of code, seperate from the main program, which can be called and executed using a statement like (CALL <procedure>)</procedure>

23
Q

what does a procedure do

A
  • it does not return a value
  • control is passed using the CALL statement with any parameters in brackets
24
Q

what is a function

A

a block of code which returns a value to a variable specific in the statement (eg you would have a function just for calculating the total of smt or the avergage)

25
what are parameters
values passed to the subroutine, which are delcared in the parentheses within the call instruction
26
what are functions and procedures essential in in the program life cycle
decomposition - breaking down a complex problem into smaller sub-problems and sub-tasks
27
what is a local variable
a variable which is only recognised inside a subroutine, if you were to call it in the main program then you would recieve an error message
28
what is a global variable
a variable which is recognised in the whole program, including all the subroutines
29
what are the two library routines
- the ROUND function - the random number generation function
30
how would you write the round function in a psuedocode program
X <- 3.14159 Y <- ROUND(X, 2) //returns 3.14 in Y as it is 2dp
31
how would you write the random interger function in a psudocode program
RANDOM() // generates a random float point number between 0 and 1
32
what is an array
a data structure used to hold several elements of the same data type
33
how do you declare a 1D array, use this example of an array of 10 student names
DECLARE StudentName : ARRAY[1:10] OF STRING
34
how would you assign the name "Morris" to the third index of the array
StudentName[3] <- "Morris"
35
how do you declare a 2D array, use this example of a table of Sales over 4 months and three different shops
DECLARE Sales : ARRAY[1:3, 1:4] OF INTEGER
36
DECLARE Sales : ARRAY[1:3, 1:4] OF INTEGER How many rows (horrizonal) are there in this array
3
37
DECLARE Sales : ARRAY[1:3, 1:4] OF INTEGER How many collumns (verticle) are there in this array
4
38
how is data stored in a hard disk or SSD so that it can be written to
files
39
what is the purpose of storing data in a file to be used by a program
because then the file can be read or written into in many different programs, without having to re-enter the data all over again
40
what are the two different things you can do to a file
- read to it - write to it
41
how would you open a text file on members to write
OPENFILE MemberFile.txt FOR WRITE INPUT MemberID, Surname, Firstname WHILE MemberID <> "END" DO MemberRecord <- MemberID + "," + Surname + "," + Firstname WRITEFFILE MemberFile.txt, MemberRecord INPUT MemberID, Surname, Firstname ENDWHILE CLOSEFILE MemberFile.txt
42
how would you close a file
CLOSEFILE .....
43
how would you open a text file to read
OPENFILE MemberFile.txt FOR READ
44
how would you read to a file after opening it
READFILE MemberFile.txt, MemberRecord WHILE NOT MemberFile.endOfFile DO OUTPUT MemberRecord READFILE MemberFile.txt, MemberRecord ENDWHILE CLOSEFILE MemberFile.txt