79
Introduction to Programming C_ITPR011 & C_ITPR111

Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction to Programming

C_ITPR011 & C_ITPR111

Page 2: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Compiled by Dale Sibanda and Tania Jordaan

Quality assured by Tania Jordaan Nee De Agrela

Edited by Chantal Joseph

Version 1.0

NQF Level 5

Credit value: 12

November 2014 CTI EDUCATION GROUP

Page 3: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

TABLE OF CONTENTS

INTRODUCTION .......................................................................................................... 1 Module aim ........................................................................................................... 1 Module abstract .................................................................................................... 1 Learning outcomes and assessment criteria ......................................................... 2 Summary of learning outcomes and assessment criteria 2 Module content ..................................................................................................... 3 Lectures................................................................................................................ 5 Class exercises and activities ............................................................................... 5 Information resources .......................................................................................... 5 Prescribed textbook ............................................................................................. 5 Prescribed textbook for Introduction to Programming 5 Recommended information sources ...................................................................... 6 Using the Study Guide .......................................................................................... 6 Purpose ................................................................................................................ 7 Structure .............................................................................................................. 7 Individual units .................................................................................................... 7 Glossary ............................................................................................................... 8 The use of icons .................................................................................................... 8 Alignment to prescribed textbook ........................................................................ 9 Study Guide/prescribed textbook alignment 10 Concluding remarks ............................................................................................ 13

UNIT 1: PROGRAMMING CONCEPTS .......................................................................... 14 Learning objectives ............................................................................................ 14 Introduction ....................................................................................................... 14 1.1 General concepts .................................................................................... 15 1.1.1 Entities and attributes 15 1.1.2 Data types and variables 15 1.1.3 Constant 18 1.1.4 The value and assignment of the variable 18 1.1.5 Arithmetic expressions 18 1.2 Analysing and solving problem ............................................................... 19 1.2.1 Simple problem solving 20 Test your knowledge .......................................................................................... 24

UNIT 2: WRITING ALGORITHMS ............................................................................... 25 Learning objectives ............................................................................................ 25 Introduction ....................................................................................................... 25 2.1 Program planning ................................................................................... 26 2.1.1 IPO chart 26 2.1.2 Properties of an algorithm 26 2.2 Testing algorithm logic ........................................................................... 26 2.3 Outcome of an algorithm ........................................................................ 27 Test your knowledge .......................................................................................... 28

UNIT 3: SELECTION STRUCTURES AND LOOP STRUCTURES ...................................... 29 Learning objectives ............................................................................................ 29 Introduction ....................................................................................................... 30 3.1 Logical and relational operators ............................................................. 30 3.1.1 Logical operators 30 3.1.2 Relational operators 31 3.2 IF statements ......................................................................................... 31 3.3 SELECT CASE statements ........................................................................ 33 3.4 FOR loops ............................................................................................... 34 3.5 DO loops ................................................................................................. 35 3.5.1 Do-While statement 36 3.5.2 Do-Until statement 37

Page 4: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Test your knowledge .......................................................................................... 41

UNIT 4: ARRAYS ....................................................................................................... 42 Learning objectives ............................................................................................ 42 Introduction ....................................................................................................... 43 4.1 An array .................................................................................................. 43 4.1.1 Properties and characteristics of arrays 43 4.2 One-dimensional array ........................................................................... 45 4.3 Two-dimensional array ........................................................................... 46 Test your knowledge .......................................................................................... 47

UNIT 5: MODULARISATION AND VARIABLE SCOPE .................................................. 48 Learning objectives ............................................................................................ 48 Introduction ....................................................................................................... 49 5.1 Variable scope ........................................................................................ 49 5.1.1 Local variables 49 5.1.2 Global variables 49 5.1.3 External variables 49 5.1.4 Static variables 49 5.2 Modularisation ........................................................................................ 50 5.2.1 Advantages of modularisation 50 5.2.2 Hierarchy charts 51 5.2.3 Parameters 51 5.3 Using function procedures ...................................................................... 51 5.4 Sub-procedures ...................................................................................... 52 5.5 Functions and subprocedures without parameters ................................. 53 5.6 Passing parameters in a function ............................................................ 54 5.6.1 Passing parameters by value 54 5.6.2 Passing parameters by reference 54 5.6.3 Passing parameters by pointer 54 5.6.4 Passing arrays as parameters 55 Test your knowledge .......................................................................................... 55

UNIT 6: SEQUENTIAL TEXT FILES ............................................................................. 57 Learning objectives ............................................................................................ 57 Introduction ....................................................................................................... 58 6.1 Input and output files ............................................................................. 58 6.2 Opening and closing a text file................................................................ 58 6.2.1 Opening a text file 58 6.2.2 Closing a text file 59 6.3 Reading and writing from and to a text file ............................................ 59 6.3.1 Reading from an input file 59 6.3.2 Writing to an output file 60 6.3.3 Reading and writing to the same file 60 Test your knowledge .......................................................................................... 61

UNIT 7: DOCUMENTATION AND ERROR PREVENTION ............................................... 62 Learning objectives ............................................................................................ 62 Prescribed reading ............................................................................................. 63 Introduction ....................................................................................................... 63 7.1 Error detection........................................................................................ 63 7.1.1 Logical errors 63 7.1.2 Syntax errors 64 7.1.3 Data errors 64 7.2 Program testing ...................................................................................... 64 7.2.1 Walkthroughs 65 7.2.2 Unit testing 65 7.2.3 Data coverage 65 7.2.4 Code coverage 65 7.2.5 Trace tables 65 7.3 Relevant program documentation ........................................................... 66

Page 5: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

7.3.1 Code comments 67 7.3.2 User interface design 68 7.3.3 User guide 68 Test your knowledge .......................................................................................... 70

GLOSSARY ................................................................................................................ 71

BIBLIOGRAPHY ........................................................................................................ 73

Page 6: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 1

© CTI Education Group

Introduction

Welcome to Introduction to Programming, in which we focus on the basic knowledge of general principles and the concepts of programming. Students

will develop programs and, although the content could be delivered from a range of languages, compilers or platforms, the module is aimed at gaining the

basic skills to be able to use any programming language, equipping the student with skills and knowledge that will easily transfer to other areas of the

qualification life cycle.

Students will adopt good practice while designing programs using industry

techniques. The student will also use variables, constants and literals. The student will understand the concepts of data storage within a computer

program and identify or select appropriate iterative and selection structures when writing simple programs. In addition to the above, the student will learn

the facilities and rules of the language, e.g. operators, I/0 commands and how to make use of comments and code layout.

The student will use or create both predefined and user-defined functions and

procedures; and map structured design onto a program using functions or procedures; pass data by value and reference and create software applications,

e.g. a word processor or graphics, analysis, design and implementation of documentation; professional standards. Students will test the data and

schedules, e.g. black box, white box, dry testing and data collection.

Module aim

The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the use

of various platforms to create real life programs with the use of C, C++, Java to mention a few.

Module abstract

When we look at our lives, we realise that technology has become embedded

in everything that we do. Information technology has been around for a very long time, and there were various means of communicating through

developments in technology. The current (Electronic) Age is one in which there is no shortage of inexpensive means of communication; through the use of

tablets, smartphones, or opportunities to communicate with friends on various social networking sites, such as Facebook and Twitter.

Page 7: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 2

© CTI Education Group

With this paradigm shift, it is vital to learn how we got to the point where we are now, in terms of change in technology. Only a few years ago, banks

regularly used cheque books, deposit slips and withdrawal slips; these have since all but vanished, due to the use of technology. Thus, applications have

been created using programming languages to initiate this change. This has led to the necessity of learning the different programming languages to keep

up to date with the changing trends.

Learning outcomes and assessment criteria

On successful completion of this module, you will:

1. Use, develop and design structured programming methods

2. Use modularisation from the chosen programming language

3. Produce appropriate documentation for a given program application

4. Create and apply appropriate test schedules

The following table outlines the assessment criteria that are aligned to the

learning outcomes.

Summary of learning outcomes and assessment criteria

Learning outcomes Assessment criteria for pass

On successful completion of

this unit, the student will The student can

1. Use, develop and design

structured programming

methods

1.1 Identify and select appropriate pre-defined data

types

1.2 Use simple input or output and appropriate

operators with the above

1.3 Identify and use appropriate selection structures

and loop structures for the given task

1.4 Produce programs to desired standards

2. Use modularisation from the

chosen programming

language

2.1 Construct a program from a design and use

appropriate functions/procedures

2.2 Demonstrate the effect of scope and life-time of

variables

2.3 Pass data effectively between modules

Page 8: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 3

© CTI Education Group

Learning outcomes Assessment criteria for pass

3. Produce appropriate

documentation for a given

program application

3.1 Produce user documentation for a completed

programming application including the user

interface design

3.2 Develop documentation for a pre-described

program application

4. Create and apply appropriate

test schedules

4.1 Demonstrate discrimination between semantic and

syntax errors

4.2 Produce test documentation

4.3 Successfully construct and use test data and

schedules to detect logic errors

4.4 Use appropriate techniques for detecting errors

These outcomes are covered in the module content and they are assessed in the

form of written assignments and semester tests. If you comply with and achieve all the pass criteria related to the outcomes, you will pass this module.

Learning and assessment may be performed across modules, at module level

or at outcome level. Evidence may be required at outcome level, although

opportunities exist for covering more than one outcome in an assignment.

Module content

1. Use, develop and design structured programming methods Content covered for learning outcome

Storage: The student will use variables, constants and literals. Understand

the concepts of data storage within a computer program. For a third generation language, the use of pre-defined data types, integers, floating

point, character, Boolean, strings, one-dimensional and two-dimensional arrays of simple types, and simple files. The student will understand the

use of these types, and the available operators within the supplied

language.

Control structures: The student will identify and select appropriate iterative and selection structures when writing simple programs.

Programming language syntax: The student will learn the facilities and

rules of the language, e.g. operators, I/0 commands, etc.

Program design: The student will develop a solution to a problem, e.g. create structure charts, write pseudo code, etc. The student will also

produce tested programs to meet given specifications.

Page 9: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 4

© CTI Education Group

Programming standards and practice: The student will make use of comments and code layout, e.g. consistent indentation and descriptive

identifiers.

2. Use modularisation from the chosen programming language Content covered for learning outcome

Use of functions or procedures: The student will use or create both

predefined and user-defined functions and procedures, and map structured design onto a program using functions or procedures.

Scope of variables: The student will use global, local, static and external

variables.

Parameters: The student will use the knowledge of passing data by value and reference e.g. using return values.

3. Produce appropriate documentation for a given program

application Content covered for learning outcome

Presentation of documentation: The student will create software applications,

e.g. a word processor or graphics, analysis, design and implementation of documentation, professional standards and the needs of the industry.

User documentation: The student will draw up user documentation for

specified programming applications, and the purpose and operation of the

program will be developed.

Program documentation: The student will draw up documentation that covers technical aspects of a given programming application, including algorithms

implemented, data table, syntax, e.g. selection and iteration structures used and user interface methods adapted.

4. Create and apply appropriate test schedules

Content covered for learning outcome

Error types: The student will apply test schedules on semantic, run-time and syntaxes.

Test documentation: The student will create a test plan and relate evidence of

testing (may include reading sample inputs from a file or writing test results to a file).

Page 10: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 5

© CTI Education Group

Test data and schedules: The student will test the data and schedules, e.g. black box, white box, dry testing and data collection.

Error detection techniques: The student will apply compiler and link error

