1.1 Fundamentals of programming Flashcards
Define a memory address
A specific location in memory where instructions or data are stored
Define assignment
The process of giving a value to a variable or constant
What is the difference between a constant and a variable?
A constant is an item of data whose value does not change, whereas a variable is an item of data whose value could change whilst the program is being run
Define debugging
The process of finding and correcting errors in programs
Define declaration
The process of defining variables and constants in terms of their name and data type
Why is naming variables important?
- Makes it easier to debug / find and correct errors in the code
- When several programmers are working on the same program at once, sensible naming conventions can make it easier to understand
- It is easier to update the program at a later date
What is a data type?
A data type determines what sort of data is being stored and how it will be handled by the program
Define an integer
An integer is any whole positive or negative number including 0
Define a real / float
A number with a fractional or decimal part
Define a string
A string is a data type used to store characters
Define boolean
A data type with 2 possible states of True or False
What is a pointer?
A data item that identifies a particular element in a data structure - normally the front or rear
What is an array?
A set of related data items stored under a single identifier. Can work on one or more dimensions
What is an element?
A single value within a set or a list - also called a member
Define a record
One line of a text file
What is the difference between a built in and a user defined data type?
Built in data types are pre-defined by the programming language, whereas user defined data types are created by the programmer for use in the code
Why are user defined data types useful?
- They can make code more efficient and can allow for reusing sections of code
- They can make code easier to read and understand
Define syntax
The rules of how words are used within a given language
Define selection and give an example
The principle of choosing what action to take based on certain criteria, in python this is an if statement
Define nesting
Placing one set of instructions within another set of instructions
Define iteration
The principle of repeating processes
Define definite iteration and give an example
A process that repeats a set number of times, in python this is a for loop
Define indefinite iteration and give an example
A process that repeats until a certain condition is met, in python this is a while loop
What is a sequence?
The principle of putting correct instructions in the right order within a program
Define arithmetic operations
Common expressions such as +, -, x, /
Define rounding
Reducing the number of digits used to represent a number while maintaining a value that is approximately equivalent
Define truncating
The process of cutting off a number after a certain number of characters or decimal places
What is the difference between random and pseudo-random number generation?
Random numbers are generated by a function that produces a completely random number whereas pseudo-random numbers are not 100% random, and are common in programming languages
Define a relational operation
A relational operation is an expression which compares two values such as equal to or greater than
Define a boolean operation
An expression that results in a True or False value
What are the 4 main boolean operators?
- AND: outputs True if both inputs are True
- OR: outputs True if at least one input is True
- NOT: inverts the input such that True becomes False and vice versa
- XOR: outputs True if only one input is True, but not both
Define string handling functions
A string handling function is one which can be carried out on sequences of characters
Define character code
A binary representation of a particular letter, number, or special character
Define event
Something that happens when a program is being run
Why are subroutines useful?
- They can be called at any time using their unique name
- They allow you to gain an overview about how the program is put together
- You can use a top-down approach to develop the whole project
- The program is easier to test and debug as each subroutine is self contained
- Very large projects can be developed by more than one programmer
What is the difference between a function, a subroutine, and a procedure?
Subroutine is the most general term, referring to a collection of processes. A function is a type of subroutine which returns a value, whereas a procedure does not return any value
Define module
A module is a number of subroutines that form part of a program
What are the benefits of using functions in a program?
- Storing complex processes as functions can make code easier to read as it allows them to all be stored in one location, with each reference in the body of the code being short and easy to read
- If you want to edit the function, this only has to be performed in one location rather than in any instance of the function
- For large algorithms that are going to be reused in several places in the code, writing this as a function will be more efficient as it saves the whole function being rewritten each time
What is functional programming?
Functional programming is a programming paradigm which uses functions to create programs
Define parameter
A parameter is data being passed into a subroutine, this behaves like a variable and is a general name referring to the specific value in each individual case
Define argument
An item of data being passed into a subroutine, this refers to the actual value being passed in
Define block interface
Code that describes the data being passed from one subroutine to another
What is the difference between a local and a global variable?
A local variable is specific to the subroutine in which it is declared - local variables in different subroutines can have the same names and not affect each other - whereas global variables apply across the whole code and can be accessed and changed at any point within a program
What are the advantages of local variables?
- You can’t accidentally change a value already being used in the program
- You can use the same variable names in different sections of the program without it referring to the same value
- Memory is saved as local variables are removed from memory after use
Define exception handling
The process of dealing with events that cause the current subroutine to stop
What is a hierarchy chart?
A diagram that shows the design of a system from the top down
What is a structure chart?
Similar to a hierarchy chart but additionally contains information showing how data is passed around the system
What is the top down approach?
When a system is designed starting at the top of a process and working your way down into smaller sub-processes
Define procedural programming languages
Languages where the programmer specifies the steps that must be carried out in order to achieve a result
Define imperative programming languages
Languages based on giving the computer commands or procedures to follow
Give an example of the overall hierarchy of a program
- Programs are made up of modules
- Modules are made up of subroutines and functions
- Subroutines and functions are made up of algorithms
- Algorithms are made up of lines of code
- Lines of code are made up of statements, instructions, and data
Define flowchart
A flowchart is a diagram using standard symbols that describes a process or system
Define system flowchart
A diagram that shows individual processes within a system
Define pseudo-code
A method of writing code which is not specific to a particular programming language
What are naming conventions?
Naming conventions are the processes of giving meaningful names to subroutines, functions, variables, and other user-defined features within a program
What is modular design?
Modular design is a method of system design that breaks a whole system down into smaller units or modules
What are the advantages of an object-oriented approach?
- Programs are written in modules which makes editing easier as only the relevant module will need editing
- It is easy to add functionality by adding a new module
- Modular design makes it easy for several programmers to work on a project at once on separate self-contained modules
- Objects can inherit attributes and behaviours making code reusable
- Changes to data are made within an object rather than the overall program
- Libraries can be created to allow for the easy reuse of code
Define encapsulation
The concept of putting properties, methods, and data in one object
What is a method?
The code or routines contained within a class designed to perform particular tasks on data within the object
Define properties
The defining features of an object or class in terms of its data
Define class
Defines the properties and methods of a group of similar objects
Define object
A specific instance of a class
Define inheritance
The concept that properties and methods in one class can be shared with a subclass. Within the subclass, features can be added or pre-existing features can be changed, but not deleted
What is a class diagram?
A way of representing the relationship between classes
Describe a class diagram
- Hierarchical in structure with base class at the top and sub-classes beneath
- Sub-class inherits properties and methods of base class
- Arrows show direction of inheritance
- Each class is a box of 3 sections, one each for name, properties, and methods
Define instantiation
The process of creating an object from a class
Define polymorphism
The ability of different types of data to be manipulated with the same method
Define overriding
Where a method described in the sub-class takes precedence over one with the same name in the base class
What are the 3 different ways methods can be set up?
- Static: the method can be used without an object of the class being instantiated
- Virtual: the method is defined in the base class but can be overridden in the sub-class where it is used, this is a feature of polymorphism
- Abstract: the method is not in the base class and must be provided in the sub-class
Define aggregation
Aggregation is a method of creating new objects that contain existing objects
What is composition aggregation?
Creating an object which contains other objects, and will cease to exist if the containing object is destroyed
What is association aggregation?
Creating an object that contains other object, which continue to exist even if the containing object is destroyed
What are the 3 key design principle of object-oriented programming?
- Encapsulate what varies: everything that varies should be put into its own class, so properties and methods are split into as many classes as needed to represent the real-life scenario
- Favour composition over inheritance: using composition or aggregation to combine existing objects is much less error prone than inheritance and should be favoured where possible
- Program to interfaces, not implementation: programs should be written around the interface that is created through the defining of methods and classes, rather than the implementation of these interfaces