ISTch15 - Software Development & Programming
ISTch15 - Software Development & Programming
15
15
CHAPTER
Software
development
and
programming
Syllabus outcomes
5.2.1 Describes and applies problem-solving processes when
creating solutions.
5.2.2 Designs, produces and evaluates appropriate solutions to a
range of challenging problems.
5.2.3 Critically analyses decision-making processes in a range of
information and software solutions.
Overview
This chapter will develop your understanding of software
development and programming. It examines the basic
programming concepts, algorithms and control structures. You will
learn about programming languages, testing and documentation.
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 332
15. 1 Programming
Programming is the process of writing programs and developing
software. A program is a collection of instructions that, when
executed, will complete a task on the computer. One or more
programs are commonly referred to as software or code. People
who write programs are called programmers or software
developers. Programmers write programs using programming
languages. There are many programming languages available such
as Java, Visual BASIC and C++.
Lit 8.1 Java is a popular language developed by Sun Microsystems. Java,
like all programming languages, has its own set of rules (syntax)
which must be strictly followed (see Figure 15.1). However, there
are basic programming concepts in all programming languages.
332 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 333
• Constant (or literal) is an item of data with only one specific value.
Constants are either numbers or strings (numbers and letters).
• Variable is an item of data that may take different values, one at
a time. They are storage containers used to hold data of the same
type.
• Identifier is the name of anything in a program such as a
variable. There are some restrictions on the use of identifiers,
such as always starting with a letter.
• Separator is a symbol for grouping sections of the program such
as { and }. The correct use of separators is essential otherwise
the program will not work.
• Assignment statement gives a value to a variable such as: x = 9.
The general form of an assignment statement is: variable =
expression. The expression can contain other variables such as:
y + 1. This will result in the assignment statement: x = y + 1.
GUI layout
The graphical user interface (GUI, pronounced ‘gooey’) gives
instructions using a mouse, and clicking on icons and menus.
A GUI provides an easy-to-use and consistent interface for a range
of applications. Modern programming languages create objects for
each component in a GUI,
such as:
• text box and labels are
used to display text
• option button (or radio
button) enables the user
to select one option from
a group
• check box, a text box and
a small box that allows
the user to click on or
off—more than one
option can be selected
from a group
• list box presents the user
with two or more options
that are viewed using a
scroll bar
• command buttons—OK to
confirm selection and
Cancel to quit. Figure 15.2 Visual basic
Data type
Data type is the kind of data that can be stored in a variable. To
create a variable it must be declared. Variable declaration involves
stating the data type of the variable and an identifier or unique
name for the variable. Most programming languages have the
following data types:
• integer number is a whole number without fractional parts
• floating-point number is a number with the fractional parts
• boolean is used to store values that have one of two possible
states such as true or false
• character is used to store one character such as a letter, number
Lit 8.2
or symbol
• string is used to store more than one character.
Data operators
Data operators (or operators) are used to represent an action to be
performed such as a calculation. Operators are classified as:
• Arithmetic operator—performs a calculation such as addition
(+), subtraction (–), division (/), multiplication (*), powers (^)
and modulus (%). Calculations are carried out using the
Interactive standard order of operations.
• Relational operator—compares two values and returns a
boolean (true or false) result. Relational operators include less
than (<), greater than (>), less-than-or-equal-to (<=), greater-
than-or-equal-to (>=), equal-to (= =) and not-equal-to (!=).
• Logical operator—compares two values and returns a boolean
(true or false) result. Logical operators include AND (&&), OR
(!!) and NOT (!).
Exercise 15.1
1 Explain the difference between:
a constant and variable
b character and string
c an arithmetic operator and a relational operator.
2 What am I?
a A collection of instructions that, when executed, will complete
a task on the computer.
b The name given to anything in a program such as a variable.
c A component in a GUI that enables the user to select one
option from a group.
d Data type for whole numbers without fractional parts.
334 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 335
Development
5 Examine the Java program in Figure 15.1.
a What is the purpose of this program?
b How could you change this program to display your name?
6 Do research to find an example of a program written using a
programming language.
a Describe the input, processes and output.
b Identify the data operators, functions, assignment statements,
variables and constants.
15. 2 Algorithms
An algorithm is a series of steps designed to solve a problem in a
finite time. An algorithm can be used to solve many types of
problems. Algorithms are not programs but are an important part
in the development of a program. In this section we examine
algorithms from familiar but non-computing contexts.
336 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 337
Keywords Meaning
BEGIN Terminal: start and finish
END
IF (condition) Selection: different tasks are performed
THEN process 1 according to the condition
ELSE process 2 The ELSE statement is optional
ENDIF
WHILE (condition) Repetition: statements between the keywords
process 1 are repeated while the condition is true
ENDWHILE (Pre-test repetition)
REPEAT Repetition: statements between the keywords
process 1 are repeated while the condition is true
UNTIL (condition) (Post-test repetition)
Symbol Meaning
Terminal: start and finish
There should be only one line in or one line out
End
338 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 339
Exercise 15.2
1 Copy and complete the following sentences:
a Algorithms are not _______ but are an important part in the
development of a program.
b _______ uses indented lines and keywords to describe an
algorithm.
c The flow of control in pseudocode is always from the _______ to
the bottom.
d A flow chart is a _______ method of describing an algorithm.
2 What am I?
a A method of algorithm description that is written using a word
processor.
b A keyword in pseudocode to start the algorithm.
c The lines and arrows in a flowchart.
d A symbol used in a flowchart to start and finish.
3 The following algorithms have errors in their sequence. Find these
errors and write the correct solution to the problem.
a Algorithm to read a book:
Read book
Open book to first page
Close book
Get book
b Algorithm to run a bath:
If bath is full, turn off the taps
If water is too hot, increase the amount of cold water
Put plug into bath
If water is too cold, increase the amount of hot water
Turn on the hot water tap
Turn on the cold water tap
4 a What is an algorithm?
b Why must the steps in an algorithm be performed in a
particular order?
c Why are the keywords in pseudocode highlighted?
d What is the purpose of indentation in pseudocode?
e What are the disadvantages of a flowchart?
f Name the basic symbols used in flowcharts.
Development
5 An algorithm to watch your favourite television show is shown
below:
Turn television on
Select television show
Watch television show
Turn television off ICT 15.1
a Convert this algorithm into pseudocode.
b Convert this algorithm into a flowchart.
Sequence
Sequence is the order the steps are executed. In pseudocode, the
steps are placed between BEGIN and END (see the problem below).
The sequence of four steps is indented to show structure and to
improve the readability of the algorithm. The flow of control is top
to bottom, starting at the first step and finishing at the last step.
Flowcharts always start and finish with a terminal symbol (oval).
The steps are placed between these symbols and joined by flowlines
(see Figure 15.4). The direction of flow is down the page between
the terminal symbols.
Problem: Design an algorithm to wash your hands.
Pseudocode solution
BEGIN
Wet hands
Clean hands with soap
Rinse off soap
Dry hands
END
Flowchart solution is shown in Figure 15.4.
340 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 341
Begin
Wet hands
Clean hands
with soap
Dry hands
End
Selection
Selection is used to make a logical decision. It requires a choice to
be made between two or more options. The choice is made
depending on the answer to a condition. There are two types of
selection: binary and case.
Binary selection involves two choices. In pseudocode, the
keywords IF … THEN … ELSE are used for binary selection
(see the problem below). The condition is put after the IF keyword.
There are only two possible answers to the condition, true or false.
If the condition is true then the process after the THEN keyword is
executed. If the condition is false then the process after the ELSE
keyword is executed. The ELSE statement is not always required
and can be omitted. In a flowchart the selection is made using a
decision symbol (diamond). The condition is placed inside this
symbol and the answer must be true or false (see Figure 15.5). It is
very important that the two flowlines from the decision symbol are
labelled with true or false to determine which path to follow. The
two flowlines join together to complete the binary selection.
Begin
False True
Is it night?
End
342 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 343
Pseudocode solution
BEGIN
CASEWHERE colour of signal
Green : Pass through lights
Amber : Slow down vehicle
Red : Stop vehicle
ENDCASE
END
Flowchart solution
Begin
Colour of the
signal is?
End
Repetition
A repetition or loop allows a number of steps to be repeated until
some condition is satisfied. The steps to be repeated are referred to
as the body of the loop. It is very important that each loop contains
a condition to stop the loop going on forever. There are two types
of repetition: pre-test or post-test.
In a pre-test repetition or guarded loop the condition is checked
at the beginning of the loop before the steps to be repeated are
executed. In pseudocode the keywords used for a pre-test repetition
are WHILE … ENDWHILE (see problem below). The condition is
put after the WHILE keyword and the body of the loop between
the WHILE and ENDWHILE keywords. In a flowchart the pre-test
repetition is made using a decision symbol and flowlines (see
Figure 15.7). The condition is placed inside the decision symbol
and checked before the body of the loop.
Begin
False
Is car moving?
True
End
344 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 345
Flowchart solution
Begin
False
Is grass cut?
True
End
Exercise 15.3
1 What control structures are represented by the following
algorithm segments?
a BEGIN
process 1
process 2
process 3
END
b WHILE (condition)
process
ENDWHILE
c IF (condition)
THEN process 1
ELSE process 2
ENDIF
d REPEAT
Process
UNTIL (condition)
e f
False
True
g h
False True False
True
2 True or false?
a Case selection involves two choices.
b In a flowchart a selection is made using a decision symbol.
c The steps repeated in a repetition are called the body of the loop.
d The REPEAT … UNTIL keywords are used for a pre-test repetition.
3 Copy and complete the following by replacing the letter in brackets
with a suitable term:
The building blocks of a program are called the (a). Sequence is the
(b) the steps are executed. Selection is making a logical (c).
Repetition allows a number of (d) to be repeated.
4 a What is the sequence in an algorithm?
b Describe the flow of control in pseudocode.
c What is binary selection in an algorithm?
d Why is it important to label the two flowlines from a decision
symbol with true or false?
e What keywords are used for a pre-test repetition in
pseudocode?
f How is a post-test repetition made in a flowchart?
Development
5 Explain what the following algorithms do.
a Pseudocode:
BEGIN
print ‘What is the capital of Australia?’
get answer from user
IF answer is Canberra
THEN print ‘Well done, correct’
ELSE print ‘Sorry the answer is Canberra’
ENDIF
END
b Pseudocode:
BEGIN
set Count to one
WHILE Count is less than eleven
print Count
increment Count by one
ENDWHILE
END
346 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 347
c Pseudocode:
BEGIN
set Count to ten
REPEAT
print Count
increment Count by one
UNTIL Count is twenty
END
d e
Begin Begin
False
Is Count
Input colour
> 0?
True
End End
Begin
Print Count
False
Is Count less
than eight?
True
End
Figure 15.15
15. 4 Programming
languages
Programming languages are used to create the instructions in a
program that can be understood by the computer. Each
programming language has its own set of rules that must be strictly
followed. The rules of the programming language are called its
syntax. Programming languages are divided into two groups:
• Low-level languages are the lowest level of computer languages
and depend on the hardware of the computer. Programs written
Tutorial
using low-level languages are often called machine code or
assembly code. They process calculations much faster than
high-level languages.
• High-level languages use English-like codes where each statement
corresponds to several lines of machine code. Programming
348 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 349
Object-oriented programming
Most programmers use a high-level language and a strategy called
object-oriented programming or OOP (rhymes with hoop). OOP
requires the programmer to package the data and the methods (or
procedures) into a single unit called an object. A program consists
of a collection of interacting objects. Writing a program involves Lit 8.4
Subprograms
Structured programming aims to create well ordered and logical
programs. It involves breaking the problem down into smaller
parts. Each part is solved separately and then combined to produce
the final solution. A structured program consists of a collection of
smaller programs. Each of these smaller programs is called a
subprogram. A subprogram is a self-contained section of code that
performs a particular task. In Java, subprograms are called ‘methods’.
For example, the code below is a method in Java. It adds two
integers (parameters) and returns the result to the calling program
(larger program).
350 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 351
Data structures
A file is a block of related data
stored on a storage device. Figure 15.17 Java program
Exercise 15.4
1 True or false?
a Each programming language has the same rules that must be
strictly followed.
b Most programmers use a high-level language.
c A class describes how objects behave and the kind of
information in the object.
d Object-oriented programming involves breaking the problem
down into smaller parts.
2 Explain the difference between:
a a low-level language and a high-level language
b a record and an array.
3 Copy and complete the following sentences:
a A program in _______ consists of a collection of interacting
objects.
b A _______ is a self-contained section of code that performs a
particular task.
c Each element within an array is _______ and accessed based on
their number.
4 a What is the purpose of a programming language?
b Describe the process of writing a program using an OOP
language.
c What are applets?
d What is the aim of structured programming?
e Describe an advantage of subprograms.
f What is the purpose of an array?
Development
5 Do research into a high-level programming language. If possible
complete a tutorial on a programming language. Identify the basic
programming concepts and control structures used in the programming
language. Write a report that summarises your investigation.
6 Write a program that will ask the user for their first name and print
this name ten times on the screen (see Figure 15.17). Execute this
program. Modify the program so that the person’s name is printed
twenty times.
352 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 353
7 Write a program that will create an array and store each letter of
the alphabet. Enter data into the array and use the array to display
a message.
354 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 355
Tasks
1 Design an appropriate introductory screen for Rite Software using a
modern user interface.
2 What are the characteristics of a modern user interface?
Exercise 15.5
1 What am I?
a An error made when a programmer has failed to follow the
rules of programming.
b An error that occurs when it is impossible for the computer to
carry out the instruction.
c An error detection that involves putting a roadblock in the
execution of the program.
d Documentation that involves writing an easy-to-read program.
2 Copy and complete the following sentences:
a When a program is _______ an error message will appear if the
program contains a syntax error.
b A desk check usually involves watching the _______.
c A _______ is a program that will perform the desk check
electronically.
d Inadequate _______ makes a program difficult to understand
and modify.
3 Unjumble these words:
a ugdinebgg
b ecdk hkiecncg
4 a What is a bug?
b What is the purpose of test data?
c List the three basic types of errors.
d What is desk checking?
e Why is documentation an important aspect of writing
programs?
f Explain the difference between internal and external
documentation.
Development
5 Examine the following algorithm. What will be the output if the
user enters 4? Perform a desk check by watching the variables
(Number, Count and Temp).
BEGIN
Get Number from the user
Set Count to zero
WHILE Count is less than Number
Set Temp to Count plus one
Print Temp
increment count by one
ENDWHILE
Print Count
END
6 Examine the following algorithm. What will be the output?
Perform a desk check by watching the variables (X and Y).
356 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 357
BEGIN
Set X to zero
Set Y to one
REPEAT
Set X to X plus Y
Print X
increment Y by one
UNTIL Y is four
Print Count
END
7 Edit the programs created in Exercise 15.4, Questions 6 and 7 by
inserting appropriate documentation.
358 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y
313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 359
Statements
1 A collection of instructions that, 6 Control structure that specifies the
when executed, will complete a task order the steps are executed.
on the computer. 7 Control structure used to make a
2 The kind of data that can be stored logical decision.
in a variable. 8 Data structure that stores a list of
3 A series of steps designed to solve a elements of the same data type.
problem in a finite time. 9 It is used to detect and correct any
4 A method of algorithm description potential problems in a program.
that uses indented lines and 10 A written description to explain the
keywords. development and operation of a
5 A method of algorithm description program.
that uses a pictorial or graphical
method.
Terms
a Algorithm f Program
b Array g Pseudocode
c Data type h Selection
d Documentation i Sequence
e Flowchart j Test data
Project 8.1
Project 8.2
Project 8.3
Cross project 3
360 H I Te c h : I n f o r m a t i o n a n d S o f t w a r e Te c h n o l o g y