messages, debugging tools and structured walk-through.

Lectures

Each week has four compulsory lecture hours for all students. It is recommended that the lecture hours be divided into two sessions of two

hours each, but this may vary depending on the campus.

Each week has a lecture schedule which indicates the approximate time that should be allocated to each activity. The week’s work schedule has also been

divided into two lessons.

Class exercises and activities

Students will be required to complete a number of exercises and activities in class. These activities and exercises may also contribute to obtaining pass;

therefore, it is important that students are present in class so that they do not forfeit the opportunity to be exposed to such exercises and activities.

Activity sheets that are handed in should be kept by the lecturer so that they

can be used as proof of criteria that were met, if necessary.

Information resources

You should have access to a resource centre or a library with a wide range of relevant resources. Resources can include textbooks and textbooks, newspaper

articles, journal articles, organisational publications, databases, etc. You can access a range of academic journals in electronic format via EBSCOhost. You

have to consult the campus librarian to assist you with accessing EBSCOhost.

Prescribed textbook

Prescribed textbook for Introduction to Programming

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd

edition. Cape Town: Pearson Education. ISBN: 9781775786030.

Page 11: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 6

© CTI Education Group

Recommended information sources

The list below contains details for supplementary reading.

Books Perry, G. 2001. Sams teach yourself beginning programming in 24 hours.

Indiana: Sams Publishing. [Covers BASIC programming, but useful for beginners.]

Veeraraghavan, S. 2002. Sams teach yourself shell programming in 24 hours.

Indiana: Sams Publishing.

Web sites www.freetutes.com/systemanalysis/

http://www.homeandlearn.co.uk/NET/ http://code.org/learn

NOTE

Web pages provide access to a further range of Internet information sources.

Students must use this resource with care, justifying the use of information gathered.

Using the Study Guide

As we indicated earlier, the prescribed textbook is your main source of

information for this module and the Study Guide serves as a guide to the prescribed textbook.

The purpose of the Study Guide is to facilitate your learning and help you to

master the content of the prescribed textbook and other material. It helps you to structure your learning and manage your time; provides outcomes and

activities to help you to master those outcomes; and directs you to the appropriate sections in the prescribed textbook. It is, therefore, important that

you start with the Study Guide.

The Study Guide has been carefully designed to optimise your study time and

maximise your learning, so that your learning experience is as meaningful and successful as possible. To deepen your learning and enhance your chances of

success, it is important that you read the Study Guide attentively and follow all the instructions carefully. Pay special attention to the course outcomes at the

beginning of the Study Guide and at the beginning of each unit.

It is essential that you complete the exercises and other learning activities in the Study Guide as your course assessments (examinations, tests and

assignments) will be based on the assumption that you have completed these activities.

This Study Guide accompanies a prescribed textbook and, therefore, it should

be read in conjunction with such: it should not be deemed as a replacement for the prescribed text.

Page 12: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 7

© CTI Education Group

Purpose

The purpose of the Study Guide is to facilitate the learning process and to help

you to structure your learning and to master the content of the module. The textbook covers certain themes in detail.

Where applicable, we give more simplified explanations in the Study Guide. It

is important for you to work through both the prescribed textbook and the Study Guide attentively and to follow all the instructions set out in the Study

Guide. In this way, you should be able to deepen your learning and enhance your chances of success.

Structure

The Study Guide is structured as follows:

Introduction

Unit 1 Programming concepts

Unit 2 Writing algorithms

Unit 3 Selection structures and loop structures

Unit 4 Arrays

Unit 5 Modularisation and variable scope

Unit 6 Sequential text files

Unit 7 Documentation and error prevention

Glossary

Bibliography

Individual units

The individual units in the Study Guide are structured in the same way and

each unit contains the following features, which should enhance your learning process:

Unit title

Each unit title is based on the title and content of a specific

outcome or assessment criterion (criteria) as discussed in the

unit.

Learning outcomes and

assessment criteria

The unit title is followed by an outline of the learning outcomes

and assessment criteria, which will guide your learning process.

It is important for you to become familiar with the learning

outcomes and assessment criteria, because they represent the

overall purpose of the module as well as the end product of

what you should have learnt in the unit.

Learning objectives

Learning objectives, which follow the learning outcomes and

assessment criteria, are statements that define the expected

goal of the unit in terms of the specific knowledge and skills

that you should acquire as a result of mastering the unit

content. Learning objectives clarify, organise and prioritise

learning and they help you to evaluate your own progress,

thereby taking responsibility for your learning.

Page 13: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 8

© CTI Education Group

Prescribed reading

The learning objectives are followed by information outlining

prescribed reading. This section indicates the relevant sections

in the prescribed textbook that you are expected to study for

the unit.

Introduction The prescribed reading section is followed by an introduction

that identifies the key concepts of the unit.

Content

The content of each unit contains the theoretical foundation of

the module and is based on the work of experts in the field of

this module. The theory is illustrated by means of relevant

examples.

Concluding remarks

The concluding remarks at the end of each unit provide a brief

summary of the unit as well as an indication of what you can

expect in the following unit.

Self-assessment The unit ends off with a number of theoretical self-assessment

questions that test your knowledge of the content of the unit.

Glossary

As you can see, we include a glossary at the end of the Study Guide. Please

refer to the glossary as often as necessary in order to familiarise yourself with the exact meaning of the terms and concepts involved in Introduction to

Programming.

The use of icons

Icons are used to highlight (emphasise) particular sections or points in the Study Guide, to draw your attention to important aspects of the work, or to

highlight activities. The following icons are used in the Study Guide:

Example This icon points to a section in the text where relevant

examples for a particular topic (theme) or concept are

provided.

Learning outcome alignment This icon is used to indicate how individual units in the

Study Guide are aligned to a specific outcome and its assessment criteria.

Page 14: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 9

© CTI Education Group

Prescribed reading

This icon indicates reference to relevant chapters and/or sections in the textbook that you are expected to study.

Supplementary reading

This icon indicates that you are expected to do some additional (supplementary) reading – i.e. you should

obtain additional information by consulting relevant, external information sources.

Test your knowledge

This icon appears at the end of each unit in the Study Guide, indicating that you are required to answer self-

assessment questions to test your knowledge of the

content of the foregoing unit.

Alignment to prescribed textbook

The following table reflects the alignment between learning outcomes, assessment criteria, units in the Study Guide and chapters in the prescribed

textbook.

Page 15: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 10

© CTI Education Group

Study Guide/prescribed textbook alignment

Learning outcome Assessment criteria Study Guide unit & textbook chapter

LO1

Use, develop and

design structured

programming

methods

AC1.1: Identify and select

appropriate pre-

defined data types

Unit 1.2 – Chapter 1.1–1.5

Unit 3.3 – Chapter 4.3–4.5, Chapter 5.1

Unit 3.4 – Chapter 5.2

Unit 3.5 – Chapter 6.1

Unit 3.6 – Chapter 7.1, 7.2

Unit 4.2 – Chapter 8.1

Unit 4.3 – Chapter 8.1

Unit 4.4 – Chapter 8.3

Unit 5.2 – N/A

Unit 6.2 – Chapter 10.1

Unit 6.3 – Chapter 10.2, 10.3

Unit 6.4 – Chapter 10.4–10.6

AC1.2: Use simple input or

output and

appropriate

operators with the

above

Unit 1.2 – Chapter 1.1–1.5

Unit 1.3 – Chapter 2.1–2.4, Appendix

A.1–A.2

Unit 2.2 – Chapter 3.1

Unit 3.2 – Chapter 4.1, 4.2

Unit 3.3 – Chapter 4.3–4.5, Chapter 5.1

Unit 3.4 – Chapter 5.2

Unit 3.5 – Chapter 6.1

Unit 3.6 – Chapter 7.1, 7.2

Unit 4.3 – Chapter 8.1

Unit 4.4 – Chapter 8.3

Unit 6.2 – Chapter 10.1

Unit 6.3 – Chapter 10.2, 10.3

Unit 6.4 – Chapter 10.4–10.6

AC1.3: Identify and use

appropriate

selection structures

and loop structures

for the given task

Unit 3.3 – Chapter 4.3–4.5, Chapter 5.1

Unit 3.4 – Chapter 5.2

Unit 3.5 – Chapter 6.1

Unit 3.6 – Chapter 7.1, 7.2

Unit 4.3 – Chapter 8.1

Unit 4.4 – Chapter 8.3

Unit 6.2 – Chapter 10.1

Unit 6.3 – Chapter 10.2, 10.3

Unit 6.4 – Chapter 10.4–10.6

Page 16: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 11

© CTI Education Group

Learning

outcome Assessment criteria

Study Guide unit & textbook

chapter

AC1.4: Produce programs to

desired standards

Unit 1.3 – Chapter 2.1–2.4, Appendix

A.1–A.2

Unit 2.2 – Chapter 3.1

Unit 3.3 – Chapter 4.3–4.5, Chapter 5.1

Unit 3.4 – Chapter 5.2

Unit 3.5 – Chapter 6.1

Unit 3.6 – Chapter 7.1, 7.2

Unit 4.3 – Chapter 8.1

Unit 4.4 – Chapter 8.3

Unit 5.4 – Chapter 9.4

Unit 5.5 – Chapter 9.5

Unit 5.6 – Chapter 9.6

Unit 6.2 – Chapter 10.1

Unit 6.3 – Chapter 10.2, 10.3

Unit 6.4 – Chapter 10.4–10.6

LO2

Use modularisation

from the chosen

programming

language

AC2.1: Construct a program

from a design and

use appropriate

functions/procedures

Unit 5.3 – Chapter 9.1–9.3

Unit 5.4 – Chapter 9.4

Unit 5.5 – Chapter 9.5

Unit 5.6 – Chapter 9.6

AC2.2: Demonstrate the

effect of scope and

life-time of variables

Unit 5.2 – N/A

AC2.3: Pass data effectively

between modules.

Unit 5.3 – Chapter 9.1–9.3

Unit 5.4 – Chapter 9.4

Unit 5.5 – Chapter 9.5

Unit 5.7 – Chapter 9.3

LO3

Produce

appropriate

documentation for

a given program

application

AC3.1: Produce user

documentation for a

completed

programming

application including

the user interface

design

Unit 7.4 – N/A

Page 17: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 12

© CTI Education Group

Learning outcome Assessment criteria Study Guide unit & textbook chapter

AC3.2: Develop

documentation for a

pre-described

program application

Unit 1.2 – Chapter 1.1–1.5

Unit 1.3 – Chapter 2.1–2.4, Appendix

A.1–A.2

Unit 2.3 – Chapter 3.2, Appendix B.2

Unit 2.4 – Chapter 3.3

Unit 3.3 – Chapter 4.3–4.5, Chapter 5.1

Unit 3.4 – Chapter 5.2

Unit 3.5 – Chapter 6.1

Unit 3.6 – Chapter 7.1, 7.2

Unit 4.3 – Chapter 8.1

Unit 4.4 – Chapter 8.3

Unit 5.4 – Chapter 9.4

Unit 5.5 – Chapter 9.5

Unit 5.6 – Chapter 9.6

Unit 5.7 – Chapter 9.3

Unit 6.2 – Chapter 10.1

Unit 6.3 – Chapter 10.2, 10.3

Unit 6.4 – Chapter 10.4–10.6

LO4

Create and apply

appropriate test

schedules

AC4.1: Demonstrate

discrimination

between semantic

and syntax errors

Unit 7.2 – Appendix B.1

