TUGAS PROGDAS 01 - Program Design and Pseudo Code
TUGAS PROGDAS 01 - Program Design and Pseudo Code
33209 33267
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.
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.
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.
5.
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.
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.
The choice between procedure-driven, Eventdriven or Data-driven program design methodologies is usually determined by the selection of a programming language.
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.
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.
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.
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.
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.
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.
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.
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.
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
Files
y
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.
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
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.
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
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.
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 :
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.
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 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:
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:
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:
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:
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
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