Professional Documents
Culture Documents
Exercise
Think how you would solve some of these real-life problems
for IT professional. You may not have the technical knowledge
to create the solution, but you can think of ways to break
down the problems.
1. A software company that specializes in accounting software
wants to create a range of general-purpose software for
home users.
2. A software developer is taking a long time to fix a piece of
faulty code, because she is not very familiar with the
programming language.
3. A software developer wants to write a program that provides
a range of statistics for data entered about cricket matches.
He wants these statistics to reflect averages, total scores,
run rates and many other figures.
4. A principal is considering a software application for inventory
in a school cafeteria. It should store records of all stocks and
warn when stocks are low.
IPO chart
You are given a problem of finding the sum of three
numbers.
- The input of the three numbers
- Add the three numbers
- Output
the three numbers
Inputthe sum of
Process
Output
Number 1
Number 2
Number 3
Read three
numbers
Add the three
numbers
together
Output the total
of the numbers
Total
Exercise
Create an IPO chart that shows the input,
processing and output statements of the
following:
Calculate the discount given to customers based
on the value of their purchases. Add the prices of
a customers items (maximum of 3 items) to get
a total. If the total is under $100, the customer
gets no discount. If the total is over $100, the
customer gets a 5% discount. If the total is over
$150, the customer gets a 10% discount. For any
amount over $200, the customer gets a 15%
discount. Show the amount of the discount and
the discounted price on the receipt.
Algorithms
An algorithm is a set of precise
instruction steps to solve a given
problem.
Algorithms can be written as a
narrative, or they can be written in
pseudocode.
They can also be represented on
flowcharts.
NOTE:
The assignment statement in an
Properties of an algorithm
An algorithm must:
1.
2.
3.
4.
5.
Be precise
Be unambiguous
Give the correct solution in all cases
Flow logically
Eventually end
Categories of data
Just as we need containers to hold or store ingredients
for a recipe, likewise, when we perform computations,
we need something to store or hold the values that we
manipulate. In the computer , values are stored in
memory locations. In order to keep track of where our
values are stored, we need to place an identifier or a
label on a particular memory location. The label or
identifier is called a variable.
Therefore, a variable is a symbolic name assigned to a
memory location that stores a particular value.
NOTE: The word variable is derived from the verb to
vary. This means that the value stored in a particular
location can change from time to time, although the
label remains the same.
Exercise
Which of these values are constants and
which are variables?
1. Your shoe size
2. The amount of a deposit into your bank
account
3. The length of a room in metres
4. The number of months in a year
5. The year you were born
6. The mark received in a test
Datatypes
To write an algorithm, you must be able to distinguish between the different
datatypes because when you write a program, the computer needs to know
what type of data it is working with.
Integers Whole number both positive and negative. They can not represent
fractions or have any decimal points. For example, if the problem you are
solving requires that you enter the number of eggs you bought at a shop, this
is most likely to be an integer because you would not buy a fraction of an egg.
Real number Numbers that include decimal points both positive and negative.
They are sometimes called floating point numbers. For example, monetary
values are almost always represented as real numbers.
Characters A program can output messages such as Pass and Fail, and
input values can consist of characters or symbols. Characters are single letters
of the alphabet or symbols. The letter a is a character and the symbol ! is a
character.
String A string is a group of characters. A string can be any number of
characters. For example, Lucy Wells is a string
Algorithm Structure
Header: Algorithms name or title.
Declaration: A brief description of
algorithm and
variables used.
Body: Sequence of steps.
Terminator: An end statement.
Example of an algorithm
Algorithm Welcome {Header}
This algorithm displays a welcome message
to the user on the screen. {Declaration}
Display Enter first name:
Accept first name
Display Hello, first name
Display Have a nice day!
Stop {Terminator}
Body
Control Structures
A control structure can be a sequence,
selection or a loop (that is, repetition).
The body of the algorithm is
comprised of various structures.
Sequential structures are:
Input statements, for example:
Get num1, num2
Read price, tax-rate
Accept guess
Input num
Flowcharts
Decision
Input/Output
Process
Flow of algorithm
Sequence
A
do
B B
do A
Selection (Decision)
No
D
If C is true then
do E
Else
Do D
Yes
Loop (Repetition)
F
Yes
No
While F is true
do G
Algorithm Average
This algorithm finds the average of three
numbers
Start
Read num1, num2, num3
Average
(num1 + num2 + num3) /
3
Print average
Stop.
Read num1,
num2, num3
Print Average
Stop
Arithmetic Operators
Operator
Meaning
Addition
Subtraction
Multiplication
Division
Relational Operators
Operator
Meaning
<
Less than
>
Greater than
Equal to
<=
>=
<>
Not equal
Purpose
IF
THEN
AND
OR
ELSE
FOR
WHILE