Sie sind auf Seite 1von 36

CHAPTER 1 PROGRAM DESIGN CHAPTER 2 PSEUDOCODE

Muh Anung Darmawan Muhammad Muzani

33209 33267

CHAPTER 1 : PROGRAM DESIGN


To write well-designed programs, we need :


1. 2.

Right tools Right steps to follow

Programming can be defined as the development of a solution to an identified problem, and the setting up of a related series of instructions which, when directed through computer hardware, will produce the desired results.

STEPS IN PROGRAM DEVELOPMENT (1)


There 1.

are seven basic steps in the development of a program


Define the problem.

For initial analysis, the problem should be divided into three separate components:
the inputs the outputs The processing steps to produce the required outputs.
We decompose problem it into smaller tasks or steps

1) 2) 3)

2.

Outline the solution (or user interface).


STEPS IN PROGRAM DEVELOPMENT (2)


3.

Develop the outline into a solution algorithm


We expand the solution outline developed in Step 2 into an algorithm: a set of precise steps that describe exactly the tasks. This step is one of the most important in the development of a program, and we must remember to finish this step. The main purpose of desk checking the algorithm is to identify major logic errors early,

4.

Test the algorithm for correctness.


5.

Code the algorithm into a specific programming language.


We code the program into our chosen programming language.

STEPS IN PROGRAM DEVELOPMENT (3)


6.

Run the program on the computer.


We uses a program compiler and programmer designed test data to machine test the code for syntax errors (those detected at compile time) and logic errors (those detected at run time). Documentation involves both external documentation (such as hierarchy charts, the solution algorithm and test data results) and internal documentation that may have been coded in the program.

7.

Document and maintain the program.


METODOLOGI DESAIN PROGRAM


The fundamental principle of program design is based on the fact that a program accepts input data, processes that data, and then delivers that data as output to the program user. Recently, a number of different approaches to program design have emerged, the most common being:
1. 2. 3.

procedure-driven process/function event-driven event/interaction data-driven data data structure

The choice between procedure-driven, Eventdriven or Data-driven program design methodologies is usually determined by the selection of a programming language.

PROCEDURAL VERSUS OBJECT-ORIENTED PROGRAMMING (1)


1. y

Procedural programming
Procedural programming is based on a structured (tasks or functions ), Top-down approach to writing effective programs. The approach concentrates on 'what' a program has to do and involves identifying and organizing the 'processes' in the program solution. The problem is usually decomposed into separate tasks or functions and includes 1)Top-down development and 2)modular design.

PROCEDURAL VERSUS OBJECT-ORIENTED PROGRAMMING (2)


1)

Top-down development
We, first, outline a general solution to the Problem, then broken down gradually into more detailed steps until finally the most detailed levels have been completed. This systematic, disciplined approach result in a higher precision of programming than was previously possible. programming than was previously possible.

2)

Modular design.
Procedural programming also incorporates the concept of modular design, which involves grouping tasks together because they all perform the same function (for example, calculating sales tax or printing report headings). Modular design is connected directly to Top-down development, as the steps or subtasks, into which the programmer divides the program solution, actually form the future modules of the program. Good modular design also assists in the reading and understanding of the program.

PROCEDURAL VERSUS OBJECT-ORIENTED PROGRAMMING (3)


2.
y

Object-Oriented Programming
Object-oriented programming is also based on decomposing the problem however, the primary focus is on the things (or objects) that make up the program. The program is concerned with how the objects behave, so it breaks the problem into a set of separate objects that perform actions and relate to each other. These objects have definite properties, and each object is responsible for carrying out a series of related tasks.

AN INTRODUCTION TO ALGORITHMS AND PSEUDOCODE (1)


1. y

Algorithm
An algorithm is like a recipe: it lists the steps involved in accomplishing a task. y The algorithm is written in simple English and is not a formal document y to be useful, there are some principles which should be adhered to. An algorithm must:
1) 2) 3)

