Algorithms & Programs Flashcards
What is an algorithm
A set of rules to solve a specific problem
What are the 3 most common methods for describing an algorithm
Pseudocode
Structured English
Flow Chart
What are 3 good programming practices to follow do that your program can be edited more easily in the future
Self documenting identifiers - suitable names for identifiers
Annotation - describe what the code is doing
Program layout - looks tidy and easy to differentiate different parts
What are parameters
Sets of conditions
Define a variable
A variable is a store of data
What is a constant
A constant is a variable which value doesn’t change during the runtime of a program
What is the lifetime of a variable
The lifetime of a variable is the duration of time for which the variable holds the value during the execution of a program
What is the scope of a variable
The scope of a variable describes the parts of the program in which the variable can be accessed.
E.g. a global variable would have a scope of the entire program
What is a subroutine
Performs a specific task packaged as a unit
What are the advantages of subroutines
Makes the program easier to understand by splitting into smaller chunks
By splitting the program into separate subroutines, it is easier to test each procedure in isolation before being used with the rest of the program
Allows team-working as different members of a team can be allocated different procedures to write
Procedures can be reused in future programs. It is also possible to compile procedures and put them into subroutine libraries so that they can be called from other programs.
What are the two types of subroutine?
Procedures or functions
What is the difference between a function and a procedure?
A function produces am output/returns a value whereas a procedure doesn’t
What is a function?
A section of code that, when programming, can be called by another part of the program with the purpose of returning one single value
What is a procedure?
A section of code which performs a specific task when called from elsewhere in the program
What is a parameter?
Values that can be sent to a procedure and/or received from a procedure
What are the two types of parameters
Value or reference
What is passing by value?
Parameters that are used to pass information into a procedure but which do not receive information back
E.g. this works by sending a copy of the parameter to the procedure so any changes made are to the copy and therefore so not affect the original value
What is passing by reference?
Parameters that need to be able to pass information back.
E.g. this works by sending a copy of the memory address is passed into the procedure and therefore any changes made are to the memory location of the variable sent to the procedure.
Subroutines as a black box, what does this mean?
Separate from the rest of the program, hides the complexity within the subroutines
Ignored by programmers who are developing it ofc
A programmer only need to know the parameters (inputs and outputs) to the procedure and doesn’t need to know how the procedure works (I.e. what goes on inside)
Therefore code inside the procedure can be modified/improved without other parts of the program bring affected as long as it continues to use the same parameters
This is also why global variables are best avoided where possible as these are ways in which the procedure can interact with the rest of the program without using parameters
What are modules
Modules are collections of subroutines (procedures & functions)
Modules should he loosely coupled and highly cohesive, what does this mean?
Loosely coupled - independent or almost independent (they can function completely without the presence of the other) (the module is not much dependent on other modules)
Cohesion - the degree at which different parts of the module related to eachother
E.g. a module used to calculate tax returns should just contain subroutines used in different steps od the tax return process, and not routines used for other parts of the system (the parts of a module fit together to a high degree)
What is validation?
Checking how appropriate the data being entered is
What are the 6 types of validation
Range check - makes sure data is between a min and max val
Presence check - ensures that a particular data item hasn’t been omitted
Length check - could be min or max length of characters entered
Type check - ensures that the correct type of data has been entered e.g. quantity field only contains digits
Format check - correct format e.g. dd/mm/yy
Lookup check - checks the data entered is present in a list of possibilities e.g. confirms a postcode exists
What is verification?
Checking to see if the data entered is consistent
E.g. asking for you to enter password twice when changing it to avoid locking yourself out of your own account