Software development and programming. Software



Similar documents
Chapter 13: Program Development and Programming Languages

Chapter 12 Programming Concepts and Languages

Chapter 13: Program Development and Programming Languages

Stage 5 Information and Software Technology

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Visual Logic Instructions and Assignments

Pseudo code Tutorial and Exercises Teacher s Version

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

EKT150 Introduction to Computer Programming. Wk1-Introduction to Computer and Computer Program

Fundamentals of Programming and Software Development Lesson Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Flowchart Techniques

Programming in Access VBA

For Introduction to Java Programming, 5E By Y. Daniel Liang

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Flowcharting, pseudocoding, and process design

#820 Computer Programming 1A

How To Understand Programming Languages And Programming Languages

Visual Basic Programming. An Introduction

McGraw-Hill The McGraw-Hill Companies, Inc.,

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

Before you can use the Duke Ambient environment to start working on your projects or

Software Development. Topic 1 The Software Development Process

Accredited Specimen Mark Scheme

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

Instructor Özgür ZEYDAN BEU Dept. of Enve. Eng. CIV 112 Computer Programming Lecture Notes (1)

Syllabus for CS 134 Java Programming

Hypercosm. Studio.

Software Design and Development

3 SOFTWARE AND PROGRAMMING LANGUAGES

Computing Concepts with Java Essentials

Java Application Developer Certificate Program Competencies

MICROSOFT ACCESS STEP BY STEP GUIDE

Computer Programming I

Course MS10975A Introduction to Programming. Length: 5 Days

Decision Logic: if, if else, switch, Boolean conditions and variables

VB.NET Programming Fundamentals

JavaScript: Control Statements I

Hermes.Net IVR Designer Page 2 36

VIRTUAL LABORATORY: MULTI-STYLE CODE EDITOR

Computer Programming I

Jump-Start Tutorial For ProcessModel

Fundamentals of Java Programming

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

Algorithms, Flowcharts & Program Design. ComPro

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

This Document Contains:

I PUC - Computer Science. Practical s Syllabus. Contents

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Computer Programming I & II*

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide

Chapter 7: Software Development Stages Test your knowledge - answers

Access Queries (Office 2003)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

C A R I B B E A N E X A M I N A T I O N S REPORT ON CANDIDATES S WORK IN THE CARIBBEAN SECONDARY EDUCATION CERTIFICATE EXAMINATION MAY/JUNE 2012

Algorithm and Flowchart Structured Programming 1

Chapter 14. Programming and Languages. McGraw-Hill/Irwin. Copyright 2008 by The McGraw-Hill Companies, Inc. All rights reserved.

EVALUATION. WA1844 WebSphere Process Server 7.0 Programming Using WebSphere Integration COPY. Developer

River Dell Regional School District. Computer Programming with Python Curriculum

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Notes on Algorithms, Pseudocode, and Flowcharts

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

Microsoft Access is an outstanding environment for both database users and professional. Introduction to Microsoft Access and Programming SESSION

18 Software. design. Learning outcomes. Credit value: 10

CS 241 Data Organization Coding Standards

Understanding class definitions

>print "hello" [a command in the Python programming language]

The C Programming Language course syllabus associate level

PL / SQL Basics. Chapter 3

Creating a Simple Macro

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

Introduction to Python

Exercise 4 Learning Python language fundamentals

50 Computer Science MI-SG-FLD050-02

The programming language C. sws1 1

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail

Informatica e Sistemi in Tempo Reale

Using FM. A guide for children and their families on how to use an FM solution with hearing aids

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Mission 1: What is Energy?

EMC Publishing. Ontario Curriculum Computer and Information Science Grade 11

How to Format a Bibliography or References List in the American University Thesis and Dissertation Template

Microsoft Access 2010 Part 1: Introduction to Access

Welcome to Introduction to programming in Python

1 Introduction. 2 Overview of the Tool. Program Visualization Tool for Educational Code Analysis

An Introduction to MPLAB Integrated Development Environment

COMPUTER SCIENCE (5651) Test at a Glance

10 STEPS TO YOUR FIRST QNX PROGRAM. QUICKSTART GUIDE Second Edition

Good FORTRAN Programs

Transcription:

CHAPTER 15 15 Software 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.

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 HI Tech: Information and Software Technology

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

Lit 8.2 Interactive 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 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 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 (<=), greaterthan-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 b c d A collection of instructions that, when executed, will complete a task on the computer. The name given to anything in a program such as a variable. A component in a GUI that enables the user to select one option from a group. Data type for whole numbers without fractional parts. 334 HI Tech: Information and Software Technology

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

Before an algorithm can be written the problem must be fully understood. How a solution is arrived at depends a lot on past experience. If a similar problem has been solved it is an obvious advantage. 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 methods of algorithm description. There are many different methods of algorithm description such as pseudocode and flowcharts. Pseudocode Pseudocode uses indented lines and keywords to describe an algorithm. Pseudocode is written using a word processor and is similar to many programming languages. There are different 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 HI Tech: Information and Software Technology

