36
CHAPTER 1 PROGRAM DESIGN CHAPTER 2 PSEUDOCODE Muh Anung Darmawan 33209 Muhammad Muzani 33267

TUGAS PROGDAS 01 - Program Design and Pseudo Code

Embed Size (px)

Citation preview

Page 1: TUGAS PROGDAS 01 - Program Design and Pseudo Code

CHAPTER 1 PROGRAM DESIGN CHAPTER 2 PSEUDOCODE

Muh Anung Darmawan 33209

Muhammad Muzani 33267

Page 2: TUGAS PROGDAS 01 - Program Design and Pseudo Code

CHAPTER 1 : PROGRAM DESIGN

To write well-designed programs, we need :1. Right tools2. 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.

Page 3: TUGAS PROGDAS 01 - Program Design and Pseudo Code

STEPS IN PROGRAM DEVELOPMENT (1)

There are seven basic steps in the development of a program1. Define the problem.

For initial analysis, the problem should be divided into three separate components:

1) the inputs2) the outputs3) The processing steps to produce the required

outputs.

2. Outline the solution (or user interface). We decompose problem it into smaller tasks or steps

Page 4: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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.

4. Test the algorithm for correctness. 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,

5. Code the algorithm into a specific programming language.

We code the program into our chosen programming language.

Page 5: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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).

7. Document and maintain the program. 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.

Page 6: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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. procedure-driven → process/function2. event-driven → event/interaction3. data-driven → data → data structure

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

Page 7: TUGAS PROGDAS 01 - Program Design and Pseudo Code

PROCEDURAL VERSUS OBJECT-ORIENTEDPROGRAMMING (1)

1. 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.

Page 8: TUGAS PROGDAS 01 - Program Design and Pseudo Code

PROCEDURAL VERSUS OBJECT-ORIENTEDPROGRAMMING (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.

Page 9: TUGAS PROGDAS 01 - Program Design and Pseudo Code

PROCEDURAL VERSUS OBJECT-ORIENTEDPROGRAMMING (3)

2. 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.

Page 10: TUGAS PROGDAS 01 - Program Design and Pseudo Code

AN INTRODUCTION TO ALGORITHMS AND PSEUDOCODE (1)

1. Algorithm An algorithm is like a recipe: it lists the steps

involved in accomplishing a task. The algorithm is written in simple English and is

not a formal document to be useful, there are some principles which

should be adhered to. An algorithm must:1) be lucid, precise and unambiguous2) give the correct solution in all cases3) eventually end.

Page 11: TUGAS PROGDAS 01 - Program Design and Pseudo Code

AN INTRODUCTION TO ALGORITHMS AND PSEUDOCODE (2)

2. 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.

Page 12: TUGAS PROGDAS 01 - Program Design and Pseudo Code

AN INTRODUCTION TO ALGORITHMS AND PSEUDOCODE (3)

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.

Page 13: TUGAS PROGDAS 01 - Program Design and Pseudo Code

PROGRAM DATA (0)

Yang akan dibahas Variable, constants, lieteral Data types Files Data Validation

Page 14: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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

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.

Literal : a constant whose name is the written representation of its value. For example, the program may contain the literal '50'.

Page 15: TUGAS PROGDAS 01 - Program Design and Pseudo Code

PROGRAM DATA (2)

Data types 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

Page 16: TUGAS PROGDAS 01 - Program Design and Pseudo Code

PROGRAM DATA (3)

2. Data structures Record

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.

file: a collection of records. For example, a student file may contain a collection of

the above student records.

Page 17: TUGAS PROGDAS 01 - Program Design and Pseudo Code

PROGRAM DATA (4)

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. 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).

String a collection of characters that can be fixed or

variable. For example, the string 'Jenny Parker' may represent a student's name.

Page 18: TUGAS PROGDAS 01 - Program Design and Pseudo Code

PROGRAM DATA (5) Files

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.

Page 19: TUGAS PROGDAS 01 - Program Design and Pseudo Code

PROGRAM DATA (6)

Data Validation Data should always undergo a validation check

before it is processed by a program. Different types of data require different checks – for example:

1. Correct type: the input data should match the data type definition stated at the beginning of the program.

2. Correct range: the input data should be within a required set of values.

3. Correct length: the input data – for example, – string should be the correct length.

4. Completeness: all required fields should be present.

5. Correct date: an incoming date should be acceptable.

Page 20: TUGAS PROGDAS 01 - Program Design and Pseudo Code

CHAPTER 2 : PSEUDOCODE

Page 21: TUGAS PROGDAS 01 - Program Design and Pseudo Code

HOW TO WRITE PSEUDOCODE (1)

Six basic computer operations1. 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.

2. A computer can put out information 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.

Page 22: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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

Page 23: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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.

Page 24: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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 :

Page 25: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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 :

Page 26: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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.

Page 27: TUGAS PROGDAS 01 - Program Design and Pseudo Code

THE STRUCTURE THEOREM (0)

The three basic control structures1. Sequence2. Selection3. Repetition

Page 28: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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.

Page 29: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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:

Page 30: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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:

Page 31: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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.)

Page 32: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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:

Page 33: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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.

Page 34: TUGAS PROGDAS 01 - Program Design and Pseudo Code

THE STRUCTURE THEOREM (7) Here is a pseudocode example that represents the

repetition control structure:

This example illustrates a number of points:1) The variable student_total is initialized before the

DOWHILE condition is executed.2) As long as student_total is less than 50 (that is, the

DOWHILE condition is true), the statement block will be repeated.

3) Each time the statement block is executed, one instruction within that block will cause the variable student_total to be incremented

Page 35: TUGAS PROGDAS 01 - Program Design and Pseudo Code

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.)

Page 36: TUGAS PROGDAS 01 - Program Design and Pseudo Code

THE END