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

ISTch15 - Software Development & Programming

Uploaded by

arwinplayz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

ISTch15 - Software Development & Programming

Uploaded by

arwinplayz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

313 ISTech Chapt 15.

3pp 23/9/04 12:45 PM Page 331

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.

Figure 15.1 Java program

Basic programming concepts


When writing a program it is necessary to consider the input,
processing and output. Input is the data needed to solve the
problem, the processing is the calculations required and the output
is the way of giving the solution. Once these factors are determined,
the actual task of writing programs is minimised. A program is
written in a programming language using the following concepts.
• Function (or keyword) is a reserved word for a particular
purpose such as class, public and private. Some functions are
very powerful, such as if and while.

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

15 Software development and programming 333


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 334

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

3 Copy and complete the following by replacing the letter in


brackets with a suitable term:
People who write (a) are called programmers. A collection of
programs is called (b). Programmers use (c) languages such as Java,
(d) and C++.
4 a What is programming?
b Describe the factors that minimise the actual task of writing
programs.
c What is the purpose of an assignment statement?
d What is a variable declaration?
e List five common data types.
f What is a data operator?

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.

15 Software development and programming 335


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 336

Algorithms can be used to describe simple daily actions or


explain a particular task. For example:
Algorithm to make a phone call:
Pick up the phone.
Dial number.
Deliver the message.
Hang up the phone.
Algorithm to catch a train:
Travel to station.
Buy a ticket.
Go to the correct platform.
If the correct train, catch the train, otherwise wait.
Repeat the above step.
Algorithm to install a smoke alarm:
Select a central location such as the hallway.
Select a wall or ceiling on which to mount the alarm.
Unlatch and remove the mounting plate from the alarm.
Use the screws to secure mounting plate to ceiling.
Install batteries into alarm body.
Hook the alarm body onto the mounting plate.

In all of these examples the algorithm presents a solution in a


definite number of steps. Each step is short enough so that it can be
easily carried out. The steps must also be performed in a particular
order (sequence) to solve the problem; for example, you cannot
hang up the phone before delivering the message. Algorithms are
represented in a number of different ways. These are referred to as
Before an
algorithm can methods of algorithm description. There are many different
be written the methods of algorithm description such as pseudocode and
problem must be flowcharts.
fully understood.
How a solution is
arrived at depends Pseudocode
a lot on past
experience. If a
Pseudocode uses indented lines and keywords to describe an
similar problem algorithm. Pseudocode is written using a word processor and is
has been solved similar to many programming languages. There are different
it is an obvious
advantage.
standards of pseudocode for different purposes, however, there are
some generally accepted rules. The flow of control in pseudocode is
always from the top to the bottom. The keywords are highlighted in
capital letters (or bold) to emphasise them and to indicate the type
of action being performed. The most common keywords are shown
in Table 15.1. These keywords are grouped together in pairs. For
example, for every BEGIN there is an END, for every IF there is an
ENDIF. Indentation is used to show the structure of the algorithm.

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

Table 15.1 Keywords used in pseudocode

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)

Problem: Write pseudocode to calculate the area of a


rectangle given a length of 3 cm and a breadth of 5 cm.
Solution:
BEGIN
Make length 3 cm
Make breadth 5 cm
Set area to length × breadth
Display area
END
Lit 8.3
Flowcharts
A flowchart is a pictorial or graphical
method of describing an algorithm.
Flowcharts often make it easy to see
the structure of the solution. However,
it is very easy to draw a flowchart that is
complex and difficult to change into a
programming language. The basic
elements of a flowchart are a set of
symbols that contain messages
and interconnecting lines. A set of
standards for flowcharts has been
established for a number of
different applications. The four
most commonly used symbols are
shown in Table 15.2.

15 Software development and programming 337


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 338

Table 15.2 Symbols used in flowcharts

Symbol Meaning
Terminal: start and finish
There should be only one line in or one line out

Process: used to describe a process or action


Set count to thirty
It contains one line in and one line out

Subprogram: process described by its own


Set count to thirty
flowchart to perform a particular task

Decision: it consists of one line coming in at the


top and two lines leaving it

The Australian standards for


