Exam code: H446
1/166
0Still learning
Know0
Define data type.
A data type is a classification of data into groups according to the kind of data they represent.

Join for free to unlock a full flashcard set, track what you know,
and turn revision into real progress.
What is the difference between an integer and a real data type?
An integer data type represents whole numbers (e.g. 10, -5, 0), while a real data type represents numbers with a fractional part (e.g. 3.14, -2.5, 0.0).
A is used to represent a single character, such as 'a', 'B', or '5'.
A char is used to represent a single character, such as 'a', 'B', or '5'.
Was this flashcard deck helpful?
Define data type.
A data type is a classification of data into groups according to the kind of data they represent.
What is the difference between an integer and a real data type?
An integer data type represents whole numbers (e.g. 10, -5, 0), while a real data type represents numbers with a fractional part (e.g. 3.14, -2.5, 0.0).
A is used to represent a single character, such as 'a', 'B', or '5'.
A char is used to represent a single character, such as 'a', 'B', or '5'.
Define casting.
Casting is the process of converting one data type to another data type.
True or False?
A string is used to represent a sequence of characters.
True.
A string holds a sequence of characters, such as words or symbols.
Why is it important to choose the correct data type for a variable in a program?
Choosing the correct data type ensures accuracy and efficiency in a program by allowing the computer to handle data correctly.
To perform calculations on input data, it is often necessary to the data from a string to a numerical format.
To perform calculations on input data, it is often necessary to cast the data from a string to a numerical format.
How do you convert the string "123" to an integer in Python?
You use the int() function: int_value = int("123").
Define arithmetic operators.
Arithmetic operators are symbols or keywords used to perform mathematical calculations and operations on numerical values, such as addition, subtraction, multiplication, and division.
What does the addition operator (+) do in programming?
The addition operator (+) adds numerical values together or concatenates strings.
The operator (*) is used to numerical values together.
The multiplication operator (*) is used to multiply numerical values together.
True or False?
The division operator (/) returns the remainder of a division.
False.
The division operator (/) returns the quotient, not the remainder. The modulus operator (MOD) returns the remainder.
Define logical operator.
A logical operator is a symbol or keyword used to compare values and return a boolean result.
True or False?
The equal to operator (==) returns true if the values on both sides are exactly the same.
True.
The equal to operator (==) compares two values and returns true only when they are equal.
The operator (!=) returns true if two values are not equal, and false if they .
The not equal to operator (!=) returns true if two values are not equal, and false if they are equal.
What does the greater than (>) operator do in programming?
The greater than (>) operator compares two values and returns true if the left operand is greater than the right operand.
Define Boolean operator.
A Boolean operator is a symbol or keyword used to combine and manipulate boolean values through logical operations such as AND, OR, and NOT.
True or False?
The AND operator returns true only if both conditions are true.
True.
The AND operator requires both operands to be true for the result to be true; otherwise, it returns false.
The OR operator returns true if of the operands is true, and false only if operands are false.
The OR operator returns true if at least one of the operands is true, and false only if both operands are false.
What does the NOT operator do to a Boolean value?
The NOT operator negates a Boolean value, returning true if the operand is false and false if the operand is true.
Define programming construct.
A programming construct is a feature of a programming language that determines the order in which lines of code are executed.
What are the three main programming constructs?
The three main programming constructs are sequence, iteration and branching (selection).
Sequence refers to lines of code which are run at a time, in the they are written.
Sequence refers to lines of code which are run one line at a time, in the order they are written.
What is branching (selection) in programming?
Branching, or selection, is when the flow of a program is interrupted and a condition is tested, determining which lines or block of code are run next.
The keywords , , , indicate that the construct is .
The keywords if, elseif, else, endif, switch, case indicate that the construct is selection.
True or False?
Iteration always repeats code a fixed number of times.
False.
Iteration can be count controlled (a fixed number of times) or condition controlled (repeats until a condition is met).
Define iteration.
Iteration is repeating a line or block of code using a loop, which can be count controlled or condition controlled.
In the example program provided, which programming construct is used to identify the largest number in the list?
Iteration is used to go through each number in the list (using a for loop), and selection (using if statements) is used to compare numbers and update the largest value found.
Define selection.
Selection is the use of branching programming constructs to test conditions, where the outcome determines which lines or blocks of code are run next.
What are the two main types of selection statements in programming?
The two main types of selection statements are if...elseif...else and switch...case.
A condition in selection is like asking a or question.
A condition in selection is like asking a yes/no or Boolean question.
True or False?
Boolean operators are used when more than one condition needs to be checked in a selection statement.
True.
Boolean operators allow multiple conditions to be tested together in selection statements.
Define if statement.
An if statement is a conditional statement that runs a block of code only if a specified condition is true.
The if... else... statement allows a program to execute one block of code if a condition is and another block if it is .
The if... else... statement allows a program to execute one block of code if a condition is true and another block if it is false.
What is the purpose of an elseif clause in an if statement?
An elseif clause allows you to check additional conditions if the initial if statement is false, enabling multiple decision branches.
In pseudocode, the if statement uses the keywords and to start and end the block.
In pseudocode, the if statement uses the keywords if and endif to start and end the block.
True or False?
You can use as many elseif clauses as you want in an if statement.
True.
You can include multiple elseif clauses to handle more than two possible outcomes in decision making.
What happens if none of the conditions in an if... elseif... else... statement are true?
If none of the if or elseif conditions are true, the else block is executed.
Define switch/case statement.
A switch/case statement is a type of conditional statement that performs multiple comparisons based on the value of an expression.
True or False?
A switch/case statement is best used when you have multiple variables to compare to different values.
False.
Switch/case statements are most useful when you have a single expression to compare against multiple possible values.
The switch keyword is followed by an , which is compared against multiple .
The switch keyword is followed by an expression, which is compared against multiple case labels.
What is the purpose of the default keyword in a switch/case statement?
The default keyword specifies a block of code to execute if none of the case labels match the expression in a switch/case statement.
Define iteration.
Iteration is the process of doing something more than once (repeat), also known as a loop.
What is the difference between a count controlled loop and a condition controlled loop?
A count controlled loop repeats code a fixed number of times, while a condition controlled loop repeats until a condition is met.
A is a loop that repeats a fixed number of times, whereas a is a loop that repeats until a condition is met.
A count controlled loop is a loop that repeats a fixed number of times, whereas a condition controlled loop is a loop that repeats until a condition is met.
True or False?
A for loop is a type of condition controlled loop.
False.
A for loop is a count controlled loop, not a condition controlled loop.
Define for loop.
A for loop is a count-controlled loop that repeats a fixed number of times, providing a concise way to perform repetitive tasks.
What are the three main parts of the syntax of a for loop?
The three main parts are initialisation, range and increment/decrement.
A is used to repeat a set of instructions a number of times.
A for loop is used to repeat a set of instructions a fixed number of times.
True or False?
In Python, the final number in range() is included in the loop.
False.
In Python, the final number in range() is not included in the loop.
Define while loop.
A while loop is a condition controlled loop that repeats until its condition becomes false. The condition is evaluated before each iteration.
True or False?
A while loop will always execute its code block at least once.
False.
If the condition is false the first time it is checked, the while loop will not execute its code block at all.
A while loop is useful when the of iterations is unknown in advance.
A while loop is useful when the number of iterations is unknown in advance.
What is the output when the number 30 is entered into the program that calculates how many times a number goes into 100 using a while loop?
The output is: 30 goes into 100 3 times.
Define do while loop.
A do while loop is a type of condition controlled loop that always executes its code block at least once before checking the condition to continue or terminate.
True or False?
A while loop always runs its code block at least once, just like a do while loop.
False.
A while loop may not run at all if the condition is already met, unlike a do while loop which always executes its code block once before checking the condition.
In a do while loop, the code block is executed evaluating the condition.
In a do while loop, the code block is executed before evaluating the condition.
What is the main difference between a do while loop and a while loop?
The main difference is that a do while loop always executes its code block at least once before checking the condition, whereas a while loop checks the condition first and may not execute the code block at all if the condition is already met.
Define modularity.
Modularity is a concept where problems are broken down into more manageable pieces, with each piece handled by a single subroutine, promoting code reusability, modularity, and organisation.
What is a subroutine in programming?
A subroutine is a standalone block of code, also known as a module, that performs a specific task when called within a program.
A returns a value, while a does not return a value.
A function returns a value, while a procedure does not return a value.
True or False?
Choosing clear and meaningful names for functions and parameters improves code readability.
True.
Descriptive names for functions and parameters help make code easier to understand and maintain.
Define function in programming pseudocode.
A function in programming pseudocode is a reusable block of code that performs a specific task, can take parameters, and may return a value.
The syntax for defining a function in pseudocode starts with the keyword and ends with .
The syntax for defining a function in pseudocode starts with the keyword function and ends with endfunction.
What is the purpose of using parameters in a function?
Parameters allow a function to receive input values so it can perform its task using different data each time it is called.
True or False?
In pseudocode, a function must always return a value.
False.
In pseudocode, a function may or may not return a value, depending on how it is defined.
Define procedure.
A procedure is similar to a function but does not return a value. It performs a series of actions or operations instead.
True or False?
A procedure in programming always has a return statement that provides a value.
False.
A procedure does not return a value. It performs actions with or without a return statement, but no value is returned.
In pseudocode, a procedure is defined using the word , followed by the procedure name and parameters.
In pseudocode, a procedure is defined using the word procedure, followed by the procedure name and parameters.
What happens when you assign the result of a procedure to a variable, like c = addNumbers(5,10)?
Since addNumbers is a procedure and does not return a value, the variable c will not receive the result of the addition. The result is printed, not returned.
Define parameter.
A parameter is a piece of data that is input into a code block such as a function or procedure so it can complete its task.
What is the purpose of passing a parameter into a code block such as a function or procedure?
Passing a parameter into a code block allows the code block to use the input data to complete its task.
When passing parameters into a code block, two standard methods are used: (byVal) and (byRef).
When passing parameters into a code block, two standard methods are used: passing by value (byVal) and passing by reference (byRef).
True or False?
Passing a parameter by value means changes to the parameter inside the function affect the original data outside the function.
False.
Passing a parameter by value means a copy of the data is passed, so changes inside the function do not affect the original data outside.
Define parameter passing by value.
Parameter passing by value means that a copy of the actual value is made and assigned to the function's parameter.
True or False?
When a parameter is passed by value, changes to the parameter within the function affect the original value outside the function.
False.
When passing by value, any changes to the parameter within the function do not affect the original value outside the function.
This approach ensures that the data remains unchanged, making it suitable when you want to protect the original data from being modified within the function.
This approach ensures that the original data remains unchanged, making it suitable when you want to protect the original data from being modified within the function.
What is a potential disadvantage of passing large data structures by value to a function?
Passing large data structures by value can lead to performance overhead because a copy of the data is made.
Define parameter passing by reference.
Parameter passing by reference is when a function receives the memory address of a value, allowing the function to directly modify the original data outside the function.
When a parameter is passed by reference, the function receives the of the value, not a copy.
When a parameter is passed by reference, the function receives the memory address of the value, not a copy.
What is a potential risk of passing parameters by reference in functions?
Passing parameters by reference can lead to unexpected side effects because changes made inside the function directly affect the original value outside the function.
True or False?
Passing a large data structure by reference can be more efficient than passing by value.
True.
Passing by reference is often more efficient for large data structures because it avoids copying all the data.
Define passing by value.
Passing by value is when a function receives a copy of the argument's value, so changes to the parameter do not affect the original data.
Define passing by reference.
Passing by reference is when a function receives a reference or memory address of the argument, allowing it to directly access and modify the original data.
True or False?
Passing by value is more memory efficient than passing by reference when dealing with large data structures.
False.
Passing by reference is more memory efficient for large data structures because it avoids making copies of the data.
Passing by protects the original data from being modified within the function, while passing by allows direct modification of the original data.
Passing by value protects the original data from being modified within the function, while passing by reference allows direct modification of the original data.
Define recursion.
Recursion is a programming technique where a function calls itself to solve a problem, using self-reference to break down complex problems into manageable subproblems.
What are the three essential features of a recursive algorithm?
A recursive algorithm must call itself, have a base case that allows it to return a value without further recursion, and a stopping base that is reachable after a finite number of calls.
A recursive function must have a case to avoid errors.
A recursive function must have a base case to avoid stack overflow errors.
True or False?
Recursive functions always require an iterative loop to solve problems.
False.
Recursive functions do not use iterative loops; instead, they solve problems by repeatedly calling themselves with modified parameters until a base case is reached.
Define recursion.
Recursion is a method where a function calls itself in order to solve a problem by breaking it down into smaller instances of the same problem.
Recursive code can be more and easier to for certain problems, but is often harder to .
Recursive code can be more concise and easier to read for certain problems, but is often harder to debug.
True or False?
Iteration is generally more memory efficient than recursion.
True.
Iteration uses less memory than recursion because it does not involve repeated function calls and stack usage.
Define iteration.
Iteration is a method where a set of instructions is repeated using loops until a condition is met, often with better performance than recursion.
Define recursive algorithm.
A recursive algorithm is an algorithm that calls itself repeatedly with modified parameters until a stopping condition is met.
What is the purpose of a stopping condition in a recursive function?
A stopping condition prevents a recursive function from calling itself forever by providing a point where the recursion ends.
The recursive function prints the current value, checks if is 0, and if not, it calls itself with .
The recursive function countdown_rec(n) prints the current value, checks if n is 0, and if not, it calls itself with n - 1.
True or False?
The recursive countdown function will continue to call itself even after n reaches 0.
False.
When n reaches 0, the stopping condition is met and the function returns, ending the recursion.
What is the purpose of tracing a recursive algorithm like countdown_rec(n)?
Tracing a recursive algorithm like countdown_rec(n) helps us understand the sequence of function calls and how the program executes each step, making it easier to follow its logic and debug errors.
Define trace table.
A trace table is a tool used to record the values of variables and function calls at each step of a program's execution, especially useful for understanding recursive algorithms.
In the recursive function countdown_rec(n), the function will stop calling itself when equals .
In the recursive function countdown_rec(n), the function will stop calling itself when n equals 0.
True or False?
A trace table for countdown_rec(5) shows the sequence of function calls from 5 down to 0.
True.
The trace table records each function call as countdown_rec is called with decreasing values until it reaches 0.
Define global variable.
A global variable is a variable declared at the outermost level of a program, outside any functions or procedures, and can be accessed and modified from any part of the program.
What are two common uses for global variables in programming?
Two common uses for global variables are data sharing between modules and storing configuration settings or constants.
A global variable can be accessed from part of the program because it has scope.
A global variable can be accessed from any part of the program because it has global scope.
True or False?
Using many global variables makes programs easier to maintain and test.
False.
Using many global variables makes programs more difficult to maintain and test, because it is harder to track where variables are changed and to test modules independently.
Define local variable.
A local variable is a variable declared within a specific scope, such as a function or code block, and is only accessible within that block.
True or False?
Once a block of code finishes executing, any local variables defined within it are destroyed and their memory is released.
True.
Local variables have a limited lifetime and their memory is automatically reclaimed when the block ends.
A local variable is accessible only within the in which it is defined.
A local variable is accessible only within the block in which it is defined.
What is one benefit and one drawback of using local variables in programming?
A benefit of using local variables is data encapsulation and hiding. A drawback is that excessive use in nested blocks can reduce code readability and cause memory overhead in loops or recursive functions.
Define global variable.
A global variable is a variable that is declared outside of functions and can be accessed and modified by any function in the program.
True or False?
In the code with the global variable, the function add_world must use the global keyword to modify global_string.
True.
The global keyword is needed to modify a global variable inside a function in Python.
In the local variable version, the function add_world returns the string, which is then assigned back to .
In the local variable version, the function add_world returns the modified string, which is then assigned back to local_string.
What is the main difference between how global_string and local_string are modified in the two Python code examples?
global_string is modified directly within functions using the global keyword, while local_string is modified by functions returning new values that are reassigned to the variable.
Define Integrated Development Environment (IDE).
An Integrated Development Environment (IDE) is a software tool that provides programmers with a comprehensive platform to write, edit, compile, debug, and manage code efficiently.
What is the main purpose of an IDE in software development?
The main purpose of an IDE is to streamline the software development process by providing features and tools that help programmers write, compile, debug, and manage their code efficiently.
IDEs can be either an to download or a platform.
IDEs can be either an app to download or a web-based platform.
Name two examples of IDEs and briefly describe one feature of each.
IDLE is a basic IDE used for writing and running Python code. Replit is a web-based IDE that supports collaboration and multiple programming languages such as Python, JavaScript, and C++.
Replit allows programmers to write and run code as well as with other programmers online.
Replit allows programmers to write and run code as well as collaborate with other programmers online.
True or False?
Autocomplete and auto indent features in an IDE are useful for both writing and debugging code.
False.
Autocomplete and auto indent features in an IDE are useful for writing code, but are not useful for debugging code.
Define syntax highlighting.
Syntax highlighting is an IDE feature that visually distinguishes elements of code, such as keywords, strings, and comments, by using different colours and styles to improve code comprehension and reduce syntax errors.
What is the purpose of the autocomplete feature in an IDE?
Autocomplete helps programmers by suggesting code completions as they type, reducing typing effort, preventing errors, and improving productivity.
The feature that automatically indents the code when starting a new line in a block is called .
The feature that automatically indents the code when starting a new line in a block is called auto indent.
True or False?
Comments in code are executed by the program but not shown to the user.
False.
Comments are not executed by the program; they serve as documentation and explanations for programmers.
Define breakpoint.
A breakpoint is a marker set in code to halt program execution at a specific line, allowing developers to inspect the program's state and variable values during debugging.
The tool in an IDE allows developers to monitor variable values as the program runs.
The variable watch window tool in an IDE allows developers to monitor variable values as the program runs.
Define class in Object Oriented Programming.
A class is a blueprint for creating objects, defining the attributes and methods that the objects will have in Object Oriented Programming.
What is the purpose of a constructor in a class?
A constructor is a special method used to initialize objects of a class by assigning values to their attributes when they are created.
A car object in a class might have attributes such as , model, , mileage, and whether it is preowned.
A car object in a class might have attributes such as manufacturer, model, price, mileage, and whether it is preowned.
List two useful methods that could be included in a car class.
Two useful methods for a car class are Accelerate (to make the car go faster) and honkHorn (to make the car honk its horn).
Define object (in OOP).
An object in Object Oriented Programming is an instance of a class that contains both attributes (data) and methods (functions).
In Python, a class is defined using the keyword, and objects are created by the class.
In Python, a class is defined using the class keyword, and objects are created by instantiating the class.
What is the purpose of a constructor in a class?
A constructor is a special method used to initialise the attributes of an object when it is created.
True or False?
Once a class is defined, you can create multiple distinct objects from it.
True.
A class acts as a blueprint, so multiple objects (instances) can be created, each with their own attribute values.
Define method (in OOP).
A method in OOP is a function defined within a class that defines the behaviour or actions that objects of the class can perform.
What is the difference between a public and a private method in Java?
A public method can be accessed from outside the class, while a private method can only be accessed from within the class it is defined in.
In Python, a method with a leading underscore is considered private by convention.
In Python, a method with a single leading underscore is considered private by convention.
True or False?
In Python, methods marked as private cannot be accessed from outside the class.
False.
In Python, methods with a leading underscore are private by convention but can still be accessed and invoked from outside the class.
Define attribute in the context of programming classes.
An attribute is a variable that is associated with a class or object, used to store data about that object.
In Python, how are attributes defined within a class?
Attributes in Python classes are defined using the self keyword, followed by the attribute name and its initial value inside the __init__ method.
In the Lizard class, the attributes are , , and .
In the Lizard class, the attributes are speed, mass, and size.
True or False?
In Java, attributes are always declared as public within a class.
False.
In Java, attributes are often declared as private within a class to enforce encapsulation.
Define inheritance (OOP).
In object-oriented programming, inheritance is the mechanism by which a class can acquire the properties and behaviours (methods and attributes) of another class.
In Java, the keyword is used to indicate that one class inherits from another.
In Java, the keyword extends is used to indicate that one class inherits from another.
What does the super keyword do in a derived class constructor?
The super keyword is used to call the constructor of the parent class, allowing inherited attributes to be initialised properly.
In Python, a class inherits from another class by placing the name in parentheses after the class name.
In Python, a class inherits from another class by placing the parent class name in parentheses after the class name.
True or False?
A derived class can access methods defined in its parent class.
True.
A derived class inherits both methods and attributes from its parent class, unless access is restricted.
What is the main advantage of using inheritance in programming?
The main advantage of inheritance is code reuse: common functionality can be written once in a base class and reused by derived classes, reducing duplication.
A class that is inherited from is called the class, while the class that inherits is called the class.
A class that is inherited from is called the base (or parent) class, while the class that inherits is called the derived (or child) class.
In object-oriented programming, what is a constructor and how does it relate to inheritance?
A constructor is a special method used to initialise objects of a class. In inheritance, derived class constructors often call the parent class constructor to initialise inherited attributes.
Define encapsulation.
Encapsulation is the concept of restricting direct access to some of an object's data or methods, usually by making attributes private and providing controlled access through public methods.
What is the main purpose of a getter method in object-oriented programming?
The main purpose of a getter method is to provide controlled access to the value of a private attribute in an object without allowing direct modification.
True or False?
Setter methods can be used to enforce validation before updating an object's private attribute.
True.
Setter methods often include validation logic to ensure that only valid values are assigned to private attributes, enforcing controlled access.
Why are attributes usually declared as private in encapsulation?
Attributes are declared as private to restrict direct access from outside the class, thereby protecting the internal state of the object and enforcing encapsulation.
A get method is also known as a or .
A get method is also known as a getter or accessor.
Setter methods are commonly used to the value of an object's private .
Setter methods are commonly used to set the value of an object's private attribute.
Define setter method.
A setter method is a method used to update or modify the value of a private attribute in a class, often including validation logic to enforce certain conditions.
What is the difference between a getter and a setter method in OOP?
A getter method retrieves the value of a private attribute, while a setter method updates or modifies the value of a private attribute, often with validation.
Define polymorphism.
Polymorphism is the ability of different object types to be accessed through the same interface, allowing the correct method to be called depending on the object's actual type at run-time.
What is method overriding in object-oriented programming?
Method overriding is when a subclass provides its own implementation of a method that is already defined in its superclass.
True or False?
Polymorphism allows the same method name to behave differently depending on the object type.
True.
Polymorphism enables the same method name to invoke different behaviors depending on the runtime type of the object.
In run-time polymorphism, a overrides a method of its , and the correct version is chosen at .
In run-time polymorphism, a subclass overrides a method of its superclass, and the correct version is chosen at run-time.
Which object-oriented programming features are essential for implementing polymorphism?
To implement polymorphism, you need inheritance and method overriding.
In the example with Animal, Dog, and Cat classes, what does the function make_sound(animal) demonstrate?
The make_sound(animal) function demonstrates run-time polymorphism, as it calls the correct speak() method based on the actual type of the object passed.
In Python, method overriding is shown when a subclass defines a with the same name as one in its .
In Python, method overriding is shown when a subclass defines a method with the same name as one in its superclass.
True or False?
In Java, a superclass reference can point to a subclass object, enabling polymorphism.
True.
In Java, a superclass reference can refer to a subclass object, which is fundamental to achieving polymorphism.
By signing up you agree to our Terms and Privacy Policy