48024 Lecture Notes - Lecture 3: Code Reuse
Study 3: Process
Procedural Programming
• Breaking up the program into different procedures
• Each sub goal does into their own method.
• Start with the main method/procedure.
• Code reuse is the main benefit of splitting code into small methods.
Process #1 – Key/Framework Approach
• Goal – what a program should achieve
• Plan – Steps to achieve a goal (English, patterns to use)
• Key – key line of code that most directly achieves the goal.
• The framework is whatever code supports the key. Can be replaced depending on
where the information source is coming back.
Process #2 – Incremental Goals
• Used to tackle really large processes.
• Simplify goal then add to the goal incrementally until the whole goal is tackled.
Integer Division
• No decimal places. Rounds down
• The % operator, odulus, gives the reaider fro a divisio operatio. To
extract digits from a number:
o The last digit of a number is:
▪ Number % 10
o To remove the last digit:
▪ Number / 10
o To obtain the first digit of an N-digit number:
▪ Number / 10 … n-1 times
o To obtain a digit somewhere in the middle, combine:
▪ /10 and %10
Testing
• Dot test every possible iput
• Devise a finite set of cases that are representative of all scenarios.
o Middle cases
o Edge cases
o Off by Oe errors
o Invalid Inputs
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
Procedural programming: breaking up the program into different procedures, each sub goal does into their own method, start with the main method/procedure, code reuse is the main benefit of splitting code into small methods. Can be replaced depending on where the information source is coming back. Process #2 incremental goals: used to tackle really large processes, simplify goal then add to the goal incrementally until the whole goal is tackled. Rounds down: the (cid:858)%(cid:859) operator, (cid:862)(cid:373)odulus(cid:863), gives the re(cid:373)ai(cid:374)der fro(cid:373) a divisio(cid:374) operatio(cid:374). Testing: do(cid:374)(cid:859)t test every possible i(cid:374)put, devise a finite set of cases that are representative of all scenarios, middle cases, edge cases, (cid:862)off by o(cid:374)e(cid:863) errors.