flowcharting indicate that the main
Begin
direction of flow is from top to bottom
or left to right. This flow of control is
indicated by lines and arrows called
Make length 3cm flowlines. Flowlines do not need an arrow
if the flow of control is following these
main directions. For example, in Figure
Make breadth 5cm
15.3 the flow of control is from top to
bottom so there are no arrows on the
flowlines.
Problem: Design a flowchart to
Set area to
length x breadth calculate the area of a rectangle
given a length of 3 cm and a
breadth of 5 cm.

Display area Solution: Figure 15.3 shows the


flowchart for this problem.

End

Figure 15.3 Flowchart to


calculate area of a rectangle

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.

15 Software development and programming 339


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 340

6 An algorithm to listen to a CD is shown below:


Turn on equipment
Insert CD
Select track
Play
a Convert this algorithm into pseudocode.
b Convert this algorithm into a flowchart.
7 Design an algorithm in both pseudocode and a flowchart for the
following:
a making a cheese sandwich
b making a bowl of cereal for breakfast.

15. 3 Control structures


Programmers solve a problem by designing an algorithm and then
coding the algorithm into a programming language. Algorithms
and programming languages consist of control structures. Control
structures are the building blocks of the program. There are three
basic control structures: sequence, selection and repetition.

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

Rinse off soap

Dry hands

End

Figure 15.4 Flowchart to


wash your hands

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.

15 Software development and programming 341


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 342

Problem: Design an algorithm for turning on the lights.


Pseudocode solution
BEGIN
IF night
THEN turn lights on
ELSE turn lights off
ENDIF
END
Flowchart solution

Begin

False True
Is it night?

Turn lights off Turn lights on

End

Figure 15.5 Flowchart for turning on the lights

Case selection (or multiway selection) involves more than two


choices. In pseudocode, the keywords CASEWHERE … ENDCASE
are used for case selection (see the problem below). The condition
is put after the CASEWHERE keyword. Careful thought is required
to cater for all possible answers to the condition. The possibilities
are indented under the CASEWHERE keyword with a process to be
executed only if the answer is true. In the problem below there are
three options: green, amber and red with a colon specifying the
process to be carried out if the option is true. In a flowchart the
case selection is made using a decision symbol (see Figure 15.6).
The condition is placed inside the decision symbol with the
answers above each process. The flowlines join together to complete
the case selection.
Problem: Design an algorithm for a set of traffic lights.

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?

Green Amber Red

Pass through lights Slow down vehicle Stop vehicle

End

Figure 15.6 Flowchart for a set of traffic lights

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.

15 Software development and programming 343


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 344

Problem: Design an algorithm for using seat belts in a car.


Pseudocode solution
BEGIN
WHILE car is moving
keep seat belts on
ENDWHILE
END
Flowchart solution

Begin

False
Is car moving?

True

Keep seat belts on

End

Figure 15.7 Flowchart for using seat belts in a car

In a post-test repetition or unguarded loop the condition is


checked at the end of the loop after the steps to be repeated are
executed. In pseudocode the keywords used for a post-test repetition
are REPEAT … UNTIL (see problem below). The body of the loop
is underneath the REPEAT keyword and the condition is after the
UNTIL keyword. In a flowchart the post-test repetition is made with
a decision symbol and flowlines (see Figure 15.8). The body of the
loop is executed before the condition is met in the decision symbol.

Problem: Design an algorithm to cut the grass.


Pseudocode solution
BEGIN
REPEAT
Use lawn mower
UNTIL grass is cut
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

Use lawn mower

False
Is grass cut?

True

End

Figure 15.8 Flowchart to cut the grass

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

Figure 15.9 Figure 15.10

15 Software development and programming 345


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 346

g h
False True False

True

Figure 15.11 Figure 15.12

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

Print ‘What is my Set Count to twenty


favourite colour?‘

False
Is Count
Input colour
> 0?

True

False Is colour True Print Count


blue?

Print ‘You are wrong, Print ‘Congratulations Decrease Count by one


blue is the answer’ you are right’

End End

Figure 15.13 Figure 15.14

Begin

Set Count to thirty

Print Count

Decrease Count by two

False
Is Count less
than eight?

True

End

Figure 15.15