AC4.2: Produce test

documentation Unit 7.3 – Appendix B.2

AC4.3: Successfully

construct and use

test data and

schedules to detect

logic errors

Unit 2.3 – Chapter 3.2, Appendix B.2

Unit 2.4 – Chapter 3.3

Unit 3.3 – Chapter 4.3–4.5, Chapter 5.1

Unit 3.4 – Chapter 5.2

Unit 3.5 – Chapter 6.1

Unit 3.6 – Chapter 7.1, 7.2

Unit 4.3 – Chapter 8.1

Unit 4.4 – Chapter 8.3

Unit 5.4 – Chapter 9.4

Unit 5.5 – Chapter 9.5

Unit 5.6 – Chapter 9.6

Unit 6.2 – Chapter 10.1

Unit 6.3 – Chapter 10.2, 10.3

Unit 6.4 – Chapter 10.4–10.6

Unit 7.3 – Appendix B.2

Page 18: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Introduction Page 13

© CTI Education Group

Learning outcome Assessment criteria Study Guide unit & textbook chapter

AC4.4: Use appropriate

techniques for

detecting errors

Unit 2.3 – Chapter 3.2, Appendix B.2

Unit 2.4 – Chapter 3.3

Unit 3.3 – Chapter 4.3–4.5, Chapter 5.1

Unit 3.4 – Chapter 5.2

Unit 3.5 – Chapter 6.1

Unit 3.6 – Chapter 7.1, 7.2

Unit 4.3 – Chapter 8.1

Unit 4.4 – Chapter 8.3

Unit 5.4 – Chapter 9.4

Unit 5.5 – Chapter 9.5

Unit 5.6 – Chapter 9.6

Unit 6.2 – Chapter 10.1

Unit 6.3 – Chapter 10.2, 10.3

Unit 6.4 – Chapter 10.4–10.6

Unit 7.3 – Appendix B.2

Concluding remarks

At this point, you should be familiar with the module design and structure as

well as with the use of the prescribed textbook in conjunction with the Study Guide.

In Unit 1, we start with the actual module content. By the end of the semester students will be familiar with the basic skills of programming which can be

used with any programming language and will thus have the foundation for programming languages such as Visual Basic. Net, C# and Java, to mention

only a few.

Page 19: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 14

© CTI Education Group

Unit 1: Programming concepts

Unit 1 is aligned with the following learning outcomes and

assessment criteria:

Learning outcomes LO1: Use, develop and design structured programming

methods. LO3: Produce appropriate documentation for a given

program application.

Assessment criteria AC1.1: Identify and select appropriate pre-defined data

types.

AC1.2: Use simple input or output and appropriate operators with the above.

AC1.4: Produce programs to desired standards. AC3.2: Develop documentation for a pre-described

program application.

Learning objectives

After studying this unit, you should be able to:

Use proper programming standards and practice; thus use of comments and code layout, e.g. consistent indentation and descriptive identifiers

Use programming language syntax (facilities and rules of the language, e.g. operators, I/0 commands, etc.)

Develop a solution to a problem, e.g. create structure charts, write pseudo code, etc. You will also produce tested programs to meet given

specifications Develop documentation for a pre-described program application,

presentation of documentation, user documentation and program

documentation

Introduction

Programming languages have evolved over the years, but the basics of

programming is found in all languages, such as Visual Basic.Net, C, C++, C# and Java. This course will introduce students to the world of programming by

introducing them to basic programming concepts that will lead to an

understanding of problem solving and how we use computer technology to implement solutions to the problems.

Page 20: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 15

© CTI Education Group

1.1 General concepts

Before we can start writing a program to solve a problem, we first need to understand some programming concepts.

1.1.1 Entities and attributes

Data models have proven very useful, as they facilitate interaction between the developers and the end-users (as a communication tool). The basic building

blocks of data models are the use of entities, attributes, relationships and

constraints.

1.1.1.1 Entity

An entity is an object or thing that an organisation wants to collect and store.

For example, a library is concerned about books, thus the entity books. An entity can either be a physical object or it can be abstract, like book rental or

borrower history.

1.1.1.2 Attributes as data

Attributes are characteristics or description of an entity. For example, ISBN

number, book title, number of pages can be referred to as attributes of an entity book. Description factors of an entity are referred to as attributes, as

they refer to an object or entity’s features. When completing a form at the library, information about yourself and your current residence are requested.

This information is then captured onto the system to allow you to obtain

membership in the library. The information describes you. (You will be the entity and the information will be the attributes.)

1.1.2 Data types and variables

In order to write computer programs, such as this library system, the programmer must provide space for the attributes to be stored. This should

not only be stored, but should be retrievable at any given time. To store the attributes, it should first be identified and then allocated a data type. When

writing a program, each attribute in use should be allocated a specific space in which it should be stored. These attributes will now become variables.

1.1.2.1 Data types

A data type is a classification of what kind of data the variables will hold. This

gives the data meaning and provides the structure of how values of that type can be stored. In this section we will discuss two categories of data types,

which are the primitive types and non-primitive types.

Page 21: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 16

© CTI Education Group

1.1.2.1.1 Primitive types

A primitive data type is a basic data type that is not built out of other data

types, thereby referring to them as predefined types of data, which are supported by the programming language. Programmers use these data types

when creating variables in their programs. For example, a programmer may

create a variable called ‘surname’ and define it as a string data type. The variable will then store data as a string of characters.

Below is a list of some primitive data types and their characteristics:

Table 1: Data types and their characteristics

Data type Description Examples

Integer Contains positive or negative whole

numbers (signed or unsigned) 32, -12, 0

Real

Contains positive or negative fractions or

decimals, regardless of decimal places.

Floating point numbers

16.35, 0.2, -987.334

Character A single letter, number or special character. ‘M’, ‘7’, ‘#’, ‘!’

String Consist of two or more characters

combined

‘Rupert’, ‘Error

message’, ‘ABC’ or

‘123’

Boolean Can only contain true or false. This

relates back to ‘Yes’ and ‘No’

Statement: The book

relates to the subject

Answer: No, 0

Boolean Value: False

Source: Dale Sibanda (2014)

1.1.2.1.2 Non-primitive types

Non-primitive data types are created by the programmer; thus, they reference

a memory location which stores the data. In some programming languages, non-primitive data types are simply called ‘objects’ because they are created,

rather than predefined. While an object may contain any type of data, the information referenced by the object may still be stored as a primitive data

type.

1.1.2.2 Variables

In programming, a variable is referred to as a memory location/storage

location. Variables are also referred to as identifiers and are assigned a value

during run time, and the value of the variable may thus change during the course of program execution. Variables are assigned a data type. When

choosing a name for a variable, certain rules must be adheres to although they may differ from one programming language to the other. A variable name

must: be meaningful (descriptive) and unique

be one word start with a letter, underscore or a dollar sign

be a combination of letters, numbers and other symbols

Page 22: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 17

© CTI Education Group

A variable name may not:

contain special characters such as &,# and @ start with a number

Examples of variables: age

department23 lastName

1.1.2.2.1 Numeric variables

Integer variables

Integer variables are negative and positive counting numbers, including zero; they can thus be written in the form -3, -2, -1, 0, 1, 3

Examples: 15, –2 334, 9 728

Real number variables

A real number variable has a positive or negative number with a decimal part,

also called a floating number. Examples of real numbers are the length of a bus in metres or an amount of money in rands and cents.

Examples: 12.47, –987.123, 17.00

1.1.2.2.2 Non-numeric variables

Character variables

A character variable contains a single letter, number or special character, such as $, % or @. The value of a character variable is always enclosed in a single

quote, which varies from that of a string which is in double quotes.

Examples: ‘A’, ‘G’, ‘*’, ‘8’

String variable

A string variable consists of two or more (concatenation) characters and must also be enclosed in double quotes. A literal string is a type of a string that

shows information as it is written in the code segment.

Examples: ‘32 Long Street’ or a message, such as ‘The name is found.’

Boolean variable A Boolean variable can only contain a true or false value. Example of a Boolean

value situation in real life: it can be compared with a light switch, which is either on or off. In a computer language, a true value is represented by one,

whereas a false value is represented by zero.

Page 23: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 18

© CTI Education Group

A Boolean variable is used to test if a specific condition is true or false, and is also called a logical variable, a.

Examples: Is the person a club member? Did the student pass an exam? True

or false?

1.1.3 Constant

A constant is a fixed value that cannot change throughout the entire program. It is refers to some value that does not change or will rarely change in a very

long time. All the rules of variables apply to constants as well, except that constants have a fixed value that cannot change throughout the entire

program. Constants are used in cases where we know that the value will never vary during the execution of the program. A constant may be any data type.

Examples of constants:

The value of Pi (3.14159)

Hours in a day

1.1.4 The value and assignment of the variable

A variable consists of a name and a data type, as discussed above. The

variable can contain a value of the assigned data type.

Example: age, data type is integer, value is 19. Integer age ~ the variable age is assigned the data type integer

Age = 19 ~ the variable age is assigned the value 19

For further examples, see prescribed reading material, Chapter 1.3–1.4.

1.1.5 Arithmetic expressions

1.1.5.1 Arithmetic operators

These operators are used to make calculations. They tell the computer how the data should be processed.

Table 2: Arithmetic operators

Operator Description Example Answer

^ Exponentiation 2^3 8

- Negation (Not) -True False

+ Addition 2+3 5

* Multiplication 2*3 6

/ Division 6/3 2

\ Integer division 7\3 2

Mod Modulus arithmetic 7Mod3 1

- Subtraction 7-3 4

Source: Dale Sibanda (2014)

Page 24: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 19

© CTI Education Group

1.1.5.2 Arithmetic key words

It is important to be able to determine what type of arithmetic is required when reading a problem statement. You will need to determine whether it is

addition, subtraction, multiplication, division, equals, or one of the other

operators that must be used.

A list of keywords, expressions and equations can be found in the prescribed textbook in Chapter 1.5.

Prescribed reading

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

Chapter 1.1–1.5.

1.2 Analysing and solving problem

Before we can attempt to solve a problem, we need to understand the

problem. According to Pretorius and Erasmus (2012:19), there are three steps that can be followed in order to ensure that you understand the problem:

1. Read the problem carefully. 2. Understand what the problem entails.

3. Only then, write down the steps to solve the problem.

The written steps for solving the problem are called an algorithm. According to Pretorius and Erasmus (2012:19), “An algorithm must be written in such a way

that it is ambiguous and precise. The computer cannot think for itself; you need to tell the computer exactly what to do”. An algorithm is divided into

three phases: 1. What data you have available

2. How the problem is going to be solved

3. What the required results are

Page 25: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 20

© CTI Education Group

Input is processed to produce meaningful output.

Figure 1: Phases in an algorithm

Source: Pretorius & Erasmus (2012:23)

People write programs to perform certain tasks. A program task could be to

perform calculations or to make decisions based on the value of one or more variables. A program could also be used to compare values and perform a

certain action based on the outcome.

1.2.1 Simple problem solving

Scenario

An IT student is asked to create a small program that will add the marks three sections in an examination paper and calculate the total marks. This simplifies

work for the markers and increases accuracy of the marking.

Solution Adhere to the three steps that must be followed in order to ensure that you

understand the problem. Divide the program into an algorithm with three phases, and write down the steps in their order of occurrence.

Start

Declare variables, assigning them data types. Input values in variables.

Use the appropriate operators to execute the problem, storing the answer in

one variable. Display the answer in the variable.

Stop.

