Procedural Abstraction and Functions Flashcards
abstraction
in comp science: means identifying + naming something complex and then usin that name to refer to the complex thing
data abstraction
eg. design a data structure to hold details about a bank account, call it bank_account
procedural abstraction
eg. give name to piece of code that does something, use name to get that something done
why use functions
- short name, less details on main
- easy to edit details as you have single point of editing
- single point of error-checking + debugging
- reusability
procedural abstraction process
- give name to an algorithm
- use name to execute algorithm within another one
eg. sqrt(x) algorithm for computing sq root
sqrt(789.54)
apply aqrt procedure to 789.54
procedural abstraction in C++
called functions in C++
function
encapsulates + names an algorithm to solve a particular problem
some built in functions
pow(i,n) (cmath) sqrt(x) fabs(x) sin(x) cos(x)
role of functions
- hide detail
- increase readability
- allow reuse of code
- modular software development
readability example
is_a_factor(n,d) more meaningful than
n%d == 0