28
It is a programming analysis tool, that is commonly used for planning the program logic. Pseudo code is made up of two words: pseudo and code . Pseudo means initiation , and code means the set of statements or instructions written in a programming language. Pseudo code act as the outline of a program. It is not the actual programming Language code. It is also called as Program Design Language. Pseudocode is not written using specific syntax of a programming language rather it is written with a combination of generic syntax and normal English language. PSEUDOCODE

Unit3 Foc Ppt Pseudocode

Embed Size (px)

Citation preview

Page 1: Unit3 Foc Ppt Pseudocode

It is a programming analysis tool, that is commonly used for planning the program logic.

Pseudo code is made up of two words: pseudo and code . Pseudo means initiation , and code means the set of statements or instructions written in a programming language.

Pseudo code act as the outline of a program. It is not the actual programming Language code. It is also called as Program Design Language. Pseudocode is not written using specific syntax of a

programming language rather it is written with a combination of generic syntax and normal English language.

PSEUDOCODE

Page 2: Unit3 Foc Ppt Pseudocode

Pseudo code uses some keywords to denote programming processes…

1) For getting Input ◦ READ : Input from a file◦ GET : Input from keyboard

2) For displaying output◦ PRINT : send output to printer◦ WRITE : send output to file◦ PUT, OUTPUT, DISPLAY : send to screen

3) For assigning value to a variable◦ INITIALIZE, SET: giving initial value to a variable◦ 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 3: Unit3 Foc Ppt Pseudocode

4) For performing arithmetic operations + for Add - for Subtract* for Multiply / for Divide( ) for Parentheses

5) For the Comparison of two variables and the selection of one or two alternate actions as the result of the comparison: IF, THEN, and ELSE

6) When there is a sequence of processing steps that need to be repeated (loop statements), keywords, WHILE or DO WHILE are used in pseudo code

Page 4: Unit3 Foc Ppt Pseudocode

To calculate the total mark and average of each student in a class

READ name,class,m1,m2,m3Total = m1+m2+m3Average = Total/3IF Average is greater than 60 Class obtained= First ClassENDIFWRITE name,Total,Average,Class Obtained

Example

Page 5: Unit3 Foc Ppt Pseudocode

Write one statement per line

Each statement in a pseudo code represents a single action and is written on a separate line.

Capitalize Initial Keywords The keywords in the pseudo code should be written in all

capital letters. Ex: READ, WRITE, IF ,ENDIF Indent to show hierarchy Indentation is the process of showing the ‘boundaries’ of

the structure. In the loop or selection structure, we must indicate the

statement which is fall in the loop or selection by using indentation

Rules for Writing Pseudocode

Page 6: Unit3 Foc Ppt Pseudocode

Ex: To find the biggest of the given two numbers

READ a, bIF a>b

PRINT a is greaterELSE

PRINT b is greaterENDIFStop

Here we have used indentation to show which statements are within the IF structure.

Page 7: Unit3 Foc Ppt Pseudocode

End multiline structure The indentation is used to indicate what statements are

executed within the structure Such structures must be ended and it provides increased

clarity. Ex : ENDIF for IF statement

Keep statements language independent Pseudocode can be written using some of the structures or

keywords of any programming language. But it can’t fully depend on any particular language.

Page 8: Unit3 Foc Ppt Pseudocode

It can be done easily in any word processor The pseudo code instructions are easier to modify in

comparison to a flowchart. It can be written easily No special symbols are used. No specific syntax is used. It can be read and understood easily. Converting pseudo code to high level language is very easy

as compared with converting a flowchart to high level language.

Writing the pseudo code involves much less time compared to drawing an equivalent flowchart.

Advantages of pseudo code

Page 9: Unit3 Foc Ppt Pseudocode

It can be quite lengthy for complex problems There is no standard format for developing a pseudo code.

So one pseudo code may be different from another. Pseudocode does not use any kind of pictorial

representations for program elements. So as compared to flowchart it is difficult to understand the program logic.

For a beginner, it is more difficult to follow the logic or write pseudo code as compared to flowchart.

Disadvantages of pseudo code

Page 10: Unit3 Foc Ppt Pseudocode

A program can be developed by using the following three structures

Sequence control structure Selection control structure (Decision

Structure) Iteration control structure (looping)

Program Control Structures

Page 11: Unit3 Foc Ppt Pseudocode

The sequence logic is used for performing instructions one after another.

Here the instructions are written in an order in which they are to be performed.

The logic flow of sequence structure is from top to bottom.

Sequence control structure

Page 12: Unit3 Foc Ppt Pseudocode

Pseudocode

Process 1 Process 2

Process n

Flow chart