Decide on whether to use pseudo code or flowcharts to represent your problem specification.

INPUT PROCESSES OUTPUT

Page 26: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 21

© CTI Education Group

1.2.1.1 Pseudo code

After a problem has been analysed, the program to be used in solving the

problem must be designed. It is designed by using pseudo code, which is an informal high-level description of the steps of the program or algorithm in

chronological order.

Start

‘Declare variables and assign the data type

Real section1_mark, section2_mark, section3_mark, total

‘Input values in variables

Input section1_mark, section2_mark, section3_mark

‘Processing the entered variables and storing the answer in the variable

total

total = section1_mark + section2_mark + section3_mark

‘Display the output of the processed data

Display total

Stop

Figure 2: Example of algorithm

Source: Dale Sibanda (2014)

1.2.1.2 Flowcharts

The program flowchart illustrates the logic of the program and gives details on manipulating the data. It is less costly to determine, arrange and rearrange

complex logic on a flowchart than to correct logic errors in an implemented program. A program flowchart is vital, if the program is to be maintained easily

and efficiently or if modifications are necessary. The program flowchart is used to show the steps in the computer programs and the logic required for each

process. Program flowcharts are constructed with a set of standardised symbols that make it easier for persons other than the original programmer to

read and maintain the program.

Page 27: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 22

© CTI Education Group

Table 3: Flowchart symbols

Symbol Description

Terminal

This symbol indicates the starting or stopping point in the logic.

Every flowchart should begin and end with this symbol.

Input/Output

This symbol represents an input or output process in the algorithm,

such as reading, writing and displaying.

Processing

This symbol is used for types of processing, such as arithmetic

statements and assigning values.

Decision

This symbol is used to compare variables/values that may change

the flow of the logic. It may cause the logic to branch in another

direction.

Module

This symbol represents another module that must be processed. This

module will have its own flowchart.

Connector

The connector joins two parts of the flowchart, e.g. from one page to

the next page.

Connecting lines

These lines connect flowchart symbols with one another

Source: Pretorius & Erasmus (2012:230–231)

Example 1

Construct a program flowchart for a computer program that will do the following:

Input an employee’s name, hourly rate of pay and number of hours worked Calculate the following:

Gross pay, as hours worked times rate PAYE, as 25% of gross pay

UIF, as 2% of gross pay

Net pay, as gross pay minus PAYE minus UIF Print out the employee’s name, gross pay, PAYE, UIF and net pay

Page 28: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 23

© CTI Education Group

Use the following variable names:

Employee name = empName Hourly pay rate = rate

Hours worked = hours

PAYE = paye UIF = uif

Net Pay = nPay Gross Pay = gPay

Solution

Figure 3: Solution to Example 1

Source: Dale Sibanda (2014)

Page 29: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 1 – Programming concepts Page 24

© CTI Education Group

Prescribed reading Pretorius, C. M. & Erasmus, H.G., 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 2.1–2.4, Appendix A.1–A.2

Test your knowledge

1. Differentiate between a variable and a constant, and provide examples.

2. The number of days in a year cannot be represented as a constant, nor can the number of weeks in a month. Explain why.

3. Fill in the table below:

Description Variable name Variable type Preferred

data type Possible value

Colour of dress

Age in years

Salary in rands

Height in metres

Number of CTI

campuses in SA

Distance to the

nearest mall

4. Read the following scenario and then answer the questions below:

Scenario You have be asked by your lecturer to create a small program that

calculates the net salary for an employee. In order to execute this program, you need to enter a gross salary and the name of the employee; the

program will then automatically calculate the net salary, Pay As You Earn

(PAYE) at a fixed rate of 14% of the gross salary and UIF, which is 1% of gross salary after the deductions are applied.

a. Identify all variables, constants and data types which you will use in the

program.

b. Write a pseudo code and flowchart for the above scenario.

Page 30: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 2 – Writing algorithms Page 25

© CTI Education Group

Unit 2: Writing algorithms

Unit 2 is aligned with the following learning outcomes and

assessment criteria:

Learning outcomes LO1: Use, develop and design structured programming

methods. LO3: Produce appropriate documentation for a given

program application. LO4: Create and apply appropriate test schedules.

Assessment criteria

AC1.1: Identify and select appropriate pre-defined data

types. AC1.2: Use simple input or output and appropriate

operators with the above. AC1.4: Produce programs to desired standards.

AC3.2: Develop documentation for a pre-described program application.

AC4.3: Successfully construct and use test data and schedules to detect logic errors.

AC4.4: Use appropriate techniques for detecting errors.

Learning objectives

After studying this unit, you should be able to:

Use variables, constants and literals Use appropriate programming language syntax in conjunction with the

control structures Develop documentation for a pre-described program application,

presentation of documentation and program documentation

Test data and schedules, e.g. black box, white box, dry testing and data collection

Use error detection techniques by applying walk-through

Introduction

An algorithm is a set of instructions written in a specific order to achieve a

specific goal by solving a given problem.

Algorithms contain the basic control structures. These structures are sequence,

selection and iteration.

Page 31: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 2 – Writing algorithms Page 26

© CTI Education Group

2.1 Program planning

You need to understand the problem; thereafter, to identify the input, output and logic of the program or algorithm.

2.1.1 IPO chart

IPO Charts are useful when planning to create simple, small programs in a programming class. IPO stands for ‘input, processing, output’, meaning that an

IPO chart only shows data inputted (entered in the system), the data

processed, and the data outputted. Programs receive input from a user through an input device such as a keyboard; process them in computer

memory and then display the data on an output device such as a monitor. Below is an example of an IPO chart.

Input Process Output

Test 1

Test 2

Assignment 1

Assignment 2

Examination

Multiply each test by 0.1 to give 20% for both,

assignments by 0.15 to give 30% for both and the

examination by 0.5 to give 50%.

Work out the combine marks for all the assessments

(tests, assignments and examination)

Final mark.

Figure 4: Example of an IPO chart

Source: Dale Sibanda (2014)

2.1.2 Properties of an algorithm

An algorithm must have the following properties:

It must have a name that clearly describes its function. The last statement is the end of the algorithm.

The body of the algorithm is those statements between the name and end. ~ (tilde) introduces a comment to explain the code.

The word ‘Display’ means that a message is shown on the screen. The word ‘Enter’ indicates data input via the keyboard.

Calculations are shown with the use of equations.

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 3.1

2.2 Testing algorithm logic

It is important to whether the algorithm is error free and will provide the expected results.

Page 32: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 2 – Writing algorithms Page 27

© CTI Education Group

One can use test data to determine whether the algorithm’s logic is correct. It

is important to use test data that is within the acceptable values and data that is not within these values.

To test the logic, you can use a trace table, also known as desk checking or a walkthrough.

For examples of the trace table, see the prescribed textbook, Chapter 3.2 and

Appendix B.2.

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education.

Chapter 3.2, Appendix B.2

2.3 Outcome of an algorithm

Sometimes the whole algorithm does not need to be tested via a trace table; in these cases it is sufficient to test the calculations of the algorithm to determine

if the outcomes are as expected.

For examples of this technique, see the prescribed textbook, Chapter 3.3.

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 3.3

Page 33: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 2 – Writing algorithms Page 28

© CTI Education Group

Test your knowledge

1. Give the definition of an algorithm.

2. Read the following scenario and answer the questions below:

Scenario

Write a program that will determine the average mark of each student. The average is dependent on the subjects which the student has completed.

The minimum amount of subjects is eight, and the maximum amount of subjects is 12. When the program starts, the administrator will indicate

how many students there are in the group.

a. Write the algorithm for this program.

b. Check if the algorithm has all the appropriate properties.

c. Chose appropriate test data for the variables.

d. Test the program with a trace table.

e. Test the calculation that provides the output of the average.

f. Draw the flowchart for the program.

Page 34: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 29

© CTI Education Group

Unit 3: Selection structures and loop structures

Unit 3 is aligned with the following learning outcomes and

assessment criteria:

Learning outcomes LO1: Use, develop and design structured programming

methods. LO3: Produce appropriate documentation for a given

program application. LO4: Create and apply appropriate test schedules.

Assessment criteria

AC1.1: Identify and select appropriate pre-defined data

types. AC1.2: Use simple input or output and appropriate

operators with the above. AC1.3: Identify and use appropriate selection structures

and loop structures for the given task. AC1.4: Produce programs to desired standards.

AC3.2: Develop documentation for a pre-described program application.

AC4.3: Successfully construct and use test data and schedules to detect logic errors.

AC4.4: Use appropriate techniques for detecting errors.

Learning objectives

After studying this unit, you should be able to:

Use variables, constants and literals. Understand the concepts of data storage within a computer program

Use appropriate programming language syntax in conjunction with the

control structures Use control structures and thus identify and select appropriate iterative and

selection structures when writing simple programs Develop documentation for a pre-described program application,

presentation of documentation, user documentation and program documentation

Test data and schedules, e.g. black box, white box, dry testing and data collection

Apply error detection techniques by applying compiler and link error messages, debugging tools and structured walk-through

Page 35: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 30

© CTI Education Group

Introduction

Depending on the result of a decision or condition made in the program, control may be directed to another part of the program. This is done with the

use of a control structure. The following control structures will be discussed:

Selection control structure 1. IF statements

2. SELECT CASE statement

Iterations 1. FOR Loop

2. DO Loop

3.1 Logical and relational operators

Logical and relational operators are necessary for control structures to function correctly.

3.1.1 Logical operators

The use of logical operators results in only one of two values, TRUE or FALSE.

Table 4: Logical operators

Operator Description Example Answer

AND Requires both variables/conditions to

be TRUE for the result to be TRUE

True AND True

True AND False

False AND True

False AND False

True

False

False

False

OR Requires either variable/condition to be

TRUE for the result to be TRUE

True OR False

False OR True

True OR True

False OR False

True

True

True

False

NOT Returns TRUE if the variable/condition

is FALSE and vice versa

NOT True

NOT False

False

True

Source: Dale Sibanda (2014)

Page 36: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 31

© CTI Education Group

3.1.2 Relational operators

Comparison operators compare two numeric or two character values. A numeric value cannot be compared with a character value.

Table 5: Relational operators

Operator Description Example

= Equal to A = 10

> Greater than number > 50

< Smaller than total < 21

<> Not equal to age <> 0

>= Greater and equal to Weight <>35

<= Smaller and equal to SubjectCount <=6

Source: Dale Sibanda (2014)

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 4.1, 4.2

3.2 IF statements

‘If-statements’ are also called if-then statements. The computer executes a

statement (the if-statement) and, based on the result, performs a resulting action (then or else). If the condition is true, the ‘then’ part will be executed.

If the condition is false, the ‘else’ part will be executed.

The basic layout of an if-statement is as follows: IF condition

THEN action when condition is true ELSE action when condition is false

For example, test if the student passed a specific module by using the module

result as input:

If result >= 50

Then message = “Student passed”

Else message = “Student failed”

End if

The above example will output a message of “Student passed” for any value

that is greater or equal to 50, and a message of “Student failed” for any input value that is less than 50.

Page 37: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 32

© CTI Education Group

If-statements can also have more than one condition. This is called a compound if-statement.

For example, to qualify for your learner’s license, you need to be a South

African citizen and be older than 16.

If nationality = “RSA” AND age >=16

Then qualify = true Else qualify = false.

The above example uses an AND logical operator that states that both

conditions need to be true in order for the system to execute the then part.

Example 1

