02 Program Design
02 Program Design
02 Program Design
Bimo Sunarfri Hantono Electrical Engineering and Information Technology Gadjah Mada University
Objective
To describe the steps in the program development process To introduce current program design methodology To introduce procedural and object-oriented programming To introduce algorithms and pseudocode To describe program data
Algorithm
Named after: Muhammad ibn Musa al-Khwarizmi of Khowarezm (now Khiva in Uzbekistan) Circa 780-850 C.E. (Common Era) Book on arithmetic:
Hindu numeration, decimal numbers, use of zero, method for nding square root Latin translation (c.1120 CE): Algoritmi de numero Indorum
Book on algebra
Hisab al-jabr wal-muqabala
Algorithm
A sequence of instructions specifying the steps required to accomplish some tasks Examples
A cooking recipe Assembly instructions for a model The rules of how to play a game Directions for driving from A to B A knitting pattern A car repair manual etc
Components of an Algorithm
Values represent quantities, amounts or measurements. May be numerical or alphabetical (or other things). Variables are containers for values, place to store values. Variables may be restricted to contain a specic type of value. Instructions should be simple and unambiguous, the system knows about and should be able to actually do. Sequences (of instruction) Selections (between instructions) Repetitions (of instructions) Procedures Documentation
An Algorithm Conclusion
An algorithm must:
simple lucid precise unambiguous give the correct solution eventually end
Outline the solution Develop the outline into an algorithm Test the algorithm for correctness Code the algorithm into a specic programming language Run the program on the computer Document and maintain the program
Develop the outline into an algorithm Test the algorithm for correctness Code the algorithm into a specic programming language Run the program on the computer Document and maintain the program
Test the algorithm for correctness Code the algorithm into a specic programming language Run the program on the computer Document and maintain the program
Code the algorithm into a specic programming language Run the program on the computer Document and maintain the program
Data Validation
Data should always undergo a validation check before it is processed by a program. Different types of data require different check, for example:
Correct type: the input data should match the data type denition stated at the beginning of the program. Correct range: the input should be within a required set of values. Correct length: the input data should be the correct length. Completeness: all required elds should be present. Correct date: an incoming data should be acceptable.
Dening Diagram:
Input Number1 Number2 Number3 Processing Output Total
Dening Diagram:
Input Number1 Number2 Number3 Processing Output Total
Dening Diagram:
Input Number1 Number2 Number3 Processing Read three numbers Add numbers together Print total number Output Total
Data Types
Should be clearly dened at the beginning of the program. Can be:
Elementary data items Data structures
Data Structures
Data structure is an aggregate of other data items. Its component could be elementary data items or another data structure. Data is grouped together in a particular way to reects the situation with which the program is concerned. The most common data structures
String: a collection of characters that can be xed or variable. Array: a data structure that is made up of a number of variables or data items that all have the same data type and are accessed by the same name. Record: a collection of data items or elds that all bear some relationship to one another. File: a collection of records.
Files
A popular method to enter and store information. Major advantage of using les are:
Several different program can access the same data Data can be entered and reused several times. Data can be easily updated and maintained. The accuracy of the data is easier to enforce.
Thank You