15 Software development and programming 347


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 348

6 Convert these algorithms into pseudocode and flowcharts:


a Go to the bus stop
Wait for the bus
Get on bus
Pay fare
b Alarm goes off
Get out of bed
If I have homework to complete, then finish homework
Get dressed
Eat breakfast
c Go to the lounge room
Turn on the TV
If it is Sunday, then watch a movie else watch news
d Wake up
Get out of bed
Have a shower
If weekday, then put on uniform else put on normal clothes
Eat breakfast
e Go to the station
Buy a ticket
Buy a magazine
Sit on a seat and read a magazine until the train comes
Put magazine in bag
Get on the train
7 Construct an algorithm in pseudocode for the following tasks:
a making a phone call
b cleaning your teeth.

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

languages such as Java, Visual BASIC and C++ are high-level


languages. A compiler or interpreter translates a high-level program
into machine code so the computer can implement the solution.

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

describing different types of objects—what they can do, how they


are created and how they interact with other objects. Creating an
object requires defining that object. This is called creating a class.
A class describes how objects behave and the kind of information
in the object. It is a template to create objects. After defining classes
and creating objects programmers write instructions to complete a
task. A task could be adding numbers or completing a simple game
(see Figure 15.16).

Figure 15.16 Instructions in Visual Basic

Object-oriented programming requires keywords, literals,


variables, identifiers, separators, data types and operators. These
concepts were examined at the start of this chapter. Java is a
popular language developed by Sun Microsystems to create small
applications. It is an object-oriented language that excels at
producing web-based applets that work on different types of
computers. Applets are graphical Java programs that execute within
a web page. They are responsible for the dynamic nature of the Web.
The Java software development kit has all the tools and resources
needed to write Java applets and applications. The Java program is
written in a text editor and a Java compiler used to convert the
program into source code for an HTML document. The control
structures used in Java are similar to pseudocode:

15 Software development and programming 349


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 350

• sequence—execute one after another from the start to the end


• binary selection—uses the if–else keywords:
if (condition)
Statement 1
else
Statement 2
• case selection—uses the switch–case keywords:
switch (Expression)
case Constant 1:
StatementList1
case Constant 2:
StatementList2
default:
DefaultStatementList
• pre-test repetition—uses the while keyword:
while (LoopCondition)
Statement
• post-test repetition—uses the do–while keywords:
do
Statement
while (LoopCondition)
Problem: Write a Java program that will ask the user for
their first name and print this name ten time on the screen.
Pseudocode solution
BEGIN
set Count equal one
input user’s name
WHILE Count is less than or equal to 10
print user’s name
increment Count by one
ENDWHILE
END
Java solution is shown in Figure 15.17

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

Public int add2Int (int x, int y)


{
Int result;
result = x + y
Return result;
}
Subprograms have a single
entry point and suspend the calling
program until they have finished.
Subprograms have the added
advantage of being reuseable.
Programmers may use the same
subprogram many times in different
problems. This reduces the time
required to program. Programmers
keep a ‘library’ of subprograms they
have written.

Data structures
A file is a block of related data
stored on a storage device. Figure 15.17 Java program

Programs are stored as files. A data structure used in many


programming languages is called a record.
A record is a collection of facts that are related in some way.
Records are a fixed length and are divided into one or more fields.
A field is a specific piece of data in a record. Shown below is a
record that consists of 17 characters: eight for field 1, seven for field
2 and two for field 3. Each record, irrespective of the data, would
have a fixed length of seventeen characters. A record is usually a
combination of other data types. The record below has a string data
type and an integer data type. The ability to have different data
types distinguishes records and arrays.
s m i t h l u k e 1 6

An array stores a list of elements of the same data type. An array


is used to efficiently store large quantities of data. Each element
within an array is numbered and accessed based on their number.
To use an array the data type and the number of items must be
declared. For example, array declarations in Java are shown below.
Int[] score = new int[10];
char[] vowel char[5];

15 Software development and programming 351


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 352

The first statement creates an integer array ‘score’ with up to ten


elements. The second statement creates a character array ‘vowel’
with up to five elements. After the array is declared each individual
element can be used to store data. In the example below vowel[1] is
storing the letter ‘E’.
vowel[0] = ‘A’;
vowel[1] = ‘E’;
vowel[4] = ‘U’;

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.