A flowchart that reads temperature, checks if it is below 32 degrees and prints

‘Below freezing’ or ‘Above freezing’.

Figure 5: Flowchart for temperature

Source: Rfflow (n.d.)

Page 38: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 33

© CTI Education Group

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 4.3– 4.5, Chapter 5.1

Supplementary reading

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

Chapter 4.6

3.3 SELECT CASE statements

The select...case statement is used in menu-like situations. It allows code to

be written where a number of if-statements would otherwise follow one another. It is a neater, more concise and better programming technique than

successive if-statements.

The basic layout of a Select Case statement is: SELECT case Number Case 1

List statements here

Case 2

List statements here

Case 3

List statements here

ELSE

List statements here

END-SELECT

Page 39: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 34

© CTI Education Group

Example 2

Pseudo code example of a select…case.

Commission is paid out based on the amount of sales made. Different

categories will earn different commission rates. Total sales of less than 25 000

will earn 2.5% commission; sales of less than 50 000 will earn 3% commission; and sales of less than 100 000 will earn 5% commission. Sales of

more than 100 000 will earn 7.5 % commission. SELECT case Sales

Case < 25 000

Commission = 2.5

Case 25 000 to 49 999

Commission = 3

Case 50 000 to 100 000

Commission = 5

Else Commission = 7.5

END-SELECT

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 5.2

3.4 FOR loops

The FOR statement is used in programming when a block of code is to be executed a specific number of times.

The basic layout of a FOR loop is:

FOR counter = begin-value TO end-value

Perform actions listed here

NEXT counter

Page 40: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 35

© CTI Education Group

Example 3

Pseudo code example to calculate the average temperature for a given week:

FOR counter = 1 TO 7 Input “day temperature”

Add “day temperature” to total

NEXT counter

Calculate average total / 7

The above example will perform the two actions (input temperature and add to

total) seven times. The average will be calculated outside of the loop.

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 6.1

Supplementary reading

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

Chapter 6.2

3.5 DO loops

A DO loop is used when the number of times of execution is unknown. The

condition will be tested every time.

There are two types of DO loops.

DO WHILE DO UNTIL

Page 41: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 36

© CTI Education Group

3.5.1 Do-While statement

The Do-While statement is executed only while a specific condition is true. As soon as the condition tests false, the loop exits. The condition is checked

before the loop is entered. A lecturer will first check if there are students in a class before starting the lecture.

The basic layout of a Do-While statement is:

DO WHILE condition is true List all the statements here

LOOP

Figure 6: Do-while-loop

Source: www.tutorialspoint.com

Page 42: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 37

© CTI Education Group

Example 4

For example, to print a list of 10 student names for a course, we will first have

to check if any students are registered for the course. Read studentName, surname

DO WHILE students < 10

Print studentName, surname

LOOP

3.5.2 Do-Until statement

The do...until statement is very similar to the do-while control statement in

that both are conditional loops. However, unlike the do-while statement, the do...until statement does not test the condition before entering the loop. It

tests the condition at the end of the loop. This means that a do...until loop will always execute at least once, whereas a do-while loop may never execute. The

basic layout of a Do-Until loop: DO

List all the statements here

LOOP UNTIL condition is true

Example 5

For example, calculate the wages for all employees. It is assumed that the

company will at least have one employee. Input hours worked

DO

Input payrate

Calculate wage as hours worked * payrate

Print wage

Input hours worked

LOOP UNTIL hours worked = 0

Page 43: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 38

© CTI Education Group

Example 6

Draw a flowchart of a program that will do the following:

Read a record from a file containing a stock item’s description, this month’s stock, last month’s stock, and the number of items received during the

month.

Calculate how many items were used during the month by taking last month’s quantity on hand, adding to it the quantity received during the

month, and then subtracting the quantity on hand this month. Print the item’s description and quantity used during the month.

Read the next inventory item and repeat until all items have been read in.

Use the following variable names:

Item description = desc Last month’s stock = lms

This month’s stock = tms Items received = rec

Items used = used

Page 44: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 39

© CTI Education Group

Figure 7: Flowchart for Example 6

Source: Dale Sibanda (2014)

Example 7

Draw a program flowchart to calculate the average in the following program:

The program must allow the user to input a series of numbers. When the user enters a zero, the program must calculate and print the average value of these

numbers.

Page 45: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 40

© CTI Education Group

Figure 8: Flowchart for Example 7

Source: Dale Sibanda (2014)

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 7.1, 7.2

Page 46: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 3 – Selection structures and loop structures Page 41

© CTI Education Group

Test your knowledge

1. Write a select case statement to calculate the new value of the price

variable, depending on the grade, based on the table below. Grade Processing of price

A Double the price

B Add VAT of 14%

C Deduct a discount of 8.75%

Other Add R5 if the price is higher than R50

Subtract R4 if the price is equal to R50 or lower

2. Write a code to calculate and display the sum of the first five odd numbers.

Use a FOR loop for the program.

3. Differentiate between a DO WHILE and a DO UNTIL, using examples.

4. Using the table in Question 1, use an IF ELSE statement to find the price variable.

5. Use Microsoft Visio 2010 or any app to draw the flowcharts.

NB: All your programs should be represented as flowcharts accompanied by pseudo code.

Page 47: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 4 – Arrays Page 42

© CTI Education Group

Unit 4: Arrays

Unit 4 is aligned with the following learning outcomes and

assessment criteria:

Learning outcomes LO1: Use, develop and design structured programming

methods. LO3: Produce appropriate documentation for a given

program application. LO4: Create and apply appropriate test schedules.

Assessment criteria:

AC1.1: Identify and select appropriate pre-defined data

types. AC1.2: Use simple input or output and appropriate

operators with the above. AC1.3: Identify and use appropriate selection structures

and loop structures for the given task. AC1.4: Produce programs to desired standards.

AC3.2: Develop documentation for a pre-described program application.

AC4.3: Successfully construct and use test data and schedules to detect logic errors.

AC4.4: Use appropriate techniques for detecting errors.

Learning objectives

After studying this unit, you should be able to:

Use variables, constants and literals. Understand the concepts of data storage within a computer program. Use pre-defined data types, integers,

floating point, character, Boolean, strings, one-dimensional and two-

dimensional arrays of simple types, and simple files Understand the properties of an array and the importance of an array as

compared to control structures Apply arrays in solving complex programs with variables of the same type,

thus using one-dimensional and two-dimensional arrays Use appropriate programming language syntax in conjunction with the

control structures Develop documentation for a pre-described program application,

presentation of documentation, user documentation and program documentation

Test data and schedules, e.g. black box, white box, dry testing and data collection

Apply error detection techniques by applying compiler and link error messages, debugging tools and structured walk-through

Page 48: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 4 – Arrays Page 43

© CTI Education Group

Introduction

When using the same data type repeatedly; for example, the names of the 12

months in a year or the days in a week, there is a need to group these like variables. These variables can be grouped together in an array using a single

name, to improve the code and make it shorter and more efficient.

4.1 An array

An array consists of a number of related variables. At any given time, the array can hold numerous values but identical data types. For example, an array

cannot store your name and your age at the same time, because they are of different data types – name is of the string data type and age is an integer.

Think of it as a row of ‘buckets’. When you need a value from one of the buckets, you will refer to the number in the row; for example, row number 6.

Arrays work with index numbers and typically start at zero (0).

4.1.1 Properties and characteristics of arrays

Properties of an array refer to what the array can do; thus, a thing or things aligned to someone, or effects. For example, Diana’s speed or height thus in

arrays: Size

Length

‘Characteristics’ refers to a feature or quality belonging to an entity, in this case an array. Its features are:

It has a single name. A single variable in an array is called an element.

All the elements in an array are the same data type. The position of an element in an array is called an index or a subscript.

A one-dimensional array can be seen as one column with many rows, one

for each element in the array.

4.1.1.1 Array name

The name of an array will have all characteristics of a variable name, but also

contains elements, data type and an index.

4.1.1.2 Element

One element in an array is a single variable that contains a value at a given

time; therefore, an element is a single variable of an array.

Page 49: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 4 – Arrays Page 44

© CTI Education Group

Examples One name of a month in monthArray, such as September

One name of a day in dayArray, such as Monday

4.1.1.3 Data type

Since an element is like a variable, elements in an array must be of the same data type, such as String or Integer. Examples:

monthArray will be of data type String quantityInStock will be of data type Integer

4.1.1.4 Index

This is the position of an element in the array. The index is sometimes referred to as a subscript. The value of an index must always be a positive integer or

zero. The index of the first element of an array is always 0 (zero) and the index of the last element of the array is (number of elements – 1).

For example, the indexes of an array called mathScores, which contains 30

elements, would start at 0, so the last index would be 29. The dayArray array can be visualised as a column with seven row elements.

dayArray(0) Monday

dayArray(1) Tuesday

dayArray(2) Wednesday

dayArray(3) Thursday

dayArray(4) Friday

dayArray(5) Saturday

dayArray(6) Sunday

4.1.1.5 Referencing

Identifying an element in an array can be done by referencing its location, thus

by the name of the array as well the index of the element is used. For instance, dayArray(0) refers to the string value ‘Monday’ and dayArray (5)

refers to the string value ‘Saturday’, as seen above.

Prescribed reading

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

Chapter 8.1

Page 50: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 4 – Arrays Page 45

© CTI Education Group

4.2 One-dimensional array

One-dimensional array consists of one column of elements. Arrays bring together variables of the same type and grouping them together to allow more

efficient coding. Assume that 10 students have written a Programming test. The average mark for the class is all the marks added together divided by the

number of students.

Since the marks are all of the same data type and are related to one another, and they all contribute to the class average, they can be stored in an array.

The index of the first element is 0 and the index of the last element is 9, because there are 10 students who wrote the test. The array contains 10

elements, each of which represents a different test mark.

totalMark = 0

for i = 0 to 9

display “Please enter student mark”, i + 1

enter testMark(i)

totalMark = totalMark + testMark(i)

next i

In the example above, data will be stored in the elements of an array. It can

be manipulated in the same way as normal variables. testMark(i) when zero (0) is first passed will be the first mark entered, which is testMark(0). When

doing calculations, you can use all the elements in the array structure or specify individual elements. You can also change or display the content of an

array element. You can find the element with: The highest or lowest value in the array

Sort the elements in a specific order Calculate the average of all the elements

The examples that follow demonstrate how elements in an array can be

manipulated.

Example 1

Problem

The identity numbers of the eight employees in a particular company are

stored in an array. The manager wants to know if a specific woman is a company employee by entering her identity number.

Page 51: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 4 – Arrays Page 46

© CTI Education Group

Algorithm FindEmployee

boolFound = False

display “Enter the identity number of the employee”

enter idNo

for m = 0 to 7

if empIds(m) = idNo then ~ empIds is an array with 8 elements

boolFound = True ~ The person is found!

m = 7 ~ Exit the loop

endif

next m

if boolFound = True then

display “The person whose id number is ”, idNo, “ is an employee”

else

display “The person whose id number is ”, idNo, “ is not an employee”

endif

end

Source: Pretorius et al. (2012:160)

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education.

Chapter 8.1

4.3 Two-dimensional array

Two-dimensional array consists of a number of rows and a number of columns. An example of a two-dimensional array can be explained by means of the

following example:

The minimum and maximum temperatures for the past seven days of the week, as can be seen in the following table:

Table 6: Maximum and minimum temperatures

3 34

4 27

1 22

6 26

4 24

3 28

3 28

Source: Dale Sibanda (2014)