General representation of Sequence Control Structure in Pseudo code and flowchart

Process 1

Process 2

Process n

Page 13: Unit3 Foc Ppt Pseudocode

Example: Multiplication of two numbers

Flowchart

START

C = a x b

Print c

Read a , b

STOP

Page 14: Unit3 Foc Ppt Pseudocode

It is also called Decision structure It is used for making decisions. It allows the program to make a choice from

alternative paths. Mainly three constructs are used in Selection

Control Structure IF …THEN IF …THEN… ELSE CASE structure

Selection control structure

Page 15: Unit3 Foc Ppt Pseudocode

The IF …THEN Structure specifies that , if the condition is true, then it carries out the process and if it is false, then it skip over the process.

General representation of IF …THEN Structure in Pseudo code and flowchart

Flowchart

IF …THEN Structure

Pseudocode

IF condition THEN process 1

END IF

If condition

Process 1

YES

NO

Page 16: Unit3 Foc Ppt Pseudocode

Example: To check whether a number is positive or not

Start

Read a

If a>0

Print a is Positive

Stop

no

yes

Page 17: Unit3 Foc Ppt Pseudocode

The IF …THEN …ELSE Structure specifies that , if the condition is true, then it executes process 1, else i.e., if the condition is false, then it executes process 2.

General representation of IF …THEN …ELSE Structure in Pseudo code and flowchart

Flowchart

IF …THEN… ELSE Structure

Pseudocode

IF condition THEN process 1

.

.ELSE process 2

.

.END IF

.

.

YES NO

Process 1 Process 2

If condition

Page 18: Unit3 Foc Ppt Pseudocode

Example: To find the biggest of the given two numbers

Start

Read a,b

If a>b

Print a is GreaterPrint b is Greater

Stop

no

yes

Page 19: Unit3 Foc Ppt Pseudocode

The CASE structure is a multiway selection logic structure.

In the IF …THEN structure and IF …THEN… ELSE structure , we can check maximum of two conditions.

But the CASE structure is used to choose one option from two or more options in the program logic.

It specifies that if the value of Type is equal to Type-1, then it executes Process-1, if it is equal to Type-2, then it executes Process-2, if it is equal to Type-3, then it executes Process-3 and so on.

END CASE is used to indicate the end of the CASE structure

CASE structure

Page 20: Unit3 Foc Ppt Pseudocode

Pseudocode .

. CASE Type

Case Type-1 :

Process -1 Case Type-2 :

Process -2 . .

Case Type-n : Process- n

. . END CASE

General representation of CASE Structure in Pseudo code and flowchart

Flow chart

Type 1

Type 2

Type 3

Process 2

Process 3

yes

yes

yes

Process 1

no

no

no

Page 21: Unit3 Foc Ppt Pseudocode

start

stop

Read m1,m2,m3

Avg=(m1+m2+m3)/3

If Avg>=60

If Avg>=50

If Avg>=35

Fail

Print First Class

Print Second Class

Print Third Class

Example: To Find the Class Obtained by a student by taking student marks as input

yes

yes

yes

No

No

No

Page 22: Unit3 Foc Ppt Pseudocode

This is also called Looping structure. This structure is used for producing loops in

programs. Loops are used to execute some instructions ,

several times based on some condition. The looping continues until the condition is true. Mainly two structures are used in Looping.

WHILE loop DO…WHILE loop

Iteration control structure

Page 23: Unit3 Foc Ppt Pseudocode

In WHILE loop the condition for looping is checked at the beginning of the loop

If the condition is false, then the loop will not be executed, otherwise the loop is executed.

It is top tested loop.

WHILE loop

Page 24: Unit3 Foc Ppt Pseudocode

Pseudocode Flow chart..

WHILE condition..

Body of the loop..

END WHILE

General representation of WHILE loop in Pseudo code and flowchart

Body of The loop

conditionno

yes

Page 25: Unit3 Foc Ppt Pseudocode

ExampleStart

Num=0

Num=Num+1

Print Num

whileNum<5

stop

no

yes

Page 26: Unit3 Foc Ppt Pseudocode

In DO…WHILE loop, the condition for the loop is checked at the bottom.

Hence the body of the loop is executed atleast once irrespective of the condition.

It is the bottom tested loop.

DO…WHILE loop

Page 27: Unit3 Foc Ppt Pseudocode

General representation of DO…WHILE Loop in Pseudo code and flowchart

Pseudocode Flow chart

DO ..

Body of the loop..

WHILE condition..

END DO WHILE

Body of The loop

condition

no

yes

Page 28: Unit3 Foc Ppt Pseudocode

ExampleStart

Num=0

Num=Num+1

Print Num

whileNum<5

stop

no

yes