15. 5 Testing and


documentation
Most programmers strive for the perfect program, however, few are
able to achieve it. It is rare for a complex program to be written
without errors. Errors in a program are called bugs. A bug is an
error that makes the program run incorrectly. The process of
finding a bug is called debugging. Debugging is often a time-
consuming and challenging task. The term ‘bug’ is
a result of a
problem with the
Testing Mark 1 computer
Test data is used to detect and correct any potential errors in a in 1945. This
computer started
program. Except for simple programs, test data will only cover a working after a
small percentage of all the possible sets of data. The programmer moth was removed
selects test data that will cater for the ‘worst-case’ situation. This is from the inside of
the machine.
data the programmer predicts will cause a problem. It is often data Consequently, any
outside the boundaries of acceptable data such as entering a decimal unknown problem
number instead of an integer. Test data is also designed to check for with a computer is
said to be a ‘bug’.
expected outcomes. For example, if a user enters 4 the program
should display the result for this value. The selection of test data
depends on the programmer’s understanding of the program.
Programmers use test data throughout the development of a program.
Lit 8.5
Error detection and correction
Error detection involves identifying and describing the error. Error
correction fixes the source of the error to create a workable program.
There are three basic types of errors:
• Logic errors result from an incorrect series of steps to solve the
problem. The program with a logic error produces incorrect or
unexpected results. Logic errors can occur if the algorithm does
not solve the problem correctly. The algorithm should be tested
before coding to eliminate logic errors. It is often a difficult task
to find and correct logic errors.
• Syntax errors are made when the programmer has failed to
follow the rules (syntax) of the programming language. A syntax
error may be a spelling error or a symbol that cannot be

15 Software development and programming 353


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 354

translated. When the program is compiled or interpreted, an


error message will appear if the program contains any syntax
errors. Correcting any syntax errors is usually a simple task.
• Run-time errors occur when it is impossible for the computer to
carry out the instruction. For example, if a calculation
attempted to divide a number by zero it would be a run-time
error. The instruction has the correct syntax but it is not
possible to carry out the instruction. Incorrect data can often
produce a run-time error.
There is a range of strategies to detect and correct errors:
• Desk checking involves the programmer checking each line of
code. Desk checking takes place after the algorithm has been
written and again after it has been coded in the programming
language. The programmer executes the program the same as
the computer. Desk checking provides a way to see exactly what
code is being executed and the flow of execution through the
program. A desk check usually involves watching the variables.
A list is constructed containing the names of variables and their
values. The list of variables is updated after each step of the desk
check. If the desk check is performed by somebody other than
the programmer it is called a peer check.
• Breakpoint is a roadblock in the execution of the program.
When the program reaches a breakpoint it stops. Breakpoints
are useful in isolating sections of the code and analysing them.
• Software debugging tools are available for most programming
languages. A debugger is a program that will perform the desk
check electronically. They are often used with a breakpoint to
watch the variables in a section of code. Debuggers are only tools
to find problems and do not provide the solution to the problem.
A trapdoor is a
section of code
used by Documentation
programmers as a Documentation is a written description to explain the development
diagnostic tool to
enable them to
and operation of a program. It is not part of the actual code.
access certain parts Documentation is an important aspect of writing programs as it
of a program. helps the reader to understand what is going on. It should be written
Trapdoors are
removed before a
during the development of the program, however, it is often neglected
program is sold. and left until last. This results in inadequate documentation making
the program difficult to understand and modify. The documentation
required in a program falls into three main categories:
• Intrinsic documentation involves writing an easy-to-read
program. It involves using correct programming techniques and
meaningful variable names such as ‘height’ instead of ‘x’.

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

• Internal documentation consists of any comments or remarks


within the program code to describe its purpose. The code
below shows internal documentation in Java using the forward
slash and asterisk:
/* This form of documentation allows the text to wrap
around onto succeeding lines
*/
// This form of documentation is restricted to one line
• External documentation consists of any written support
material. This may include a problem statement, input data,
output data, processes, algorithm, test data and a listing of the
program, user manuals and installation guides.

