dct 1123 problem solving & algorithms pseudocode & flowchart
TRANSCRIPT
![Page 1: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/1.jpg)
DCT 1123 Problem Solving & AlgorithmsPseudocode & Flowchart
![Page 2: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/2.jpg)
Con
tents
• How to write a pseudocode• Meaningful names• The structure theorem• Flowchart
![Page 3: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/3.jpg)
SIX
basic co
mpu
ter
opera
tion
1. A computer can receive information
2. A computer can put out information3. A computer can perform arithmetic4. A computer can assign a value to a
variable or memory location5. A computer can compare two
variable and select one of two alternative actions
6. A computer can repeat a group of actions
![Page 4: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/4.jpg)
Rece
ive In
form
atio
n
• When computer is required to receive information or input from a particular source, whether it be a terminal, a disk or any other device
• ‘Read’ and ‘Get’ are used in the pseudocode
• Read – receive input from a record/file
• Get – receive input from keyboard
![Page 5: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/5.jpg)
Rece
ive In
form
atio
n
• For example:Read student nameGet system dateRead number1, number2Get tax code
![Page 6: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/6.jpg)
Pu
t Ou
t Info
rmatio
n
• When a computer is required to supply information or output to a device, the verbs Print, Write, Output or Display are used
• Print – output is sent to the printer• Write – output is to be written to a
file• Put, Output and Display – output is
to be written to the screen
![Page 7: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/7.jpg)
Pu
t Ou
t Info
rmatio
n
• For example:– Print ‘Program Completed’– Write customer record to master file– Put out name, address and postcode– Output total_tax– Display ‘End of Data’
![Page 8: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/8.jpg)
Perfo
rm A
rithm
etic
• Most programs require the computer to perform some sort of mathematical calculation and apply a formula
• The following symbols can be written in pseudocode:– + for add– - for substract– * for multiply– / for divide– () for parantheses
• The verbs ‘Compute’ and ‘calculate’ also used in the pseudocode
![Page 9: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/9.jpg)
Perfo
rm A
rithm
etic
• For example:– Divide total marks by student_count– Sales_tax = cost_price * 0.10– Compute C = (F – 32) * 5 / 9
![Page 10: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/10.jpg)
Assig
n a
valu
e to
a
varia
ble
/ mem
ory
loca
tion
• There are 3 instances in which you may write a pseudocode to assign a value to a variable / 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
![Page 11: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/11.jpg)
Assig
n a
valu
e to
a
varia
ble
/ mem
ory
loca
tion
• For example:– Initialize total_price to zero– Set student_count to 0– Total_price = cost_price + sales_tax– Total_price cost_price + sales_tax– Store customer_no in last_customer_no
![Page 12: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/12.jpg)
Com
pare
two v
aria
ble
s & se
lect
on
e o
r two a
ltern
ativ
e a
ction
• To represent this operation in pseudocode, special keywords are used: IF, THEN and ELSE
• The comparison of data is established in the IF clause
• The choice of alternatives is determined by the THEN or ELSE
![Page 13: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/13.jpg)
Com
pare
two v
aria
ble
s & se
lect
on
e o
r two a
ltern
ativ
e a
ction
• For example:
IF attendance_status is part_time THENAdd 1to part_time_count
ELSEAdd 1 to full_time_count
ENDIF
![Page 14: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/14.jpg)
Repeat a
gro
up
of a
ction
• When there is a sequence of processing steps that need to be repeated, two special keywords, DOWHILE and ENDDO are used in pseudocode
• The repetition condition is established in the DOWHILE clause and the actions to be repeated are listed beneath it
![Page 15: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/15.jpg)
Repeat a
gro
up
of a
ction
• For example:
DOWHILE student_total < 50Read student recordPrint student name, address to reportAdd 1 to student_total
ENDDO
![Page 16: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/16.jpg)
Mean
ing
ful N
am
es
• A programmer must introduce some unique names, which will be used to represent the variables or objects in the problem
• A name given to a variable is simply a method of identifying a particular storage location in the computer
• A name describes the type of data stored in a particular variable
• A variable may be one of three simple data types: an integer, a real number or a character
![Page 17: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/17.jpg)
Mean
ing
ful N
am
es
• If more than one word is used in the variable name, the underscores are useful as word separator. For example student_number
• If underscore cannot be used, then words can be joined together with the use of a capital letter as a word separator. For example studentNumber
![Page 18: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/18.jpg)
Flo
wch
art
• Flowchart is an alternative method of representing algorithms
• It is popular because they graphically represent the program logic through series of standard geometric symbols and connecting lines
![Page 19: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/19.jpg)
Flo
wch
art S
ym
bols
Terminal SymbolIndicates the starting or stopping point in the logic. Every flowchart should begin and end with a terminal symbol.
Input / Output SymbolRepresents an input or output process in an algorithm, such as reading input or writing output
![Page 20: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/20.jpg)
Flo
wch
art S
ym
bols
Process SymbolRepresents any single process in an algorithm, such as assigning a value or performing a calculation
Predefined Process SymbolRepresents an input or output process in an algorithm, such as reading input or writing output
![Page 21: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/21.jpg)
Flo
wch
art S
ym
bols
Decision SymbolRepresents a decision in the logic involving the comparison of two values. Alternative paths are followed, depending on whether the decision symbol is true or false
FlowlinesConnect various symbols in a flowchart, and contain an arrowhead only when the flow control is not from top to bottom or left to right
![Page 22: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/22.jpg)
Flow
chart C
ontro
l Stru
cture
• There are three basic control structures:1. Sequence
• Straightforward execution of one processing step after another
2. Selection• Presentation of a condition, and the choice
between two actions depending on whether the condition is true or false
3. Repetition• Presentation of a set of instructions to be
performed repeatedly, as long as condition is true
![Page 23: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/23.jpg)
Flow
chart C
ontro
l Stru
cture
• Sequence flowchart example:
Statement A
Statement C
Input / Output
![Page 24: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/24.jpg)
Flow
chart C
ontro
l Stru
cture
• Selection flowchart example
Condition p?
Statement A Statement B
True False
![Page 25: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/25.jpg)
Flow
chart C
ontro
l Stru
cture
• Repetition Flowchart Example
Condition p?
Statement A
True
False
![Page 26: DCT 1123 Problem Solving & Algorithms Pseudocode & Flowchart](https://reader030.vdocuments.mx/reader030/viewer/2022033018/56649de95503460f94ae33a3/html5/thumbnails/26.jpg)
Su
mm
ary
• Six basic computer operations were listed – receive information, put out information, perform arithmetic, assign a value o a variable, decide between two alternative actions and repeat a group of actions
• The algorithm can be represented in the pseudocode or flowchart