The particulars of a single day can be found in a row; for instance, Row 0

contains the minimum and maximum temperatures for Day 1, which is 3 and 34.

Page 52: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 4 – Arrays Page 47

© CTI Education Group

Similarly, Row 3, Column 0 contains the minimum temperature for Day 4 and

Row 3, Column 1 the maximum temperature for Day 4. We can now name the array temperatures, which consists of seven rows and two columns. When

referencing a particular element, we need to specify both the row and the

column number: temperatures (2, 1) = 22

temperatures (4, 0) = 4

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education.

Chapter 8.3

Supplementary reading

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

Chapter 8.2

Test your knowledge

1. What is a one-dimensional array?

2. An array called noInStock already contains the following valid positive

integer values in the 20 elements:

4, 15, 38, 53, 8, 95, 129, 653, 45, 658, 12, 40, 0, 98, 74, 32, 9, 39, 25,

87

The index and value of the highest number in noInStock need to be found and displayed. Solve the problem; use arrays.

3. Write down the structure of an array and give two examples of arrays.

Page 53: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 5 – Modularisation and variable scope Page 48

© CTI Education Group

Unit 5: Modularisation and variable scope

Unit 5 is aligned with the following learning outcomes and

assessment criteria:

Learning outcomes LO1: Use, develop and design structured programming

methods. LO2: Use modularisation from the appropriate functions/

procedures chosen programming language. LO3: Produce appropriate documentation for a given

program application. LO4: Create and apply appropriate test schedules.

Assessment criteria:

AC1.1: Identify and select appropriate pre-defined data types.

AC1.4: Produce programs to desired standards. AC2.1: Construct a program from a design and use

appropriate functions/procedures. AC2.2: Demonstrate the effect of scope and life-time of

variables. AC2.3: Pass data effectively between modules.

AC3.2: Develop documentation for a pre-described program

application. AC4.3: Successfully construct and use test data and

schedules to detect logic errors. AC4.4: Use appropriate techniques for detecting errors.

Learning objectives

After studying this unit, you should be able to:

Use variables, constants and literals. Understand the concepts of data storage within a computer program. Be able to use pre-defined data types,

integers, floating point, character, Boolean, strings. You will understand the use of these types, and the available operators within the supplied language

Understand the scope of variables and, thus, use of global, local, static and external variables

Understand the use of functions or procedures; you will use or create both predefined and user-defined functions and procedures, and map structured

design onto a program using functions or procedures Use the knowledge of passing data by value and reference, e.g. using return

values Develop documentation for a pre-described program application,

presentation of documentation, user documentation and program documentation

Page 54: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 5 – Modularisation and variable scope Page 49

© CTI Education Group

Test data and schedules, e.g. black box, white box, dry testing and data collection

Apply error detection techniques by applying compiler and link error messages, debugging tools and structured walk-through

Introduction

The focus on this unit will be more in the domain of Mathematics and could be very challenging, requiring careful planning. However, we encourage you to

see all problems as opportunities and to try various solutions until you find one that solves the problem in the most efficient, effective and economical way.

You will be introduced to basic programming concepts that will lead to an understanding of a problem and how to use computer technology to implement

a solution to the problem.

5.1 Variable scope

There are four different types of variable scopes: Local

Global External

Static

5.1.1 Local variables

A local variable can only be used inside the procedure or function where it was first declared.

5.1.2 Global variables

A global variable can be used in the main program and inside procedures or

functions.

5.1.3 External variables

An external variable is used externally. External variables are declared outside

any procedure or function.

5.1.4 Static variables

A static variable is a variable that has been declared inside the main program and re-declared inside a procedure or function. The scope of a static variable is

the procedure where the variable is declared, excluding any other procedures that may contain a variable with the same name.

Page 55: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 5 – Modularisation and variable scope Page 50

© CTI Education Group

Example 7

Start

real a, b, total; // global variables

sum()

{

total = a + b;

real division = a\b; // local variables

print total, division;

}

5.2 Modularisation

Modularisation is the subdivision of the program into separate subprograms. This gives programmers or teams easier subdivision of tasks which can be

reused repeatedly. Modularisation improves the flexibility of a program and

shortens its development time. Large and complex programs can be divided into independently developed modules. Each module is made up of one or

more statements to perform a specific task. The various modules are then linked to form a working program. Modules can take several forms, depending

on the programming language used. Two such forms are function procedures and sub procedures.

5.2.1 Advantages of modularisation

Provides abstraction

Focuses on important properties while ignoring non-essential details thus

avoiding low-level details thereby making complex tasks look simple.

Allows multiple programmers to work simultaneously Commercial programs are written by a multiple programmers to reduce time

taken to complete the program. These programs are divided into smaller pieces called modules which are written by various programmers.

Allows code reuse

Subroutines that are useful should be used more than once in a program

Example: routine that calculates income tax

Page 56: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 5 – Modularisation and variable scope Page 51

© CTI Education Group

Reusability allows a programmer to use modules in a variety of applications; it gives assurance that a module has been tested and has proven to function

correctly. It is reliable and saves time and money as you do not need to hire a programmer to recreate module.

5.2.2 Hierarchy charts

Hierarchy charts allow you to have an overall view of your program, and show

you how the different components fit together.

It is necessary to draw a hierarchy chart if your program has more than one procedure associated with it.

5.2.3 Parameters

A parameter is either a value or an address of a variable which is sent to a

procedure. Parameters are found enclosed within the brackets of a method; for example, DP (Asg1) has only 1 parameter, called Asg1. There are two main

types of parameters.

Value parameters contain the actual value being passed to the procedure. Reference parameters contain the address of the variable being sent to the

procedure; at this address we can find out what the exact value is.

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 9.1–9.3

5.3 Using function procedures

A function is defined as a number of statements grouped together to execute a single task. A function always returns a value and can receive numerous or no

variables (called parameters).

A program that needs to calculate a total based on a specific formula can be created as a function. For example, the student DP is calculated as 15% per

assignment and 10% per test. The DP counts 50% of the year mark. In order to create the function, we need to determine the parameters.

CalculateDP (Asg1, Asg2, Test1, Test2)

DP = (Asg1 + Asg2) * 0.15 + (Test1 + Test2) * 0.1

Return DP

Page 57: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 5 – Modularisation and variable scope Page 52

© CTI Education Group

The above function needs to be called as part of a calculation or by a variable that will store the value of the answer. To call the function by a variable, we

can use the following statement in our main program: studentMark = Function CalculateDP (assignment1, assignment2,

testMark1, testMark2)

This can also be done as part of a calculation as indicated below:

Result = Function CalculateDP (assignment1, assignment2,

testMark1, testMark2) + Exam * 0.5

When a function receives parameters, the order of the parameters is very

important.

Important notes for using functions: The function and the main program are two separate entities.

The main program and function communicate using parameters.

If the function does not receive the parameters in the same order, the result will be calculated incorrectly.

There may be more than one return statement in a function, but only one of the return statements can be executed, and execution of this return

statement must be just before the end statement.

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 9.4

5.4 Sub-procedures

A sub-procedure (also called a procedure) can also be used to solve a specific part of a problem, and has the following properties:

It can receive parameters. It does not return a value.

It can change the value of reference parameters.

A reference parameter should be used when you need to change the value of an actual parameter variable in the procedure. When you declare a reference

parameter, the function call will pass the memory address of where the actual parameter is, instead of copying the parameter value into the formal

parameter.

Page 58: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 5 – Modularisation and variable scope Page 53

© CTI Education Group

Procedures are called by their name. The basic syntax of calling a procedure is as follows:

Call ProcedureName (argument list)

For example, the following transactions can be captured for a tenant per

month: DisplayRental, AssignNewRental, or AccumulateInterestl.

The following procedures should be created:

Sub DisplayRental(Tenant, rentMonth, rentAmount)

Display Tenant, “rental for the month of “, rentMonth, “,is

R“,rentAmount

End-Sub

Sub AssignNewRental (interestRate, refAmount, refMonthInt)

refMonthInt= refAmount * interestRate / 100

refAmount = refAmount + refInterest

End-Sub

Sub AccumulateInterest(MonthInt, refInterest)

refInterest = refInterest + MonthInt

End-Sub

The main program should call these procedures by name: Call DisplayRental( TenantName, rentPerMonth, amount) Call AssignNewRental( percInterest, amount, monthInterest)

Call AccumulateInterest( monthInterest, Interest)

It is possible to send no parameters to procedures or functions. For example, to display menu options, one can make use of procedures, or when a value

must be entered and validated until it is correct. When a correct value is entered, it must be returned to the calling module.

Prescribed reading

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

Chapter 9.5

5.5 Functions and subprocedures without parameters

It is possible that a function or subprocedure can be called without sending it

any parameters. For instance, a function can be called where a value must be entered and validated until it is correct. When a correct value is entered, it

must be returned to the calling module.

Page 59: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 5 – Modularisation and variable scope Page 54

© CTI Education Group

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 9.5

5.6 Passing parameters in a function

5.6.1 Passing parameters by value

When you use pass-by-value, the compiler copies the value of an argument in a calling function to a corresponding non-pointer or non-reference parameter

in the called function definition. The parameter in the called function is

initialised with the value of the passed argument.

Parameter passing by value is a default parameter passing mechanism and it utilises parameters that are evaluated or defined before the called function is

entered. Only the value of the parameter is transferred to the called function and so the caller function does not see the value of the parameter being

affected by the called function.

This parameter passing method is efficient, but less likely to terminate when dealing with infinite data structures and recursive functions.

5.6.2 Passing parameters by reference

Passing by reference refers to a method of passing the address of an argument

in the calling function to a corresponding parameter in the called function. Parameter passing by reference is used when programmers do not want to

pass by value always and also used when we want to return more than one value from a function. Passing by reference is much cleaner than using

pointers and it accomplishes the same general function.

5.6.3 Passing parameters by pointer

Passing the arguments of a pointer in the calling function thus from a

parameter of a called function, which can modify the value of the variable to which the pointer argument points (Point to a memory location). Call by

reference is based on pointers.

Page 60: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 5 – Modularisation and variable scope Page 55

© CTI Education Group

5.6.4 Passing arrays as parameters

5.6.4.1 Call by reference

When passing an array argument to a function, you need to specify the name of the array without including brackets, as seen below:

int myArray[ 24 ];

myFunction( myArray, 24 );

The array size is also passed to the function, and the array passed is called by reference. The array is declared and called within a function, as the function

knows where the array is stored.

5.6.4.2 Call by value

Passing array elements:

Passed by call-by-value Pass subscripted name (i.e., myArray[ 6 ]) to function

Test your knowledge

1. List and explain three parameter passing techniques.

2. Why is it important to study modularisation in programming?

3. Define ‘reference parameter’ and explain how it works.

4. Differentiate between a function procedure and a sub-procedure, and provide examples.

5. Write a program that passes the parameters length and width to the

method called Area_of_Rectangle, which calculates the area.

6. Represent Question 5 as both flowcharts and pseudo code.

Page 61: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 5 – Modularisation and variable scope Page 56

© CTI Education Group

7. Do research on the following:

The importance of the mainline logic for a complete program focusing on the mainline logic structure consisting of housekeeping tasks, main loop

and end-of-job routines.

Page 62: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 6 – Sequential text files Page 57

© CTI Education Group

Unit 6: Sequential text files

Unit 3 is aligned with the following learning outcomes and

assessment criteria:

Learning outcomes LO1: Use, develop and design structured programming