Table 15.1 Keywords used in pseudocode Keywords BEGIN END IF (condition) THEN process 1 ELSE process 2 ENDIF WHILE (condition) process 1 ENDWHILE REPEAT process 1 UNTIL (condition) Meaning Terminal: start and finish Selection: different tasks are performed according to the condition The ELSE statement is optional Repetition: statements between the keywords are repeated while the condition is true (Pre-test repetition) Repetition: statements between the keywords are repeated while the condition is true (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 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. Lit 8.3 15 Software development and programming 337

Table 15.2 Symbol Symbols used in flowcharts Meaning Terminal: start and finish There should be only one line in or one line out Set count to thirty Process: used to describe a process or action It contains one line in and one line out Set count to thirty Subprogram: process described by its own flowchart to perform a particular task Decision: it consists of one line coming in at the top and two lines leaving it Begin Make length 3cm Make breadth 5cm Set area to length x breadth Display area The Australian standards for flowcharting indicate that the main direction of flow is from top to bottom or left to right. This flow of control is indicated by lines and arrows called flowlines. Flowlines do not need an arrow if the flow of control is following these main directions. For example, in Figure 15.3 the flow of control is from top to bottom so there are no arrows on the flowlines. Problem: Design a flowchart to calculate the area of a rectangle given a length of 3 cm and a breadth of 5 cm. Solution: Figure 15.3 shows the flowchart for this problem. End Figure 15.3 Flowchart to calculate area of a rectangle 338 HI Tech: Information and Software Technology

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: b Read book Open book to first page Close book Get book 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 a Convert this algorithm into pseudocode. b Convert this algorithm into a flowchart. ICT 15.1 15 Software development and programming 339

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 HI Tech: Information and Software Technology

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

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 Is it night? True 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 HI Tech: Information and Software Technology

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

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 Is car moving? False 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 HI Tech: Information and Software Technology

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 b c d e END WHILE (condition) process ENDWHILE IF (condition) THEN process 1 ELSE process 2 ENDIF REPEAT Process UNTIL (condition) f False Figure 15.9 Figure 15.10 True 15 Software development and programming 345

g False True h 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: b 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 Pseudocode: BEGIN set Count to one WHILE Count is less than eleven print Count increment Count by one ENDWHILE END 346 HI Tech: Information and Software Technology

c d Pseudocode: BEGIN set Count to ten REPEAT print Count increment Count by one UNTIL Count is twenty END e Begin Begin Print What is my favourite colour? Set Count to twenty Input colour Is Count > 0? True False False Is colour blue? True Print Count Print You are wrong, blue is the answer Print Congratulations you are right Decrease Count by one End End Figure 15.13 Figure 15.14 f 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

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 Tutorial 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 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 HI Tech: Information and Software Technology

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 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). Lit 8.4 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

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 HI Tech: Information and Software Technology

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. 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 Figure 15.17 Java program 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

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 HI Tech: Information and Software Technology

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 timeconsuming and challenging task. Testing Test data is used to detect and correct any potential errors in a program. Except for simple programs, test data will only cover a small percentage of all the possible sets of data. The programmer selects test data that will cater for the worst-case situation. This is data the programmer predicts will cause a problem. It is often data outside the boundaries of acceptable data such as entering a decimal number instead of an integer. Test data is also designed to check for 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. 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 The term bug is a result of a problem with the Mark 1 computer in 1945. This computer started working after a moth was removed from the inside of the machine. Consequently, any unknown problem with a computer is said to be a bug. Lit 8.5 15 Software development and programming 353

A trapdoor is a section of code used by programmers as a diagnostic tool to enable them to access certain parts of a program. Trapdoors are removed before a program is sold. 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. Documentation Documentation is a written description to explain the development and operation of a program. It is not part of the actual code. Documentation is an important aspect of writing programs as it helps the reader to understand what is going on. It should be written during the development of the program, however, it is often neglected 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 HI Tech: Information and Software Technology

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. 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. ICT 15.2 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

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 HI Tech: Information and Software Technology

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

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

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, when executed, will complete a task on the computer. 2 The kind of data that can be stored in a variable. 3 A series of steps designed to solve a problem in a finite time. 4 A method of algorithm description that uses indented lines and keywords. 5 A method of algorithm description that uses a pictorial or graphical method. 6 Control structure that specifies the order the steps are executed. 7 Control structure used to make a logical decision. 8 Data structure that stores a list of elements of the same data type. 9 It is used to detect and correct any potential problems in a program. 10 A written description to explain the development and operation of a program. Terms a Algorithm b Array c Data type d Documentation e Flowchart f g h i j Program Pseudocode Selection Sequence Test data Part C: Extended response questions Write at least one paragraph for each of the following: 1 Variable declaration involves stating the data type of the variable. Briefly describe five different data types that are commonly used in programs. 2 Explain the purpose of data operators. Identify and describe three different types of operators. 3 Pseudocode and flowcharts are two popular methods for algorithm description. Outline the main features of these methods. 4 Explain the difference between: a binary selection and case selection b a pre-test repetition and a posttest repetition. 5 What is a high-level language? Outline the processes involved in structured programming. 6 Testing should be done throughout the development of a program to detect errors. Describe three basic 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

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 HI Tech: Information and Software Technology