be lucid, precise and unambiguous give the correct solution in all cases eventually end.

AN INTRODUCTION TO ALGORITHMS AND PSEUDOCODE (2)


2. y

Pseudocode
Pseudocode has been chosen as the primary method of representing an algorithm because it is easy to read and write and allows the programmer to concentrate on the logic of the problem.

AN INTRODUCTION TO ALGORITHMS AND PSEUDOCODE (3)


y

Like many versions of pseudocode, this version has certain conventions, as follows:
Statements are written in simple English. Each instruction is written on a separate line. Keywords and indentation are used to signify particular control structures. Each set of instructions is written from top to bottom, with only one entry and one exit. Groups of statements may be formed into modules, and that group given a name.

PROGRAM DATA (0)


Yang akan dibahas


Variable, constants, lieteral y Data types y Files y Data Validation
y

PROGRAM DATA (1)


Variables, constants and literals


Variable : It is called a variable because the value stored in those memory cells may change or vary as the program executes y Constant : a data item with a name and a value that remain the same during the execution of the program. For example, the name 'fifty' may be given to a data item that contains the value 50. y Literal : a constant whose name is the written representation of its value. For example, the program may contain the literal '50'.
y

PROGRAM DATA (2)


Data types
y

At the beginning of a program, the programmer must clearly define the form or type of the data to be collected. The data types can be elementary data items or data structures.
1.

Elementary data items Ada 4 : Integer, real, character, boolean

PROGRAM DATA (3)


2.

Data structures Record


y

all collection of data items or fields bear some relationship to one another. For example, a student record may contain the student's number, name, address and enrolled subjects. For example, a student file may contain a collection of the above student records.

file: a collection of records.


y

PROGRAM DATA (4)


Array
y

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. For example, an array called 'scores' may contain a collection of students exam scores. Access to the individual items in the array is made by the use of an index or subscript beside the name of the array for example, scores (3). a collection of characters that can be fixed or variable. For example, the string 'Jenny Parker' may represent a student's name.

String
y

PROGRAM DATA (5)


Files
y

The major advantages of using files are:


Several different programs can access the same data. The data can be entered and reused several times. The data can be easily updated and maintained. The accuracy of the data is easier to enforce.

There are two different methods of storing data on files:


sequential or text files, where data is stored and retrieved sequentially. direct or random access files, where data is stored and retrieved random using a key or index.

Sequential files may be opened to read or to write, but not both operations on the same file. Random access files can be opened to read and write on the same file.

PROGRAM DATA (6)


Data Validation
y

Data should always undergo a validation check before it is processed by a program. Different types of data require different checks for example:
1.

2.

3.

4. 5.

Correct type: the input data should match the data type definition stated at the beginning of the program. Correct range: the input data should be within a required set of values. Correct length: the input data for example, string should be the correct length. Completeness: all required fields should be present. Correct date: an incoming date should be acceptable.

CHAPTER 2 : PSEUDOCODE

HOW TO WRITE PSEUDOCODE (1)


Six basic computer operations


1.

A computer can receive information


Read is usually used when the algorithm is to receive input from a record on a file Get is used when the algorithm is to receive input from the keyboard. Print is usually used when the output is to be sent to the printer Write is used when the output is to be written to a file. Put, Output or Display are used when the output is to be written to the screen.

2.

A computer can put out information


HOW TO WRITE PSEUDOCODE (2)


3.

A computer can perform arithmetic


The equal symbol '=' has been used to indicate assignment of a value as a result of some processing. The following symbols (from high level language) can be written in pseudocode: + for Add - for Subtract * for Multiply / for Divide () for Parentheses The verbs Compute and Calculate are also available

HOW TO WRITE PSEUDOCODE (3)


4.

A computer can assign a value to a variable or memory location


To give data an initial value in pseudocode, the verbs Initialize or Set are used. To assign a value as a result of some processing, the symbols '=' or ' ' are written. To keep a variable for later use, the verbs Save or Store are used.