methods. LO3: Produce appropriate documentation for a given

program application. LO4: Create and apply appropriate test schedules.

Assessment criteria

AC1.1: Identify and select appropriate pre-defined data

types. AC1.2: Use simple input or output and appropriate

operators with the above. AC1.3: Identify and use appropriate selection structures

and loop structures for the given task. AC1.4: Produce programs to desired standards.

AC3.2: Develop documentation for a pre-described program application.

AC4.3: Successfully construct and use test data and schedules to detect logic errors.

AC4.4: Use appropriate techniques for detecting errors.

Learning objectives

After studying this unit, you should be able to:

Use variables, constants and literals. Understand the concepts of data storage within a computer program using text files

Use appropriate programming language syntax in conjunction with the

control structures Use control structures; thus, identify and select appropriate iterative and

selection structures when writing simple programs using a text file Develop documentation for a pre-described program application,

presentation of documentation, user documentation and program documentation

Test data and schedules, e.g. black box, white box, dry testing and data collection

Apply error detection techniques by applying compiler and link error messages, debugging tools and structured walk-through

Page 63: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 6 – Sequential text files Page 58

© CTI Education Group

Introduction

Besides using variables during run time to store the values of data that is needed during the program, it is possible to make use of data in an existing

text file and to write data to a text file for later use.

Text files are also known as sequential access files. This means that the data needs to be read from the text file sequentially. Line one, then line two, etc.

6.1 Input and output files

An input file is a text file that contains data that can be used during run time.

An output file is a text file that a program uses during run time to write data permanently into that can be used at another time. A file pointer is used to

determine where in the text file the data must be read or written to.

Prescribed reading

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

Chapter 10.1

6.2 Opening and closing a text file

6.2.1 Opening a text file

To open a text file the ‘open’ statement is used. When a file is opened the file pointer will be pointing to the first line in the file.

If you want to open an input file, you use the following statement:

Open input(name_of_file)

If you want to open an output file, you use the following statements:

Open outputCreate(name_of_file) ~ this creates a new file

Open outputAppend(name_of_file) ~ this opens an existing file with

the file pointer at the end of the

file.

Also, it is important to first check if the file exists before you try to open the file, and if it does not exist some kind of action should be taken.

Page 64: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 6 – Sequential text files Page 59

© CTI Education Group

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 10.2

6.2.2 Closing a text file

When closing a text file, it is not necessary to indicate whether it is an input

file or an output file.

If you want to close a text file, you use the following statement: Close (name_of_file)

You need to close the file when you are finished using it.

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education.

Chapter 10.3

6.3 Reading and writing from and to a text file

6.3.1 Reading from an input file

You start reading the data from the first line in the file, and you continue reading the data until you either find what you are looking for or until you

reach the end of the file.

Each line in the file is placed into a variable, and then that variable is used according to the program.

The statement to read from a text file is: Read(name_of_file)

The statement that will read a line from the text file into a variable is: Variable_name = read(name_of_file)

Page 65: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 6 – Sequential text files Page 60

© CTI Education Group

The end of the file contains an end-of-file (eof) character.

For an example of reading from an input file, see the prescribed textbook, Chapter 10.4.

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 10.4

6.3.2 Writing to an output file

When writing to an output file, you need to open an output file, and then

indicate that you want to write to file. Once you have written to the file, it will be necessary to write the statement to go to the next line in the file before you

can write the next value(s).

The statement to write to a file is: Write(name_of_file)

Normally the text that is written to the file is first stored in a variable. You will need to indicate that the value of the variable must be written to the file with

the following statement:

Write (name_of_file) from Variable_name

The statement to go to the next line in the text file is:

Write new line

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education.

Chapter 10.5

6.3.3 Reading and writing to the same file

If you want to read and write to the same file, you need to read all the values into an array, then create a new file, and then use the array write to the new

file.

For an example, see the prescribed textbook, Chapter 10.6.

Page 66: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 6 – Sequential text files Page 61

© CTI Education Group

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Chapter 10.6

Test your knowledge

1. You are given the scenario below. Answer the questions that follow.

Scenario You are a lecturer and need to remember all the students in your class, and

you need to print an attendance register on a daily basis.

a. Write a program that the lecturer can use to write the list of students’ names into a text file, assuming that the lecturer adds the students in

alphabetical order. Give the algorithm.

Draw a flow chart. Test the algorithm.

b. Write a program that the lecturer can use to view a list of all the students in his class, assuming that they are all in the text file.

Give the algorithm. Draw a flow chart.

Test the algorithm.

c. Write a program that the lecturer can use to add new students to the list, assuming that the lecturer adds the students in alphabetical order.

Give the algorithm. Draw a flow chart.

Test the algorithm.

Page 67: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 7 – Documentation and error prevention Page 62

© CTI Education Group

Unit 7: Documentation and error prevention

Unit 7 is aligned with the following learning outcomes and assessment criteria:

Learning outcomes

LO3: Produce appropriate documentation for a given program application.

LO4: Create and apply appropriate test schedules.

Assessment criteria AC3.1: Produce user documentation for a completed

programming application including the user

interface design. AC3.2: Develop documentation for a pre-described

program application. AC4.1: Demonstrate discrimination between semantic and

syntax errors. AC4.2: Produce test documentation.

AC4.3: Successfully construct and use test data and schedules to detect logic errors.

AC4.4: Use appropriate techniques for detecting errors.

Learning objectives

After studying this unit, you should be able to:

Explain and differentiate between the various error types and apply test schedules on semantic, run-time and syntaxes

Test documentation and, thus, create a test plan and relate evidence of testing (you may include reading sample inputs from a file or writing test

results to a file)

Test data and schedules, e.g. black box, white box, dry testing and data collection

Apply error detection techniques by applying compiler and link error messages, debugging tools and structured walk-through

Understand presentation of documentation, user documentation and program documentation

Page 68: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 7 – Documentation and error prevention Page 63

© CTI Education Group

Prescribed reading

Prescribed reading

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

Chapter 2, 3 and Appendix B

Introduction

When a new system or program is created, documentation is used to indicate

what the program is about; when it was created; by whom it was created; how the program functions; error messages that may occur during the interactivity

phase of the program, etc. Documentation is used to document everything that is part of the program.

7.1 Error detection

Error detection is the ability to detect any errors that may occur during the

writing, compiling and running of a program. Error handling or correction is the ability to correct and fix the errors.

7.1.1 Logical errors

Even if a program is carefully planned and written, you can never assume that the algorithm used is error-free. Logical errors, also known as semantic errors,

are the most difficult to find and to correct. Some programmers tend to forget that the computer does not have an overall idea of the program it is executing.

Therefore, computers cannot correct logical errors.

Logical errors can be checked by performing desk checking. Desk checking is

used to manually validate a program by using trace tables. The important data of the program (input, output, variables, values, etc.) is written down on paper

and the programmer steps through the design, making changes where needed on the paper.

When performing desk checking, a set of test data should be identified and

their results calculated beforehand. The result received when desk checking is performed should be the same as the test data result. Test data should include

valid-, invalid-, highest valid- and lowest valid- values.

Page 69: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 7 – Documentation and error prevention Page 64

© CTI Education Group

7.1.2 Syntax errors

Syntax errors occur while the program is being written. Syntax errors are also known as grammatical errors. An example is the developer spelling a function

or procedure name incorrectly. This type of error is easy to correct.

7.1.3 Data errors

Data errors are usually found in the input data. Data errors are also called

runtime errors. When writing any program, it is necessary to make sure that the quality of the runtime error-handling is good. This will prevent the program

from crashing. The users do not have any resources or files to help them when a runtime error occurs. The user cannot debug or fix a runtime error. Only the

developer knows the code and knows how to debug and fix runtime errors. An

example of a runtime exception is a user inputting a string value instead of an integer value.

Prescribed reading

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

Appendix B.1

7.2 Program testing

Program testing, as the name suggests, involves testing the program. Once the program is completed, it is tested for any errors or problems it might have.

Normally, in big organisations, teams consist of developers who develop the program and testers who test the program once it is developed. Before any

testing can occur, a test plan should be created. A test plan is a document which displays the test cases planned for a program or module, their purpose,

inputs, expected outputs and criteria for success. There is no set layout for a test plan. For the purposes of this course, we will use the layout as indicated

below.

A test plan should have: The name of the program that will be tested

The names of the people who are preparing the testing A testing strategy indicating each test that will be performed, its

participants and the method that will be used for the testing Requirements for testing the data (hardware and software)

Test data that will be used

The features that will be tested

Page 70: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 7 – Documentation and error prevention Page 65

© CTI Education Group

There are numerous types of program testing that should be performed before the program can be labelled as acceptable. These include:

7.2.1 Walkthroughs

Walkthroughs are similar to desk checking and are known as a group activity.

The program is tested manually by keeping track of the program’s data using paper or a blackboard. Walkthroughs are mostly used for discussion of the way

in which the programmer chooses to implement or design the program’s requirements.

7.2.2 Unit testing

Unit testing is where the complete program is broken down into smaller parts

for the testers to verify. Once the first part of the program is completed, it is tested. When using this method, the testers will not have a stack of testing to

complete at once after the program is completed. Unit testing is known as testing a module or procedure by itself.

7.2.3 Data coverage

Data coverage is also known as black-box testing. Data coverage is where a set of valid inputs is extremely small and is verified by a sub-program by

testing it against every possible input value. Using this method will ensure that the program meets the desired requirements and values that may be used.

7.2.4 Code coverage

Code coverage is also known as white-box testing. Code coverage is similar to

data coverage, but instead of testing the input values, the execution of statements or groups of statements are tested. This method will verify the

number of times the statements are executed and if each statement is executed correctly.

7.2.5 Trace tables

A trace table can be used to test the correctness of a program and also

prepare the programmer to create a program with a specific outline of the solution. This method is also called desk checking, because it is done before

the program is written in programming language. There may be only a small error that is not obvious. However, when a program is carefully checked, the

chances are very good that the output will be correct. Let us use an example to illustrate this concept.

Write an algorithm to calculate the product of two integers, the variables num1

and num2. Store the answer in the variable product.

Page 71: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 7 – Documentation and error prevention Page 66

© CTI Education Group

Algorithm

CalcProduct

~ This program calculates the product of two integers

display “Enter the first integer”

enter num1

display “Enter the second integer”

enter num2

product = num1 * num2

display “The product is”, product

end

To create a trace table, we need an instruction column, a column for each of

the variables and a column for the output (which will be shown on the screen). The instructions will be written in the first column in the same sequence as in

the program.

To test the program, we will use num1 = 4 and num2 = 5.

Table 7: Trace table

Instruction num1 num2 product Output

display Enter the first

integer

enter 4

display Enter the second

integer

enter 5

calculate 20

display The product

is 20

Source: Dale Sibanda (2014)

Prescribed reading Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming

principles. 2nd edition. Cape Town: Pearson Education. Appendix B.2

7.3 Relevant program documentation

Different types of projects call for different types of documentation.

Documentation can be displayed in any form. This can be represented in the

form of text, video, audio, etc. The majority of documentation consists of text files, such as Word or HTML documents.

Page 72: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 7 – Documentation and error prevention Page 67

© CTI Education Group

All programs should be documented adequately so that: People who have to maintain the code know what was intended by every

single line of code (program design documentation and source code documentation)

People who have to use the program know how to run it, what to expect,

and what output will be displayed or printed (user documentation)

7.3.1 Code comments

When mentioning documentation, code comments are probably the most

