IPRG5111_Lecture 2S_2024
IPRG5111_Lecture 2S_2024
png)
HMAW – IPRG5111
Introduction to Programming Logic
Lecture 2
Lecturer: Brendan van der Merwe Email times: 8am – 5pm,
Email: [email protected] Monday to Friday
Objectives
- An overview of IPRG5111
• Flowchart
– Pictorial representation of the logical steps it takes to solve
a problem
Drawing Flowcharts
Pseudocode Standards
• Programs begin with the word start and end with the
word stop; these two words are always aligned
• Whenever a module name is used, it is followed by a
set of parentheses ()
• Modules begin with the module name and end with
return. The module name and return are always
aligned
• Each program statement performs one action—for
example, input, processing, or output
Pseudocode Standards
• Program statements are indented a few spaces more
than the word start or the module name
• Each program statement appears on a single line if
possible. When this is not possible, continuation lines
are indented
• Program statements begin with lowercase letters
• No punctuation is used to end statements
start
input myNumber
set myAnswer = myNumber * 2
output myAnswer
stop
Drawing Flowcharts
Drawing Flowcharts
Drawing Flowcharts
Drawing Flowcharts
Drawing Flowcharts
Summary
• Hardware and software accomplish input, processing,
and output
• Logic must be developed correctly
• Logical errors are much more difficult to locate than
syntax errors
• Use flowcharts and pseudocode to plan the logic
Exercise 1
1. Draw a flowchart and write pseudocode to represent the logic of a
program that allows the user to enter a value. The program divides
the value by 2 and outputs the result.
start
output “Please enter in a number“
input myNumber
set myAnswer = myNumber / 2
output myAnswer
stop
Exercise 2
2. Draw a flowchart and write pseudocode to represent the logic of a
program that allows the user to enter two values. The program outputs
the product of the two values.
Exercise
3. Draw a flowchart or
3 (You do)
& write pseudocode to represent the logic of a program
that allows the user to enter a value for hours worked in a day. The program
calculates the hours worked in a five-day week and the hours worked in a 252-
day work year. The program outputs all the results.
Exercise 4 (You do)
&
Chapter 2
Programming Basics
What is a variable?
• Variable names:
– Must be one word
– Must start with a letter
– Should have some appropriate meaning
Example:
Example:
Example:
The current 3-character prefixes
that will be used with the names
of variables. This could serve as
an extra classification of the
variable.