HOW TO WRITE PSEUDOCODE (4)


5.

A computer can compare two variables and select one of two alternate actions
An important computer operation available to the programmer is the ability to compare two variables and then, as a result of the comparison, select one of two alternate actions. To represent this operation in pseudocode, special keywords are used: IF, THEN and ELSE. Contoh :

HOW TO WRITE PSEUDOCODE (5)


6.

A computer can repeat a group of actions


When there is a sequence of processing steps that need to be repeated, Two special keywords, DOWHILE and ENDDO, are used in pseudocode. Contoh :

MEANINGFUL NAMES

When designing a solution algorithm, a programmer must introduce some unique names, which will be used to represent the variables or objects in the problem. All names should be meaningful. A name given to a variable is simply a method of identifying a particular storage location in the computer Should be transparent enough to adequately describe the variable). If you need to use more than one word in a variable name, then underscores are useful as word separators _ for example, sales_tax and word_count.

THE STRUCTURE THEOREM (0)


The three basic control structures


1. 2. 3.

Sequence Selection Repetition

THE STRUCTURE THEOREM (1)


1.

Sequence
The sequence control structure is the straightforward execution of one processing step after another. In pseudocode, we represent this construct as a sequence of pseudocode statements.

THE STRUCTURE THEOREM (2)

The sequence control structure can be used to represent the first four basic computer operations listed previously: to receive information, put out information, perform arithmetic, and assign values. For example, a typical sequence of statements in an algorithm might read:

THE STRUCTURE THEOREM (3)


2.

Selection
The selection control structure is the presentation of a condition and the choice between two actions, the choice depending on whether the condition is true or false. This construct represents the decision-making abilities of the computer and is used to illustrate the fifth basic computer operation, namely to compare two variables and select one of two alternate actions. In pseudocode, selection is represented by the keywords IF, THEN, ELSE and ENDIF:

THE STRUCTURE THEOREM (4)


If condition p is true, then the statement or statements in the true case will be executed, and the statements in the false case will be skipped. Otherwise (the ELSE statement) the statements in the true case will be skipped and statements in the false case will be executed. In either case, control then passes to the next processing step after the delimiter ENDIF. A typical pseudocode example might read:

(The selection control structure is discussed fully in Chapter 4.)

THE STRUCTURE THEOREM (5)


3.

Repetition The repetition control structure can be defined as the presentation of a set of instructions to be performed repeatedly, as long as a condition is true. The basic idea of repetitive code is that a block of statements is executed again and again, until a terminating condition occurs. This construct represents the sixth basic computer operation, namely to repeat a group of actions. It is written in pseudocode as:

THE STRUCTURE THEOREM (6)


The DOWHILE loop is a leading decision loop that is, the condition is tested before any statements are executed. If the condition in the DOWHILE statement is found to be true, the block of statements following that statement is executed once. The delimiter ENDDO then triggers a return of control to the retesting of the condition. If the condition is still true, the statements are repeated, and so the repetition process continues until the condition is found to be false. Control then passes to the statement that follows the ENDDO statement. It is imperative that at least one statement within the statement block alters the condition and eventually renders it false, because otherwise the logic may result in an endless loop.

THE STRUCTURE THEOREM (7)


Here is a pseudocode example that represents the repetition control structure:

This example illustrates a number of points:


1)

2)

3)

The variable student_total is initialized before the DOWHILE condition is executed. As long as student_total is less than 50 (that is, the DOWHILE condition is true), the statement block will be repeated. Each time the statement block is executed, one instruction within that block will cause the variable student_total to be incremented

THE STRUCTURE THEOREM (8)


4)

After 50 iterations, student_total will equal 50, which causes the DOWHILE

condition to become false and the repetition to cease. It is important to realize that the initializing and subsequent incrementing of the variable tested in the condition is an essential feature of the DOWHILE construct. (The repetition control structure is discussed fully in Chapter 5.)

THE END

Das könnte Ihnen auch gefallen