common understanding amongst programmers. For any serious program that you develop, it is almost guaranteed that either you or another programmer

will have to return to the code one day to correct a problem or add a new feature.

It is thus important that your code is easy to read. It should also contain

comments that clearly explain what is intended by structures and blocks in the

code. If a programmer who has to maintain the code has to try to understand what it was that you intended, it wastes time and also opens the possibility

that the intention may be misunderstood, which may lead to further problems.

A well-documented program will be easier to follow, modify, debug and maintain than a program that does not contain sufficient documentation.

Comments stating what steps are intended should be included for each

program flow or control statement (e.g. for, if, while, etc.). Any block of code should have a short explanation of its purpose.

Code should also include a prologue. A prologue can be found at the top of the

file and contains the following information: Name of the file

Name of the author

Date created Operating system

Description of the code

For example:

~ File name: ConvertingTemps.exe ~Author: John Smith

~Created: January 2014 ~ Operating System: Windows 7

~ConvertingTemp is an application that allows users to instantly convert any temperature from Celsius to Fahrenheit, and Fahrenheit to Celsius.

Other functions of this application are to compare different temperatures and display of two temperatures.

Page 73: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 7 – Documentation and error prevention Page 68

© CTI Education Group

7.3.2 User interface design

The first part that should be documented about your interface is the structure and navigation. This will indicate how different menus or pages link together

and how to navigate back and forth in the program.

Figure 9: Navigation for user interface

Source: Dale Sibanda (2014)

7.3.3 User guide

The old saying of “when all else fails, read the manual” is commonly used these days. So why do people only use documentation as a last resort? User

guides are often hard to follow and some tend to bury the information that users need amongst other related but irrelevant information.

The purpose of a user guide is to indicate to the user how to use and interact with a specific program. The guide should focus on the needs of the user,

support the task at hand and be available when needed.

Screenshots should be included only to support written documentation.

Page 74: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 7 – Documentation and error prevention Page 69

© CTI Education Group

Note: A user guide is not a collection of screenshots!

Example 1

Introduction

The gate remote key with two button entry transmitter, red button and green

button on a black button holder. This is a convenient transmitter that is used for easier opening of the gate without necessarily having to manually open the

gate or when you are at a distance.

Opening the gate Press the green button from within a distance of 50 m; it will take a few

seconds for the gate to start opening and 10 seconds for the gate to totally open.

**NB** The gate will not open if the distance is further than the stated distance.

Pausing the gate

When you click the green/red button before it fully opens/closes, the gate will pause/stop moving at the time you press, and will only continue when you

press the button again, depending on which button you have pressed.

Closing the gate

Press the red button from within a distance of 50 m; it will take a few seconds for the gate to start closing and 10 seconds for the gate to totally close.

**NB** The gate will not close if the distance is further than the stated distance.

Page 75: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Unit 7 – Documentation and error prevention Page 70

© CTI Education Group

Test your knowledge

1. Numerous types of program tests should be performed before the program

can be labelled as acceptable. Explain any three types. Also recommend the best type and give reasons for your answer.

2. Compare a logical error and a syntax error with the use of examples.

3. What is a ‘User Guide’? Create a user guide showing how you register for an e-active account and how you would log in after registering.

NB: Use screenshots.

4. Write an algorithm in the form of a pseudo code:

Enter two numbers. If the numbers are equal, increase the sum of the two

numbers by 20%, but if the first number is less than the second number, calculate the difference between the two numbers. If the first number is

greater than the second number, decrease the product of the two numbers by 25%. In each case, store the answer in a variable called answer.

Document your program from the start to the end.

Hint: Use the trace-table method to test your algorithm.

Test the algorithm using the numbers 12 and 5, 4 and 8, 7 and 7.

Page 76: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Glossary Page 71

© CTI Education Group

Glossary

Algorithm A set of instructions written in a specific sequence to solve a

problem

Array Variables of the same data type grouped under a single name

Array element A single variable in an array that can contain a value at a given

time

Boolean variable A variable that can take only one value, true or false

Constant A fixed value that cannot change throughout the entire program;

may be any data type

Data A collection of facts, such as values, measurements or readings

Data errors Incorrect data that causes a program to cease processing or

provide incorrect results

For loop

Also known as a fixed count loop or an automatic count loop, a

statement used when the number of iterations of a set of

instructions is known

Function call A statement that activates or calls a function from another part of

the algorithm

Function header The first line of a function, which contains the word function, a

function name and a possible list of parameters

If statement An instruction that controls program flow by allowing a section of

code to execute only when a specified condition is true

If-then-else statement

An If statement that specifies two actions: one action to take when

the specified condition is true and another action to take when the

condition is not true

Index Also known as a subscript, an indicator of the position of an

element in an array

Input The data entered into a system for processing into output

Integer variable A variable that contains a whole number that has no fractional or

decimal part; the number can be positive, negative or zero

IPO chart

An Input/Processing/Output (IPO) chart, which enables

programmers to do comprehensive planning; the Input and Output

columns contain only variable names, and the Processing column

provides an overview of the steps

Iteration Also known as looping, a type of programming used when sets of

instructions are repeated a number of times

Logical error An error resulting from faulty reasoning; a bug in a program that

causes it to terminate abnormally or to produce incorrect output

Logical operator An operator that joins two Boolean expressions to yield a Boolean

result, either true or false

Modularisation The division of a program into smaller pieces called modules, to

improve flexibility and shorten development time

Object A container for data, with attributes, and the operations needed to

manipulate that data

Operator A symbol used in an expression or equation, which tells the

computer how to process the data

Output The result of processing input data

Parameter

Data in the form of variables or values that is sent to a function or

a sub procedure so that it can perform the task it has to do; when

dealing with a subprocedure, a parameter may also contain the

address in memory to obtain and manipulate a value.

Post-test loop

A Do-until loop in which the statements in the body of the loop

are processed at least once, and the condition is tested only after

the statements in the body of the loop have been processed.

Page 77: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Glossary Page 72

© CTI Education Group

Pretest loop A Do-while loop in which the condition is tested before the

statements in the body of loop are processed

Pseudo code The way in which algorithm steps are written so that they can be

followed easily and understood

Reference parameter A parameter that is passed by reference to a location in memory

Relational operator An operator used in a comparison between two values, the

outcome of which is always a Boolean value

String A variable consisting of two or more alphanumeric characters

Subprocedure A separate procedure that consists of lines of code to solve a

specific part of a larger problem

Subprocedure call A statement that activates or calls a subprocedure

Trace table

Also known as desk checking or a walkthrough table, a method of

testing the logic of an algorithm normally done prior to writing it in

a programming language

Value parameter A copy of the value is passed to the function or subprocedure as a

parameter

Page 78: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

Bibliography Page 73

© CTI Education Group

Bibliography

Farrell, J. 2007. Programming logic and design comprehensive. 4th edition. Boston: Thomson Course Technology.

Gaddis, T. 2013. Starting out with programming logic & design. USA: Pearson

Education.

Johnsonbaugh, R. 2009. Discrete mathematics. USA: Pearson Education.

Labuschagne, C. 2012. Fundamentals of computer science. South Africa: CTI Education Group and London School of Business and Management.

Pretorius, C. M. & Erasmus, H.G. 2012. Basic programming principles. 2nd edition. Cape Town: Pearson Education.

RFFlow Professional Flowcharting. 2012. Sample flowcharts and templates.

[Online] Available from: http://www.rff.com/flowchart_samples.htm [Accessed: 27 November 2014].

Tutorialspoint. 2014. While loop in C. [Online] Available from:

http://www.tutorialspoint.com/cprogramming/c_while_loop.htm [Accessed: 27 November 2014].

Page 79: Introduction to Programming · The aim of the module is to introduce students to the world of programming, giving them the foundation to use other programming languages. Thus the

© CTI Education Group

Contact details

Bedfordview Campus

9 Concorde Road East, Bedfordview P.O. Box 1389, Bedfordview, 2008 Tel: +27 (0)10 595 2999, Fax: +27 (0)86 686 4950 Email: [email protected]

Bloemfontein Campus

Tourist Centre, 60 Park Avenue, Willows, Bloemfontein P.O. Box 1015, Bloemfontein, 9300 Tel: +27 (0)51 430 2701, Fax: +27 (0)51 430 2708 Email: [email protected]

Cape Town Campus

The Brookside Building, 11 Imam Haron Str (old Lansdowne Road), Claremont P.O. Box 2325, Clareinch, 7740 Tel: +27 (0)21 674 6567, Fax: +27 (0)21 674 6599 Email: [email protected]

Durban Campus

1 Lunar Row, Umhlanga Ridge, Durban

P.O. Box 20251, Durban North, 4016 Tel: +27 (0)31 564 0570/5, Fax: +27 (0)31 564 8978 Email: [email protected]

Durbanville Campus

Kaapzicht, 9 Rogers Street, Tyger Valley P.O. Box 284, Private Bag X7

Tyger Valley, 7536 Tel: +27 (0)21 914 8000, Fax: +27 (0)21 914 8004 Email: [email protected]

East London Campus

12 Stewart Drive, Berea, East London PostNet Suite 373

Private Bag X9063, East London, 5200 Tel: +27 (0)43 721 2564, Fax: +27 (0)43 721 2597 Email: [email protected]

Nelspruit Campus 50 Murray Street, Nelspruit P.O. Box 9497, Sonpark, Nelspruit, 1206 Tel: +27 (0)13 755 3918, Fax: +27 (0)13 755 3918 Email: [email protected]

Port Elizabeth Campus

Building 4, Ascot Office Park Cnr Ascot & Conyngham Roads, Greenacres P.O. Box 40049, Walmer, 6065 Tel: +27 (0)41 374 7978, Fax: +27 (0)41 374 3190 Email: [email protected]

Potchefstroom Campus

12 Esselen Street, Cnr Esselen Street & Steve Biko Avenue, Die Bult, Potchefstroom P.O. Box 19900, Noordbrug, 2522 Tel: +27 (0)18 297 7760, Fax: +27 (0)18 297 7783 Email: [email protected]

Pretoria Campus

22 Umgazi Street, Menlo Park, Pretoria PostNet Suite A147, Private Bag X18, Lynnwood Ridge, 0040 Tel: +27 (0)12 348 3060, Fax: +27 (0)12 348 3063 Email: [email protected]

Randburg Campus

6 Hunter Avenue, Cnr Bram Fischer Drive Ferndale, Randburg P.O. Box 920, Randburg, 2125 Tel: +27 (0)11 789 3178, Fax: +27 (0)11 789 4606 Email: [email protected]

Vanderbijlpark Campus

Building 2, Cnr Rutherford & Frikkie Meyer Boulevards Vanderbijlpark P.O. Box 6371, Vanderbijlpark, 1900 Tel: +27 (0)16 931 1180, Fax: +27 (0)16 933 1055 Email: [email protected]

Group Head Office

Management Services Building 44 Alsatian Road, Glen Austin Extension 3, Midrand P.O. Box 1398, Randburg, 2125 Tel: +27 (0)11 467 8422, Fax: +27 (0)86 583 6660 Website: www.cti.ac.za

CTI is part of Pearson, the world’s leading learning company. Pearson is the corporate owner, not a registered

provider nor conferrer of qualifications in South Africa. CTI Education Group (Pty) Ltd. is registered with the Department of Higher Education and Training as a private higher education institution under the

Higher Education Act, 101, of 1997. Registration Certificate number: 2004/HE07/004. www.cti.ac.za.