Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 33

The step-by-step procedure of

solving a problem.
A. End Point
B. Starting Point
C. Algorithm
D. Outcome
What is the second step in the algorithm of a
program asking a user for an email address.

A. Ask the user for an email address.


B. Create a variable to receive the user’s
email address.
C. Store the response in the variable.

D. Check the stored response to


see if it is a valid email address.
What is the fourth step in the algorithm of a
program asking a user for an email address.
A. Clear the variable in case it’s not
empty.
B. Ask the user for an email address.
C. Check the stored response to see
if it is a valid email address.
D. Store the response in the
variable.
What is the fourth step in the algorithm of a
program asking a user for an email address.

A. Store the response in the variable.


B. Clear the variable in case it’s not
empty.
C. Check the stored response to see
if it is a valid email address.
D. Ask the user for an email address.
What is the sixth step in the algorithm for
asking a user for an email address.

A. Check the stored response to see


ifB.itAsk
is a the
valid email address.
user for an email address.
C. Clear the variable in case it’s not
empty.
D. Store the response in the
variable.
PSEUDOCODE
P seudocode
• It means:
• IMITATION or FALSE CODE
• It is an imitation of the computer
instruction.
• Using this programmer can concentrate
on developing logic without worrying
about syntax.
• Easy to convert into programming
language.
Writing Pseudocode
Basic computer operations
There are six basic computer operations
1. Computer can receive information.
2. Computer can put out information.
3. Computer can perform arithmetic.
4. Computer can assign a value to a variable
or memory location.
5. Computer can compare two variables and
select one of two alternate actions.
6. Computer can repeat a group of actions.
Six Basic Computer Operations
1. A computer can receive information
– When a computer is required to receive
information or input from a particular source,
whether it is a terminal, a disk or any other
device, the verbs Read and GetExample
are used in
pseudocode
Pseudocode.
1.Read student name
2.Get system data
Read => Input from a record 3.Read number1, number2
Get => Input from keyboard 4.Get tax_code
5
Six Basic Computer Operations
2. A computer can put out information
– When a computer is required to supply
information or output to a device, the verbs
Print, Write, Put, Output, or Display are used
in pseudocode
– Print => send output to printer

– Write => send out to file Example pseudocode


1.Print ‘Program Completed’
– Put, Output, Display => send 2.Write customer record to master file
3.Output total tax
to screen 4.Display ‘End of data’
6
Six Basic Computer Operations
3 A computer can perform arithmetic
– Most programs require the computer to perform some sort of
mathematical calculation, or formula, and for these, a
programmer may use either actual mathematical symbols or the
words for those symbols
– To be consistent with high-level programming languages, the
following symbols can be written in pseudocode:
+ for Add - for Subtract
* for Multiply / for Divide ( ) for Parentheses
– When writing mathematical calculations for the computer,
standard mathematical ‘order of operations’ applies to
pseudocode and most computer languages.

7
Six Basic Computer Operations
4. A computer can assign a value to a variable or
memory location.
– There are three cases where you may write pseudocode
to assign a value to a variable or memory location:
1. To give data an initial value in pseudocode, the verbs
Initialize or Set are used

2. To assign a value as a result of some processing the symbols


‘=‘ or ‘’ are written

3. To keep a variable for later use, the verbs Save or Store are
used.

8
Six Basic Computer Operations
4 A computer can assign a value to a variable
or memory location
Example pseudocode

1.Initialize total_price to zero


2.Set student_count to zero
3.Total_price = cost_price + sales_tax
4.Total_price  cost_price + sales_tax
5.Store customer_num in last_customer_num

9
Six Basic Computer Operations
5. A computer can compare two variables and
select one or 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 and ELSE.

10
The Selection Structure

yes no
amount < 100

interestRate = .06 interestRaate = .10

1. IF amount < 100


1. interestRate = .06
2.
Pseudocode  ELSE2.1 Interest Rate = .10
Six Basic Computer Operations
6. A computer can repeat a group of actions

– When there is a sequence of processing steps that need to be


repeated, a special keyword, WHILE is used in pseudocode

– The condition for the repetition of a group of actions is


