Programming Concepts (Cambridge (CIE) IGCSE Computer Science)

Flashcards

1/124
  • Front

    What is a variable?

Enjoying Flashcards?
Tell us what you think

Cards in this collection (124)

  • What is a variable?

    A variable is an identifier that can change in the lifetime of a program.

  • Define the term constant.

    A constant is an identifier set once in the lifetime of a program.

  • True or False?

    Variables can start with a number.

    False.

    Variables must start with a capital letter and not a number.

  • What does Pascal case mean for identifiers?

    Pascal case means identifiers should be in mixed case, starting with a capital letter.

  • State the pseudocode for declaring a variable.

    DECLARE <identifier> : <datatype>

    E.g. DECLARE Age: Integer.

  • How are constants named?

    Constants are named in all uppercase characters.

  • What is the purpose of using constants?

    Constants aid the readability and maintainability of programs.

  • True or False?

    Constants can be changed during program execution.

    False.

    Constants are set once in the lifetime of a program and cannot be changed.

  • State the pseudocode for declaring a constant.

    CONSTANT <identifier> ← <value>

    E.g. CONSTANT Password ← "letmein".

  • What is casting?

    Casting is changing data types within a program.

  • What is a data type?

    A data type is a classification of data into groups according to the kind of data they represent.

  • Define the term Integer.

    Integer is a data type used for whole numbers.

  • What does the Real data type represent?

    The Real data type represents numbers with a fractional part (decimal).

  • True or False?

    The Character data type can store multiple characters.

    False.

    The Character data type stores a single character.

  • What is the Boolean data type used for?

    The Boolean data type is used for true or false values.

  • State the pseudocode for assigning the value 3.142 to variable named Pi.

    Pi 3.142

  • What is the purpose of choosing the correct data type?

    Choosing the correct data type ensures accuracy and efficiency in the program.

  • Define the term String.

    String is a data type used for a sequence of characters.

  • True or False?

    The Integer data type can store decimal numbers.

    False.

    The Integer data type stores whole numbers only.

  • What is the difference between CHAR and STRING data types?

    CHAR stores a single character, while STRING stores a sequence of characters.

  • What is an input?

    An input is a value that is read from an input device and then processed by a computer program.

  • Define the term output.

    An output is a value sent to an output device from a computer program.

  • What is considered the standard for user input in programming?

    The keyboard is considered the standard for user input in programming.

  • True or False?

    The monitor is considered the standard for user output.

    True.

    The monitor is considered the standard for user output.

  • State the pseudocode for an input with the identifier Age.

    INPUT Age

  • What does the OUTPUT command do in pseudocode?

    The OUTPUT command in pseudocode sends data to the screen.

  • True or False?

    Inputs are only received from keyboards.

    False.

    Inputs can be received from various devices including mice, sensors, and microphones.

  • State two examples of output devices?

    Examples of output devices include:

    monitors,

    speakers,

    printers.

  • What happens when the INPUT command is executed?

    When the INPUT command is executed, a program will wait for the user to type a sequence of characters.

  • Why are inputs important in programming?

    Inputs are important because without them, programs can't interact with the outside world and always produce the same result.

  • What is sequence in programming?

    Sequence refers to lines of code which are run one line at a time in the order that they are written.

  • True or False?

    The order of instructions in a sequence doesn't matter.

    False.

    The order of instructions in a sequence is crucial to the flow of a program.

  • What can happen if instructions are out of sequence?

    If instructions are out of sequence, it can lead to unexpected behaviour or errors.

  • Why is sequence important in programming?

    Sequence is important because it determines the flow of a program and ensures instructions are executed in the correct order.

  • What is the first step in ensuring correct sequence?

    The first step in ensuring correct sequence is to plan the logical order of instructions before writing the code.

  • True or False?

    In Python, indentation affects the sequence of code execution.

    True.

    In Python, indentation affects the sequence of code execution by defining code blocks.

  • What is the output of the following pseudocode?

    INPUT1 ← 4

    INPUT2 ← 5

    Number ← INPUT2 - INPUT1

    OUTPUT Number

    The output would be:

    1

  • What is the output of the following pseudocode?

    INPUT1 ← 3

    INPUT2 ← 2

    INPUT3 ← 7

    Number ← INPUT2 * INPUT1

    Number ← Number + INPUT3

    OUTPUT Number

    The output would be:

    13

  • What is selection in programming?

    Selection is when the flow of a program is changed, depending on a set of conditions.

  • Define the term IF statement.

    An IF statement is a selection statement that allows you to execute a set of instructions if a condition is true.

  • What are the two ways to write selection statements?

    The two ways to write selection statements are:

    if... then... else...

    and

    case...

  • True or False?

    IF statements always require an ELSE clause.

    False.

    IF statements do not always require an ELSE clause.

  • What is nested selection?

    Nested selection is a selection statement within a selection statement, e.g., an If inside of another If.

  • What is a CASE statement?

    A CASE statement is a selection statement used when comparing multiple values of the same variable.

  • True or False?

    CASE statements are more flexible than IF statements.

    False.

    IF statements are more flexible and are generally used more in languages such as Python.

  • What is the purpose of selection in programming?

    The purpose of selection in programming is to allow different code to be executed based on certain conditions.

  • State the basic syntax of an IF statement in pseudocode.

    IF <condition> THEN <statement> ENDIF

    E.g.

    IF Age < 18 THEN
    OUTPUT "Too young"
    ENDIF

  • What is the difference between IF-THEN and IF-THEN-ELSE statements?

    IF-THEN statements execute code only if the condition is true, while IF-THEN-ELSE statements provide an alternative action if the condition is false.

  • What is iteration in programming?

    Iteration is repeating a line or a block of code using a loop.

  • Define the term count controlled loop.

    A count controlled loop is when the code is repeated a fixed number of times (e.g., using a for loop).

  • What is a condition controlled loop?

    A condition controlled loop is when the code is repeated until a condition is met.

  • True or False?

    FOR loops are always count controlled.

    True.

    FOR loops are always count controlled.

  • What are the two types of condition controlled loops?

    The two types of condition controlled loops are:

    post-condition (REPEAT)

    and

    pre-condition (WHILE).

  • What is the difference between WHILE and REPEAT loops?

    WHILE loops test the condition before executing the loop, while REPEAT loops execute the loop at least once before testing the condition.

  • Define nested iteration.

    Nested iteration is a loop within a loop, e.g., a FOR inside of another FOR.

  • State the data type that must be used for all identifiers in a count-controlled loop.

    Integer

  • State the basic syntax of a FOR loop in pseudocode.

    FOR <identifier> ← <value1> TO <value2> <statements> NEXT <identifier>

    E.g.

    FOR Score ← 1 TO 10
    ....
    NEXT Score

  • What is the purpose of the STEP keyword in a FOR loop?

    The STEP keyword in a FOR loop determines the increment or decrement value for each iteration.

  • What is totalling in programming?

    Totalling involves adding up values, often in a loop.

  • Define the term counting in programming.

    Counting involves keeping track of the number of times a particular event occurs.

  • How is a total variable typically initialised?

    A total variable is typically initialised to 0 at the beginning of the program.

    E.g.

    Total ← 0

  • True or False?

    Counting and totalling always occur in loops.

    False.

    While counting and totalling often occur in loops, they can also be done outside of loops.

  • How is a count variable typically updated?

    A count variable is typically updated by incrementing it by 1 (Count ← Count + 1).

  • True or False?

    A total variable can only be used for adding numbers.

    False.

    A total variable can be used for various types of accumulation, not just adding numbers.

  • In what situations would you typically use totalling?

    You would use totalling when you need to accumulate values, such as calculating a sum or average.

  • In what situations would you typically use counting?

    You would use counting when you need to keep track of occurrences, such as counting the number of times a condition is met.

  • What is string manipulation?

    String manipulation is the use of programming techniques to modify, analyse or extract information from a string.

  • Define the term case conversion.

    Case conversion is the ability to change a string from one case to another, for example, lower case to upper case.

  • What does the LENGTH function do?

    The LENGTH function counts the number of characters in a string.

  • True or False?

    Substring extraction always starts at the first character of a string.

    False.

    Substring extraction can start at any position within the string.

  • How does slicing work in string manipulation?

    Slicing in string manipulation uses specific start and end positions to extract the desired characters from a string.

  • True or False?

    In pseudocode, the first character of a string is at position 0.

    False.

    In pseudocode, the first character of a string is at position 1.

  • What is the difference between UCASE and LCASE functions?

    UCASE converts a string to uppercase, while LCASE converts a string to lowercase.

  • State the pseudocode for extracting the first three letters from a string named "Book" and outputting to the screen.

    Book ← "An Inspector Calls"

    OUTPUT SUBSTRING(Book, 1, 3)

  • What is the purpose of the LENGTH function in the following pseudocode?

    Password ← "letmein"

    IF LENGTH(Password) >= 8

    THEN

    OUTPUT "Password accepted"

    ELSE

    OUTPUT "Password too short"

    ENDIF

    To count how many characters are in the password.

  • What is the output of this pseudocode?

    Name ← "Michael J Fox"

    OUTPUT SUBSTRING(Name, 7, 11)

    l J F
    (with spaces)

  • What is an operator in programming?

    An operator is a symbol used to instruct a computer to perform a specific operation on one or more values.

  • Define the term arithmetic operator.

    An arithmetic operator is a symbol used for mathematical operations such as addition, subtraction, multiplication, and division.

  • What does the modulus operator do?

    The modulus operator returns the remainder after division.

  • True or False?

    The '=' symbol is used for both assignment and comparison.

    False.

    In most programming languages, '=' is used for assignment, while '==' is used for comparison.

  • What are the three main Boolean operators?

    The three main Boolean operators are:

    AND, OR, and NOT.

  • How does the AND operator work?

    The AND operator returns True if both conditions are True.

  • True or False?

    The OR operator returns True if at least one condition is True.

    True.

    The OR operator returns True if at least one condition is True.

  • What is the difference between '/' and '//' in Python?

    In Python, '/' performs floating-point division, while '//' performs integer division (quotient).

  • State the symbol for exponentiation in pseudocode and Python.

    In pseudocode: ^, in Python: **.

  • What does the NOT operator do?

    The NOT operator returns the opposite of the condition (True if False, False if True).

  • What is a sub program in programming?

    A sub program is a sequence of instructions that perform a specific task or set of tasks.

  • Define the term procedure.

    A procedure is a type of sub program that performs a specific task but does not return a value.

  • What is a function in programming?

    A function is a type of sub program that performs a specific task and returns a value.

  • True or False?

    Parameters are always required in sub programs.

    False.

    Sub programs can be defined with or without parameters.

  • What is the purpose of using sub programs?

    The purpose of using sub programs is to simplify a program by breaking it into smaller, more manageable parts and to avoid duplicating code.

  • How do you call a procedure in pseudocode?

    You call a procedure in pseudocode using the CALL keyword,

    E.g.

    CALL Login

  • True or False?

    Functions are always called within an expression.

    True.

    Functions are always called within an expression because they return a value.

  • What is the difference between a function and a procedure?

    A function returns a value, whereas a procedure does not.

  • State the basic syntax for defining a function in pseudocode.

    FUNCTION function_name(parameters)

    ....

    RETURN ....

  • What does it mean to 'call' a sub program?

    To 'call' a sub program means to execute it from the main program.

  • What is a local variable?

    A local variable is a variable declared within a specific scope, such as a function or a code block.

  • True or False?

    Local variables can be accessed from anywhere in the program.

    False.

    Local variables are accessible only within the block in which they are defined.

  • What happens to a local variable when the execution of its block ends?

    When the execution of the block ends, the local variable is destroyed and its memory is released.

  • Define the term global variable.

    A global variable is a variable declared at the outermost level of a program, outside any modules such as functions or procedures.

  • What is the scope of a global variable?

    The scope of a global variable is global, meaning it can be accessed and modified from any part of the program.

  • True or False?

    Local variables have a longer lifetime than global variables.

    False.

    Local variables have a limited lifetime to the block in which they are defined, while global variables exist for the entire duration of the program.

  • In Python, how do you declare a variable as global inside a function?

    global VariableName

  • What is the main difference between local and global variables in terms of accessibility?

    The main difference between local and global variables in terms of accessibility is that local variables can only be accessed within their defined block, while global variables can be accessed from any part of the program.

  • Variable scope

    Variable scope refers to the area of a program where a variable can be accessed and modified.

  • True or False?

    In Python, you need to use the 'global' keyword to access a global variable inside a function.

    False.

    In Python, you can access a global variable inside a function without using the 'global' keyword, but you need to use it if you want to modify the global variable.

  • What are library routines?

    Library routines are reusable code that can be used throughout a program, made public through reusable modules or functions.

  • True or False?

    Using library routines increases development time for programmers.

    False.

    Using library routines saves programmers time by using working code that has already been tested.

  • Random library

    The random library is a library of code which allows users to make use of 'random' in their programs, such as generating random choices or random numbers.

  • What is random number generation used for in programming?

    Random number generation is used to add an element of unpredictability in programs, such as simulating dice rolls, selecting random questions, or in cryptography.

  • In Python, how do you import the random library?

    In Python, you import the random library by using the statement:

    import random

  • What does the randint() function do in Python's random library?

    The randint() function in Python's random library generates a random integer within a specified range.

  • Round library

    The round library is a library of code which allows users to round numerical values to a set amount of decimal places.

  • True or False?

    The round function in Python can only round to the nearest whole number.

    False.

    The round function in Python can round to a specified number of decimal places.

  • What is the syntax for the round function in pseudocode?

    The syntax for the round function in pseudocode is:

    ROUND(<identifier>, <places>)

  • In Python, how would you round the number 3.14159 to 2 decimal places?

    In Python, you would round 3.14159 to 2 decimal places using:

    round(3.14159, 2)

  • What is the main goal of writing easy-to-maintain programs?

    The main goal is to make code easy to read using consistent techniques.

  • Define code Layout.

    Layout refers to the spacing between sections of code, which helps improve readability and maintainability.

  • What does indentation contribute to in programming?

    Indentation contributes to clearly defining sections of code, making it easier to read and maintain.

  • What are code comments?

    Comments are explanations of key parts of the code, which help other programmers understand the code's purpose and functionality.

  • True or False?

    Using meaningless variable names improves code maintainability.

    False.

    Using meaningful variable names that describe what is being stored improves code maintainability.

  • White space

    White space refers to adding suitable spaces in the code to make it easier to read and understand.

  • What are sub-programs in the context of maintainable code?

    Sub-programs are functions or procedures used where possible to organise and modularise code, making it more maintainable.

  • True or False?

    Consistency in coding techniques leads to easier program maintenance.

    True.

    When consistency is applied in coding techniques, programs are easier to maintain.