Fundamentals of Programming (C1) Flashcards
(20 cards)
Define the character & string datatype
A character is a single letter, digit or symbol.
A string is a sequence of characters.
What is the pointer/reference datatype?
Stores a memory address pointing to where data is stored.
What is a record data type?
A data structure which stores multiple relates items of data under a single unit.
Define an array
A collection of items of the same data type stores in a fixed-size list.
What is variable/constant declaration?
- Declaring a named memory location to store data which can change.
- Declaring a named value which cannot be changed after it’s declared.
What is assignment and declaration.
- The process of defining variables and constants in terms of their name and data type.
- The process of giving a value to a pre-existing variable.
What is selection and subroutines in code?
Selection: Runs code based on whether it meets set conditions or not.
Subroutine: A block of code which can be run from anywhere in a program, function returns a value, procedure does not.
Advantages of exception handling
- Prevents program from crashing
- Give helpful error messages.
- Reduces the need for multiple if statements.
- Shows you exactly what type of error happened and where it occurred.
Advantages of subroutines
- Break program into logical sections.
- Avoid repeated code..
- Easier testing and debugging.
- Improve readability (each block of code has a purpose).
- Allows for modular development.
Define recursion
A technique where the subroutine calls itself in order to solve a problem, with a base case and recursive case.
What are the base and recursive cases in recursion?
- Base case is the condition which stops the recursion, and returns a result without calling the function again.
- Recursive case is when the function calls itself with a modified input.
Advantages to object oriented programming
- Programs are written in modules, so they can easily be amended as only the particular module needs editing.
- Easily add functionality by adding a new module.
- Modular design allows teams of programmers to work on different self-contained modules.
- Object can inherit attributes and behaviours making code reusable.
- Changes made are made within an object, so they’re less likely to affect other code in the program, reducing risk of bugs.
- Libraries can be made enabling the reuse of code.
What is encapsulation?
Encapsulation is an OOP principle where data (attributes) and methods are bundled together inside a class, and the internal data is made private so it can only be accessed or modified through public methods or properties.
What are the benefits of encapsulation?
- Security: sensitive data is hidden from outside interference
- Control: access to data is only through approved public methods (e.g. validation)
- Maintainability: internal implementation can change without affecting other code
- Reusability: clean, self-contained objects are easier to reuse
- Cleaner interface: only necessary details are exposed to the outside
What is polymorphism?
Polymorphism allows different objects to respond differently to the same method call, based on the class they were created from.
What are the two types of polymorphism?
- Overriding is when a subclass provides a new version of a method that already exists in its parent class.
- The method in the child class replaces the parent version at runtime, allowing specialised behaviour for that subclass.
Static Methods
The method can be used without an object of the class being instantiated
Virtual Methods
The method is defined in the base class but can be overridden by the method in the subclass where it will be used. This is a feature of polymorphism.
Abstract Methods
The actual method is not supplied in the base class, which means that it must be provided in the subclass. In this case, the object is being used as an interface between the method and the data.