established in the WHILE clause, and the actions to be
repeated are listed beneath it.

12
Repetition using WHILE
Start 1. count = 0
2. WHILE count < 10
count = 0
2.1 ADD 1 to count
2.2 WRITE count
3. WRITE “The End”
count
Mainline
<10

1.count = 0 Modular
Write
add 1 to “The End” 2.DOWHILE count < 10
count
2.1 DO Process
Stop 3.WRITE “The End”
write count
Process
1. ADD 1 to count
2. WRITE count
RulesforPseudocode
• Write only one statement per
line.
• Capitalize initial keyword.
• Indent to show hierarchy.
• End multiline structures.
• Keep statements language
independent.
One S tatement P er L ine
Each statement inpseudocode should
express just one action for the computer.

Pseudocode
READ name, hoursWorked, payRate gross =
hoursWorked * payRate WRITE name,
hoursWorked, gross
CapitalizeInitialKeyword

In the example below note the words:READ and


WRITE.These are just a few of the keywords to
use,others include:

READ,WRITE,IF,ELSE,ENDIF,WHILE,ENDWHILE
Pseudocode
READ name, hoursWorked, payRate
gross = hoursWorked * payRate WRITE
name, hoursWorked, gross
Rules for Variable Names

• Begin with lowercase letter


• Contain no spaces
• Additional words begin with capital
• Unique names within code
• Consistent use of names
IndenttoShowHierarchy
Each design structure uses a particular
indentation pattern
• Sequence:
Keep statements in sequence all starting in the same column.

• Selection:
Indent statements that fall inside selection structure,but not the keywords
that form the selection.
• L oop:
Indent statements that fall inside the loop but not keywords that form
the loop.
READ name, grossPay, taxes
IF taxes > 0
net = grossPay – taxes
ELSE
net = grossPay
ENDIF
WRITE name,
EndMultilineStructures
READ name, grossPay, taxes
IF taxes > 0
net = grossPay – taxes
ELSE
net = grossPay
ENDIF
WRITE name,
net
S e theIF/ELSE/ENDIFasconstructed

above, theENDIFisinlinewiththeI F.

ThesameappliesforWHILE/ENDWHILE
Types of Logic
Structure
• Sequence
• Selection
• Iteration
Sequence
• Performing instruction one after another
The Selection Structure

yes no
amount < 100

interestRate = .06 interestRate = .10

IF amount < 100


interestRate = .06

Pseudocode  ELSE
Interest Rate = .10
ENDIF
The Looping Structure

In flow charting one of the more confusing


things is to separate selection from looping.
This is because each structure use the
diamond as their control symbol.In
pseudocode we avoid this by using specific
keywords to designate looping.
WHI L E /E NDWHI L E
REPEAT/UNTIL
WHILE / ENDWHILE
Start
count = 0
WHILE count < 10
ADD 1 to count
count = 0
WRITE count
ENDWHILE
WRITE “The End”
count
Mainline
<10

count =
Write Modular
0WHILE count < 10
add 1 to “The End”
count DO Process
ENDWHILE
Stop
write count WRITE “The End”

Process
ADD 1 to count
WRITE count
REPEAT / UNTIL
Start count = 0

count = 0
ADD 1 to count
REPEAT
WRITE count
UNTIL count >= 10
add 1 to WRITE “The
count
End”
Mainline

count = 0
write count
Modular
REPEAT
DO Process
count
<10 UNTIL count >= 10
WRITE “The
End”
Write Process
“The End”
ADD 1 to count
Stop WRITE count
Advantages & Disadvantages
Flowchart Advantages: Pseudocode Advantages
 Standardized Easily modified

 Visual Implements structured concepts

Done easily on Word


Processor

Flowchart Disadvantages: Pseudocode Disadvantages:


Hard to modify Not visual
Structured design elements not No accepted standard, varies from
implemented company to company
 Special software required
 Time Consuming
Working with Fields
Calculations
Selection
+ add > greater than
- subtract < less than
* multiply = equal to
/ divide >= greater than or
equal to
** or ^ exponentiation
<= less than or equal to
() grouping
!= not equal to
Any Questions

You might also like