Please enable JavaScript.
Coggle requires JavaScript to display documents.
Ch.23 Algorithm Design (II) - Coggle Diagram
Ch.23 Algorithm Design (II)
23.1 Input Statements, Output Statements and Assignment Statements
Data is usually not pre-written in a program as part of program code
Variables are used to temporarily store the data inputted by users when a program is running
A variable can hold data like:
character
number
number
A flexible program can handle different sets of data without changing the program code
Output Statement
Used to output the processed input
Assignment Statements
Used to place a value or the value of an expression into a variable
23.2 Basic Control Structures
Selection control structure
Allows a program to choose between two or more alternatives
Decision logic structure
Use the IF...THEN...ELSE statement structure and a conditional expression to determine what the program should do next
A conditional expression is a logical expression returning a Boolean value
If the condition is true
The THEN part will be executed
If the condition is false
The THEN part will be skipped.
If there is an ELSE part, it will be executed instead.
Relational operators and logical operators are commonly used in the conditional expression of a control structure
Case logic structure
Usually used to make a decision from more than one possible value of an expression
The expression that comes after the word CASE can be of any data type:
Numeric (integer/real)
Character (single character/string)
Logical (Boolean)
Sequence control structutre contains a series of steps or
statements that are executed in the same order as they are written
Iteration
The same block of statements will be repeated as long as a certain condition is met
WHILE-loop
pretest loop
FOR-loop
pretest loop
DO...WHILE-loop
posttest loop
REPEAT...UNTIL-loop
posttest loop
23.3 Algorithms for Manipulating Arrays
Arrays
A way of organizing a collection of homogeneous data items
Grouping the data items into a sing l e data structure
load is used to describe the action of entering data into an array
Searching for an element of an array
Checking whether a value exists in an array
L ocating the position of a particular element and then deleting it
Determining the position where a new item should be inserted
Linear search involves examining every element of an array, one by one, starting from the first one
23.4 Advantages of Using the Modular Approach in Programming
Writing standard procedures in separate modules can save us a lot of time
Each module can be tested separately
It is easier to understand and debug a module because its
size is relatively small and its purpose is also clearly defined and documented
Modularization makes a large project easier to be monitored and collected
Modularization allows a team of programmers to work on a large program