programming concepts (paper 2) Flashcards
what happens to data used in a program
it is stored in memory locations while the program is running
what is a variable
a data item held in memory which may change value during program execution
what is a variable referred to by
its identifier
what are the different types of data variable can be
- integer (5, -297)
- real (3.12, 9.999)
- char (A, @, $, 4)
- string (Yes, Hello world)
- boolean (TRUE, FALSE)
what is a constant
a value that cannot change during the execution of hte program (CONSTANT VAT <- 0.2)
what is the diifference between a variable and a constant
a variable can change during the program execution, a constant does not
what is an input
when the user inputs data or a request into the program to get an output (INPUT Name)
what is an output
it is used to output data on the screen after information has been processed by the user (OUTPUT “Area = “, Length * Width)
what is a boolean expression
something which uss one or more logical operators and evalutes to either TRUE or FALSE
what is a sequence control structure
when two or more statements are written and executed one after the other in sequence
what is a selectrion control structure
comprises an IF or CASE statement and a logical expression (CASE OF… OTHERWISE… ENDCASE…, IF… THEN…)
give an example of a nested if statement
IF Num1 >= Num2 AND Num1 >= Num3
THEN
OUTPUT Num1
ELSE
IF Num2 >= Num1 AND Num2 >= Num3
THEN
OUTPUT Num2
ELSE
OUTPUT Num3
ENDIF
ENDIF
what does a case statement actually allow to happen
one of several brances of code to be executed depending on what data has been inputed by the user
give me an example of a case statement
INPUT MemberType
CASE OF MemberType
“Junior” : EntryFee <- 2.0
“Senior” : EntryFee <- 3.0
“Special” : EntryFee <- 0.0
OTHERWISE OUTPUT “Invalid member type”
ENDCASE
what does iteration mean
repetition
what loop is count-controlled
FOR… NEXT
give an example of a FOR.. NEXT loop nested
FOR Table <- 2 TO 10
FOR N <- 1 TO 10
Answer <- Table * N
OUTPUT Answer
NEXT N
NEXT Table
what loop is condition controlled
WHILE… DO … ENDWHILE (pre-condition - checked at the start)
REPEAT… UNTIL (post-condition - checked at the end)
Give an example of a WHILE… DO… ENDWHILE loop
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
how is a string defined
as zero or more characters enclosed in quote marks (“”)
what are the different string functions and what do that do
- 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
what is a procedure
a named block of code, seperate from the main program, which can be called and executed using a statement like (CALL <procedure>)</procedure>
what does a procedure do
- it does not return a value
- control is passed using the CALL statement with any parameters in brackets
what is a function
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)