Project: Rite Software


Arla is a programmer who has been contracted to update the user
interface for Rite Software. Rite Software is a suite of programs to help
children read and write. The user interface was written seven years ago
and looks dated. She solved the problem using the four stages in
project development.
• Define and analyse the problem: Arla spoke with the manager to
determine the exact requirements of the problem. She collected
information to be displayed on the screen. A project plan was
written and submitted for approval to the manager.
• Design possible solutions: Arla designed four possible screens. Each
possible solution had the same objects; however, they were
formatted and displayed in different ways. A feasibility report was
written and presented to the manager. The recommendation from
the feasibility report was accepted by the manager. Arla designed
an algorithm using pseudocode to solve the problem.
• Produce the solution: Arla used Visual BASIC programming
language to code the algorithm. She created forms and added
objects to those forms. The properties of each object were
specified. Arla entered the code and saved the project.
ICT 15.2
• Evaluate the solution: Arla tested the program to ensure each
screen and form was working correctly. There was a problem
displaying one of the images and this was fixed. The new software
was presented to the manager.

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?

15 Software development and programming 355


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 356

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.

15 Software development and programming 357


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 358

Part A: Multiple choice questions


Select the alternative (a), (b), (c) or (d) that best answers each question.
1 Which of the following is a reserved a Case repetition
word for a particular purpose? b Case sequence
a Variable c Case selection
b Separator d Case algorithm
c Constant
6 Which of the following is a loop
d Function
checked at the end after the steps to
2 Which of the following describes a be repeated are executed?
data type to store a value that has a Pre-test repetition
one of two possible states such as b Post-test repetition
true or false? c Pre-test selection
a Boolean d Post-test selection
b String 7 Which of the following is a self-
c Floating-point
contained section of code that
d Yes/no
performs a particular task?
3 Which of the following statements is a Array
incorrect? b Subprogram
a Algorithms present a solution in a c Programming language
definite number of steps d File
b Keywords in pseudocode are
8 Which of the following requires a
highlighted to indicate the type of
programmer to package data and the
action being performed
methods into a single unit called an
c Flowcharts are easier than
pseudocode to convert into a object?
programming language a OOP
d Flow of control is indicated by b GUI
lines and arrows called flowlines c Low-level languages
d High-level languages
4 Which method of algorithm
description uses keywords grouped 9 Which of the following is the result
in pairs? from an incorrect series of steps to
a Pseudocode solve the problem?
b Flowchart a Syntax error
c Java b Run-time error
d Visual BASIC c Logic error
d Desk check
5 What control structure is represented
by the following algorithm segment? 10 Which of the following describes
comments or remarks within the
CASEWHERE (condition)
program code to explain its purpose?
process 1
process 2 a Comment documentation
b External documentation
ENDCASE
c Intrinsic documentation
d Internal 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

Part B: Match the term


For each of the following statements (1 to 10), select from the list of terms (a to j)
the one that most closely fits the statement.

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

Part C: Extended response questions


Write at least one paragraph for each of the following:
1 Variable declaration involves stating 4 Explain the difference between:
the data type of the variable. Briefly a binary selection and case selection
describe five different data types b a pre-test repetition and a post-
that are commonly used in programs. test repetition.
2 Explain the purpose of data 5 What is a high-level language?
operators. Identify and describe three Outline the processes involved in
different types of operators. structured programming.
3 Pseudocode and flowcharts are two 6 Testing should be done throughout
popular methods for algorithm the development of a program to
description. Outline the main detect errors. Describe three basic
features of these methods. types of errors. Which type of error
usually takes the longest
to correct? Give reasons
for your answer.
e Tester

15 Software development and programming 359


313 ISTech Chapt 15.3pp 23/9/04 12:45 PM Page 360

Project: Arithmetic program


Max is a primary teacher who needs software to test his student’s arithmetic skills.
The program should present students with ten problems to add and subtract
numbers. The numbers selected should be done randomly and not require the
student to calculate negative numbers. The program should total the number of
correct answers and store their results for Max. This is a group project to be
developed using the four stages in project development. Demonstrating the
operation of the arithmetic program and documenting the solution are important
criteria for this project.

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

You might also like