Download presentation
Presentation is loading. Please wait.
Published byDerrick Hill Modified over 9 years ago
1
The Pseudocode Programming Process Chapter 9
2
Summary of Steps in Building Classes and Routines
3
Steps in Creating a Class 1) Create a general design for the class –Define the class’s specific responsibilities. –Define what “secrets” the class will hide. –Determine whether the class will be derived from another class, and whether other classes will be allowed to derive from it. –Identify the class’s key public methods. –Identify and design any non trivial data members used by the class.
4
Steps in Creating a Class.. continue 2) Construct each routine within the class - See next slides … 3) Review and test the class as a whole - After the class as a whole becomes operational, the class as a whole should be reviewed and tested
5
Steps in Building a Routine The major activities involved in creating a routine are –designing the routine, –checking the design, –coding the routine, and –checking the code
6
Steps in Building a Routine
7
Experts have developed numerous approaches to creating routines, and one of the favorite approach is the Pseudocode Programming Process Or PPP
8
Pseudocode Programming Process an informal, English-like notation for describing how an algorithm, a routine, a class, or a program will work. defines a specific approach to using pseudocode to streamline the creation of code within routines.
9
Guidelines for using pseudocode effectively Use English-like statements that precisely describe specific operations. Avoid syntactic elements from the target programming language. Describe the meaning of the approach rather than how the approach will be implemented in the target language. Refine the pseudocode in more and more detail until it seems as if it would be easier to simply write the code.
10
Example of Good Pseudocode Keep track of current number of resources in use If another resource is available Allocate a dialog box structure If a dialog box structure could be allocated Note that one more resource is in use Initialize the resource Store the resource number at the location provided by the caller Endif Return TRUE if a new resource was created; else return FALSE
11
Example of Bad Pseudocode increment resource number by 1 allocate a dlg struct using malloc if malloc() returns NULL then return 1 invoke OSrsrc_init to initialize a resource for the operating system *hRsrcPtr = resource number return 0
12
The previous example is bad Pseudocode because.. it includes coding details such as *hRsrcPtr in specific C-language pointer notation, and malloc(), a specific C- language function It focuses on how the code will be written rather than on the meaning of the design. It gets into coding details—whether the routine returns a 1 or a 0
13
Example Write a Pseudocode to read 10 numbers and find out the average
14
Set default summation to 0 If number of read numbers less than 10 Read another number Add it to summation Endif Divide summation by 10 and print the result
15
The benefits you can expect from using this style of pseudocode 1) Pseudocode makes reviews easier. –You can review detailed designs without examining source code 2) Pseudocode makes changes easier. –A few lines of pseudocode are easier to change than a page of code. 3) Pseudocode minimizes commenting effort. –In the PPP, the pseudocode statements become the comments 4) Pseudocode is easier to maintain than other forms of design documentation.
16
Constructing Routines Using the PPP ● Design the routine ● Code the routine ● Check the code ● Clean up leftovers ● Repeat as needed
17
Design the routine Check the prerequisites Define the problem the routine will solve Name the routine Decide how to test the routine Think about error handling Think about efficiency Research functionality available in the standard libraries Research the algorithms and data types Write the pseudocode Check the pseudocode Try a few ideas in pseudocode, and keep the best (iterate)
18
Code the Routine Write the routine declaration Turn the pseudocode into high-level comments Fill in the code below each comment Check whether code should be further factored
20
Check the Code Mentally check the routine for errors Compile the routine Step through the code in the debugger Test the code Remove errors from the routine
21
Clean Up Leftovers Check the routine’s interface. (all parameters used) Check for general design quality Check the routine’s data. Check the routine’s statements and logic. Check the routine’s layout. Check the routine’s documentation Remove redundant comments.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.