|
Top-Down Approach
Take the original problem and break it down into smaller pieces - divide and conquer
- 1. problem analysis
- 2. top-down design: break large, complex problems into smaller simpler ones
- 3. top-down programming: write (and test!) high-level modules before low-level modules
Don't form bad habits! Test each piece of code before writing the next!
- Start with the big picture leaving the details vague
- Work your way down to greater detail
- Each task is identified with a capitol letter
- Each level is identified with a number (start with 0)
(see PowerPoint presentation)
CALL SubprogramName (parameter1, p2, p3 ...)
putting STATIC after the parameter list keeps the parameters from being reinitialized on the next call to the subroutine.
Subprograms end with END SUB (actually, the editor puts it in for you)
QBasic will automatically put in DECLARE statements in MAIN to declare the subroutines
Internal subprograms are part of the same program External Subprograms:
- separate and distinct
- part of another program
- Qbasic library
Stubs - hold the "place" of a subroutine before it is coded
SUB StubSub PRINT " You are in subprogram StubSub" END SUB
Debug after each level to make sure program flow is OK, using stubs in place of coded subprograms. (Yes, I said this before and I’ll probably say it again)
Each Subprogram should start with a comment box
Indent content of subprogram 3 spaces
nested subprogram - A subprogram called by a different subprogram
SAVE will save both main and its subs
|