C) Programming Paradigms Flashcards
What are some data types?
- Boolean: true or false
- character: a single item e.g. a letter or a number
- float: a decimal number
- integer: a whole number
- string: one or more characters
Why are constants useful?
They protect from the value being accidentally changed and they can make a program easier to read and maintain.
What is the difference between declaring and defining a variable?
Declaring a variable is creating it, whereas defining a variable is setting/changing it.
Why is it important to give variables meaningful names?
- more readable
- easier to maintain
- easier to debug
What are some common naming conventions?
- camelCase
- snake_case
- PascalCase
What is a reserved word?
A set of words that cannot be used as identifiers, including instructions of the programming language.
What is the difference between local and global variables?
These are known as the scope of a variable, which refers to what parts of the program can access the data stored by the variable. Global variables are accessible throughout the entire code, whereas local variables are only accessible within the function they are declared in.
Why is it better to use local variables in a function rather than global?
They are more efficient as they only take up memory when the subprogram is running. They also increase code security as the values can only be accessed and altered within specific sections of the code.
What are the standard arithmetic operators?
- adds one value to another
- subtracts one value from another
- / divides one value by another
- multiplies one value by another
- % returns the remainder of dividing one value by another
- DIV (integer division) divides one value by another, ignoring any remainder
What is a relational operator and what are the standard relational operators.
They allow us to compare values and return either true or false.
- == returns true if both values are the same
- != returns true if both values are not the same
- = sets the value of a variable
- > returns true if a value is greater than another
- < returns true if a value is less than another
- >= returns true if a value is greater than or equal to another
- <= returns true if a value is less than or equal to another
What is a logical operator and what are the standard logical operators?
Allow multiple relational operators to eb combined for more complex expression.
- AND returns true if both conditions together are true
- OR returns true if either condition (or both) is true
- NOT returns true if the condition is false and vise versa
What is a function?
A named section of code that performs a set task when called. they are used to make code more readable, maintainable and reusable.
What is a library and what are their advantages/disadvantages?
A collection of predefined code that can be used in programs.
adv:
- saves time
- code in libraries have been extensively tested
disadv:
- you are relying on code someone else has produced
What are some common built-in arithmetic functions?
- random number generation
- generating a range of numbers
- rounding numeric values
What are some common built-in string handling functions?
- returning the length of a string
- extracting characters from a string
- returning substrings
- concatenation (joins two or more strings together)
- conversion (strings to arithmetic values)
- truncation (trims a string to a specified length)
What are some common built-in general purpose functions?
- input/output
- file handling
What are some functions of file handling and the modes of files?
functions:
- open opens a file for reading or writing
- close closes a file so that other programs can use it
- read reads data from a file into RAM
- write writes data from RAM to a file
modes:
- read allows data to be read from the file but not changed
- write allows data to be written to a file overwriting previous content
- append adds new data to the end of the file, leaving previous data unchanged
What is validation and why is it important?
Checks that data input into a system meets a series of requirements. It is only as good as the criteria used. It ensures code is secure and can prevent cybercriminals from doing serious damage.
What is verification?
Checks that no errors have been introduced when data is input.
What are the types of validation check?
- Data type check: checks that data is the correct type
- Range check: checks that data is within a set range
- Length check: checks that the number of characters in a string is within the predefined range
- Presence check: checks whether data is present or not
- Format check: checks whether data is in a predefined format e.g. dd/mm/yy for dates
- Spelling check: checks whether words can be found within a predefined dictionary
- Constraints check: rules than an input must meet
- Check digits: a character that is calculated based on the value of a specified piece of data using an algorithm. If the character is different from the stored value, it is invalid.
What are some post-check actions?
Error handling allows software to manage invalid or unusual inputs.
Error reporting provides useful information to inform users of what is correct, or to help a programmer debug their code
What are the three basic control structures?
- Sequence: when instructions run one after another
- Selection: when a program can branch into different sequences depending on the condition
- Iteration: when a part of a program loops until a condition is met, or sometimes forever
What is the difference between pre-condition and post-condition loops and what are some examples?
A pre-condition loop is when the condition determining if the loop will run takes place at the beginning of the loop e.g. for loops and while loops. A post-condition loops is when the condition determining if the loop will run takes place at the end of the loop e.g. repeat… until loops.
What are some examples of data structures?
- array
- list
- record
- set