IRENEANASTASIAPATRIC
145 views
21 slides
May 07, 2024
Slide 1 of 21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
About This Presentation
Flowchart, Algorithm and Pseudocode
Size: 927.25 KB
Language: en
Added: May 07, 2024
Slides: 21 pages
Slide Content
Algorithm design and problem
solving
PROGRAM DEVELOPMENT LIFE
CYCLE(PDLC )
The program development life cycle is divided into five stages:
Analysis
Design
Coding
Testing
Maintenance
Analysis
•Before solving a problem, it is essential to define and document the
problem clearly, known as the "requirements specification" for the
program.
•The analysis stage involves using tools like abstraction and
decomposition to identify the specific requirements for the program.
•Abstraction focuses on the essential elements needed for the solution
while eliminating unnecessary details and information.
•Decomposition involves breaking down complex problems into smaller,
more manageable parts that can be solved individually.
•Daily tasks can be decomposed into constituent parts for easier
understanding and solving.
Design
The program specification derived from the analysis stage is used as a
guide for program development.
During the design stage, the programmer should clearly understand the
tasks to be completed, the methods for performing each task, and how
the tasks will work together.
Documentation methods such as structure charts, flowcharts, and
pseudocode can be used to document the program's design formally.
Coding and iterative testing
•The program or set of programs is developed based on the design.
•Each module of the program is written using a suitable programming
language.
•Testing is conducted to ensure that each module functions correctly.
•Iterative testing is performed, which involves conducting modular tests,
making code amendments if necessary, and repeating tests until the
module meets the required functionality.
Testing
•The completed program or set of programs is executed multiple times
using various test data sets.
•This testing process ensures that all the tasks within the program work
together as specified in the program design.
•Running the program with different test data can identify and address
potential issues and errors.
•The testing phase aims to verify the overall functionality and
performance of the program by evaluating its behaviour with various
inputs.
Decomposition
This is the act of breaking down a large problem into smaller, clear,
manageable and understandable sub-parts. Sub-parts can be divided until they
are easily solvable and cannot be broken down any further. An example of
decomposition could be getting ready in the morning to go to school
Step 1: Wake up
Step 2: Brush teeth
Step 3: Get breakfast
Step 4: Put clothes on
Step 5: Make sure the bag and school supplies are ready
Step 6: Find transport to school e.g. walk, bus, car, bike, etc
Example 1:
These steps could be further subdivided, for example, “Step 2: Get
breakfast” would entail:
Step 2.1 Get a bowl
Step 2.2 Get cereal
Step 2.3 Get milk
Step 2.4 Get a spoon
Step 2.5 Put cereal in a bowl
And so on…
Methods used to
design and construct
a solution to a
problem
❑Structure diagrams
❑Flowcharts
❑Pseudocode
Example 2: Structure diagrams
Consider the alarm application for a smart phones. It contain
three sub-systems – setting the alarm, checking alarm time,
sounding alarm
Flowcharts
A flowchart show graphical /
diagrammatically the steps required to
complete a task the order that they are to
be performed. The steps together with the
order, are called an algorithm.
FLOWCHARTS SYMBOL
Example 3: Concert
ticket Sales
Tickets are sold for a concert at $20 each, if
10 tickets are bought then the discount is
10%, if 20 tickets are bought is 20 %. No
more than 25 tickets can be bought in a single
transaction. This is flowchart an algorithm to
calculate the cost of buying a given number of
tickets.
PSEUDOCODE
Pseudocode is a simple method of showing an algorithm. It describe what
the algorithm does by using English keywords that are very similar to
those used in a high-level programming language.
Example of pseudocode assignment statements:
Cost 10 Cost has the value 10
Price Cost * 2 Price has the value 20
Tax Price * 0.12 Tax has the value 2.4
Selling Price Price + Tax Selling Price has the value 22.4
Gender “M” Gender has value M
Choose False Chosen the value False
Pseudocode for Conditional
Statements
Two Types of conditional Statement:
1.Condition that can be true or false as: IF ..THEN …ELSE…END IF
IF AGE > 18
THEN
OUTPUT “ELIGIBLE FOR VOTING
ELSE
OUTPUT “NOT ELIGIBLE FOR VOTING
ENDIF
CONT..
2. A choice between several different values, such as: CASE
OF…OTHERWISE….ENDCASE
CASE OF Grade
“A” : OUTPUT “Excellent”
“B”: OUTPUT “Good”
“C”: OUTPUT “Average”
OTHERWISE, OUTPUT “Improvement is needed
ENDCASE
IF..THEN..ELSE..ENDIF
For an IF condition the THEN path is followed if the condition is true and
the ELSE path is followed if the condition is false. There may or may not
be an ELSE path. The end of the statement is shown by ENDIF.
There are different ways that an IF condition can be set up:
IF (Height >1) OR (Weight > 20) AND (Age < 70) AND (Age > 5)
THEN
OUTPUT “You can ride”
ELSE
OUTPUT “Too small, to young or old to ride”
ENDIF
Example: CASE
OF…OTHERWISE…ENDCASE
CASE OF Choice
1: Answer Num1 + Num2
2: Answer Num1 – Num2
3: Answer Num1 * Num2
4. Answer Num1 / Num2
OTHERWISE, OUTPUT “Please enter a valid choice”
ENDCASE
Pseudocode for iteration
Some action performed as part of an algorithm need repeating this
is called iteration. Loop structure are used to perform the iteration.
•FOR …TO…NEXT ---> A set number of repetitions
•REPEAT …UNTIL ---> A repetition, where the number of repeats
is not known, that is completed at least once.
•WHILE..DO..ENDWHILE ---> A repetition, where the number of
repeats is not known, that may never be completed.
All types of loops
A FOR …NEXT loop
A WHILE
…DO…ENDWHILE loop
A REPEAT….UNTIL loop