0% found this document useful (0 votes)
2 views

Practical Programming -L03

This lecture introduces flowcharts as a visual representation of algorithms, highlighting their role in simplifying complex processes, enhancing communication, and aiding in debugging. It covers flowchart symbols, control structures (sequential, selection, and looping), and provides practical examples and best practices for designing flowcharts. The lecture concludes with tools for creating flowcharts and emphasizes their importance in programming education and system design.

Uploaded by

Jaafar Abbakar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Practical Programming -L03

This lecture introduces flowcharts as a visual representation of algorithms, highlighting their role in simplifying complex processes, enhancing communication, and aiding in debugging. It covers flowchart symbols, control structures (sequential, selection, and looping), and provides practical examples and best practices for designing flowcharts. The lecture concludes with tools for creating flowcharts and emphasizes their importance in programming education and system design.

Uploaded by

Jaafar Abbakar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

University of Juba

Programming with C++


Practical Training
Lecture 3: Graphical Algorithmic Language
Overview
• This lecture introduces flowcharts, a visual representation of
algorithms, and explains how they simplify complex processes,
enhance communication, and serve as a debugging tool.
• We will explore flowchart symbols, control structures, and real-
world applications, followed by practical examples and best
practices for designing flowcharts.
1. Introduction to Flowcharts
• Definition: A flowchart is a visual blueprint of an algorithm, using shapes
and arrows to map out the flow of execution.
• Purpose:
• Simplifies complex processes into digestible steps.
• Enhances communication and collaboration.
• Acts as a debugging tool to identify logical errors.
• Real-World Applications:
• Software Development: Designing algorithms before coding.
• Business: Mapping workflows (e.g., employee onboarding).
• Engineering: Visualizing system operations.
• Daily Life: Planning tasks or decision-making (e.g., "Should I take
an umbrella?").
2. Why Flowcharts Matter
• Clarity: Breaks down complex ideas into easy-to-follow steps.
• Debugging: Helps spot logical errors and inefficiencies.
• Collaboration: Acts as a universal language for teams.
• Documentation: Provides a clear record of processes for future
reference.
3. Flowchart Symbols
Flowcharts use standardized symbols to represent different actions:
4. Control Structures in Flowcharts
There are three types of control structures in structured
programming:
(i) Sequential structure.
(ii) selection structure.
(ii) Looping structure.
(i) Sequential Structure:
The sequential structure follows a straight-line execution
mechanism, where statements are executed one after another in a
linear fashion.

How It Works:
Statements are executed in the order they appear.
There is no branching or repetition; the program flows from one
statement to the next.
(i) Sequential Structure:

Start

Statement 1

Statement 2

Statement 3

End
(ii) Selection Structure (Decision-Making)
• The selection structure allows the program to choose between
multiple paths of execution based on a logical condition.
How It Works:
• A condition is evaluated.
• If the condition is true, the program executes the sequence of
statements under the "Yes" branch.
• If the condition is false, the program executes the sequence of
statements under the "No" branch.
(ii) Selection Structure (Decision-Making)
Relational Operators for Conditions:
Operator Meaning
> Greater than • The comparison in the condition
>= Greater than or equal to can be between:
• A variable and another variable.
< Less than • A variable and a constant.
<= Less than or equal to • An expression and a variable.
== Equal to • An expression and a constant.
!= Not equal to
Types:
• Single Selection: IF-THEN (executes a block of code if the condition is
true).
• Double Selection: IF-THEN-ELSE (chooses between two paths based on
the condition).
• Multiple Selection: CASE or SWITCH (chooses among multiple paths
based on the value of an expression).
(ii) Selection Structure (Decision-Making)
• <= Less than or equal to
• == Equal to
• != Not equal to
• The comparison in the condition can be between:
• A variable and another variable.
• A variable and a constant.
• An expression and a variable.
• An expression and a constant.
(ii) Selection Structure

IF-THEN IF-THEN-ELSE
(iii) Looping Structure (Repetition)
• The looping structure allows the program to repeat a set of statements
multiple times based on a condition.
How It Works:
• A condition is evaluated at the beginning (or end) of the loop.
• If the condition is true, the loop body (sequence of statements) is executed.
• The loop continues until the condition becomes false.
Types:
• Pre-Test Loop: The condition is evaluated before executing the loop body
(e.g., WHILE loop).
• Post-Test Loop: The condition is evaluated after executing the loop body
(e.g., REPEAT-UNTIL loop).
• Count-Controlled Loop: The loop runs for a fixed number of iterations (e.g.,
FOR loop).
(iii) Looping Structure (Repetition)
5. Flowchart Design Examples
Example 1: Determining the square-root of the variable x
5. Flowchart Design Examples
Example 2: Determining if a Number is Positive or Negative
5. Flowchart Design Examples
Problem: Find the maximum number in a list.
Algorithm from Lecture 2:
1. Start
2. Read the list of numbers.
3. Set the first number as the maximum.
4. Compare each number with the current maximum.
5. If a number is greater, update the maximum.
6. Repeat until the end of the list.
7. Print the maximum number.
8. Stop.
Start

Read list of numbers

Set max = first number

No Yes
If number > max

Display max max = number

End
5. Flowchart Design Examples
Problem: Calculating the Average of Numbers
Algorithm from Lecture 2:
1. Input: A list of numbers, numbers = [n1, n2, n3, ……,nk].
2. Steps:
• Initialize a variable total_sum to 0.
• Initialize a variable count to 0.
• Iterate through each number in the list:
• Add the current number to total_sum.
• Increment count by 1.
• Calculate the average by dividing total_sum by count
• Return the average.
3. Output: The average of the numbers in the list.
Start

Read list of numbers

total_sum = 0

Count = 0

No Yes
For each number in list

average = total_sum / count total_sum = total_sum + number

Display average count = count + 1

End
5. Flowchart Design Examples
Problem: Write an algorithm to sort a list of numbers in ascending order.
Algorithm from Lecture 2:
a. Input: A list of numbers, numbers = [n1, n2, n3, ……,nk].
b. Steps:
1. Start with the first element of the list.
2. Compare the current element with the next element.
3. If the current element is greater than the next element, swap
them.
4. Move to the next element and repeat step 2-3 until the end of list.
5. Repeat the entire process for the list until no swaps are needed.
6. Return the sorted list
c. Output: Sorted list.
5. Flowchart Design Examples
Draw a flow chart to write the output for a simple calculator that
performs addition (+), or subtraction (-), or multiplication (*), or
division (/), on two numbers entered in the following manner: First
number, symbol of operation, second number. If the user enters a
symbol which is not one of the previous operations, the following
message should be displayed "INVALID OPERATION".
6. Flowchart Best Practices
Use Consistent Symbols:
• Ovals for start/end.
• Rectangles for processes.
• Diamonds for decisions.
Label All Shapes:
• Clearly describe what each shape represents.
Keep It Simple:
• Avoid unnecessary complexity.
Use Arrows for Flow:
• Clearly show the direction of control flow.
7. Tools to Create Flowcharts
Draw.io:
• Free online tool for creating flowcharts.

Lucidchart:
• Web-based tool with collaboration features.

Microsoft PowerPoint/Word:
• Use shapes and arrows to manually create flowcharts.

Pen and Paper:


• Draw the flowchart by hand for practice.
8. Conclusion
The Graphical Algorithmic Language is a powerful tool for
illustrating arithmetic and logical operations in algorithms.

It helps programmers and analysts understand and interpret


algorithms easily, making it an essential element in programming
education and system design​.
10. Q&A and Discussion
Discussion Questions

• Why are flowcharts important in algorithm design?


• What challenges do you face when creating flowcharts?
Practical Exercise

• Create a flowchart for a temperature conversion algorithm


(Celsius to Fahrenheit).

You might also like