[go: up one dir, main page]

100% found this document useful (1 vote)
6K views411 pages

Tie Computer Science Form Five

The document is a textbook titled 'Computer Science for Advanced Secondary Schools Student’s Book Form Five' published by the Tanzania Institute of Education in 2022. It covers various topics including computer basics, data representation, problem solving, C++ programming, website development, and system development, aimed at form five students in Tanzania. The book includes illustrations, activities, and exercises to enhance learning and is aligned with the 2010 Computer Science Syllabus for Advanced Secondary Education.

Uploaded by

Joshua Bachuba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
6K views411 pages

Tie Computer Science Form Five

The document is a textbook titled 'Computer Science for Advanced Secondary Schools Student’s Book Form Five' published by the Tanzania Institute of Education in 2022. It covers various topics including computer basics, data representation, problem solving, C++ programming, website development, and system development, aimed at form five students in Tanzania. The book includes illustrations, activities, and exercises to enhance learning and is aligned with the 2010 Computer Science Syllabus for Advanced Secondary Education.

Uploaded by

Joshua Bachuba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 411

FOR ONLINE USE ONLY

Computer

Chapter One: Computer basics


DO NOT DUPLICATE

Science
for Advanced Secondary Schools

LY
Student’s Book

N
Form Five

O
SE
U
E
N
LI
N
O
R
FO

Tanzania Institute of Education

i
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 1 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
©Tanzania Institute of Education 2022
Computer Science

Published 2022

LY
N
O
ISBN: 978-9987-09-589-6

SE
U
Tanzania Institute of Education
P.o. Box 35094
E

Dar es Salaam, Tanzania


N

Mobile numbers: +255 735 041 170 / +255 735 041 168
E-mail: director.general@tie.go.tz
LI

Website: www.tie.go.tz
N
O
R

All rights reserved. No part of this textbook may be reproduced, stored in any retrieval
system or transmitted in any form or by any means whether electronic, mechanical,
FO

photocopying, recording, or otherwise without prior written permission of the Tanzania


Institute of Education.

ii
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 2 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Table of Contents

Acronyms and Abbreviations.................................................................. v


Acknowledgements................................................................................. vii
Preface..................................................................................................... viii

Chapter One: Computer basics................................................................ 1

LY
Computer organisation............................................................................ 1
Computer applications............................................................................. 21
Troubleshooting....................................................................................... 62

N
Chapter summary.................................................................................... 65
Revision exercise 1.................................................................................. 67

O
Chapter Two: Data representation .......................................................... 69

SE
Digital and Analogue concepts................................................................
Number system and conversion..............................................................
Data coding.............................................................................................
69
72
93
U
Boolean algebra....................................................................................... 97
Logic gates.............................................................................................. 107
Chapter summary.................................................................................... 116
E

Revision exercise 2.................................................................................. 118


N

Chapter Three: Problem solving............................................................... 120


LI

The concept of problem solving.............................................................. 120


Problem solving process.......................................................................... 121
N

Algorithm representation......................................................................... 123


Chapter summary.................................................................................... 143
O

Revision exercise 3.................................................................................. 144


R

Chapter Four: C++ programming ........................................................... 146


Introduction to programming languages................................................. 146
FO

Introduction to C++ programming.......................................................... 154


Data types................................................................................................ 171
Variables and constants........................................................................... 175

iii
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 3 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Input and output streams......................................................................... 181
Computer Science

Operators, expressions and assignments................................................. 183


Control structures.................................................................................... 191
Functions................................................................................................. 205
Arrays and strings.................................................................................... 214
Chapter summary.................................................................................... 223
Revision exercise 4.................................................................................. 226

LY
Chapter Five: Website development......................................................... 230
Concept of website.................................................................................. 230
Website design......................................................................................... 236

N
HTML...................................................................................................... 239

O
Cascading Style Sheets............................................................................ 256
Introduction to JavaScript....................................................................... 258
Introduction to application programing interface.................................... 276
SE
Website publishing..................................................................................
Chapter summary....................................................................................
296
318
Revision exercise 5.................................................................................. 318
U
Chapter Six: System development............................................................ 322
Concept of system development.............................................................. 322
E

System planning...................................................................................... 348


N

System analysis....................................................................................... 353


System design.......................................................................................... 369
LI

System Implementation........................................................................... 379


System documentation............................................................................ 383
N

System maintenance................................................................................ 390


Chapter summary.................................................................................... 392
O

Revision exercise 6.................................................................................. 394


R

Glossary....................................................................................................... 395
Bibliography............................................................................................... 396
FO

Appendices.................................................................................................. 399
Index .......................................................................................................... 401

iv
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 4 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Acronyms and Abbreviations

ALU Arithmetic Logic Unit

ASCII American Standard Code for Information Interchange

ASD Agile Software Development

LY
BCD Binary Coded Decimal

N
BIPS Billion Instructions Per Second

O
COBOL Common Business Oriented Language

CPU
SE
Central Processing Unit
U
CSS Cascading Style Sheets
E

DBMS Database Management Systems


N

EMAS Electronic Marking System


LI
N

FORTRAN FORmula TRANslation


O

HTTP Hypertext Transfer Protocol


R

HTTPS Hypertext Transfer Protocol Secure


FO

MIPS Million Instructions Per Second

v
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 5 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
NECTA National Examination Council of Tanzania
Computer Science

PNG Portable Network Graphics

RAD Rapid Application Development

SDLC System Development Life Cycle

LY
SQL Structured Query Language

N
TBC Tanzania Broadcasting Corporation

O
URL Uniform Resource Locator

SE
U
E
N
LI
N
O
R
FO

vi
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 6 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Acknowledgements

The Tanzania Institute of Education (TIE) would like to acknowledge the


contributions of all the organisations and individuals who participated in designing
and developing this textbook. In particular, TIE wishes to thank the University
of Dar es Salaam (UDSM), Mzumbe University (MU), The Open University of
Tanzania (OUT), The Mwalimu Nyerere Memorial Academy (MNMA), University
of Dodoma, Institute of Accountancy Arusha, Arusha Technical College, School
Quality Assurance (SQA) Department, Teachers’ Colleges and Secondary Schools.

LY
Besides, the following individuals are acknowledged:

Writers: Dr Hashim Uledi Iddi (CoICT-UDSM), Dr Eng. Morice

N
Daudi Tegeje (MU), Dr Fabian G. Mahundu (MNMA), Mr.
Chacha Maro Nsaho (Mpwapwa T. C.), Mr. Hamadi Khalifa

O
Dinyo (Loyola S.S), Mr. Watson G. Mtewele (TIE).

Editors:
SE
Dr Edephonce N. Nfuka (OUT), Dr Eng. Morice Daudi
Tegeje (MU), Dr Adam B. Mtaho (Arusha Tech), Cesilia
J. Mambile (UDOM), Zawadi W. Mduma (Pamba Sec),
Leonard L. Mutembei (IAA).
U
Editors (Language): Dr Philipo Lonati Sanga (UDSM), Dr Solomon Emmanuel
Muguba (IAA)
E

Designer: Amani J. Kweka


N

Illustrators: Mr Fikiri A. Msimbe (TIE), Alama Art and Media Co.


Ltd,
LI

Coordinator: Watson G. Mtewele (TIE)


N

TIE also appreciates secondary school teachers and students who participated in
the trial phase of the manuscript of this book. Likewise, TIE would like to thank
O

the Ministry of Education, Science and Technology for facilitating the writing and
printing of this textbook.
R
FO

Dr Aneth A. Komba
Director General
Tanzania Institute of Education

vii
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 7 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Preface

This textbook, Computer Science for Advanced Secondary Schools Student’s Book
Form Five, is written specifically for form five students in the United Republic of
Tanzania.

It is written in accordance with the 2010 Computer Science Syllabus for Advanced

LY
Secondary Education, Form V-VI issued by the then Ministry of Education and
Vocational Training. The book consists of six chapters, which are: Computer basics,
Data Representation, Problem solving, C++ programming, Website development,

N
and Systems development. In addition to textual descriptions, each chapter contains
illustrations, activities, and exercises. You are encouraged to do all activities and

O
exercises in this book, and other assignments provided by your teacher. This will
enable you to develop the intended competencies.
SE
Tanzania Institute of Education
U
E
N
LI
N
O
R
FO

viii
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 8 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE

Chapter
One Computer basics

Introduction

LY
Computers are becoming an indispensable element of our daily life. They play
an essential role in various areas such as banks, corporations, government
offices, businesses, at home and schools. Since information is at the heart of

N
peoples’ lives, computers have mostly replaced ‘file cabinets’ that previously
dominated public and private offices in documentation and records keeping.

O
Today, information can quickly and efficiently be processed, stored and accessed
electronically through computers. In this chapter, you will learn about computer
organisation, applications, and troubleshooting. The competencies developed
SE
in this chapter will enable you to use computer and other advanced features of
the office management software in performing various office related tasks.
U
Think about the following:
E

(a) You are requested by your Headmaster or Headmistress to assist in preparation


N

of some examination forms and academic assessment reports generation


following the absence of the examination officer in the academic office. In
LI

order for the office to operate, it should have a personel who possesses several
skills to accomplish the mentioned tasks.
N

(b) Have you ever thought of what kind of knowledge or skills you must possess if
O

you will be working in a large organisation which has various departments or


sections such as secretarial office, graphics department, point of sales section,
supermarket, and digital recreation center?
R

Computer organisation
FO

and disseminates the results as required.


A computer is a programmable electronic It is organised in two key aspects, namely,
device that accepts data, performs hardware and software. Hardware refers
operations on that data, presents, stores to all of the physical components of a

1
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 1 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
computer system. Computer hardware the computer what to do. The software
Computer Science

typically includes Central Processing Units must be installed in the hardware to


(CPU) for processing data, input devices enable computer system to perform tasks.
such as keyboard and mouse for entering Everything that runs on a computer such
data to be processed, output devices such as an operating system, a diagnostic tool,
as monitor and printer for communicating games, and applications, can be defined
the results to users and memory such as as software. Even the malware that
Random Access Memory (RAM) and hard is intentionally developed to damage
disk for temporary and permanent data
computers and disrupt other software is

LY
storage as shown in Figure 1.1.
also defined as software. Other examples
of software are Microsoft Windows, Linux,
Software, on the other hand, refers to a set
Mac OS, Office applications, Accounting

N
of instructions which enable the hardware
to perform specific sets of tasks. It is a systems and Student Management

O
set of instructions or programs that tell Systems.

INTEGRATED VIDEO CAMERA MONITOR WITH


(input)
SE INTEGRATED SPEAKERS
(output)

MODEM/ROUTER
U
(communications)
E
N

PRINTER
(output)
LI

SYSTEM UNIT
KEYBOARD AND MOUSE
(houses processing and storage
(input)
N

USB FLASH DRIVE hardware; contains ports to


connect external hardware)
(storage)
O

Figure 1. 1: Typical computer hardware


(Source: Morley and Parker 2017)
R

Computer hardware
FO

Computer hardware refers to all physical components of a computer including the


electronic circuits (motherboard) within the system unit, the mouse, keyboard,
printer and scanner. In other words, you can say that hardware refers to the
visible and tangible parts of a computer. Any computer hardware comprises of

2
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 2 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
four main components: input devices, components such as processors, memory,
output devices (collectively termed as storage and network connections.
Input/Output (I/O) devices), a central Motherboad acts as a backbone for
processing unit (CPU), and storage the entire computer as it consists of a
devices. In order to function, most of large flat circuit boards with ‘chips’
these devices are integrated or attached and other electronic components. Some
in the motherboard. components are soldered or fixed directly
to the board while slots or sockets for
Motherboad adding or removing other components

LY
Motherboad is the computer’s main easily. Figure 1.2 shows an example of a
circuit board that houses many hardware computer motherboard.
RAM slots

N
O
SE
U
E

Motherboard
N

Figure 1.2: Computer motherboard


LI
N

Input and output devices


The input and output devices of the computer system are the devices that enable
O

the user to use the computer. Data and user commands can be transferred to the
computer system via input devices. The functionality of input and output devices is
R

similar although they perform opposite roles, Figure 1.3 shows an example of input
and output devices.
FO

3
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 3 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Scanner Microprocessor printer

Outputs
Inputs Speaker

LY
Camera

N
O
Mouse Keyboard System unit Monitor

Figure 1.3: Some examples of input and output devices and their sequences

Input devices
Interacting with the computer system is
SE
these input devices are processed, and
results are stored in a storage unit using
various devices such as hard disks, flash
U
done using input devices. For example,
you can type data into a computer system disks, and memory cards. The following
using a keyboard or scan data into a are descriptions for some common input
computer system using a scanner. In devices.
E

other words, the computer receives data


and instructions from the user via various Keyboard
N

input devices such as a keyboard, mouse, The keyboard is the most common and
LI

joystick, microphone, barcode reader, and widely used input device for entering data
digital camera. Other input devices can into a computer. Although there are some
automatically enter data into a computer, additional keys for performing additional
N

such as automatic data entering using functions, the keyboard layout is similar
electronic sensors, scanners, and optical
O

to a traditional typewriter as shown in


mark recognition (OMR). Figure 1.4.
R

The forms used in inputting data in the


computer system are such as manual
FO

inputs from a keyboard, inputs from


instruments or sensors, and inputs from
a storage device such as a flash drive and
Compact Disc (CD). Data entered using Figure 1.4: Keyboard

4
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 4 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Mouse
A mouse is a pointing device (well-
known as a cursor-control device) that
consists of a small palm-sized box
with a spherical ball or optical light at
its base that detects mouse movement
and delivers appropriate signals to
the CPU when the mouse buttons are Figure 1. 6: Scanner
pushed. It usually has two buttons, one

LY
on the left (1) and another on the right Joystick
(2) (see Figure 1.5). It also has a wheel The joystick is a pointing device that moves
(3) for scrolling. Mouse can be wired or the cursor’ position on a monitor screen.

N
wireless. A mouse controls the cursor’s It is a stick with a spherical ball at both
position on the screen rather than lower and upper ends as shown in Figure

O
entering text into the computer. A mouse 1.7. The lower spherical ball moves in a
pad is a pad over which you can move a socket. The joystick can be moved in all
mouse. directions. The function of the joystick is

Wheel
3.
SE
similar to that of a mouse. It is mainly used
in Computer-Aided Designing (CAD) and
playing computer games.
Right click
2.
U
1.
E

Left click
N
LI

Figure 1.5: Mouse

Figure 1.7: Joystick


Scanner
N

A scanner is an input device that allows Digitizer


O

users to view data such as images or text A digitizer is an input device that
on a computer. It can read images or text transforms analog data into digital data,
printed on paper and convert the data an example is shown in Figure 1.8.
R

into a computer-readable format. In other A television or camera signal can be


words, it converts images (photos) and text converted into a series of numbers that
FO

into a data stream. Scanners are helpful can be stored in a computer by using a
in publishing and sharing the physical digitizer. The computer can utilise these
documents electronically. An example of to construct an image of whatever the
a scanner is shown in Figure 1.6. camera was pointing at.

5
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 5 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
the product. A supermarket barcode
Computer Science

scanner, which reads and records the


price of a product, is an example of
the commonly used barcode reader for
increasing productivity.

Figure 1.8: Digitizer

LY
Magnetic ink card reader
A Magnetic Ink Card Reader (MICR) is
an input device that is commonly used

N
in the banks, where they handle many
Figure 1.10: Barcode reader
checks each day as shown in Figure 1.9.

O
The bank’s code numbers and cheque Touch Screen
numbers are printed on the cheques using A touch screen is a computer display
a particular type of ink that incorporates screen that serves a an input device, when
machine-readable magnetic particles.
Therefore, Magnetic Ink Character
Recognition is the name given to this
SE
a touch screen is touched by a finger or
stylus, it registers the event and sends it
to a controller for processing.
U
method of reading. The advantage of
MICR is that it is quick and error-free. A touch screen may contain pictures or
words that the user can touch to interact
with the device.
E
N
LI
N

Figure 1. 9: Magnetic ink card reader (MICR) Figure 1.11: Touch screen laptop
O

Barcode reader Output devices


A barcode reader (BCR) or scanner, Output devices are electronic components
R

commonly known as a POS (point of of a computer’s hardware that give out


sale) scanner is a laser-based hardware and send processed data to users or other
FO

input device that can read a barcode. devices. In other words, an output is
An example of BCR is shown in Figure anything that comes out of a computer (e.g.,
1.10. It can also put product information text, graphics, audio, or video). Monitors,
into a database or log information about printers and projectors are the commonly

6
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 6 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
used output devices. Other devices are version of the information. The printer
headphones, computer speakers, projector, output provided to the user is either in
braille readers, speech synthesisers, and text or visual formats. Some old-fashioned
plotters. Thus, an output device sends data printers can only print in black and white.
out of the system. The user can only see However, nowadays, powerful printers are
the result after processing data through employed to create high-quality photos.
output devices. There are two types of printers:
(a) Impact printers (e.g., character
Monitor printers and line printers) print the

LY
A monitor is an essential computer output characters by striking them on the
device in the computing environment. ribbon and then pressing them on
A monitor, as shown in Figure 1.12, is the paper, and

N
commonly called a Visual Display Unit (b) Non-impact printers (e.g., laser
(VDU). The monitor is intended to show
printers and inkjet printers) can

O
both symbolic and graphical data. It
print without getting any striking
displays all the data and information as
a soft copy on its screen. It serves as a on the ribbon.
link between the user and the CPU. Thus,
the computer is not complete without a
monitor. There are five (5) key types of
SE
monitors:
U
(a) Cathode Ray Tube (CRT) Monitors,
(b) Liquid Crystal Display (LCD)
Monitors,
E

(c) Light Emitting Diode (LED) Figure 1.13: An example of a printer


Monitors,
N

(d) Organic Light-Emitting Diode Projector


(OLED) Monitors, and A projector is an output device that allows
LI

(e) Plasma Monitors. users to display content onto a giant screen,


a wall, or a large flat surface. It uses light
N

and optics to magnify texts, images, and


movies. Projectors are commonly used in
O

meetings for presentations to respective


audiences. An example of a projector is
shown in Figure 1.14.
R

Figure 1.12: An example of a plasma monitor


FO

Printer
A printer, as shown in Figure 1.13, is a
hardware device that provides a hard copy Figure 1.14: An example of a projector

7
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 7 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Plotter
Computer Science

Exercise 1.1
A plotter is an output device that works
similarly to a printer, but allows users Answer the following questions.
to print large format documents like 1. List down and describe any four (4)
architectural drawings, banners, flyers, input devices other than the ones
and pamphlets. It is primarily used in included in this chapter.
engineering for drawing a specific image
2. List down and describe the
on a series of straight lines. An example
basic components of a computer
of a plotter is shown in Figure 1.15. hardware.

LY
3. Explain with examples the
relationship between input and
output devices.

N
4. Describe input and output devices

O
that contribute to having efficient
digital-enabled shopping in
supermarkets and other related
SE
establishments.

Central Processing Unit


U
The Central Processing Unit (CPU), as
shown in Figure 1.16, is considered as the
computer’s heart or brain because of the
E

Figure 1.15: An example of a plotter


core functions it executes. A computer’s
N

CPU executes all arithmetic and logical


Activity operations as well as organising the
LI

activities of all other computer units. It


Activity 1. 1: Using search engine or is housed on the motherboard or system
N

physical observation board as a microprocessor chip. It can


also be called a microprocessor or
O

(a) Visit or select any national or


international airport, processor.
(b) Find out input devices and output
R

devices used for managing


travellers and baggage, and
FO

(c) Describe the uses of each one and


its contribution to the travellers and
airport operations.
Figure 1.16: An example of a CPU (Processor)

8
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 8 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
The computer user cannot receive the processor and how the instructions
desired output if the CPU does not execute are executed.
the commands that the user issues to the (b) Getting the data, translating into
computer system. The functions of CPU signals, and storing it for later use.
are as follows: (c) Regulating the operation of other
(a) It is considered as the computer’s CPU components such as the ALU
brain. and Registers.
(b) It is responsible for all data
processing operations. Arithmetic logic unit

LY
(c) It monitors data processing, and Arithmetic logic unit (ALU) also known
directs programs what to do. as the computer’s mathematical brain,

N
(d) It is responsible for the computer’s consists of two units namely arithmetic
overall functionality. unit and logic unit. The arithmetic unit

O
performs arithmetic operations on the
Components of Central Processing data that is made available to it. Some
Unit of the arithmetic operations supported
CPU guides the computer through each
step of the problem-solving process.
SE
by the arithmetic unit are addition,
subtraction, multiplication and division.
Logic unit performs comparisons of
The CPU comprises of three major
numbers, letters and special characters.
U
components that are essential in carrying
out its key functions: the Control Unit Logic operations include testing
(CU), Arithmetic Logic Unit (ALU), and for greater than, less than or equal
memory unit (MU). conditions.
E

The ALU performs arithmetic and logic


N

Control Unit
calculations and uses registers to hold the
The Control Unit (CU) organises the data that is being processed. It receives
LI

processing of data and instructions. It data from input registers, processes it,
does not do any actual processing of and puts the results in an output register.
N

data. It acts as a supervisor to control and ALU’s functions are as follows:


coordinate the activities of other units of (a) They are primarily used to make
O

a computer. It specifically monitors how decisions such as arithmetic and


input and output devices, the Arithmetic logical procedures.
R

Logic Unit (ALU), and the computer’s (b) They serve as a link between the
memory react to CPU commands. computer’s primary and secondary
FO

Generally, the CU is responsible for a memory.


variety of tasks including: (c) They transfer all information
(a) Regulating the order in which between the primary and secondary
instructions enter and exit the memory.

9
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 9 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Memory unit in or near the CPU chip. It is faster than
Computer Science

Memory unit, also known as processor random access memory (RAM). Further,
registers or CPU registers are storage it is a memory storage buffer that stores
spaces for units of memory that are used the data in small quantities that is used
to transfer data for immediate use by more often, temporarily, and makes them
the CPU. They are used temporarily to available to CPU at a fast rate. The data
store data, instructions, addresses and and instruction that are required during
intermediate results and send them to the processing of data are brought from
the processor. These registers contain the secondary storage devices and

LY
data in the form of memory addresses, stored in the RAM. For processing, it
and once the instruction at that memory is required that the data and instructions
address has been processed, it stores are accessed from the RAM and stored

N
the memory address for the following in the registers. The time taken to move
instruction. There are various types the data between RAM and CPU registers

O
of registers, each with its own set of is relatively large. This affects the speed
functions as follows: of processing of computer and results in
(a) The input registers carry the input.
(b) The output registers carry the
output.
SE
decreasing performance of the CPU. In
order to improve this situation, during
processing, the CPU first checks cache
for the required data as it is faster than the
U
(c) Temporary registers are used
rest. If data is not found in cache, then it
temporarily to store data.
looks in the RAM and so on. In summary,
(d) Address registers are used to store the cache has the following functions:
E

the memory address. (a) It reduces the time taken by the


(e) The program counter is used to CPU to fetch and execute data and
N

store the address of next instruction instructions.


to be processed. (b) It temporarily stores data in small
LI

(f) Data registers have the role of quantities to be reused as needed.


holding the memory operand.
N

(g) Instruction registers contain the Bus


O

current instructions most recently A bus is a set of electronic signal


fetched. pathways that allows information and
signals to travel between components
R

Cache memory inside or outside a computer. It connects


The cache is a small and fast piece of several components of the computer
FO

memory designed to speed up processing system to the CPU with the intention to
such as data transfer and instructions. It send signals and data from the processor
also works on data that are available in to other devices and the vice versa. Buses
it to be reused when needed. It is located are also housed in the motherboard.

10
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 10 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Buses are divided into three categories impulses that control the functions’ timing
as shown in Figure 1.17. The address bus and pace. The computer operating speed
which is used to send memory addresses is linked to the speed of the system
from one process to another; the data bus clock. The clock frequency is measured
which transfers data from the CPU to the in millions of cycles per sec or megahertz
components; and the control bus which (MHz) or Gigahertz (GHz), which is
specifies whether data is to be read or billions of cycles per second. A CPU’s
written to the memory. Generally, buses performance is measured by the number
have four essential functions: of instructions it executes in a second,

LY
(a) to share data between different that is, Million Instructions Per Second
devices; (MIPS) or Billion Instructions Per Second
(b) to supplying power to different (BIPS). The clock’s essential functions

N
sections or components of the are two, namely:
computer system; (a) Ensuring that the components

O
(c) to convey control, timing and of the computer system are in
coordination of signals to other synchronisation.
parts of the system; and (b) Maintaining a record of the current
(d) to identify memory address for the
transferred data.
SE time and date.
In brief, it can be said that the CPU’s
primary components are responsible for
U
Memory Input and
CPU Output the computer system’s smooth processing
of instructions and data as shown in
Figure 1.18.
E

Control bus CPU


System bus

Clock Registers
N

Address bus Control unit


Arithmetic unit
Cache
LI

Data bus
Control bus
Address bus Data bus External
Figure 1.17: System bus
N

components

System clock Primary memory


O

A system clock is an electronic device Figure 1.18: Main components of CPU


that gives a specific frequency signal to
R

synchronise all internal components on the Computer memory


motherboard. The clock speed of a CPU Computer memory has risen fast due
FO

is defined as the frequency with which a to increased usage of and demand for
processor executes instructions or the data computer systems. Each generation of
is processed. High clock frequencies mean memory has resulted into a computer with
more clock ticks. It sends out electrical a quicker and larger memory capacity. As

11
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 11 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
a result, a new level of memory units and (b) Nibble: this is a group of 4 bits.
Computer Science

new words for describing memory size (c) Byte: this is a group of 8 bits. It is
have emerged. In computer science, the the smallest unit that can represent
concept of ‘memory’ is almost similar to a character or data item.
that of the human brain. It is where the
users keep their data and instructions. (d) Word: a computer word, like a byte,
Computer memory, therefore, can be is a group of fixed number of bits
defined as a ‘storage area’ within a processed as a unit, which varies
computer where data and instructions are from computer to computer but it is

LY
stored for processing. fixed for each computer. The length
of a computer word is called word
Memory capacity units size or word length. It may be as
small as 8 bits or may be as long

N
A memory capacity unit can be described
as the amount of data stored in the as 96 bits. A computer stores the

O
‘storage unit’ whose storage capacity is information in form of computer
expressed as ‘Bytes’. The following are words.
the central memory storage units:
(a) Bit (Binary Digit): a binary digit
is logical 0 and 1 representing a
component’s passive or active state
SE
Generally, a computer stores the
information in a multiple of computer
words or bytes. Table 1.1 shows memory
in an electric circuit. units progression to higher storage.
U
Table 1.1: Memory Units
Kilobyte (KB) 1 KB A kilobyte (1 KB) consists of 1024 bytes
E

Megabyte (MB) 1 MB A Megabyte (1 MB) consists of 1024 kilobytes


N

GigaByte (GB) 1 GB A Gigabyte (1 GB) consists of 1024 megabytes


TeraByte (TB) 1 TB A Terabyte (1 TB) consists of 1024 gigabytes
LI

PetaByte (PB) 1 PB A Petabyte (1 PB) consists of 1024 terabytes


N

Note: 1KB=210 bytes, 1MB=220 bytes, 1GB=230bytes, 1TB=240 bytes, 1PB= 250 bytes
O

Therefore, a memory unit is a way of demonstrating different computer system’s


memory or storage capacity. Although those bits and bytes are the most fundamental
memory units, capacity is usually represented in terms of bytes in multiples, thus,
R

creating different storage naming from Byte, Kilobyte to Petabyte as indicated in


Table 1.1. This will keep evolving as further invention and memory needs arise.
FO

Types of computer memory


There are two types of computer memory: primary memory (also known as main
memory) and secondary storage (also known as auxiliary memory) as indicated

12
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 12 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
in Figure 1.19. Generally, the primary memory holds instructions and data when
a program is executing while the secondary memory holds data and programs not
currently in use and provides long-term storage. The main distinction between the
two types is the access speed.
Computer
memory

Primary or Secondary or
main memory auxiliary

LY
RAM ROM Magnetic Solid state
Optical
drive

N
Hard Disk Solid State

O
SRAM CD
Drive (HDD) Drive (SSD)

DRAM
SE
Floppy disk Flash drive

Figure 1.19: The types of computer /memory/storage


DVD
U
Primary memory Random-Access Memory (RAM)
Primary memory is the essential storage RAM, as shown in Figure 1.19, is
space in the computer system. It is the based on data stored in random access
E

place where accessing data is faster memory and can easily be accessible as
N

because it is an internal memory of the the name proposes in any random order.
computer. The primary memory is of The most significant thing to emphasise
LI

utmost volatility (i.e. data in primary concerning RAM is that it is speedy, it


memory will never exist if it is not can be written to as well as read and it
N

saved during the power failure. The is volatile that is, the entire data stored
primary memory consists of Random- in RAM is lost when it loses power. It
O

Access Memory (RAM) and Read-Only is also costly in comparison to several


Memory (ROM). They are positioned other types of secondary memory in
near the CPU on the computer terms of cost per gigabyte. Since RAM
R

has a relatively high cost compared


motherboard allowing the CPU to scan
to secondary memory types, many
data from the primary memory. It is used
FO

computer systems use primary and


to store data that the CPU requires right
secondary memory. Data required for
away while processing so that it does
imminent processing is moved to RAM,
not have to wait for it for long to arrive.
where it can be accessed and modified

13
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 13 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
quickly so that the CPU does not keep waiting for long. Once the data is no longer
Computer Science

needed, and the RAM space that has been released is then filled with the next chunk
of data that is required for use by a CPU. There are two main types of RAM, namely
Dynamic RAM (DRAM) and Static RAM (SRAM).

LY
N
O
SE
Figure 1.20: RAM

Dynamic RAM most expensive, making DRAM the more


U
Dynamic RAM is commonly used as a common memory in computer systems.
computer’s main memory. Each DRAM
Read-Only Memory
memory cell comprises a transistor and
E

Read-Only Memory is a non-volatile


a capacitor within an integrated circuit,
memory. It only allows reading the
N

and a data bit is stored in the capacitor. memory. The storage in ROM is permanent
Since transistors continuously release a in nature, and it used to store standard
LI

small amount, the capacitors will gently processing programs that permanently
discharge it causing information stored reside in the computer. ROM comes
N

to drain; therefore, DRAM needs to be programmed by the manufacturer. It


refreshed (given a new electronic charge) comes with the Basic Input Output System
O

every few milliseconds to retain data. (BIOS). BIOS provides the processor
with the instructions that are required
Static RAM to initialise or boot the system. It stores
R

the data needed for the startup of the


Static RAM is composed of four to
computer, thus, allowing a computer to
FO

six transistors. It preserves data in the


start up or regenerate each time it is turned
memory as long as power is supplied to on. It provides the system with settings
the system, unlike DRAM, which must and resources that are available on the
regularly be refreshed. SRAM is faster but system.

14
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 14 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Secondary memory devices such as laptops and tablets. An
Secondary memory is non-volatile and optical drive is an internal or external
persistent in nature. It allows a user computer disk drive that uses laser
to store data that may be instantly and beam technology to read and write data.
easily retrieved, transported and used by Examples includes CD, DVD and Blue-
applications and services. It is therefore, Ray disk. Some examples of secondary
storage are shown in Figure 1.21.
used for permanent storage of data and
programs. A program or data that has
to be executed is brought into the RAM

LY
from the secondary memory. Secondary
memory is typically housed in a separate
storage device, such as a hard disk drive

N
(HDD) or solid-state drive (SSD). It

O
is connected to the computer system
either directly or through a network.
Secondary memory is available in
large capacity and has a lower cost per
gigabyte, but read and write speeds
SE Figure 1.21: Secondary storage
are relatively slower compared to the
U
primary memory. There are three main Relationship between primary and
categories of the secondary memory, secondary memory
namely magnetic, solid state drive and
The primary memory is an internal memory
E

optical memory.
that hold information temporarily while
N

secondary memory is an auxiliary memory


Magnetic storage refers to any type
that store information permanently for
of data storage using a magnetized
LI

future use. The data bus can access primary


medium. Examples are the hard disk
drive and floppy disk. A solid-state memory during the processes whereas
N

drive (SSD) is a storage device that I/O channels can access secondary
uses integrated circuit assemblies memory. The processing unit can access
O

to store data persistently, typically primary memory data directly whereas


using flash memory, and functioning the processor cannot access secondary
memory data directly. In comparing the
R

as secondary storage in the hierarchy of


computer storage. Examples of magnetic primary and secondary storage devices,
FO

storage include flash memory which it can be said that the primary storage
is used for easily copying files from devices are more expensive and faster than
one device to the other and solid-state secondary storage devices. The primary
drive (SSD) which is used in compact memory and secondary memory are

15
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 15 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
both related as computer memory, but
Computer Science

5. List down and describe the


they can be distinguished on the fact that application of four examples of
primary memory (RAM) is volatile while memory.
secondary memory is non-volatile and it 6. Differentiate the components of the
allows permanent storage and alteration CPU.
when required.
7. Describe the importance of buses
in the computer system.
Exercise 1.2
8. Explain the main functions of CPU

LY
components.
Answer the following questions.
1. How does computer memory store
Computer software
data?

N
Computer software, as indicated earlier,
2. Explain two main types of memory.
is a set of instructions which enable the

O
3. What is the difference between hardware to perform a specific set of
Dynamic RAM (DRAM) and Static tasks. It controls and tells a computer
RAM (SRAM)? what to do. There are two main types
4. What is the difference between
optical drives and SSD. Provide
SE
of computer software: the application
software and systems software as
examples and the use for each. indicated in Figure 1.22.
U
Software
Set of programs that govern
the functioning of computer
E
N

System software Application software


Controls the internal Carries out necessary operations for
LI

computer operations a specified application to function


N

System System General Specific


O

management development purpose software purpose software


software software 1. Word processor 1. Reservation
1. Operating 1. Programming 2. Presentation System
language
R

System 3. Spreadsheet 2. Human Resource


2. Device drivers 2. Language system
translator 4. Image editor, etc
FO

3. System utilities 3. Student system


3. Linker 4. Banking system,
4, Loader etc

Figure 1. 22: Types of computer software

16
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 16 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Computer systems software There are three main categories of system
System software provides basic management software: operating systems,
functionality to the computer. It controls device drivers and system utilities.
the internal computer operations. The
Operating System (OS)
purpose of system software is to provide
basic functionality to computer and Operating system acts as intermediate
control computer hardware. It also enables between the user of a computer and the
application software to run when installed computer hardware. Examples of OS
are includes Windows, Mac, Android,

LY
on top of it. Generally, there are a number
Linux and Unix. They are classified
of main characteristics or features of the
into different types depending on their
systems software:
capability of processing i.e. single user,

N
(a) They are more closely related to
multi user, multitasking, multiprocessing,
system or hardware components
real time and embedded. The functions

O
rather than users.
of these operating systems are process
(b) They are much faster in performance
management, memory management,
or processing.
(c) They are usually written or
developed in a low-level language
SE
file management, device management,
protection and security, and user interface
or command interpreter.
so that they can interact with
U
machines at the maximum possible
Device driver
speed.
A device driver is a software that acts as
(d) They do not interact much with a translator between the hardware and
E

the users compared to application the system that uses the devices. In other
software. They usually work in the words, it intermediates between the device
N

background. and the operating system in order to use


(e) They are comparatively difficult the device. Each device has its own device
LI

to manipulate as it is complex to driver. Nowadays, the system comes


understand or design them. preloaded with some commonly used
N

device drivers like the device driver for


System software can be grouped into mouse, webcam and keyboard. The device
O

two main categories, namely system drivers of these devices are preinstalled
management software and system on the computer such that the operating
R

development software. can automatically detect the device when


it is connected to the computer, thus, they
FO

System management software are called plug and play devices. These
System management software refers to devices sometimes get updates to function
systems software that are used to control better, thus a need to constantly ensure
and stabilise the computer operations. that they are updated.

17
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 17 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
System utilities Programming languages
Computer Science

System utilities are required for the Programming languages consist of a set
maintenance of computer. They are used of vocabulary and grammatical rules to
for supporting and enhancing programs express the computations and tasks that the
and data in the computer. Some utilities computer has to perform. Programming
may come embedded with OS and others languages are used to write a program
may be added later on. Some examples which controls the behaviour of computer,
codifies the algorithms precisely or enables
of system utilities are:
the human-computer interface. Each

LY
(a) Antivirus utility to scan computer
language has a unique set of keywords
for viruses;
and a special syntax for organizing
(b) Cryptographic utility to encrypt and program instructions. The programming

N
decrypt files; language should be understood, both by
(c) Disk compression utility to compress the programmer and the computer. A

O
contents of a disk in order to increase computer understands the languages of
capacity of a disk; 0s and 1s while the programmer is more
comfortable with English like language.
(d) Disk partitioning to divide a single
drive into multiple logical drives;
(e) Disk cleaners to find files that have
SE
Programming language usually refers to
high-level language like C++, Java, and
COBOL.
not been used for long time;
U
(f) Backup utility to make a copy of all Translator software
information stored on the disk. It also Translator software is used to convert a
restores the backed-up contents in
E

program written in high level language


case of disk failure; and assembly language to a form that
N

(g) System profiling utility provides the computer can understand. Translator
detailed information about the software converts a program written
LI

software installed on the computer in assembly language and high-level


and hardware attached to it; and language to a machine language. The
N

(h) Network managers to check the translated program is called the object
computer network and to log events. code.
O

System development software Linkers


A linker is a program that links object
R

System development software are


systems software that are used in modules or files to a single executable
FO

developing applications for some program. A source code of a program


specified tasks. The main categories is often very large consisting of several
include programming languages, hundred or more lines. The source
language translators, linkers and loaders. code may also include reference to

18
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 18 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
libraries. All these independent modules documenting and analysing research,
may not be stored in a single object managing operations, providing services,
file. The code is broken down into writing notes and reports, playing
many independent modules for easy computer games and producing videos.
debugging and maintenance. Before These applications fundamentally lie
execution of the program, these modules above the system software. They have
and the required libraries are linked specific functions or tasks intended to
together using the linkers software. The perform, and they are often developed
compiled and linked programs are called based on the user’s requirements. The

LY
the executable codes. essential feature of application software
is that the user interacts directly with
Loaders it. Generally, there are a number of

N
A loader software is used to load and main characteristics or features of the
relocate the executable program in the application software such as:

O
main memory. Software has to be loaded (a) They are mainly developed or
into the main memory during execution. programmed to complete specific
The loader assigns storage space to tasks on computers such as image
the program in the main memory for
execution.
SE editing, word processing, gaming,
etc.
(b) They are mostly big in size and hence
U
Activity 1.2 take up more storage or space on the
machines/systems.
Cleaning unnecessary files or (c) They are typically written or
programs
E

developed in high-level languages.


Use your computer and disk clean- (d) They interact more with users,
N

up system utility software to helping them to use the software


describe step by step, how to clean easily.
LI

unnecessary files or programs that (e) They are somewhat easier to design
reside in your computer. and develop than system software.
N
O

There are two main types of application


Applications software
software, namely general purpose
Application software is a software that application software and specific purpose
performs specific tasks for an end user. It
R

application software.
is commonly known as end-user program
FO

or productivity program. Application General purpose application software


software are programs that support the General purpose application software is
users in carrying out different tasks such sometimes referred to as off-the-shelf
as calculations, designing graphics, applications, and they are designed as

19
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 19 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
fully-featured packages. General purpose Application software perform task by
Computer Science

application software are available in interacting with users of a system who


standalone versions or they are bundled use computers which are installed with
together to make up application suites. operating systems. The relationship
Some examples include MS Office, between a user, application software,
ApacheOpenOffice, iWork, CorelDRAW system software and hardware is shown
Suite, and Adobe Creative Suite. These in Figure 1.23.
are bundles of applications with different
functionalities. They complement each User 1 User 2 User ‘x’

LY
other to make complete productive
packages for office, school, and home.

N
Specific purpose application software
(Custom application software) System Application

O
softwares softwares
The specific purpose application Software
software are the software designed and
used for a specific set of tasks. They are Operating System
developed to perform specific task only.
The specific purpose software or custom
SE
application software range from simple Hardware CPU RAM I/O DEVICE
U
accounting system to complex banking
system. Typical examples include payroll
system, students system, billing system Figure 1.23: Relationship between computer
and banking system. Many organisations
E

system software, application


use them to manage their operations and software, hardware, and user
N

contribute to decision making.


Exercise 1.3
LI

Activity 1.3
Answer the following questions.
N

Comparing general purpose software


1. Define a computer software.
and specific purpose software
2. Briefly describe two main types of
O

Use internet or library search to:


computer software.
1. Identify any general-purpose
application software and custom 3. What is system software? Give two
R

application software. examples and the use of each of


them.
FO

2. Analyse the general-purpose


application software and custom 4. Describe the categories of systems
application software by comparing software, and give one example for
their acquisition and usage. each category.

20
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 20 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
and storage of data in tabular form.
5. What is the purpose of device It also provides flexible presentation
driver on computer compared to of data and capability to interact with
the loader? databases, populate fields and help
6. List any five system utilities and in automation of data creation and
the purpose for each. modification. Examples include MS
7. Name any three operating systems Excel and Google spreadsheet.
and the main area of use for each. (c) Database Software: this application
software is used to create and

LY
manage a database. This application
Computer applications is also referred to as the Database
Computer applications have become Management System (DBMS).

N
our everyday companions. As it was The DBMS is essential for data
indicated earlier examples of computer organisation. Examples of DBMS

O
applications include Microsoft Office include Clipper, dBase, FileMaker,
products to Google docs, Gmail, Twitter, FoxPro, MS Access, MySQL, SQL
Facebook, Instagram, and web browsers. Server and Oracle.
People use various computer applications
to meet their various personal, academic,
SE
(d) Simulation application software
This is developed by modelling
business, or professional purposes. During
a true phenomenon with a set of
U
the ancient generation of computers,
people had just one application software mathematical prescriptions. Usually,
installed on a specific machine using CD it is designed as an animated model
ROMs or floppy disks. But, today, there that replicates the operation of an
E

are multiple computer applications that existing/proposed system. They


N

are intended to suit people’s purposes. are helpful in gaming, military


Here are some typical groups of computer engineering, training, and industries
LI

applications: such as power plants, and space


(a) Word Processors: word processors shuttle navigation contexts in which
N

are applications for documentation. improper operation or learning


They help store, format, and print can lead to disastrous outcomes.
O

documents in different ways. Therefore, simulation application


Examples include Apple iWork software supports the analysis
Pages, MS Word, Google Docs, and observation of an operation
R

Corel WordPerfect, and Open office through simulation (i.e., without


FO

writer. physically doing it or involving


(b) Spreadsheet software: a spreadsheet physical movement. Simulation for
is a computer application for training pilots is a good example of
computation, organization, analysis application software.

21
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 21 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
(e) Multimedia Software: this is the
Computer Science

Activity 1.4
software that can play, create or
record images, audio or video files. Searching for computer applications
They are used for video editing,
animation, graphics, and image Use library or internet search to:
editing. Multimedia software 1. Identify and describe four computer
examples are Adobe Photoshop, applications that can be used to
Inkscape, Media Monkey, Picasa, increase the efficiency in teaching
VLC Media Player, Windows Media and learning.

LY
Player, iSpring Suite, and Windows 2. Evaluate, which application can be
Movie Maker. adopted most by your school and
provide reasons for your opinions?

N
(f) Education and Reference Software
These types of software are

O
specifically designed to facilitate Advanced features of word
learning on a particular subject processing application software
or programme. There are various
kinds of tutorial software that fall
under this category. These are also
SE
In understanding the advanced features
of word processing application , the
Microsoft Word 2016 is used. Word
termed as educational software. 2016 is among the word processing
U
Delta Drawing, Gcompris, Jumpstart applications that allow you to create
titles, KidPix, MindPlay, Tux Paint, various documents including flyers,
EndNote, Mendeley, and RefWorks letters, business cards, and resumes. When
E

are some examples. working with Microsoft Word 2016, you


(g) Web Browsers: these applications are can use its most essential features, such
N

used to surf the internet. They help as the Ribbon, Quick Access Toolbar,
and Backstage view. For the first time
LI

the user in locating and retrieving


data across the web. Examples of you open Word 2016, the Start Screen
will appear where you can now create a
N

web browsers are Internet Explorer,


Microsoft Edge, Google Chrome, new document, pick a template, and or
O

Mozilla Firefox, Opera, Safari and access your recently edited documents.
From the Start Screen, locate and select
UC Browser.
Blank document to access the Microsoft
(h) Search engines: these are software
R

Word (MS Word) interface as shown in


designed to carry out web searches Figure 1.24.
FO

for a particular information specified


in a web search query. Examples of Step 1: Click Windows Logo (Start)
search engines are Google, Yahoo button at the bottom left corner
and Bing. of a computer screen as shown

22
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 22 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
in the Figure 1.24, in this case Windows 10 Pro was used.

Figure 1. 24: Windows start button

Step 2: On the list of applications in the dialog box, scroll or search and click
‘Microsoft Office 2016’ folder shown in Figure 1.25 to expand it.

LY
N
O
SE
U

Figure 1.25: List of applications


E

Step 3: After expanding the folder, click ‘Word 2016’, the Microsoft word 2016
N

window will appear as shown in Figure 1.26.


LI
N
O
R
FO

Figure 1.26: Opening a new document in Word 2016

23
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 23 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 4: Click the template written ‘Blank document’ as shown in Figure 1.26 to open
Computer Science

and see its features, Figure 1.27 will appear showing the main components
of Word 2016.

LY
N
O
SE
U
E

Figure 1.27: Main components in Word 2016


N

Inserting the table of contents in the reflect the heading levels, names, and
LI

report page numbers. Once you have finished


Word places the Table of Contents (ToC) assigning the heading levels (heading
styles) to your report, follow these steps
N

field at the insertion pointer’s location


as shown in Figure 1.28, although you to create a table of contents:
O

probably prefer to have the thing on its


page. A blank page near the start of your Steps to create a separate page for the
document is ideal for a ToC. In creating TOC
R

a Table of Contents for your report, Step 1: Open your document that
you have to assign heading levels to contains your report and click
FO

your report titles using heading styles the Home tab .


(Heading 1 for main heads, Heading 2 Step 2: Format all the headings or titles
for subheads, and Heading 3 for lower- that you need to appear in a
level heads and titles). The ToC will ToC by highlighting the first

24
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 24 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
heading and select Heading 1 style from the style group in the home tab.
For the second heading, select Heading 2 and so on, as shown in Figure
1.28.

LY
N
O
Figure 1. 28: Formatting the headings

Step 3: Move the cursor to the blank page and click the mouse to place the insertion
SE
pointer on it as shown in Figure 1.29. The TOC will be inserted at that
point.
U
E
N
LI
N

Figure 1. 29: Inserting the table of contents


O

Step 4: Click the References tab as shown in Figure 1.30


Step 5: In the ‘Table of Contents’ group, click the ‘Table of Contents’ button. The
ToC menu will appear as shown in Figure 1.30.
R
FO

25
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 25 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
N
O
SE
U
Figure 1. 30: Choosing a format of table of contents

Step 6: Choose a format among those that appear as in Figure 1.30.


The TOC is created and placed in your document with page numbers. The
E

final output will appear as shown in Figure 1.31.


N
LI
N
O
R
FO

Figure 1. 31: An example of a completed table of contents

26
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 26 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Sometimes you may wish to edit or paragraph format postulates the proper
format the title of the table of contents outline level.
that comes with the table. Do not format
as a heading 1, except if you want it to be The TOC field cannot be edited. Hence,
part of the TOC, but it is not standard for it will not reflect extra edits in your
the table to contain its title. Note that, if document. Thus, to update the field, (1)
the steps you have used do not produce click once to select it. (2) Click on the
the required output of TOC, it implies References tab, (3) click the Update Table
that your document does not use the button. Use the Update Table of Contents

LY
heading styles. If your document uses dialog box to choose what to update. (4)
specific heading styles, ensure that the Click OK as shown in Figure 1.32.

N
O
SE
U
E
N
LI
N
O

Figure 1.32: Updating the table of content

Mail merge
R

Mail Merge is a suitable tool that allows anyone to create multiple letters, envelopes,
labels, name tags, and others using the information stored in a list, spreadsheet, or
FO

database. When creating a Mail Merge, you will need a Word document (you can
create a new one or start with an existing one) and a recipient list (basically an MS
Excel workbook for this example).

27
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 27 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Steps to create Mail Merge
Computer Science

In this example, it is intended to create a document, in this case, a document ‘Letter’


will be selected in the ‘step-by-step’ procedure .
Step 1: Create a new Word document or open an existing one.
Step 2: From the ‘Mailings’ tab, in the ‘Start mail merge’ group, open the ‘Start
Mail Merge’ command and click ‘Step-by-Step Mail Merge Wizard’ as
shown in Figure 1.33.

LY
N
O
SE
U
E

Figure 1.33: Opening a Mail Merge Wizard


N

The Mail Merge pane will appear,


LI

guiding you through the six main steps


of merging your emails. The example
N

in Figure 1.33 shows how to generate


a form letter and merge it with a list of
O

recipients.

Step 3: Select ‘Letters’, then click


R

‘Next: Starting document’ as


shown in Figure 1.34 to move
FO

to Step 4 as shown in Figure


1.34.

Figure 1.34: Mail Merge Wizard-selecting


document type
28
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 28 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Step 4: Choose ‘Use the current a new address list within the
document’, then click ‘Next: Mail Merge Wizard.
Select recipients’ as shown in (a) Choose ‘Use an existing’ list, then
Figure 1.35 to move to Step 5. click ‘Browse’ to select the file as
shown in Figure 1.36.

LY
N
O
SE
U
E
N
LI
N

Figure 1.35: Mail merge wizard-Selecting


recipient
O

Step 5: Next, you will now need the


address list so that Word can
R

Figure 1.36: Mail merge wizard-Selecting


automatically place every the file
address into the document.
FO

The list can be in an Excel (b) Locate your file, then click Open
workbook, or you can type as in Figure 1.37.

29
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 29 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
N
O
SE
Figure 1.37: Mail merge wizard-Selecting mailing addresses worksheet

(c) In the Mail Merge Recipients dialog box, you can check or uncheck each box
U
to control which recipients are included in the merge. By default, all recipients
should be selected. When you’re done, click OK as shown in Figure 1.38.
E
N
LI
N
O
R
FO

Figure 1.38: Mail merge wizard-selecting recipients

30
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 30 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
(d) Click ‘Next: Write your letter’ letter will be the same; only the
as shown in Figure 1.39 (g) recipient data (such as the name
shows to move to Step 6. If and address) will be different.
you do not have an existing You will need to add placeholders
address list, you can click the for the recipient data so that Mail
‘Type a new list’ button, click Merge knows precisely where to
Create, and type your address add the data.
list manually.
To insert the recipient data:

LY
(a) Place the insertion point in the
document where you want the
information to appear.

N
(b) Select one of the placeholder options.
In this case, you have to select the

O
Address block as it is indicated in
Figure 1.40.

SE
U
E
N
LI

Figure 1.40: Mail merge wizard-Selecting the


address block
N

(c) Based on your selection, a dialog box


Figure 1.39: Mail merge wizard-Writing may appear with various customisation
O

your letter options. Select the desired options,


Step 6: Hence, now you are ready to then click OK. A placeholder will
appear in your document (for example,
R

write your letter. When it


is printed, each copy of the «AddressBlock») as in Figure 1.41.
FO

31
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 31 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
N
O
Figure 1.41: Mail merge wizard- Showing placeholder

SE
(d) You may add any other placeholders you need. See an example of a Greeting
line (2) placeholder just above the body of the letter as shown in Figure 1.41.
You can add by clicking the link ‘Greeting Line’ in (1) then you proceed to
U
steps 4 of 6 in (3)
E
N
LI
N
O
R

Figure 1.42: Mail merge wizard- adding placeholders


FO

(e) Once you are done, click Next: Preview your letters to move to Step 5 of 6
as shown in Figure 1.43.

32
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 32 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE

LY
N
O
Figure 1.44: Mail merge wizard-
Previewing letters-II

Figure 1.43: Mail merge wizard-Previewing


letters-I
SE
Step 7: Click Print as shown in Figure
1.45 to print the letters.
U
Note: Sometimes, the letters only need
to add an Address block and
Greeting line. However, you
E

can also add more placeholders


(such as recipients’ names or
N

addresses) in the body of the letter


to personalise it even further.
LI

Step 6: Make sure you preview the


N

letters to ensure that the


information from the recipient
O

list appears correctly in the


letter. You can use the left (1)
R

and right (2) scroll arrows


as shown in Figure 1.44 (l)
FO

to view each version of the


document before proceeding
with the next steps 5 of 6 in (3). Figure 1.45: Mail merge wizard- Printing
letters

33
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 33 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Next, A dialog box will


appear. Decide if you want to
print all the letters, the current
document (record), or only a
select group, then click OK.
In our example, you will print
all the letters as shown in
Figure 1.46. Figure 1.46: Mail merge wizard-Printing all letters

LY
Consequently, the Print dialog box will appear. Now, choose a printer of your
preference and adjust the print settings (if needed), then click OK as shown in

N
Figure 1.47. The letters will be printed.

O
SE
U
E
N
LI
N
O
R

Figure 1.47: Mail merge wizard- Choosing a printer


FO

Inserting tables in the report


A table is created using columns and rows. Any table contains cells which are the
points where rows and columns meet as shown in Figure 1.48. Tables are commonly
used to organise and present data, but they can also be used for several other purposes.

34
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 34 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
For example, tables can be used to arrange numbers and generate unique page
layouts. You can create a table in MS Word 2016 document using one of MS Word’s
table creation commands to create a custom row and column grid by following the
steps in the next activity.

Activity 1.5

Creating a table
Follow the provided steps to create a table:

LY
Step 1: Place the insertion point where you want the table to appear (4) as
shown in Figure 1.48.
Step 2: Click the Insert tab on the Ribbon (1), as shown in Figure 1.48.

N
Step 3: Click on Table (2) as shown in Figure 1.48.

O
Step 4 : Highlight the number of columns and rows you would like (3), as
shown in Figure 1.48.
Step 5: Place the insertion point in any cell to enter text, then begin typing. An
SE
example of a filled table is shown in Table 1.2.
U
E
N
LI
N

Figure 1. 48: Creating a table in MS word


O

Table 1. 2: An example of a completed Table in MS word


R

SN Name Subject Marks


FO

1. Kajumulo Balinge Computer science 100


2. Atusakye Mbilimbi Physics 98
3. Palugendo Msasati Computer science 95

35
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 35 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Activity 1.6 Exercise 1.4


Using a mail merge
Answer the following questions.
Use the following steps to create a 1. What do you understand about
mail merge: ‘placeholder ’ when you are using
Step 1: Create a blank word document mail merge in word 2016.
and insert a table containing 2. Why are other options like ‘type a
five (5) rows and four (4) new list’ and ‘select from outlook

LY
columns. Fill with a subject contacts’ not used when using mail
result indicating No, Fname, merge, rather ‘use an existing list’
Lname and Marks. is used? Explain briefly.

N
Step 2: Prepare a very brief letter 3. Describe two essential components
and use a spreadsheet to of every mail merge.

O
create the recipients list with
4. You can not use mail merge to create
the following titles: Last
personalized messages for custom
Name, First Name, Address,
Region, and Country.
Step 3: Open the Mail Merge Wizard
SE
catalogs, Newsletters, marketing
emails, and form letters. Respond
if it is true or false and explain why.
to merge the letter with the
U
recipients list.
Step 4: Make sure you insert an Advanced features of spreadsheet
address block at the top applications
E

of the document. Choose The use of spreadsheets is continuously


the second format: Joshua becoming popular. Individuals,
N

Randall Jr. institutions, and organisations use a


Step 5: Just above the body of the
LI

spreadsheet to do calculations (much like


letter, insert a Greeting a calculator) and manipulate text (like a
Line. word processor). Its strength comes from
N

Step 6: Check your letters to make its grid structure, which allows the user
sure they are formatted to perform several related calculations.
O

correctly. So, while you can do simple summations


Step 7: Complete the merge using a calculator or on paper, you can
R

assignment and do a preview do those summations many times in a


of the letters. You may print spreadsheet. Today, there are several
FO

a sample letter if you wish. advanced features such as ‘data’ used


for data entry and manipulation. Other

36
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 36 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
features and function used in Excel 2016 Data entry and manipulation
includes cell referencing, IF functions, In entering data in a spreadsheet as seen
data sorting, macros, scenarios and goal in Figure 1.49, consider the following
seek. These advanced features allow
tips:
deeper data analysis, enhanced visuals,
and more advanced business logic. It is (a) Make sure there are columns of
the primary tool many institutions and data consisting data types such as
firms use today to generate reports and numbers, dates, or text.
other key insights that support future (b) Keep the information used (e.g.,

LY
planning objectives. There are a number names, numbers, and Formats (date))
of spreadsheet software in the market as
in their respective column 1, 2, 3, 4,
it was presented earlier in this section. In
5, and 6 depending on the data type

N
this case, Microsoft Excel 2016 is used
to provide examples. to be entered.

O
SE
U
E
N
LI

Figure 1.49: Data entry in a spreadsheet


N

(c) Enter all data in one table or worksheet to enable a statistical program to work
O

appropriately than multiple small tables requiring human intervention.


(d) Save your work in different locations for the purpose of having a backup.
R

(e) MS Excel have limitations of up to the maximum of 1,048,576 rows, for latest
versions of Excel 2016 and above.
FO

(f) Audit your work or data before running further operations.


Numerous tools are simple but very supportive when manipulating data in a
spreadsheet. Such tools include the following;

37
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 37 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Freezing panes
Computer Science

This tool allows you to freeze rows and columns in a spreadsheet. If you want to
freeze panes, make sure you locate the cursor before running this tool. All cells on
top and to the left of the cursor will be frozen, as shown in Figures 1.50 and 1.51.
Practically, you may follow these steps.
(a) Select View > Freeze Panes > Freeze First Column.
The faint line that appears between Columns A and B shows that the first column
is frozen.

LY
N
O
SE
U
Figure 1.50: Freeze Panes
E
N
LI
N
O
R
FO

Figure 1.51: Freeze pane options in the ‘View’ tab

38
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 38 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
To freeze the first two columns: Spreadsheet functions
a) Select the third column A function is a formula that conducts
b) Select View > Freeze calculations using specific values in a
Panes > Freeze Panes predetermined order. Spreadsheet and
To freeze columns and rows MS Excel in this case contains several
a) Select the cell below the rows and useful functions for quickly calculating
to the right of the columns, you the sum, average, count, maximum value,
want to keep visible when you and minimum value for a set of cells. To
scroll. run such functions, you must know the

LY
b) Select View > Freeze different sections of a function and how
Panes > Freeze Panes. to build arguments to calculate values and
To unfreeze rows or columns: cell references. The following functions

N
a) On the View tab > Freeze are beneficial for use in manipulating data,
Panes > Unfreeze Panes. as shown in Table 1.3.

O
Table 1. 3: Spreadsheet/MS Excel functions
= Average(A1:A10) Calculates the average of a set of data
= Count(A1:A10) SE
Counts the number of cells in a range that contains
numbers
= CountA(A1:A10) Counts the number of cells in a range that are
U
not empty
= Countif(A1:A10,”>10”) Counts the number of cells that meet a specific
condition
E

= Large(A1:A10,n) Returns the nth largest value in a data set


= Max(A1:A10) Finds the maximum value in a set of data
N

= Median(A1:A10) Finds the median value in a set of data


= Min(A1:A10) Finds the minimum value in a set of data
LI

= Mround(A1,5) Returns a number rounded to the desired multiple


N

= Product(A1:A10) Multiplies a range of data


= Rand() Returns a random number between 0 and 1
O

= Randbetween(bottom,top) Returns a random number between the numbers


specified
= Round(A1,2) Rounds a selected cell to a specified number of
R

digits
= Small(A1:A10,n) Returns the nth smallest value in a data set
FO

= Sum(A1:A10) Sums a range of data


=Sumproduct(A1:A10,B1:B10) Sums the Products of pairs of data
= Sumif(A1:A10,”>10”) Sums a set of data that meet selected criteria

39
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 39 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Cell referencing the formula =A1+B1 from row 1 to row
Computer Science

Cell references are of two types, namely 2 in the same column, the formula will
relative and absolute. All these behave become =A2+B2.
differently when copied and filled into
other cells. Relative references change Steps to calculate Relative references are
when a formula is copied to another as follows. In our case, the example will
cell, while absolute references remain focus on the Relative references that
constant no matter where they are will give you a foundation to understand
copied. By default, all cell references the calculation of absolute references.

LY
are relative references. Once copied Steps are as follows:
across multiple cells, they will change Step 1: Select the cell containing the
based on the relative position of rows formula. From our example,

N
and columns. For example, if you copy select cell D2 as in Figure 1.52.

O
SE
U
E

Figure 1. 52: Cell referencing.


N

Step 2: Enter the formula to calculate the desired value. In our case, type =B2*C2
as shown in Figure 1.53
LI
N
O
R
FO

Figure 1.53: Cell referencing

40
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 40 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Step 3: Press Enter on your keyboard, and then the formula will be calculated and
the result will be displayed in the cell as shown in Figure 1.54.
Step 4: Find the fill handle in the lower-right corner of the desired cell. In our
case, you will locate the fill handle for cell D2 as in Figure 1.54.

LY
N
O
SE
Figure 1.54: Calculating absolute reference

Step 5: Click, hold, and drag the fill handle over the cells you wish to fill. In our
U
case, you will select cells D3:D6 as in Figure 1.55.
E
N
LI
N
O
R

Figure 1.55: Cell referencing


FO

Step 6: Release the mouse to allow the copied formula to the selected cells with
relative references, and the values will be calculated in each cell as shown
in Figure 1.56.

41
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 41 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
N
Figure 1.56: Cell referencing

O
IF function
Use this function to return one value if a condition is true and another value if it is
false. You have to start with an equals sign (=). Suppose function begins with =IF(…,
SE
followed by a statement, then by statement2). For example, you want to know if the
value in cell G2 is greater than or equal to 5 and otherwise.. Here you have to use
some mathematical operators ( > for greater than and = for equals ) to write the
U
condition, for example: =IF(G2>=5). When combined with a statement, you can
write =IF(G2>=5, “Not Sponsored”, “Sponsored”). Once you have written that
formula,Press Enter key, the words Sponsored and Not Sponsored should appear
E

in the cell as shown in Figure 1.57 and Figure 1.58.


N
LI
N
O
R
FO

Figure 1.57: IF function

42
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 42 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
You can now drag the fill handle down to add the formula to the other cells in
column H:

LY
N
O
Figure 1.58: IF final function output

Data sorting SE
Sorting data lets you change how you want to view it. For example, you can view
the newest or oldest data at the top when you have a dataset with a date column.
You may also decide to sort the data based on the values such as product names or
U
grouped brands.

To sort a sheet: Now, sort a T-shirt order form alphabetically by Second Name
E

(column C) in the examples indicated in Figures 1.59 to 1.61.


N

Step 1: Select a cell in the column you want to sort by; for this case, you have to
select cell C2, as shown in Figure 1.59.
LI
N
O
R
FO

Figure 1.59: Data sorting

43
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 43 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 2: Choose the Data tab on the Ribbon, then from Sort & Filter group click
Computer Science

the A-Z command to sort A to Z or the Z-A command to sort Z to A as


seen in Figure 1.60. In this example, you are going to sort from A to Z.

LY
N
Figure 1.60: Data sorting

O
The output of the sorted column of a worksheet, sorted by the second name is seen
as in Figure 1.61.
SE
U
E
N
LI

Figure 1.61: Data sorted by second name


N

Data sorting is of different types depending on the purpose. Using similar steps,
you may decide to sort a range of data or customise your sort. To do so, you have to
O

follow the following steps:

Sorting a range of data


R

Using the datasheet in Figure 1.62, you must select a separate table in our T-shirt
order form to sort the number of shirts ordered in each grade as indicated in Figures
FO

1.62 to 1.66.
Step 1: Select the cell range you want to sort. In our example, you have to select
cell range D2:F6 as in Figure 1.62.

44
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 44 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE

Figure 1.62: Sorting a range of data-Selection-I

LY
Step 2: After selecting the range (1), choose the Data tab (2) on the Ribbon as
shown in Figure 1.63, then click the Sort command (3).

N
O
SE
U
E
N

Figure 1.63: Sorting a range of data-Selection-II


LI

Step 3: Once the Sort dialog box appears, select the column you want to sort by.
In our case, you have to sort the data by the number of T-shirt orders thus,
N

select Orders as in Figure 1.64.


O
R
FO

Figure 1.64: Sorting a range of data-selecting column

45
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 45 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 4: Decide your sorting order (either ascending or descending); in our case,
Computer Science

sort from the Largest to the Smallest as shown in Figure 1.65.

LY
N
O
Figure 1.65: Sorting a range of data-sorting order

SE
Consequently, the cell range will be sorted by the selected column. In this example,
the Orders column is sorted from the highest to the lowest as shown in Figure 1.66.
Please, note that the other content in the worksheet was not affected by the sort.
U
E
N
LI
N
O

Figure 1.66: Data sorted from highest to lowest


R

Activity 1.7
FO

Sorting a range of data


Use your environment to collect or create any data and demonstrate the steps of
sorting that data in a range.

46
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 46 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Goal seeks down options, click Goal Seek
Goal Seek function as What-if-Analysis (keyboard shortcut is Alt, A, W, G),
tool in Ms Excel, is a way of solving the (c) When the dialog box appears (as
desired output by changing a guess that shown below), make “Set cell”
drives it. The function applies a ‘trial equal to the revenue cell (E10),
and error approach’ to back-solving (d) Set “To value” equal to the output
the problem by inserting estimates till you want to achieve (type the
it reaches the answer. Follow the steps number in),

LY
below to use the Goal Seek function in
(e) Set “By changing cell” equal to the
MS Excel.
assumption you want to solve for
(a) Place your cursor on the cell that
(# of units, or cell E4),

N
has an output you need to change
(e.g., revenue), (f) Press OK.

O
(b) Hover to the Data ribbon, choose The output from the analysis will be
What-if-analysis, then in drop shown in Figure 1.67.

SE
U
E
N
LI
N

Figure 1.67: Goal seek


O

Scenarios
The spreadsheet lets you create and save sets of input values that yield different
results as scenarios. Use the Scenario Manager in the What-If Analysis tab, found
R

in the drop-down menu on the Data tab of the Ribbon, to create scenarios. A scenario
FO

comprises of a group of input values in a worksheet where you assign a name such
as Best Case, Worst Case, and Most Likely Case. When creating a scenario for your
worksheet, you have to create a spreadsheet that uses some cells that can change in
each scenario (appropriately enough, called changing cells).

47
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 47 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Steps to create scenarios using Scenario
Computer Science

with the Prevent Changes


Manager: and Hide checkboxes. Almost
Step 1: Select the cells whose values now, you are in a position to
vary in each of your scenarios. specify the changing values for
Step 2: Choose non-adjacent cells in the new scenario.
the worksheet by holding down Step 7: Press OK in the Add Scenario
the Ctrl key as you click them. dialog box.
Step 3: Click the What-If Analysis Step 8: Cross-check the values in each

LY
command-tab on the Ribbon’s changing cell’s text box and
Data tab, and then click modify the values if needed.
Scenario Manager on its Step 9: Press Add tab in the Scenario
drop-down menu (you can also

N
Values dialog box.
use the shortcut: Alt+A,W,S) Step 10: Repeat Steps d to g to add all

O
Step 4: Press Add in the Scenario other scenarios of your choice
Manager dialog box. that you plan to create.
Step 5: Now, Type the descriptive Step 11: Press OK in the Add Values
name for your new scenario in
the Scenario Name text box.
SE dialog box. Next, press the
Close button in the Scenario
Step 6: Next, Add the Scenario dialog Manager dialog box and you
U
box (in the Protection section), will get the scenario summary
and select the type of scenario as indicated in Figure 1.68.
protection you need (if any)
E
N
LI
N
O
R
FO

Figure 1.68: Scenario Summary

48
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 48 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Data visualisation You can choose from different chart
Data analysis is the process of cleaning, types available in Excel and visualise
manipulating, and interpreting data your data based on the type of data you
to identify usable information, draw have. You can always change the chart
conclusions, and make an informed type at any time. The following are the
decision. Data analysis is vital in today’s
main chart types available in Ms Excel:
business environment since it helps
business to make more scientific decisions Bar Chart, Column Chart, Line Chart,
and run more efficiently. On the other Pie Chart, Doughnut Chart, Area Chart,
XY (Scatter) Chart, Bubble Chart, Stock

LY
hand, data visualisation represents data
to absorb information quickly, improve Chart, Surface Chart, Radar Chart, and
insights, and make quicker decisions. In Combo Charts.
other words, data visualisation is changing

N
data into a “visual representation” such To create charts in Excel, you need
as a graph or map, making it easier to

O
first to prepare your data. Once done,
spot trends and patterns. MS excel has a
number of data analysis and visualisation highlight the data you want to visualise
as covered in this section: as shown in Figure 1.69 and click Insert

Types of charts and their use


SE
tab >> choose your chart type under
the chart area. You can select your
MS Excel has a variety of charts to choose preference chart based on the available
U
from depending on the user’s needs. data and purpose.
E
N
LI
N
O
R
FO

Figure 1.69: Bar chart creation


In MS Excel, you can change your chart depending on your data type.

49
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 49 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Pivot chart
Computer Science

A pivot chart is a visual depiction of the MS Excel pivot table.


Inserting pivot table is as follows:
(a) Pick any cell in the data and click Pivot Table on the Insert tab of the Ribbon
as shown in Figure 1.70.

LY
N
O
SE
Figure 1.70: Pivot table
U
MS Excel will show Create Pivot Table window. You will find that the data range
has already been filled in, as shown in Figure 1.70. The default position for a new
pivot table is New Worksheet.
E

Inserting Pivot Chart: to insert a pivot chart in Ms Excel, all you need is a data
N

sheet (e.g., simple sales data above). Then run the following steps. You can use the
same steps in all versions of MS Excel (2007, 2010, 2013, 2016, 2019, and 365).
LI

Here are the steps to follow:


N

Step 1: Select any of the cells in your datasheet and go to Insert Tab → Charts →
Pivot Chart as shown in Figure 1.71.
O
R
FO

Figure 1.71: Inserting pivot chart

50
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 50 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Step 2: After executing the above step, the pop-up window will automatically
pick the entire data range. You can choose New Worksheet or Existing
Worksheet as in Figure 1.72.
Step 3: Click OK

LY
N
O
SE
U
Figure 1.72:Pivot chart pop-up window

Step 4: An empty pivot chart and associated pivot table will be created as shown
in Figure 1.73. You can add the required fields to generate the report and
E

chart.
N
LI
N
O
R
FO

Figure 1.73:Pivot chart-report generation

51
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 51 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Databases are widely used to boost
Computer Science

Activity 1.8
company performance and decision
making. Presently, businesses have
Creating a Pivot chart access to more data than ever before
Using the spreadsheet program, because of huge data collection from
demonstrate step by step how to create various systems. Enterprises can now
a pivot chart. use databases to evaluate vast amounts
of data from numerous systems, beyond
simple data storage and transactions.

LY
Exercise 1.5 Organisations may now have control of
the data they acquire using databases
Answer the following questions. and other computing and business

N
1. Explain what is missing in the intelligence technologies to function
formula: If (D7>=90, ‘selected”, more effectively. It enables better

O
not selected) which intends to select decision making, and become more
students to study higher levels. agile and scalable.
2. Cell referencing uses the signs
‘:’ and ‘+’ at the same time in a
formula. Analyse the truth of this
SE
Sometimes, database software is called a
“database management system” (DBMS)
statement. because the DBMS is used to control
U
3. Present the importance and use of the database. Examples of database
‘Goal seeks’ and ‘scenarios’ tools software are MS Access, MySQL, Oracle,
by relating with every day life. Use PostgreSQL, and SQL Server.
E

the context of data analysis.


Advanced features of Access 2016
N

Database application software In this example we use Access 2016. A


database in Access has four objects:
LI

A database is a logically organised


collection of structured data kept Tables- store your data in your database;
N

electronically in a computer system. Forms- allow you to collect and view


Database software is used to build, edit, data stored in your tables;
O

and maintain database files and records. Queries-ask questions about information
It allows an easier way of creating files stored in your tables; and
and records, data entry, editing, updating,
R

Reports- allow you to print data based


and reporting. The database software also
on queries/tables that you have created.
FO

handles data storage, backup and reporting,


multi-access control, and security. Robust
database security is essential today, as data Access 2016 allows you to manage your
information in a single database file.
theft is becoming more frequent.

52
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 52 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
These listed objects allow you to enter, edit, analyse, store, and compile data. The
following are steps for creating a database:
Step 1: Open Access 2016 from the list of application by searching from the start
button. In this case, Windows 10 start button has been used.
Step 2: Click on ‘Blank desktop database’ as shown in Figure 1.74.

LY
N
O
SE
U
Figure 1.74:Opening blank desktop database

Step 3: Under File Name, type a name for the database as shown in Figure 1.75.
E
N
LI
N
O
R

Figure 1.75: Creating a blank database


FO

Step 4: If you want to change the location of where to store the database, click the
folder icon and select a location.
Step 5: Click Create (Access will open in a new table in Datasheet View).

53
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 53 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Creating a table in database
Computer Science

A table in a database contains data on a particular topic, such as employee information,


products or customers. You must first enter the fields and data types to create a
table. This is usually done in either Datasheet View or Design View. However, it is
recommended setting up the table in Design View. In Access, Field is an element of
the table which contains a specific item of information like “last name” whereas the
Field’s Data Type determines what kind of data the field can store. Key terms in the
MS Access database use are as indicated in Table 1.4.
Table 1.4: Field data types in the MS Access database

LY
Format Use to display
Short Text Alphanumeric data (names, titles) - up to 255 characters
Long Text Large amounts of alphanumeric data: sentences and paragraphs –

N
64,000 characters
Number Numeric data

O
Date/Time Dates and times
Currency Monetary values
AutoNumber
Yes/No
SE
The unique value generated by Access for each new record
Yes and No values and fields that contain only one of the two
values
U
OLE Object Pictures, graphs, or other ActiveX objects from another Windows-
based application
Hyperlink A link address to a document or file on the Internet
Attachment You can attach files such as pictures, documents, spreadsheets, or
E

charts.
N

The attachment field can contain an unlimited number of attachments


per record, up to the storage limit of the size of a database file.
LI

Calculated You can create an expression that uses data from one or more
fields. You can designate different result data types from the
N

expression.
Lookup Displays either a list of values retrieved from a table or query
Wizard or a set of values you specified when you created the field. The
O

Lookup Wizard starts, and you can create a Lookup field.

How to create a table in the design view Step 4: If you are asked to save the table,
R

enter a name and click on OK.


Step 1: Click on the Create tab.
Step 5: Type the field names and select
FO

Step 2: Then, Click on Table. the appropriate data type for each
Step 3: Switch over to Design View on field as shown in Figure 1.76.
the Home tab. Step 6: Continue until all the fields are
added.

54
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 54 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Note: The order in which you enter the field names is the order the fields will
appear in the table.

LY
N
O
SE
Figure 1.76: Database design view
U
How to enter data in a table
Step 1: In Datasheet View, start typing the data in the table by pressing the tab key
to move to the next cell as shown in Figure 1.77.
E

Step 2: After completing the record (row), press Enter.


Step 3: You can also click on the New record icon on the Home tab in the Records
N

group.
LI
N
O
R
FO

Figure 1.77: Datasheet View

55
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 55 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
How to create queries Step 5: Repeat steps 3 and 4 until all
Computer Science

In Access, you may use queries to view, tables are added.


change, and analyse data in various Step 6: Close the Show Table window.
ways. You can also use them as a source The table(s) will now be shown
of records for forms and reports. To in the upper part of the Query
create a Query, follow steps below: Design Screen by boxes that
contain the tables’ fields as seen
Step 1: Click on the Create tab. in Figure 1.78.
Step 2: Click on Query Design in the Step 7: Double-click on the field names

LY
Queries group. in the field list window which
Step 3: Select the table that you would you would like to include in the
query
like to base your query on.

N
Step 8: Then run the query on the
Step 4: Click Add.
design tab in result group

O
SE
U
E

Figure 1.78: Query view


N

How to create forms and sub-forms


LI

A form is a database object used to enter or display data in a database. To create a


form, you should follow these steps as shown in Figure 1.79:
N

Step 1: Open the table or query on which you are basing the form
Step 2: Click on the Create tab (1)
O

Step 3: Click on Form in the Forms group (2)


R
FO

56
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 56 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
A form will be created and will open in Layout View.

LY
N
O
Figure 1.79: Form creation

A sub-form is a form that exists inside


another form. Sub-forms are helpful
SE
Step 3: Tap to the Sub-form/Sub-
report icon to select it; then,
tap on the form in the location
when you need to display data from
U
tables or queries with a one-to-many where you like the sub-form
connection. A Customer form, for to be displayed. This launches
instance, may have a sub-form that the Sub-form wizard.
displays each customer’s orders. The Step 4: You can also base your sub-
E

main form and sub-form are connected. form on a table, query, or


N

So, the sub-form displays only entries existing form. (Here, select Use
related to the main form’s current record. existing Tables and Queries.
LI

Once you have selected the


Steps to add a sub-form to a form in option, click Next.)
N

Access 2016: Step 5: Select the table or query


Step 1: Right-click on the Form in from the drop-down list once
O

the left navigation pane and prompted to choose the fields


select Design View from the to use in the sub-form. Select
contextual menu. each field you want to keep
R

on the sub-form from the left


Step 2: Go to the controls group on
panel; then, click the little
the Design Tab in the ribbon.
FO

> button to move it across


Click the little down-arrow to
to the right pane. You can
expand the list of the available
choose fields from more than
form controls. one table or query. Select

57
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 57 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
another table/query from the in step 3; now, it appears like
Computer Science

drop-down - After completing a significant, embedded form.


all these, click on the Next Step 9: It would be best if you made
option. some minor changes to the
Step 6: You must have a field that links formatting. Such as adjusting
the main form and its sub- label position, colours, and
form. This is typically an ID font weight. Now go to the
field or much similar like that. Layout view and get back to
If you have already set up the the Design view to modify as

LY
relationship for the tables, then, required.
access will decide which fields Step 10: Switch to the Form view to see
to use on the relationship’s how it appears to the user. The

N
primary and foreign keys. main form will appear with
MS access allows you to the sub-form embedded within

O
choose your fields or another it. Here, the sub-form will
one from the given list in this appear like a regular table or
wizard section. After selecting, query results as in Figure 1.80.
complete fields, tap on the next
option.
SE Search through the records in
the main form and the data in
Step 7: Now assign the name to the the sub-form updates.
U
sub-form and then click the Step 11: Now, it is time to save the
Finish option. form. So, when you save the
Step 8: Sub-form is now added to the form, the sub-form is saved as
E

form at the location specified a separate form.


N
LI
N
O
R
FO

Figure 1.80: Sub-form view

58
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 58 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
Reports generation Step 2: Click on the Create tab
Reports can be generated based on tables Step 3: Click on Report Wizard in
or queries. To generate a report, use the the Reports group as shown in
following steps: Figure 1.81.
Step 1: Open the table or query on Step 4: Click the drop-down arrow
which you want to base your to select the table or query that
report. contains the desired field(s).

LY
N
O
Figure 1.81: MS report creation

Step 5: SE
Select a field from the list on the left and click the right arrow to add it to
the report as shown in Figure 1.82.
U
E
N
LI
N
O
R

Figure 1.82: MS Access report wizard


FO

You may add fields from more than one tables or queries by repeating the above
steps. Once added the desired fields, click Next as in Figure 1.82. Continue with the
processes until the Finish step as in Figure 1.83.

59
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 59 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
N
O
SE
Figure 1.83: MS Access report wizard

Step 3: Configure the Action by


U
Macros
selecting Albums from the
A macros is a set of actions that can be
Form Name combo box.
performed automatically on demand.
Then, Set View to Form and
E

Macros can be used to automate Window Mode to Normal.


repeating tasks, saving time and effort Step 4: To Select another Action,
N

for the user. Macros are often set to click GoToRecord from the
run whenever a specific event happens. combo box. You may also do
LI

When you construct the macro, you this by selecting GoToRecord


indicate a particular event. from the Action Catalog on
N

Steps to create a simple Macro as shown the right side of the screen and
in Figure 1.84: double-clicking it.
O

Step 1: Create a new Macro by Step 5: You must Configure the


clicking the Macro button Action by selecting New from
the Record combo box.
from the Create tab on the
R

Step 6: You can now Save the Macro


Ribbon. This will create a
by Right-clicking on the
blank macro, ready for set up.
FO

macro’s tab and selecting Save


Step 2: Select an Action by clicking on the shortcut menu. Name
the Open Form from the the macro AutoExec and click
combo box. OK.

60
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 60 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE

LY
N
O
SE
Figure 1.84: Creating simple macro
U
Activity 1.9 2. Describe how to create a Sub-form
in MS Access. Provide examples.
Creating macros
E

Using an example of a repeating 3. With examples explain the steps of


task, create a macro that automates creating a simple Macro.
N

it step by step.
LI

Activity 1.10 Overview of Big data


Creating database Big data refers to all structured, semi-
N

Using an example in education or structured, and unstructured collected


health, create a simple database on information that may be mined for
O

MS Access with all objects (table, information and used in machine learning,
form, query and report). predictive modelling, and other advanced
R

analytics initiatives. Big data analytics


Exercise 1.6 can assist in creating improved and fast
FO

decisions, simulation and forecasting


Answer the following questions. future consequences, and improving
1. Explain with examples the reports business intelligence. As you build your
generation in MS Access. big data solution, consider open-source

61
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 61 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
software like Apache Hadoop, Apache Troubleshooting
Computer Science

Spark, and the entire Hadoop ecosystem Troubleshooting is a method of


as cost-effective, versatile data processing determining the source of a computer
and storage tools built to handle the
system’s problem and resolving the
generated volume.
underlying hardware and software
issues. Using a logical and methodical
There are so many benefits of big data
analytics in today’s world. Institutions approach to problem-solving is critical
and companies make use of the big data for a successful resolution. There are

LY
due to several advantages such as: several steps to follow to ensure that
(a) Access to the enormous volume your troubleshooting is more productive
of data: businesses can access a and efficient.

N
significant volume of data and
evaluate various data sources to Computers encounter problems in day-to-

O
obtain new insights and take action day usage. Such problems can be related
fast and in a better way. to hardware or software. Ask yourself the
(b) Cost savings and operational following question What would you do if
efficiency: organisations and
companies can save money by
SE
the screen on your computer goes blank?
OR what would be a solution if you fail to
using flexible data processing and close an application or your computer’s
U
storage systems to store and analyse speakers are not working? There are
massive amounts of data. They can always solutions to such problems. You
find patterns and insights to help you
can utilise a variety of fundamental
run your company more efficiently.
E

troubleshooting techniques to solve these


(c) Improved data-driven market entry: problems. A primary diagnosis should
N

organisations and companies may


begin with the following troubleshooting
become data-driven by analysing
LI

considerations:
data from devices, transactional
(a) Write down the steps: once you have
apps, the web, and social media.
started troubleshooting, you might
N

Hence, it may help them to create


innovative products and services want to keep track of what you are
O

based on client demands. doing. You will be able to recall


precisely what you have done and
Activity 1.11 avoid making the same mistakes.
R

If you need to seek assistance from


Searching big data
others, it will be easier if they know
FO

Using internet or library search,


your previous attempts.
analyse and describe how big data is
created and visualised. Explain the (b) Consider taking a note of error
benefits it provides. messages: if your computer

62
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 62 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
displays an error message, note that PC common troubleshooting
information. You might be able to techniques and tools
utilise this information later to see In troubleshooting your PC, you have
if anyone else experiences the same to note that PC problems can be caused
problem, and you can follow the by hardware, software, networks, or a
same procedure for the solution. combination of the three. Some of these
(c) Always double-check the cables problems are easier to solve than others.
If you have problems with specific
The following are common hardware

LY
computer hardware like a monitor
problems:
or keyboard, a simple first step is
(a) Storage device: problems related
to double-check all related cables
to storage devices are frequently

N
to ensure they are appropriately caused by faulty or loose cable
connected and the power is turned

O
connections, incompatible drive
on. and media formats, erroneous
(d) Restart your computer: if everything jumper and BIOS settings.
else fails, rebooting your computer
is a viable option. This can help
SE
(b) Motherboard and internal
components: these problems are
you with a variety of fundamental frequently caused by improper or
U
computer issues. loose cables, failure of components,
wrong drivers, and damaged
In other words, in the process of making updates.
E

troubleshooting, you are required to: (c) Power supply: these are problems
(a) Determine the problem triggered by inadequate power
N

(b) Set up a theory of probable cause supply, loose connections, and


inappropriate wattage.
LI

(c) Test out the theory to determine the


cause (d) CPU and memory: these problems
are closely related to the processor
N

(d) Set up a plan of action to resolve


and memory. The leading causes are
the problem and implement the
O

often caused by faulty installations,


solution wrong BIOS settings, insufficient
(e) Validate full system functionality cooling and ventilation, and
R

and, if appropriate, conduct the compatibility issues.


preventive measures (e) Displays: these problems are
FO

(f) Document results or findings, frequently caused by improper


actions, and outcomes settings, loose connections, and
corrupted or incorrect drivers.

63
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 63 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
PC troubleshooting tools machine’s configurations, hardware
Computer Science

There exist several best free and paid and software.


troubleshooting tools or packages. (g) Joeware Utilities: this is a pack of
These may assist you in resolving or free tools used to discover expired
determining the root cause of the PC accounts or passwords.
problems. Some of the free tools include: (h) Nirsoft NirLauncher: this is a pack
(a) Microsoft Easy Fix Solutions, as of tools to help smooth operations
shown in Figure 1.85. This is a tool of computers. It includes tools to

LY
developed for Microsoft Windows, recover passwords and monitor
Ms Office and other applications. network.
It provides mechanisms to repair (i) Microsoft Sysinternals Suite: this it is

N
common computer issues. a collection of troubleshooting tools
(b) Problem Steps Recorder: this is a to manage, diagnose and monitor Ms

O
program that helps to troubleshoot Windows environments.
device by recording the exact steps (j) WSCC (Windows System Control
some one took when a problem
occurred. It was found in Windows 7.
(c) Reliability Monitor: is a feature
SECenter): this a tool that consists
of programs to install updates and
execute troubleshooting utilities.
founded in Windows 10, it was also
U
found in Windows 7, that allows PC troubleshooting based on
to view the stability, and history of internet references
computer. The Internet is a superb source of
E

(d) Henrypp Error Lookup: this is a information about specific hardware


N

tool for retrieving information about problems and workable solutions. The
Windows error codes. following options are beneficial in
LI

offering troubleshooting information:


(e) PowerShell Troubleshooting Packs:
this is a tool used to identify the root (a) Internet search engines
N

causes. It is a collection of diagnostic (b) Manufacturer FAQs


tests that are related to a specific area
O

(c) Online forums and chat


of that system.
(d) Newsgroups
(f) WinAudit: this is an inventory
(e) Technical websites
R

utility for Windows computer for


(f) Online computer manuals
creating a comprehensive report on
FO

64
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 64 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE

LY
N
O
SE
Figure 1.85: Microsoft Easy fix solution as an example of troubleshooting tools
U
Activity 1.12 Chapter Summary
E

Troubleshooting registry error 1. Computer is an electronic device


Analyse the troubleshooting tools in that stores, retrieves, and processes
N

Windows 10; select one tool which binary data based on the user’s
you can use to troubleshoot the requirements.
LI

“registry error” problem. 2. Computers are organised in two key


aspects: hardware and software.
N

3. The computer executes four primary


Activity 1.13 functions or roles: input, process,
O

output, and storage functions.


Searching troubleshooting tools 4. Computer hardware components
R

Use library or internet search to have four parts: the central


processing unit, input devices,
analyse two (2) troubleshooting tools,
FO

output devices, and storage.


describe how each works and where
5. The CPU is considered the
they are indicated to be applied.
computer’s heart or brain due to

65
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 65 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

the core functions it executes. functions for quick calculation of


6. CPU has the following components the sum, average, count, maximum
that are essential in carrying out its value, and minimum value for a set
key functions: an Arithmetic Logic of cells. An example of spreadsheet
Unit (ALU), a Memory unit (MU) with such functions is MS Excel
and Control Unit (CU). 13. IF function returns one value if a
condition is true and another if it
7. There are two main types of
is false.

LY
computer memory: primary
memory and secondary memory. 14. Data sorting: lets you arrange data
in particular order.
8. The primary memory consists of

N
RAM and ROM positioned near the 15. Goal Seek function in Excel (also
CPU on the computer motherboard, known as What-if-Analysis) is used

O
allowing the CPU to scan data from in solving for the desired output by
the primary memory. changing a guess that drives it.
16. The spreadsheet lets you create and
9. The secondary memory is grouped
in three categories, namely
Magnetic such as HDD, Solid State
SEsave sets of input values that yield
different results as scenarios.
U
Drive such as SSD and Flash disk, 17. Data analysis is the process of
and Optical such as CD, DVD and cleaning, manipulating, and
Blu-ray disk. interpreting data to identify usable
information; draw conclusions, and
E

10. Applications software or just


applications (apps) also commonly make an informed decision.
N

known as end-user programs or 18. A database is a logically organised


productivity programs support collection of structured data kept
LI

the users in carrying out different electronically in a computer


system. The database is commonly
N

tasks like calculations, designing


graphics, conducting research, controlled by the DBMS.
O

making notes, playing computer 19. Databases in MS Access have four


games, or even producing videos. objects: Tables, Queries, Forms and
11. Spreadsheet is one of the most Reports. MS Access allows you
R

widely used data analysis and to manage your information in a


FO

visualisation programs. An example single database file.


is MS Excel. 20. A table in the database contains
12. Spreadsheet contains several useful data on a particular topic such as

66
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 66 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter One: Computer basics


DO NOT DUPLICATE
employee information, products or Revision Exercise 1
customers.
21. A form is a database object used to Answer the following questions.
enter or display data in a database. 1. Explain the following terms and
22. A sub-form is a form that exists provide examples for each:
inside another form. Sub-forms are (a) Computer software
helpful when you need to display (b) Computer Hardware

LY
data from tables or queries with a (c) Data
one-to-many connection. (d) Instruction
23. A query in database such as MS (e) Computer organisation

N
Access that allows you to view, 2. Describe the components of a
change or analyse data in various computer system organization.

O
ways.
3. Explain the relationship between
24. A report is an object in MS Access computer hardware and software.
that is used to display and print your
data in an organized manner.
SE
4. Describe the main components of
the Central Processing Unit (CPU).
25. A macro is a set of actions that 5. Describe the two main types of
U
can be performed automatically computer software.
on demand. Macros can be used
6. Analyse the difference among two
to automate repeating tasks, saving
main computer memory.
E

time and effort for the user.


7. What is the difference between
26. Big data refers to all structured,
N

ROM and RAM?


semi-structured, and unstructured
8. Describe the key components of
LI

collected information that may be


the computer.
mined for information and used
9. List two examples for each of the
N

in machine learning, predictive


following: an input and output
modelling, and other advanced
devices
O

analytics initiatives.
10. Describe the components of the
27. Troubleshooting is a method
CPU.
R

of determining the source of a


11. Define memory and explain its
computer system’s problem and
storage units.
FO

resolving the underlying hardware


and software issues. 12. What is the main difference between
primary and secondary memory?

67
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 67 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

13. List and define five (5) types of 23. List down and describe the steps
computer applications software. used to create a database using MS
14. Explain the steps used to insert a Access.
table of contents in a report. 24. Evaluate the differences between a
15. How would you merge the mail in query and a macro in MS Access
the context of 50 employees who based on their usage.
are to be informed about their 25. Create a database in MS Access that
participation in the organisation’s

LY
can record patient data treatment
annual conference? and reports on revenue collections.
16. Describe the steps required to
26. Explain the importance of Big
freeze panes in a spreadsheet.

N
data in the 21st century. Provide
17. List down six (6) Spreadsheet an example in which it is used

O
or Excel commands and their or it might be used to experience
functional meaning. In which
these benefits in your community
scenario or case can each one be
or country.
used?
18. Explain the difference between
relative references and absolute
SE
27. Mwanamwema connected new
Multimedia speakers to her
computer and tried to play a
U
references.
favourite Music CD, but no sound
19. Describe the steps used to sort data
came out. Suggest two causes that
alphabetically in Excel.
led to this problem and propose
E

20. What is a goal seek? Explain how solutions to this error.


it is computed in MS Excel.
N

28. A form six computer students


21. Outline five (5) common types of is attempting to print a word
LI

charts used to visualise data. In document. The printer is not


which scenario or case can each responding to the print command.
N

one be used or applied? Suggest three possible reasons for


22. Describe with examples/screenshots that problem and its solutions.
O

the steps of creating a Pivot Chart.


R
FO

68
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 68 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE

Chapter
Two Data representation

LY
Introduction
In daily life, people represent data in a way that differs from how computers
represent it. Modern computers use zeros and ones to represent data. In

N
this chapter, you will learn about the digital and analogue concept, number
systems and conversion, data coding, Boolean Algebra, and logic gates. The

O
competencies developed will enable you to know how data is represented in
a computer and use the acquired concepts to develop electronic circuits for
various applications in our daily life.
SE
U
Think about the following:

You are prepared to become a computer systems engineer and expected to be


E

able to design various digital circuits. As an engineer you also will be expected
to explain to your customers (clients) on how the data used in everyday life
N

during interactions with computers are manipulated, including the explanations


of how the internal parts of a computer operates.
LI
N

Digital and Analogue concepts consist of two main categories: analogue


and digital quantities.
O

The real world is mainly analogue in


nature. Most things that can be measured
Analogue quantity
numerically exist in an analogue form
R

The analogue quantity is a signal


with continuous values. Other things use
that varies in continuous time values.
FO

discrete set of values that characterise


Examples of analogue quantities include
digital quantities with only two states:
temperature, pressure and light intensity.
one (1) and zero (0). Electronic circuits Figure 2.1 shows the waveform of an
that are commonly used in computers analogue signal.

69
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 69 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
than in analogue form. In addition, digital
Computer Science

Amplitude
data has a significant advantage whenever
storage is required because it is easier to
store data in digital form than in analogue
Time form. Sound which is in analogue signal
form, for example, may be stored in a more
Figure 2.1:Waveform of analogue signal compact form and with more precision and
clarity in digital form than in analogue
Digital quantity form.

LY
The digital quantity is a signal that
processes data in a discrete form with two Analogue and digital conversions
states: ones and zeros, LOW and HIGH, Conversion of analogue quantity to a

N
ON and OFF, or true and false. Examples digital quantity
of digital device include computers, Natural signals are usually in analogue

O
digital pens and digital phones. Figure form, and to be used in a digital system,
2.2 shows an example of the waveform you must transform them into a digital
of a digital signal.
Voltage
SE
form. Challenges experienced when
you need to input analogue data into a
computer or export digital data from a
+5V 0 1 0 0 1 0 1 1 computer in analogue form can be solved
U
using a converter, either analogue to digital
converter (ADC) or digital to analogue
OV Time converter (DAC). One example of using
E

Figure 2.2:Waveform of digital signal an ADC is when you use a microphone


connected to a computer or built in a
N

Advantages of digital data over computer. The microphone picks up sound


analogue as moving air, translating the pressure
LI

Digital data representation has many signals into electrical impulses. The ADC
advantages over analogue data then converts electrical signals into digital
N

representation in electronic applications. signals that the computer can understand.


The signal in digital form is more reliable Figure 2.3 shows the conversion process
O

and efficient to process and transmit data from analogue to digital signal.

0
R

Analogue
Digital output
ADC
input 1
(Analogue 1 (Digital signal)
FO

signal) 0
Analogue to
digital converter
Figure 2.3: Analogue to Digital conversion

70
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 70 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Converting an analogue signal to a digital signal involves two basic steps: sampling
and quantization(encoding). Sampling gathers the variation of analogue data such
as sound wave to digital form to create a digital signal (sound). It is called sampling
because you select predetermined points for taking a reading (or sample) and do not
record every change in amplitude of the waveform. Since the analogue sample values
are real numbers that occur in continuity, then quantizing/encoding is required. The
process of converting sampled analogue voltage values to discrete voltage levels,
represented by binary bits, is known as quantization(encoding).

LY
Conversion of digital quantity to analogue quantity
Digital devices such as the iPod store music in digital format; therefore, the digital

N
to analogue converter (DAC) is required to listen to iPod music. Digital-to-analogue
conversion refers to changing a digital signal to an analogue signal. The conversion

O
process is similar to the analogue-to-digital conversion process, but in reverse order.
The analogue signal is reconstructed by translating the bits of the digital signal into
the appropriate quantization levels, then holding for one sample period, resulting in
SE
the stair-step signal. Figure 2.4 shows digital to analogue conversion process.
U
Digital 0
Analogue
DAC
output 1
signal
1
0
E

Digital to analogue
converter
N

Figure 2.4: Digital to analogue conversion


LI

Exercise 2.1
Activity 2.1
N

Answer the following questions:


O

Analysis of analogue and digital 1. Define the following terms:


quantities in surroundings (a) Analogue quantities
(b) Digital quantities
R

Using the environment that surrounds 2. Explain the advantages of digital


you, make analysis of various quantities over analogue data representation.
FO

that you observe, and evaluate them to


3. In each of the following systems,
see whether they are analogue or digital
state with reasons whether it is
quantities.
analogue or digital device.

71
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 71 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Binary number system
Computer Science

(a) Electronic calculator


(b) Pressure gauge Binary numbers consist of only zero (0)
and ones (1) values which represent two
(c) Electrical switch
discrete states. All binary numbers have
(d) Clinical thermometer base 2. Examples of binary numbers
4. Give two examples of analogue include 110112, 11100112, and 0011012.
quantities.
5. Explain how to convert analogue Octal number system
to digital quantity. Octal numbers consist of eight (8) digits

LY
with a base 8 . These numbers are 0, 1,
2, 3, 4, 5, 6 and 7. The octal numbers are
Number systems and conversion represented using numbers and base 8

N
In real life, you are accustomed to utilise or the letter ‘o’, which represents octal.
standard number systems such as the These numbers are similar to decimal

O
decimal number to count, quantify, label numbers except numbers 8 and 9 which
and measure things. You are familiar are not used in octal numbers. Examples
with decimal numbers in day-to-day life. of octal numbers are such as 4568 or
Computers use decimal numbers as input
and output values although its internal
SE
456o, 1578 or 157o etc. Using letter “o”
they can also be written as o1242.
working or processing uses binary
U
number system (0s and 1s). However, Hexadecimal number system
you can convert one number system
Hexadecimal numbers consist of sixteen
to another number system. Common
(16) symbols with a base 16 . Usually,
E

number systems include binary, octal,


decimal, and hexadecimal. hexadecimal numbers are shortened with
N

the letter ‘Hex’. Hexadecimal numbers


Decimal number system includes a combination of decimal
LI

numbers (0, 1, 2, 3, 4, 5, 6, 7, 8 and 9)


Decimal numbers consist of ten (10)
digits with a base-ten (10). These are and six (6) letters from A to F, where
N

standard numerals which include 0, 1, 2, A=10, B=11, C=12, D=13, E=14 and
3, 4, 5, 6, 7, 8 and 9. Decimal numbers F=15. Examples of hexadecimal numbers
O

are common in our daily lives. Examples are 456816, A9116, 23FA16, etc. They can
of decimal numbers include 2345, also be represented as oxCD, “o” and
93245 and 1764. The decimal number “x” indicates the number shown is a
R

is usually written without indicating its hexadecimal. Tables 2.1 and 2.2 show the
FO

base. However, you can write decimal summary of the number systems used in
numbers with its base to differentiate the computer system and the relationship
it with other number system. For between binary, decimal and hexadecimal
example1210, 38610,132710 and 12457610. numbers respectively.

72
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 72 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Table 2.1:Summary of the number system in computer

Name Base Digits


Binary 2 0, 1
Octal 8 0, 1, 2, 3, 4, 5, 6, 7
Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Table 2.2: The relationship between

LY
binary, decimal and Exercise 2.2
hexadecimal numbers
Answer the following questions:
Binary Hexadecimal Decimal

N
1. Define the following terms:
number number number (a) Decimal numbers

O
0000 0 0 (b) Binary numbers
0001 1 1 2. Differentiate between octal numbers
0010 2 2 and decimal numbers.
0011
0100
3
4
3
4
SE
3. Differentiate between binary and
decimal numbers.
4. Why is it important to study
0101 5 5
U
number systems such as binary,
0110 6 6 hexadecimal and octal numbers?
0111 7 7
1000 8 8
E

Number conversions
1001 9 9
Concept of number conversion
N

1010 A 10
Number conversion is the operation that
1011 B 11
changes a number from one number
LI

1100 C 12 system to another. Generally, the computer


1101 D 13 accepts different number systems;
N

1110 E 14 therefore, the usual decimal number


1111 F 15 system used in our daily life needs to be
O

converted from one number system to


another system and vice versa.
Activity 2.2
R

Counting decimal numbers Advantages of number conversion


The advantage of number conversion
FO

Count the decimal numbers from 0


up to 15 and compare their equivalent is that computers that use only binary
numbers as their language can be able
numbers in binary and hexadecimal
to convert numbers from other forms
systems.
which are used as input and output.

73
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 73 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Decimal to binary conversion
Computer Science

The binary numbering system is the The decimal number 6510 is equivalent
foundation for all computer and digital to 10000012
systems. Therefore, understanding how
to convert binary to decimal numbers
and vice versa is crucial. Converting a Example 2
decimal number to a binary number can Convert the decimal number 24510 to
be done using a repeated division method its binary number equivalent.
which is the most frequently used. In this

LY
method, the decimal number is divided by Procedure:
two, then the whole number is taken as the
following number to be divided by two,
2 245 Remainder Read

N
and remainders, 0 and 1, are recorded. The 2 122 1 in
binary equivalent of the decimal number reverse
2 61 0

O
is generated by writing the remainders order
in reverse order to obtain the final binary 2 30 1
result. The last remainder will be the Most
Significant Bit (MSB). SE
2 15

27
0
1
The following examples show the steps 23 1
U
required to convert decimal to binary
21 1
numbers.
0 1
Example 1
E

The decimal number 24510 is equivalent


Convert the decimal number 6510 to
N

its binary number equivalent. to 111101012


LI

Procedure:
A decimal number may have a fraction
2 65 Remainder Read or be entirely a fraction. To convert the
N

in
2 32 1 fraction of the decimal number into
reverse
O

binary, octal or hexadecimal, you have


2 16 0 order
to use the following steps:
28 0
Step 1: Multiply the fraction number
R

24 0 by its base (for example, if


22 0 you are converting to binary
FO

21 0 multiply by 2; to octal multiply


by 8, and; to hexadecimal
0 1
multiply by 16)

74
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 74 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Step 2: There shall be two parts Example 3
of the resultant number:
a non-fractional part Convert the decimal number 0.475 into
and a fractional part. binary number.
Step 3: Keep track of the non- Procedure:
fractional component Product Integer to Read in
of the final number. the left of the forward
Step 4: Repeat step 1 to 3 at decimal point order
least four times. 0.475 × 2 0.95 0

LY
Step 5: Start writing the 0.95 × 2 1.9 1
numerals in the non- 0.9 × 2 1.8 1
fractional part from the 0.8 × 2 1.6 1

N
top and work your way 0.6 × 2 1.2 1
down.

O
0.2 × 2 0.4 0
0.4 × 2 0.8 0
Note: In fractional decimal
conversion, the 0.8 × 2 1.6 1
fractional is repeatedly
multiplied by two (2)
SE
The binary equivalent of (0.475)10 is
(0.01111001...)2 . If the fractional does not
and count the most
U
become zero, the calculation can be terminated
significant bit as they
appear. after a few steps.
E

Example 4
N

Convert the decimal number 14.7510 to its binary number equivalent.


LI

Procedure:
Product Integer to Read in
N

2 14 Remainder Read
the left of the forward
27 0 in
decimal point order
O

reverse
23 1 order 0.75 × 2 1.5 1
21 0.5 × 2 1.0 1
1
R

0
1
FO

The decimal number and its fractional are represented by 1410 = 11102 and
0.7510 = 0.112 respectively. Therefore, 14.7510 = 1110.112 .

75
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 75 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Decimal to octal conversion
Computer Science

If the fractional does not become zero,


The same method in the binary conversion the calculation can be terminated after
is used to convert octal numbers through a few steps. Therefore, the decimal
dividing them by eight until the quotient number 0.12410 is equivalent to
is zero. The last remainder is the most 0.0773718 .
significant bit. Examples 5 and 6 show
how to convert from decimal to octal
numbers.
Example 7

LY
Example 5 Convert the decimal number
Convert the decimal number 204110 4130.12510 to its octal number
to its octal number equivalent. equivalent.

N
Procedure:
Procedure:

O
8 2041 Remainder Read
For the integer number 413010
8 255 1 in
reverse
8 31

83
7
7
order SE
8 4130

8 516
Remainder
2
Read
in
reverse
0 3 8 64 4 order
U
The decimal number 204110 is
88 0
equivalent to 37718 81 0
E

0 1
Example 6
N

For the fractional number 0.12510


Convert the decimal number 0.12410 to
LI

its octal number equivalent. Product Integer to Read in


Procedure: the left of the forward
decimal point order
N

Product Integer to Read in 8 × 0.125 1.0 1


O

the left of the forward


decimal point order Therefore, the decimal number
8 × 0.124 0.992 0 4130.12510 is equivalent to 10042.18 .
R

8 × 0.992 7.936 7
8 × 0.936 7.488 7
FO

Decimal to hexadecimal conversion


8 × 0.488 3.904 3
8 × 0.904 7.232 7 The same method in the binary conversion
8 × 0.232 1.858 1
is used to convert hexadecimal numbers
through dividing them by 16 until the

76
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 76 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
quotient is zero. The last remainder is
the most significant bit. The following
16 21414 Remainder Read
examples illustrate how to convert
in
decimal to hexadecimal numbers. 16 1338 6
reverse
16 83 A order
Example 8
16 5 3
Convert the decimal number 674110 to 0 5
its hexadecimal number equivalent.

LY
The decimal whole number 2141410 is
Procedure: equivalent to 53A616

N
16 6741 Remainder Read For the fractional part 0.6310
in

O
16 421 5
reverse Product Integer to Read in
16 26 5 order the left of the forward
decimal point order
16 1

0
A
1
SE
16 × 0.63
16 × 0.08
10.08
1.28
A
1
16 × 0.28 4.48 4
U
The decimal number 674110 is 16 × 0.48 7.68 7
equivalent to 1A5516 16 × 0.68 10.88 A
16 × 0.88 14.08 E
E

16 × 0.08 1.08 1
Note: 26  16  1 remaining 10. The
N

hexadecimal starts from 0 to


The fractional part 0.6310 is equivalent
F, 10 is equivalent to ‘A’ in
LI

hexadecimal. Therefore, A to 0.A147AE14...16


replaces the remainder 10.
If the fractional does not become zero,
N

the calculation can be terminated after


O

Example 9 a few steps. Therefore, the decimal


Convert the decimal number number 21414.6310 is equivalent to
53A6.A147AE14...16 .
R

21414.6310 to its hexadecimal number


equivalent.
FO

Binary to decimal conversion


Procedure:
Each binary digit has a weight based
For the integer number 2141410 on its position relative to the least

77
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 77 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

significant bit. To convert a binary number to a decimal, multiply each digit by 2n


where n represent the index relative to the Least Significant Bit (LSB). Then add
it all together to get the decimal number. The following examples show how to
convert from binary to decimal numbers.

Example 10

Convert the binary number 111012 to its decimal number equivalent.

LY
Procedure:
Step 1: Indicate the place value of each digit starting from LSB.
141312 0110 2

N
Step 2: Multiply each digit with 2n where n represents the weight for each bit.

O
1413120110 2  1 24  1 23  1 22  0  21  1 20

141312 0110 2 = 16 + 8 + 4 + 0 + 1

141312 0110 2 = 2910


SE
The binary number 111012 is equivalent to 2910
U
Example 11
E

Convert the binary number 1110101.1012 to its decimal number equivalent.


N

Procedure:
Step 1: Indicate the place value of each digit starting from LSB.
LI

Note: For a fractional binary number, its weight starts from -1.
N

6 5 4 3 2 1 0 1 2 3
1 1 1 0 1 0 1 .1 0 1 2
O

Step 2: Multiply each digit with 2n where n represents the weight for each bit.

1×26 +1×25 +1×24 + 0×23 +1×22 + 0×21 +1×20 +1×2−1 + 0×2−2 +1×2−3
R

= 64 + 32 +16 + 0 + 4 + 0 +1+ 0.5+ 0 + 0.125


FO

1110101.1012 = 117.62510

The binary number 1110101.1012 is equivalent to 117.62510

78
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 78 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Binary to octal conversion
Binary to octal conversion can be done by first converting binary to decimal, then
from decimal to octal. Another method used is dividing the binary number in a
group of three digits from LSB for integers part and start from MSB for fractional
part, and then writing the equivalent decimal number of each group to get an octal
equivalent number. If the last group has less than three digits, you add zeros from
the left to fill the gap. The following examples show how to convert from binary to
octal number.
Example 12

LY
Convert the binary number 1010111102 to its octal number equivalent.

N
Procedure:
Step 1: Divide the binary number into a group of three digits from LSB.

O
101 011 110 2
Step 2: Write the equivalent decimal number for each group
= 101 011 110 2
= 5 3 68
SE
U
= 5368
The binary number 1010111102 is equivalent to 5368
E

Example 12 can also be done by first converting to decimal then to octal as follows:
N

Procedure:
LI

Step 1: Indicate the weight of each digit starting from LSB.


180716 051413121100 2
N

Step 2: Multiply each digit with 2n where n represents the weight for each bit.
O

 1 28  0  27  1 26  0  25  1 24  1 23  1 22  1 21  0  20
= 256 + 64 + 16 + 8 + 4 + 2
R

1010111102 = 35010
FO

The binary number 1010111102 is equivalent to 35010

Step 3: Convert the decimal number 35010 to octal.

79
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 79 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

8 350 Remainder Read


8 43 6 in
reverse
85 3 order
0 5

The binary number 1010111102 is equivalent to 5368

LY
Example 13
Convert binary number 0110011.1011 into octal number.

N
Procedure:

O
Since there is binary point here and fractional part, group each 3 bits of binary
numbers and then write its equivalent octal number.

SE
For integer part (binary point), start from LSB to MSB, for fractional part, start
from MSB to LSB.

{0110
{ 011
{ .101
{ 100
U
{
0 6 3 5 4

∴ (0110011.1011)2 = (63.54)8
E

Binary to hexadecimal conversion


N

The same methods used to convert binary to octal may also be used to convert
binary to hexadecimal. In this conversion, the binary number is divided into a group
LI

of four digits from LSB. Then, write the hexadecimal number equivalent of each
group to get the hexadecimal equivalent number. If the last group has less than four
N

digits, you add zeros from the left to fill the gap. The following example shows how
to convert from binary to hexadecimal.
O

Example 14
Convert the binary number 110010011111.11012 to its hexadecimal number
R

equivalent.
FO

Procedure:
Step 1: Divide the binary number into a group of four digits from LSB.
1100 1001 1111 . 1101 2

80
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 80 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Step 2: Write the equivalent hexadecimal number for each group

1100 1001 1111 . 1101 2


= 12(C ) 9 15( F ) . 13( D) 16
= C 9 F . D 16
= C 9 F .D16
The binary number 110010011111.11012 is equivalent to C 9 F .D16

LY
Octal to decimal conversion

N
The same method applied in the binary to decimal conversion is used to convert
octal to decimal; however, each digit is multiplied by 8n where n represents the

O
index relative to LSB. The following examples illustrate how to convert octal to
decimal numbers.

Example 15 SE
Convert the octal number 14568 to its decimal number equivalent.
U
Procedure:
Step 1: Indicate the weight of each digit starting from LSB.
13 4251608
E

Step 2: Multiply each digit with 8n where n represents the weight for each bit.
N

134251608  1 83  4  82  5  81  6  80
LI

134251608  1 83  4  82  5  81  6  80
14568 = 81410
N

The binary number 14568 is equivalent to decimal number 81410


O

Example 16

Convert the octal number 5461.4218 to its decimal number equivalent.


R

Procedure:
FO

Step 1: Indicate the weight of each digit starting from LSB.


Note: For fractional octal numbers, their weight starts from -1.
5342 6110.4122138

81
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 81 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Step 2: Multiply each digit with 8n where n represents the weight for each bit.
5461.4218  5  83  4  82  6  81  1 80  4  81  2  82  1 83
= 2560 + 256 + 48 + 1 + 0.5 + 0.03125 + 0.001953125
5461.4218 = 2865.53320312510
The octal number 5461.4218 is equivalent to 2865.53320312510

LY
Octal to Binary conversion Octal to hexadecimal conversion
Example 17 There is no direct relationship between
octal to hexadecimal conversion. So,

N
Convert octal number (540 ) into you can convert octal to hexadecimal by
8
binary number. using two ways:

O
(a) Converting Octal number into
Procedure: decimal number and then into
Write each digit of octal number with hexadecimal number
its corresponding binary number with
3 bits
SE
(b) Converting Octal number into
binary number and then into
hexadecimal number
Binary equivalent
U
5 4 0 This section present only conversion of
↙ ↙ ↙ octal number into binary and then into
101 100 000 hexadecimal number.
E

∴ (540)8 = (101100000)2
N

Example 19
Example 18
LI

Convert (56 )8 into hexadecimal.


Convert Octal number (352.563)8 into
N

binary number
Procedure:
Procedure: Step 1: To convert the octal number
O

Represent each digit of Octal number into binary, express every octal
with its equivalent binary number with value using 3 binary digits.
3 bits 352.563
R

5
{ 6
{
35 2 . 5 6 3
FO

↙ ↘↘ ↘↘ ↘ 101 110
011 101 010 . 101 110 011
Binary equivalent is (101110 )2
∴ ( 352.563)8 = ( 011101010.101110011)2

82
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 82 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Example 21
Step 2: Convert (101110 )2 into
Convert the hexadecimal number
hexadecimal.
513616 to its decimal number
Group every 4 binary bits and write
equivalent.
its equivalent hexadecimal number
0010
{ 1110
{ Procedure:
2 E
Step 1: Indicate the weight of each
∴ (56 )8 = ( 2E )16 digit starting from LSB.

LY
5312316016
Example 20 Step 2: Multiply each digit with 16n

N
where n represents the weight
Convert (1234 ) into hexadecimal. for each bit.
8

O
Step1: Change octal number system 5312316016  5 163  1162  3 161  6 160
to binary number system first
5312316016 = 20480 + 256 + 48 + 6
1 {
{ 2 { 3 {4
001 010 011 100
SE 513616 = 2079010

The hexadecimal number 513616 is


U
Step 2: Change binary number system
equivalent to 2079010
to hexadecimal number system
by grouping 4 digits
E

0010 Example 22
{ 1001
{ 1100
{
2 B D
N

Convert the hexadecimal number


∴ (1234 )8 = ( 2BD )16
461.12116 to its decimal number
LI

equivalent.
N

Hexadecimal to decimal conversion


Procedure:
To convert a hexadecimal number to
O

a decimal, multiply each digit by 16n Step 1: Indicate the weight of each
where n represent the index relative digit starting from LSB.
to LSB. Then add it all together to get
R

the decimal number. The following Note: For a fractional hexadecimal


number, its weight starts from -1.
FO

examples show how to convert from


hexadecimal to decimal number. 426110.11221316

83
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 83 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Step 2: Multiply each digit with 16n where n represent the weight for each bit.
(42 6110.112213 )16  4 162  6 161  1160  116 1  2 16 2  116 3
= 1024 + 96 + 1 + 0.0625 + 0.0078125 + 0.0002441406
461.12116 = 1121.070556640610
The hexadecimal number 461.12116 is equivalent to decimal number
1121.070556640610

LY
Hexadecimal to Octal conversion Example 24

N
Example 23
Convert ( FF.2 A)16 into octal

O
Convert (1BC )16 into octal number
system. Procedure:
Procedure: Step 1: Write given hexadecimal
Step 1: Write the given hexadecimal
number. 1 B C
SE number.
F F. 2A
U
Step 2: Write each hexadecimal Step 2: Represent each hexadecimal
number to its equivalent number into its equivalent
binary number with 4 bits binary number with 4 bits
E

1 B C F F . 2 A
↙ ↓ ↓ ↘
0001
{ 1011
{ 1100
N

{ 1111 1111.0010 1010



Step 3: Change binary equivalent
LI

Its binary equivalent, (1BC )16


= (000110111100) 2 to octal by grouping 3 bits
starting from LSB to MSB
N

for integers part and MSB to


Step 3: Change binary equivalent by
LSB for fractional part.
O

grouping into 3 bits starting


from LSB to MSB.
011
{ 111
{ 111
{ . 001
{ 010
{ 10
{
000
{ 110
{ 111
{ 100
R

{ 3 7 7 1 2 4
0 6 7 4

∴ (1BC )16 = ( 674 )8 ∴ ( FF.2 A)16 = (377.124)8


FO

84
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 84 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Hexadecimal to binary conversion
(c) 374.2510 (d) 2364.62510
Example 25 4. Convert the following binary
number to decimal numbers.
Convert ( FACE )16 into binary number.
(a) 101102 (b) 10101112
Procedure: (c) 10101110.11012
Step 1: Write hexadecimal number (d) 10111101.012
F A C E

LY
5. Convert the following octal
Step 2: Represent each number by four
numbers to decimal numbers.
bits of binary number.
(a) 6518 (b) 56728
FA C E

N
↙ ↓ ↓ ↘ (c) 635.1348 (d) 1431.658
1111 1010 1100 1110

O
6. Convert the following hexadecimal
Binary equivalent is numbers to decimal numbers.
(1111101011001110 )2 (a) 69116 (b) 715.1516


∴ ( FACE )16 is equivalent to
SE (c) 541.14516 (d) 1FB16

(1111101011001110 )2 7. Convert the following hexadecimal


U
numbers to octal numbers.
(a) 4 F 216 (b) 423116
Exercise 2.3
(c) 6 A15.12716 (d) 546.14516
E

Answer the following questions.


8. Convert the following octal
N

1. Convert the following decimal


numbers to decimal numbers
numbers to binary numbers.
(a) 4538
LI

(b) 6748
(a) 81410 (b) 421410
(c) 234.148 (d) 2431.258
N

(c) 5614.5210 (d) 215410


O

2. Convert the following decimal


Binary number arithmetic operations
numbers to octal numbers.
Binary number uses the basic arithmetic
(a) 72410 (b) 671410
R

operations of addition, subtraction,


(c) 6374.6510 (d) 8764.12510 multiplication and division.
FO

3. Convert the following decimal Binary addition


numbers to hexadecimal numbers.
Binary addition works in the same way
(a) 345410 (b) 721410 as the addition in the decimal system.

85
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 85 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
In binary addition, you can carry into Binary subtraction
Computer Science

higher-order in the same way as you do Binary subtraction works in the same
in decimal addition. The four basic rules way as binary addition. The same rule
that apply when you do binary addition will be used in decimal subtraction when
are as follows: subtracting a one (1) from zero ( 0). The
“0” in the borrowing column becomes
0 1 0 1 “2” (the 0-1 becomes 2-1 = 1) while the
+ + + + 1 in the column being borrowed from is
0 0 1 1
0 1 1 10 reduced by 1. The basic rules for binary

LY
subtraction are illustrated as follows:
An example of carrying into higher-order 10
0  0  0 , 1 1  0 , 1  0  1 ,
with more than one digit is as follows: 
1

N
11 1
+

O
10
101 Note: The result is negative when a
large number is subtracted from
Example 26
Compute the following binary addition.
SE
a smaller number. Therefore, you
have to subtract a smaller number
from the larger number and use
(a) 111 + 110
the sign of the larger number.
U
(b) 101 + 111
(c) 1100 + 1011 Example 27
E

Compute the following binary


Procedure:
subtraction:
(a) 111 + 110 =
N

(a) 111  110 (b) 011  111


111
+ (c) 110  001
LI

(d) 1100  0011


110
1101 Procedure:
N

(b) 101 + 111 = (a) 111  110 


O

101 111
+ 
111 110
1100 001
R


(b) 011  111 
(c) 1100 + 1011
FO

11 0 0 111
+ 
10 1 1 011
10111  100

86
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 86 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
(c) 110  001  (b) 1010 110
110 1010
 
001 110
101 0000

 1 01 0
(d) 1100  0011 
101 0
1100 1 1 110 0

LY
0 01 1
10 01 (c) 10111101

10 11

N
Binary multiplication 11 01
1 0 11

O
Binary multiplication works the same way
as multiplication in the decimal system, 0000

but binary multiplication is simple as only 1011
“0” and “1’ are used. The following basic
rules are used:
0  0  0 , 0  1  0 , 1 0  0 , 1 1  1
SE

1011
1 0 0 0 1111

(d) 110110
U
Note: Fractional multiplication for
binary numbers is the same as 1101
decimal number multiplication.  10
E

0000
Example 28  1101
N

Compute the following binary 11010



LI

multiplication.
(a) 110111 (b) 1010 110
Binary division
N

(c) 10111101 (d) 110110


The division of binary numbers uses
O

Procedure: the same procedures as decimal number


division. The following examples show
(a) 110111 
1101 binary division:

R

 11 Example 29
FO

1101 Compute the following binary division.


 1101 (a) 100  10 (b) 101010  11
100111 (c) 1100.00  101 (d) 1111.00  110

87
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 87 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Procedure:
Computer Science

(d) 1111.00  110 


(a) 100  10 
1 0
10 1 0 0
1 0
0 0
 0 0

LY
0
(b) 101010  11  Complement operations
Complement operation is the one used

N
1 1 1 0
to simplify subtraction operations. It
11 1 0 1 0 1 0 turns the subtraction operation into an

O
1 1 addition operation which is very useful
1 0 0 in computer operation. Every integer
 1 1
0 1 1
SE
in decimal arithmetic has an additive
complement, which is a value that gives
zero when added to the original number.
0 1 1 For example, 7 and -7 are additive
U
0 0 complements because 7 + (-7) = 0.
0 0
Types of complement operations
E

0 There are two types of complement


operations in binary numbers. These
N

(c) 1100.00  101  are one’s and two’s complements. The


one’s and two’s complements of a binary
LI

1 0. 0 1 1 0 1 ...
101 1 1 0 0. 0 0 number indicate negative values in digital
systems. Two’s complement arithmetic is
N

1 0 1
the most common computer method when
1 0 0 0 working with negative numbers.
O

1 0 1
One’s complement
1 1 0 0 0
R

One’s complement of a binary number is


1 0 1 calculated by replacing all 1’s with 0’s and
FO

1 0 0 0 all 0’s with 1’s. The normal method for


1 0 1 binary subtraction explained in previous
sections is not computer friendly. If this
1 1 0
method is used, you will need a distinct

88
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 88 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
subtraction algorithm. In arithmetic Example 31
operations, subtracting ‘B’ from ‘A’ equals
adding (-’B’) to ‘A’. Therefore, binary Perform the following binary
subtraction is converted into addition in subtraction using one’s complement.
a computer using the one’s complement 111002  100112
approach.
Procedure:
Example 30 111002  100112 =

LY
Compute the one’s complement of 1510 11100
using 8 bits:
 01100 1's complement
(1)01000

N
Procedure:
Step 1: Convert 1510 into 8 bits binary  1  Carry

O
number, that is, 000011112 . 01001

Step 2: Convert one’s complement by
replacing all 1’s with 0’s and
all 0’s with 1’s = 111100002 .
Therefore, one’s complement
SE Example 32

Subtract (1011) 2 from (1110) 2 using


of 000011112 is 111100002 .
the 1’s complement method.
U
The one’s complement of 1510 in binary Procedure:
form is 111100002 which is 1510 11102 - 10112
E

1110
N

Subtraction using one’s complement + 0100


One’s complement subtraction is a method 10010
LI

 1  Carry
that enables the subtraction using an
0011
addition operation. The following steps
N

show how to subtract a small number ∴ 11102 – 10112 =0011


from a large number:
O

Step 1: Compute the one’s complement


of the small number. Example 33
R

Step 2: Add the one’s complement of Subtraction of large number from small
the small number to the large number using 1’s complement
FO

number.
Compute 101011 – 111001 by using
Step 3: Add the final carry to get the
result. 1’s complement

89
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 89 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Procedure: Example 36
1’s complement of 111001 = 000110 Compute 7-10 using 1’s complement
method
101011
Add + 000110 Procedure:
Step 1: Write the numbers in their
110001
binary equivalent.
Find 1’s complement of the 7 = 0111
result = −001110

LY
10 = 1010
∴ 101011 - 111001 = − 001110 Step 2: Write 1’s complement of
number 10(1010) = 0101

N
Example 34 Step 3: Add two numbers.
0111

O
Subtract 11010.10 from 10110.01
+ 0101 , No carry, therefore:
Procedure:
10110.01 - 11010.10 1100

1’s complement of 11010.10 = 00101.01


SE
Step 4: Find 1’s complement of the
result.
10110.01 − (0011)= (−3)
U
Add + 00101.01 ∴ 7 − 10 = −3
11011.10
Example 37
E

Find 1’s complement of the result and


assign negative. -00100.01 Perform the binary subtraction operation
N

using 1’s complement in 15 − 20


Example 35
LI

Procedure:
Subtract 1010 from 1000 using 1’s Step 1: Write the numbers in their
binary equivalent.
N

complement method
15 = 01111
Procedure:
O

1’s complement of 1010 = 0101 20 = 10100


1000 Step 2: Find 1’s complement of number
20(10100) = 01011
R

Add + 0101
1101 Step 3: Add two numbers.
FO

Find 1’s complement of the result and 01111


put (-) sign = -0010 + 01011
∴10110. 01 − 11010.10 = − 0010 11010

90
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 90 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Step 4: Find 1’s complement of the 0 0 0 0 0111
result. ! 1 1 1 1 1 0 11
(11010)= − (000101)
(1)0 0 0 0 0 01 0
= −5
∴ 15 − 20 = −5 Step 6: The overflow bit is ignored to
get the result.
0000 00102 Which is
Subtraction using two’s complement
equivalent to +2.

LY
Two’s (2’s) complement of a binary
number is calculated by adding 1 to
the one’s complement. The following Subtraction of a large number from a
example shows how to subtract a small small number using two’s complement

N
number from a large number.
Example 39

O
Example 38
Subtract 10101 – 10111.
Find the difference of 7  5 using two’s
complement:

Procedure:
SE
Procedure:
Find 2’s complement of 10111
Now, add both of the number:
Step 1: Rearrange the expression 7  5 10101
U
to 7  (5) . + 01001
Step 2: Convert the small number into 11110
binary equivalent.
E

In the above result,we did not get the


510 = 0000 01012
carry bit, so find the 2’s complement
N

Step 3: Compute the one’s complement of the result,


LI

of the small number. 00001


0000 01012  1111 10102 + 1
N

Step 4: Add 1 to the Least Significant  00010


Bit (LSB) of one’s complement
O

∴ 1010 – 10111 = – 00010


of the small number.
111110102 +1⇒ 111110112 Example 40
R

Step 5: Add the two’s complement of Subtract 101011 – 111001 using 2’s
FO

the small number to the binary complement method.


equivalent of a large number.
Procedure:
710 = 0000 01112 Find the 2’s complement of 111001:

91
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 91 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
101
Computer Science

10111 = 01000
+ 010
+ 1
111
000111
Step 5: Find 2’s complement of the
Add 101011 result (111) =
+ 000111 001
110010 + 1
001

LY
Find 2’s complement of the result and
put (-) sign ∴− (001)2 = (−1)10
001101
(b) 12 – 25

N
+ 1 Step 1: Write each number in their
− 001110 binary equivalent

O
12 = 01100 , 25 = 11001
Example 41 Step 2: Find 1’s complement of

Perform the following subtraction


operation using 2’s complement
SE number 11001 = 00110
Step 3: Add 1 to 1’s complement of
a result and becomes 2’s
method. complement.
U
(a) 5 – 6 (b) 12 – 25 00110
+ 1
Procedure:
E

(a) 5 – 6 00111
Step 1: Write each number in their Step 4: Add 2’s complement of number
N

binary equivalent. 25 with number 12(01100).


5 = 101 , 6 = 110 01100
LI

+ 00111
Step 2: Find 1’s complement of
10011
N

number 110 = 001


Step 3: Add 1 to 1’s complement of Step 5: Find 2’s complement of the
O

a result and becomes 2’s result (10011) =


complement. 01100
+ 1
R

001
+ 1 01101
FO

∴ − (01101)2 = (−13)10
010
Step 4: Add 2’s complement with − (001)2 = (−1)10
number 5(101) ∴ 12 – 25 = -13

92
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 92 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Exercise 2.4 (0 to 9), alphabetic characters and special
characters such as punctuation marks. The
Answer the following questions. combination of numeric and alphabetic
characters is called alphanumeric. A group
1. Perform the following binary
of bits represents a single character in a
addition.
computer, such as a letter or numeric.
(a) 11 + 10 (b) 1101 + 1110 Popular coding schemes are used to
(c) 110111 + 100110 represent characters, such as the Binary
(d) 110001 + 110100 Coded Decimal (BCD), American Standard
2. Perform the following binary Code for Information Interchange (ASCII),

LY
subtraction. Unicode, and Extended Binary Coded
(a) 111  100 (b) 1111  1010 Decimal Interchange Code (EBCDIC).
(c) 11100011  10011101

N
3. Perform the following binary BCD codes
multiplication: The BCD is used to encode decimal

O
numbers which are represented by four
(a) 11111 (b) 11111010
bits expressed by considering their place
(c) 1101101 (d) 1101111001
value from left to right (23222120 = 8421).
4. Perform the following binary
division:
(a) 110  10 (b) 10110  11
SE
Table 2.3 shows 4-bits BCD words.

Table 2.3: BCD Codes


(c) 11100011  10011101
U
Decimal BCD Code
5. Perform the following in binary Digits 8421
form using ones and two’s
0 0000
complement: 1 0001
E

(a) 1610  1010 (b) 2710  1510 2 0010


3 0011
(c) 10610  7610
N

4 0100
5 0101
LI

6 0110
Data coding 7 0111
Concept of data coding 8 1000
N

Data coding is the representation of 9 1001


characters using a combination of binary
O

number patterns. Example 42

Representation of a character in a Determine the BCD representation of


R

computer the decimal number x = 564 .


The digital computer uses binary x = 564 5 6 4
FO

numbers for data manipulation and 0101 0110 0100


representation. All characters are stored
The BCD representation of ( x = 564 )
in computers as binary numbers. These
is 0101 0110 0100
character sets include numeric characters

93
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 93 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
EBCDIC codes defines characters used in computers,
Computer Science

EBCDIC uses the full 8 bits consisting such as number characters, letters and
8
of 256 characters (= 2 ) used for data special characters. The word ‘BOY’ in
presentation and transfer. It is used to word processor becomes 0100 00102
represent numbers and texts. 010011112 0100110012 . The word ‘boy’
is 0110 00102 011011112 011110012 . As
ASCII codes the need increased for various characters
ASCII was developed as a 7-bit to to represent different languages such as
7
represent 128 (= 2 ) different characters Arabic, Greek, and Hebrew, Unicode was

LY
and then extended to an 8-bit code. For introduced representing between 8 and 48
7-bits, ASCII code uses a byte (8 bits) bits. The increased number of bits makes
with MSB not used. Table 2.4 ASCII it suitable for various characters.

N
Table 2.4: ASCII code table

O
Character Decimal Number Binary Number Character Decimal Number Binary Number
Blank space 32 00100000 ^ 94 01011110
! 33 00100001 – 95 01011111
“ 34 00100010 ` 96 01100000

A
B
#
$
35
36
65
66
00100011
00100100
01000001
01000010
a
b
c
d
SE 97
98
99
100
01100001
01100010
01100011
01100100
C 67 01000011 e 101 01100101
U
D 68 01000100 f 102 01100110
E 69 01000101 g 103 01100111
F 70 01000110 h 104 01101000
G 71 01000111 i 105 01101001
E

H 72 01001000 j 106 01101010


I 73 01001001 k 107 01101011
N

J 74 01001010 l 108 01101100


K 75 01001011 m 109 01101101
L 76 01001100 n 110 01101110
LI

M 77 01001101 o 111 01101111


N 78 01001110 p 112 01110000
O 79 01001111 q 113 01110001
N

P 80 01010000 r 114 01110010


Q 81 01010001 s 115 01110011
R 82 01010010 t 116 01110100
O

S 83 01010011 u 117 01110101


T 84 01010100 v 118 01110110
U 85 01010101 w 119 01110111
R

V 86 01010110 x 120 01111000


W 87 01010111 y 121 01111001
X 88 01011000 z 122 01111010
FO

Y 89 01011001 { 123 01111011


Z 90 01011010 | 124 01111100
[ 91 01011011 } 125 01111101
\ 92 01011100 ~ 126 01111110
] 93 01011101

94
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 94 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
in the binary sequence as a sign bit. If the
Activity 2.3 leftmost bit is 0, the number is positive,
Use the ASCII code to write the word and if the leftmost bit is 1, the number is
Shule in binary numbers. negative.
Step 1: Find the position of each
In a binary system, a positive sign is
letter of the word Shule in
represented by 0 while a negative sign is
the ASCII code table.
represented by 1. The leftmost bit of any
Step 2: Read the values of binary
signed number represents the sign bit. For
numbers corresponding to

LY
example, a BYTE, which is eight-bit, is a
each letter. common unit of information in computer
Step 3: Arrange the binary number systems. A byte as a signed binary number
according to the word Shule.

N
can be represented as follows for decimal
Step 4: Write the binary equivalent values (35)10 and (-62)10:

O
of the word Shule.
(+35)10 = 0010 00112

Signed and unsigned integers in a (62)10  101111102


computer
Signed and unsigned integers
SE
The first digit represents the sign, and the
underline digits represent the magnitude
Computers and other digital systems must
U
of the number.
be able to deal with both positive and
negative numbers. Sign and magnitude Example 43
information are both included in a signed Find the decimal equivalent of the
E

binary number. The sign of a number tells following signed binary numbers.
whether it is positive or negative. The
N

(a) 011100012
binary representation is straightforward
if computers only represent non-negative (b) 100110002
LI

integers (unsigned). Computers have also


Procedure:
to handle negative integers (signed).
N

A signed number has both a sign and (a) 011100012


a magnitude. The sign of a number
O

The number is positive from the


determines whether it is positive or definition of a signed binary number
negative whereas the magnitude represents since the most significant digit is 0.
R

the value of the number.


011100012 = +(161514 0302 0110 ) 2
FO

Representation of signed integers 011100012 = +(1×26 +1×25 +1×24 +1×102 )


The typical convention to distinguish 011100012 = +(64 + 32 + 16 + 1)
between a signed and unsigned number is 011100012 = +(113)10
to treat the most significant (leftmost) bit

95
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 95 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Real number representation in a
Computer Science

(b) 100110002
computer
The number is negative from the
For easier understanding, you assumed
definition of a signed binary number
a computer stores and functions with
since the most significant digit is 1.
decimal numbers, even if it uses only a
100110002  (06 05141302 0100 2 ) binary number system for its operation.
100110002 = – (1×24 +1×23 ) There are two methods used to represent
real numbers in computers. These are
100110002  (16  8)
fixed-point representation and floating-

LY
100110002  (24)10 point representation. The fixed point
representation normally fixes the
decimal point after six points from the

N
The disadvantage of using this method is left. The maximum positive number the
that, it is challenging to test 0 although it computer can store is 999999.99, and the

O
is a common process in computers. That smallest number the computer can store
zero (0) number may be written as 0000 for is 000000.01. The main disadvantage of
this method is an inadequate range, and
+0 or 1000 for -0. Another disadvantage
is that addition and subtraction involve
considering both the sign and relative size
SE
therefore, the floating-point representation
is the most used method to represent
decimal numbers.
of the integers to perform the required
U
operation, making the hardware design Floating-point numbers
of the computer’s arithmetic unit more
The floating-point number has a much wider
challenging. The most economical way
E

range than the fixed-point representation, it


to represent a signed integer is by using is a widely used real number representation.
N

the 2’s complement format. Floating-point representation is divided


into mantissa, exponent, and sign. The
LI

2’s complement representation following is an example of a floating-point


This method does not affect the number’s number that shows possible decimal places
N

sign by modifying an MSB in the number’s within the number.


representation. Negative binary numbers 24546.437 = 2454.6437×101 W h e r e
O

are expressed in 2’s complement form by 2454.6437 represents mantissa and 1


adding 1 to 1’s complement and leaving represent the exponent.
R

the sign bit unchanged, as illustrated in 24546.437 = 245.46437×102


the following example: 24546.437 = 24.546437×103
FO

(24)10  100110002 111010002 24546.437 = 2.4546437×104

True value 2’s complement 24546.437 = 0.24546437×105

96
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 96 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Three parts of a floating-point number numbers.
Parts of a floating-point number which (a) 011010102 (b) 111011102
has four digits in the mantissa, are
illustrated in Figure 2.5. 6. Compare fixed point and floating-
point representations.
Implied decimal point

±
Boolean algebra
Boolean algebra is a way of representing
Mantissa Exponent the relationship between the inputs and

LY
Sign of
Mantissa outputs of a logic circuit. A logic circuit
operates in two values: 1 and 0. Boolean
Figure 2.5: Floating-point representation
algebra in digital logic circuit differs from

N
ordinary mathematic algebra because
Sign
logic circuit involves only two values,

O
The most significant bit indicates a sign.
For binary number, 0 indicates a positive which are 1 and 0. In contrast, ordinary
number, and 1 shows a negative number. mathematics can represent more than two
values. Boolean 0 and 1 represent the
Mantissa
The first part of a floating number
SE
status of a voltage variable, also known as
its logic level, rather than actual numbers.
representation of a number is called the A voltage in a digital circuit is at the logic
U
mantissa, and it represents a signed fixed- 0 or logic 1 level depending on the exact
point number. numerical values.
Exponent
Boolean operations
E

The exponent designates the decimal (or


binary) point’s position. Boolean algebra has three basic
N

operations: OR, AND, and NOT. The OR


Exercise 2.5 and AND gates are linked with addition
LI

and multiplication logic operations.


Answer the following questions:
Logical addition
N

1. Define the following terms: Logical addition uses the logical symbol
(a) data coding (b) mantissa ''+ '' which can be placed between any
O

(c) exponent number of variables; for example, between


2. Identify any three popular coding A and B which represent the logical
schemes. value of 1 and 0. The logical addition
R

3. Identify BCD representation of the (+) is represented by the “OR” operator;


decimal number x = 346 therefore, the expression A + B reads as
FO

4. Differentiate between signed and “A” OR “B”. The possible combinations


unsigned integers of logical addition are as follows:
5. Calculate the decimal equivalent
of the following signed binary 0 + 0 = 0 , 0 +1 = 1 , 1+ 0 = 1 ,1+1 = 1

97
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 97 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
The logical addition operation represents Laws and rules of Boolean algebra
Computer Science

the same binary addition except for the There are different laws of Boolean
last entry, whereby when both entries algebra as described below. These laws
A and B are at logical 1, then A+B=1. are all the same as ordinary algebra.
Therefore, the symbol + represents logical
addition and not normal binary addition. Commutative law
The logical addition applies for more than The commutative law used in Boolean
one variable. For example, X+Y+Z=P; algebra is the same as ordinary algebra.

LY
when values of X, Y and Z are logical The addition and multiplication using
values ''1'' , the value of P is ''1'' . commutative laws using two variables A
and B are as follows:
Logical multiplication

N
A + B = B + A and A.B = B. A
Logical multiplication uses the logical

O
symbol ''.'' or AND operator. The possible Associative law
combination of logical multiplication for
The associative law used in Boolean
variables A and B and the resulting outputs
of A.B are as follows: SE
algebra is the same as ordinary algebra.
The addition and multiplication using
associative laws using three variables
0.0 = 0 , 0.1 = 0 1.0 = 0 , 1.1 = 1
are as follows:
U
The logical multiplication represents the ( A + B ) + C = A + ( B + C ) and
same binary multiplication except for
the last entry, whereby when both entries ( A.B).C = A.( B.C )
E

A and B are at logical 1, then A.B = 1.


Distributive law
N

Therefore, the symbol "." represents


logical multiplication. The logical The distributive law used in Boolean
LI

multiplication applies for more than one algebra is similar to ordinary algebra.
variable; for example, X .Y .Z = P when The addition and multiplication using
N

X, Y and Z values are logical values "1", distributive laws using three variables
the value of P is "1". are as follows:
O

( A + B ).C = AC + B.C and


Basic laws and rules of Boolean A + B.C = ( A + B).( A + C )
algebra
R

Laws and rules were invented to help Identity law


FO

to simplify logical expressions and as The identity law used in Boolean algebra
a result, they minimize the number of is used as follows:
logic gates needed to construct various A + 0 = A and A.1 = A
logic circuits.

98
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 98 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Idempotent law the same variable.
This law applies a variable OR or AND
by itself; the output is always the same A= A
variable as follows:
A + A = A and A. A = A Boolean algebra expression and
simplification
Annulment law
Annulment law applies when a variable Boolean algebra expression
OR with 1 equal 1 or AND with 0 gives Boolean expressions are algebraic

LY
0 as follows: statements that use variables and logical
A.0 = 0 and A + 1 = 1 operators, such as AND, OR, XOR, and
NOT.

N
Complementary law
Complementary law applies when a Simplification using Boolean laws

O
variable AND with its complement is The simplification of Boolean expression
0 and when OR with its complement reduces the number of logic gates required
result is 1.
A. A = 0 and A + A = 1
SE
to implement the logic circuit. There are
different ways used to simplify Boolean
expressions. These include using laws of
Double complementary law algebra and the Karnaugh map (K-map).
U
The double negation law applies when In this textbook, you will cover only
a variable is inverted twice. Its output is simplification using the laws of Algebra.
E

Example 44
N

Using laws of Boolean algebra, simplify the following expression: ( A + B ).( A + C ) .


LI

Procedure:
( A + B ).( A + C ) =
N

= A. A + A.C + B. A + B.C - Distributive law


O

= A + A.C + B. A + B.C - Idempotent AND law (A.A = A)


= A(1 + C ) + B. A + B.C - Distributive law
R

= A.1 + B. A + B.C - Annulment OR law (1 + C = 1)


= A(1 + B) + B.C - Distributive law
FO

= A.1 + B.C - Annulment OR law (1 + B = 1)


= A + B.C - Identity AND law (A.1 = A)

99
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 99 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Example 45

Using laws of Boolean algebra, simplify the following expression: ABC + AB + ABC
Procedure:
ABC + AB + ABC = ABC + ABC + AB - Commutative law
= AB(C + C ) + AB - Distributive law
= AB.1 + AB - Complementary law
= AB + AB - Identity AND law (A.1 = A)

LY
= A( B + B ) - Distributive law
= A.1 - Complementary law
=A - Identity AND law (A.1 = A)

N
O
Exercise 2.6 logic circuit. It is used to show all
possible combinations of the inputs and
Answer the following questions. outputs of a given logic circuit. You must
1. Prove the following using Boolean
laws and rules:
SE
evaluate the Boolean expression for all
possible combinations of values for the
(a) AB + AC + ABC = AB + AC input variables as part of the method.
U
(b) A( A + B ) = AB Construction of truth tables
2. Use laws of Boolean algebra to The construction of a truth table involves
simplify the following expression. some steps depending on the number of
E

inputs. The following steps are used to


(a) ABC + ABC
N

construct a truth table:


(b) BC + BC + AC Step 1: Determine the number of
LI

(c) B + AB + ABC variables for a given Boolean


expression, whereby, for n
N

(d) ABC + AC + ABC variables, the number of rows


(e) AC + ABC will be 2n . For example, the
O

truth table will need 22 = 4


(f) ABC D + ABC D rows for two variables, A and
B. The variables must have all
R

possible combinations of 1 and 0.


Truth tables
FO

Note: When you set up the truth


Concept of a truth table table, you always make the
A truth table is a table used to represent first column (whether a 4, 8,
the Boolean expression of the given or 16-row table) half zeros (0)

100
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 100 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
(1st half) and half ones (1) (2nd Step 2: Identify the variables and every
half). Before switching to 0’s, possible combination of 1 and 0
write half as many consecutive for each variable.
1’s in the next column as you
Step 3: Create a new column for each
did first.
term of the Boolean expression.
For instance, the truth table that Step 4: Compare the two statements.
has two variables A and B, as
Note: The two statements are
shown in Table 2.5, the variable

LY
equivalent if their truth tables
A has two (2) zeros and two (2)
ones followed by alternating have the same value.
ones and zeros for variable B.
Example 46

N
Table 2.5: Truth table with two (2) variables

O
Create a truth table for the following
A B
expression: x = A + B .
0 0
Step 1: Identify the variables in the
0
1
1
0
SE expression. That is, the two
variables are A and B.
1 1
Step 2: Determine the number of rows.
U
For two variables, the rows are
For three variables, A, B, and C, variable
22 = 4 .
A has four (4) zeros and four (4) ones,
E

followed by two (2) ones and two (2) Step 3: Present every possible
zeros for variable B. Lastly, variable C combination of 1 and 0 for
N

has alternating zeros and ones as shown each variable A and B as in


in Table 2.6. Table 2.7.
LI

Table 2.6:Truth table with three (3) variables


Table 2.7: Possible combinations of 1
N

A B C and 0 for variable A and B


0 0 0
O

0 0 1 A B A+B
0 1 0 0 0 0
R

0 1 1 0 1 1
1 0 0
FO

1 0 1
1 0 1 1 1 1
1 1 0
1 1 1

101
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 101 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Example 47
Prove the distributive law ( A + B ).C = AC + B.C by using truth table.
Step 1: Identify variables in the expression. That is, the three variables are A, B
and C.
Step 2: Determine the number of rows. For the three variables A, B, and C the
number of rows are 23 = 8
Step 3: Present every possible combination of 1 and 0 for each variables A, B,
and C as in Table 2.8:

LY
Table 2.8: Possible combinations of 1 and 0 for variable A, B ,and C

A B C A+B BC AC (A+B).C AC + BC

N
0 0 0 0 0 0 0 0

O
0 0 1 0 0 0 0 0

0
1

1
0

1
1

1
0

1
SE
0

0
0

1
0

1 0 0 1 0 0 0 0
U
1 0 1 1 0 1 1 1

1 1 0 1 0 0 0 0
E

1 1 1 1 1 1 1 1
N
LI

Write Boolean expression from the Step 2: To obtain the final Boolean
truth table expression, you write down the
N

The truth table is used to describe the combined Boolean equations


Boolean expression of a given logic with the output one (1)
O

circuit; therefore, it is possible to write connected by AND operator


Boolean expression from the truth table and join them by the OR
operator.
R

and vice versa. The following steps show


how to derive the Boolean expression Step 3: The Boolean expression
FO

from the truth table: obtained may not be the final


Step 1: Write down the Boolean simplified form. Therefore, it
equation for each row in the can be simplified using the laws
truth table whose output is 1. and rules of Boolean algebra.

102
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 102 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
The following are examples of writing Example 49
Boolean expressions from the truth table.
Write the Boolean expression from
Example 48
the following truth Table 2.10.
Write the Boolean expression from the
truth table as shown in Table 2.9. Table 2.10: Possible combinations of 1
and 0 for variable A, B ,C,
Table 2.9: Possible combinations of 1 and x
and 0 for variable A, B ,and x
A B C X

LY
A B x
0 0 0 0
0 0 0
0 0 1 0
0 1 1
0 1 0 0

N
1 0 1
0 1 1 1
1 1 1

O
1 0 0 0
Step 1: Write down the Boolean 1 0 1 1
equation for each row in the 1 1 0 0
truth table whose output is 1.
AB , AB and AB
SE 1 1 1
Step 1: Write down the Boolean
1
U
Step 2: To obtain the final Boolean equation for each row in the
expression, you write down the truth table whose output is 1.
combined Boolean equation ABC , ABC and ABC
whose output is one and by
E

using OR operator. Step 2: To obtain the final Boolean


expression, you write down
N

x = AB + AB + AB
the combined Boolean
Step 3: The Boolean expression equations whose output is
LI

obtained may not be the final one and OR together.


simplified form, but it can be
N

simplified using the laws and x = ABC + ABC + ABC


rules of Boolean algebra. Step 3: The Boolean expression
O

x = AB + AB + AB obtained may not be the final


x = AB + AB + AB + AB - Idempotent law simplified form, but it can be
simplified using the laws and
R

x = AB + AB + AB + AB - Associative law
rules of Boolean algebra.
x = ( A + A) B + A( B + B ) - Distributive law
FO

x = 1.B + A.1 - Complementary law x = ABC + ABC + ABC


x = B+ A - Identity(A.1 = A) x = ABC + ABC + ABC + ABC - Idempotent law

x = A+ B x = ABC + ABC + ABC + ABC - Commutative law

103
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 103 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

x = ( A + A) BC + AC ( B + B ) - Distributive law Exercise 2.7


x = 1.BC + AC.1 - Complementary law Answer the following questions.
x = BC + AC - Identity(A.1 = A) 1. Explain the term truth table as used
x = C ( B + A) in logic circuit.
2. Prove the following using the truth
table.
Activity 2.4 (a) AB + AC + ABC = AB + AC

LY
Designing a car safety buzzer circuit (b) A + ( B + C ) = ( A + B) + C
As an electronic engineer, you are 3. Create the truth table of the
required to design a car safety buzzer following expression:

N
circuit. The design specifications
x = A + BC
are as follows: The buzzer is ON

O
4. Given the truth Table 2.12,
whenever the door is OPEN or when
determine the Boolean expression
the key is in the IGNITION, and the
for Y in terms of A and B.
seat belt is NOT BUCKLED.

Create a truth table that describes


SE
Table 2.12: The truth table for A,B, and Y

A B Y
these design specifications in terms
U
of “highs” (1) and “lows” (0). This is 0 0 0
when a sensor or indicator is active or 0 1 1
not active. Table 2.11 will guide you
1 0 1
to draw the truth table.
E

1 1 0
N

Table 2.11: Information for the truth table


of buzzer circuit
DeMorgan’s theorem
LI

Concept of DeMorgan’s theorem


Input Buzzer
DeMorgan’s theorems are very useful
N

Seat belt Door Key Output


relationships in simplifying Boolean
0 0 0
O

algebra. These theorems were named after


0 0 1 a mathematician known as DeMorgan,
0 1 0 who proposed these theorems. There are
R

0 1 1 two DeMorgan’s theorems. These are OR


1 0 0 sum inverted theorem and AND product
FO

1 0 1 inverted theorem.
1 1 0
The OR sum inverted version of
1 1 1
DeMorgan’s theorem states that the

104
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 104 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
complement of two or more variables Step 2: Since the expression has two
joined by the OR operator is equal variables, A and B; then, the
to the complement of individual number of rows are 22 = 4
variables connected by AND Step 3: Variables are A and B, and every
operator. possible combination of 1 and 0
For two variables, A and B, and three for each variable is as in Table
variables, A, B and C, the OR sum 2.13:
inverted theorem can be expressed
as follows: Table 2.13: Possible combinations for A and B

LY
A + B = A.B and A + B + C = A.B.C A B A B A+B A+ B A.B
0 0 1 1 0 1 1
The AND product inverted version of
0 1 1 0 1 1 1

N
DeMorgan’s theorem states that the
complement of two or more variables 1 0 0 1 1 1 1

O
joined by AND operator is equal 1 1 0 0 1 0 0
to the complement of individual
variables connected by OR operator.

For two variables, A and B and


three variables, A, B and C, the
SE
Example 51

Prove DeMorgan’s theorem AB = A + B ,


by using truth table.
AND product inverted theorem can
U
Step 1: The expression has two variables,
be expressed as follows:
A and B.
AB = A + B and ABC = A + B + C Step 2: Since the expression has two
E

variables, A and B; then, the


Creating a truth table to prove number of rows are 22 = 4
N

DeMorgan’s theorem Step 3: Variables are A and B, and every


The truth table is usually used to possible combination of 1 and 0
LI

prove different Boolean expressions. for each variable is as in Table


The truth table in this section is used 2.14:
N

to prove DeMorgan’s theorem. The


following examples show the proof Table 2.14: Proving DeMorgan’s theorem
O

of DeMorgan’s theorem using the for AB = A + B


truth table.
R

Example 50 A B A B AB AB A+ B
0 0 1 1 0 1 1
Prove DeMorgan’s theorem
FO

A + B = A.B , by using truth table. 0 1 1 0 0 1 1


1 0 0 1 0 1 1
Step 1: The expression has two
1 1 0 0 1 0 0
variables, A and B.

105
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 105 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Application of DeMorgan’s theorem
Computer Science

and treat each term as a single


DeMorgan’s theorem can be used to variable. Let x = A + BC and
simplify Boolean expression and create y = BC
alternative gates from the basic gates.
Step 2: Using DeMorgan’s theorem
The following steps will guide you to
simplify a Boolean expression using expression y = BC will be
DeMorgan’s theorem and Boolean y = B + C therefore
algebra laws.
A + BC = A + B + C

LY
Example 52 Step 3: Using DeMorgan’s theorem in
Simplify the Boolean expression expression A + B + C will be
A + BC using DeMorgan’s theorem = A.B.C

N
and Boolean algebra laws. Step 4: Using double negation law
in expression A.B.C will be

O
Step 1: Determine the terms you can
apply DeMorgan’s theorem A.B.C

Example 53 SE
Simplify the Boolean expression ABC + BC using DeMorgan’s theorem and
Boolean algebra law.
U
Step 1: Determine the terms you can apply DeMorgan’s theorem and treat each
term as a single variable.
E

Step 2: Using DeMorgan’s theorem expression ABC + BC will be:


  
N

ABC  BC  ABC . BC

  
Step 3: Using DeMorgan’s theorem expression ABC . BC will be:
LI


ABC  BC  A  B  C . B  C 
N

Step 4: Using laws of Algebra


O


ABC  BC  A  B  C . B  C 
  
R

ABC  BC  A  B  C . B  C - Double negation


FO

ABC + BC = AB + AC + BB + BC + BC + CC - Distributive law

ABC + BC = AB + AC + BC + BC + CC - Complementary law

106
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 106 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
ABC + BC = AB + AC + BC + BC + C - Idempotent law

ABC + BC = AB + AC + BC + C ( B + 1) - Distributive law

- Annulment law
ABC + BC = AB + AC + BC + C.1

ABC + BC = AB + AC + BC + C - Identity law

ABC + BC = AB + C ( A + B + 1) - Distributive law

LY
ABC + BC = AB + C ( A + 1) - Annulment law, B + 1 = 1

ABC + BC = AB + C.1 - Annulment law, A + 1 = 1

N
ABC + BC = AB + C - Identity law

O
and one binary output signal. These gates
Exercise 2.8

Answer the following questions.


SE
are critical when dealing with electronics,
they are used to construct the digital
system. The logic gates can perform the
1. State the DeMorgan’s theorems.
U
2. Use DeMorgan’s theorem and laws logic operation in single or multiple binary
of Boolean algebra to simplify the inputs and give one binary output. Logic
following expressions: gates are considered as a single unit;
however, gates comprise one or more
E

(a) ABC + ABC transistors. The basic logic gates include


N

OR, AND and NOT, NAND, NOR and


(b) BC + BC + AC
XOR gates. The NOT gate has only one
LI

(c) B + AB + ABC input signal and one output signal while


other gates have two or more input signals.
N

(d) ABC + AC + ABC


3. Use truth table to prove the Function and operation of logic gates
O

following DeMorgan’s theorem: The function and operation of each logic


A.B = A + B gate are as follows:
R

OR gate
Logic gates
FO

OR gate is the digital circuit with two or


Concept of logic gates more input signals, and its output signal
A logic gate is an electronic circuit that is the OR combination of its input signal.
involves two or more binary input signals The logical symbol of the OR gate is

107
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 107 25/12/2022 03:43


FOR ONLINE USE ONLY
DO NOT DUPLICATE
shown in Figure 2.6 (a). Figure 2.6 (b) illustrates the truth table for OR gates. The
Computer Science

OR gate is expressed mathematically using the (+) sign between the variables; for
example, Boolean operations Y = A + B represent the OR gate whereby the output
of the OR gate will be 1 when either of the input is 1 or both inputs are 1. The OR
gate output will only be 0 if both inputs are 0. The same idea is used for more than
two inputs. The output will only be 0 if both inputs are 0; otherwise, the output is 1.

A B A+B
A 0 0 0

LY
Y
0 1 1
B
1 0 1
1 1 0

N
(a) (b)

O
Figure 2.6:(a) OR gate (b) Truth table for OR gate

AND gate
SE
AND gate is the digital circuit with two or more input signals, and its output signal
is the AND combination of its input signal. The logical symbol of the AND gate is
U
shown in Figure 2.7(a). Figure 2.7 (b) illustrates the truth table for AND gates for
Boolean operations Y = A.B whereby the output of the AND gate will be high (1)
when both inputs are high (1); otherwise, the output is 0. The same idea is used for
more than two inputs. The output will only be one (1) if both inputs are 1; otherwise,
E

the output is 0.
N

A B A.B
A 0 0 0
LI

Y 0 1 0
B
N

1 0 0
1 1 1
O

(a) (b)
R

Figure 2.7:(a) AND gate (b) Truth table for AND gate
FO

NOT gate (Inverter)


Unlike OR and AND gates, the NOT gate is the digital circuit with only one input
signal and one output signal, and its output signal complements its input signal. The
logical symbol of the NOT gate is shown in Figure 2.8(a). Figure 2.8(b) illustrates

108
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 108 25/12/2022 03:43


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
the truth table for NOT gates. If the input signal A is subjected to NOT gate, its
output is A .

A A
A Y
1 0
(a) (b)
Figure 2.8:(a) NOT gate (b) Truth table for NOT gate

LY
NAND gate
The term NAND stands for NOT-AND and refers to the complement of AND gate
output. It works oppositely to the AND gate. The NAND gate has two or more input

N
signals, and its output signal complements the AND gate. The logical symbol of
the NAND gate is shown in Figure 2.9 (a). Figure 2.9 (b) illustrates the truth table

O
for NAND gates which shows that the output will be 0 only when both inputs are 1.
When any input is 0, the output will be 1.

A
AND NOT SE A B Y = AB
Y 0 0 1
B
U
0 1 1
1 0 1
A
Y 1 1 0
E

B
N

(a) (b)
LI

Figure 2.9: (a) NAND gate (b) Truth table for NAND gate

Note: Using DeMorgan’s theorem, you can create other gates from basic gates. For
N

example, the NAND gate is the same as the OR gate with inverted inputs as
shown in Figure 2.10.
O

A
Y A
R

B Y
B
FO

Y = AB Y = A+ B
(a) (b)
Figure 2.10: (a) NAND gate (b) NAND equivalent using OR and NOT gate

109
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 109 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
NOR gate
Computer Science

The term NOR stands for NOT-OR, it refers to the complement of OR gate output.
It works oppositely to the OR gate. The NOR gate has two or more input signals, and
its output signal complements the OR gate. The logical symbol of the NOR gate is
shown in Figure 2.11(a). Figure 2.11(b) illustrates the NOR gate’s truth table which
shows that the output will be 0 when any inputs are 1. When both inputs are 0, the
output will be 1.

OR NOT

LY
A B Y = A+ B
A
Y 0 0 1
B
0 1 0

N
1 0 0
A
1 1 0

O
Y
B

(a)
SE (b)
Figure 2.11: (a) NOR gate (b) Truth table for NOR gate
U
XOR gate
The logical symbol of the exclusive OR (XOR) gate is shown in Figure 2.12 (a).
The XOR has only two inputs, and its output is one (1) only when two inputs are at
opposite inputs, that is, 1 and 0. Figure 2.12 (b) illustrates the XOR gate’s truth table.
E
N

A B Y
0 0 0
LI

A
Y 0 1 1
B
1 0 1
N

1 1 0
O

(a) (b)
Figure 2.12:(a) XOR gate (b) Truth table for XOR gate
R

Activity 2.5
FO

Activity on the relationship between Boolean operators and logic gates


Two electrical switches, a bulb and battery are connected as shown in Figure
2.13. As a technical expert, you are required to establish the truth table to reflect

110
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 110 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
the circuit operations that control Designing a logic circuit
switches A and B, which will light up
Concept of the logic circuit
the bulb, and then propose the logic
gate for the circuit. The following Logic circuit
conditions will guide you:
A logic circuit is the combination of two
(a) What happens when both switches
are OFF? or more logic gates. These gates are OR
(b) What happens when only one gate, AND gate, NOT gates and other
switch is ON (either A or B)? gates. Examples of logic circuits are adder,

LY
(c) What happens when both switches subtractor, multiplexer and demultiplexer.
are ON?
Types of a logic circuit

N
A
There are two types of logic circuits:

O
combinational logic circuits and sequential
logic circuits. The combinational logic
Y circuit is the combination of logic gates
SE
whereby the output at any instant depends
on the input at the present state. A major
characteristic of the combinational logic
U
Figure 2.13: Electrical circuit to switch bulb circuit is that it does not have memory.
Combinational logic circuit are very useful
in designing computational components in
Exercise 2.9
E

the CPU, such as the Arithmetic logic unit.


N

Answer the following questions:


1. Explain the term logic gate and give The sequential logic circuit is the
LI

two examples. circuit that comprises a combinational


2. Explain three benefits of using a logic circuit and memory. A sequential
N

logic circuit that uses few gates. logic circuit is essential in designing
3. Define the following gates and draw memory components such as register
O

their circuit: and memory. However, the sequential


(a) NOT logic circuit is out of the scope of this
R

(b) OR book. The combinational and sequential


(c) AND logic circuit block diagram is illustrated
FO

(d) NAND in Figure 2.14.


(e) NOR
(f) XOR

111
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 111 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Combinational Output Memory Outputs

Input Output
Combinational Combinati- Memory
onal Logic Elements
Logic Circuit

External inputs

LY
Figure 2.14: (a) Combinational logic circuit (b) Sequential logic circuit

Designing a combinational logic Example 54

N
circuit for a given Boolean expression
Create a logic circuit of the Boolean
Boolean algebra provides a simple

O
expression Y = A + BC .
approach to define the operation of a
logic circuit which is constructed by a Step 1: Determine the number of input
combination of two or more logic gates.
The output of the logic circuit is due to
a combination of various input values.
SE variables A , B and C .
Step 2: Identify the operators required
in the expression.
U
(a) One AND gate for BC
Drawing logic circuits from the
required.
Boolean expression
(b) One OR gate is needed to
The Boolean expressions are usually
E

combine A and BC .
written to describe the mathematical
C
N

behaviour of the logic circuit. Therefore,


B
it can determine how the input and output
LI

BC
signals are connected in the logic circuit.
Y
For example, you will realise that two A
N

inputs OR gate is needed to represent


an expression Y = A + B . Therefore, Figure 2.15: Logic circuit for Y=A+BC
O

using the same analysis, you can


create a complex circuit. The essential Example 55
R

steps required to create a logic circuit Given the Boolean expression


from the Boolean expression include Y = AC + ABC + ABC + AB .
FO

crosschecking it and translating it into (a) Simplify the expression using


logic gates. The following example Boolean algebra
illustrates the conversion of Boolean (b) Draw the logic circuit of the
expression to a logic circuit. expression obtained in (a).

112
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 112 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
Step 1: Simplify the Boolean expression Step 2: The output of the left most NOT
Y = AC (1 + B) + AB(C + 1) gates is the OR gate’s input.
Therefore, the expression for
Y = AC.1 + AB.1
OR gate is A + B .
Y = AC + AB
Step 3: The output of the OR gate
Y = A( B + C ) is one of the inputs to the
rightmost AND gate, and B and
Step 2: Determine the number of input
variables A , B and C . C are other inputs. Therefore,

LY
the expression for AND gate
Step 3: Identify the operators required
in the expression. is ( A + B) BC . The output
expression for the entire logic
(a) One NOT gate is required

N
circuit is ( A + B) BC .
B.

O
(b) One OR gate is needed to A ( A + B ) BC
combine C and B . B
B
( A + B) BC
(c) One AND gate is required B

B B
for A and B + C C SE Figure 2.17: Logic circuit
X

B+C
U
C

Y Exercise 2.10
A
Answer the following questions.
E

Figure 2.16: Logic circuit for 1. Define the following terms:


N

Y = A(B + C) (a) Logic circuit


(b) Combinational logic circuit
LI

Creating Boolean expressions from 2. Mention two examples of the


logic circuits combinational logic circuits.
N

You can create Boolean expressions from 3. Create a logic circuit of the Boolean
expressions:
O

the logic circuit by writing the expression


for each gate at the leftmost inputs and (a) AB + BC
working to the last output. For example,
R

the logic circuit in Figure 2.17, the (b) BC + ( B + AC )


Boolean expression can be determined (c) AB + ABC
FO

using the following steps:


4. Determine the Boolean expression
Step 1: The expression for left most
and draw the truth table from the
NOT gate with inputs A and B
following circuit in Figure 2.18:
is A and B , respectively.
113
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 113 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
together. Adders are the circuits within
Computer Science

A
the ALU in the CPU that perform binary
B addition. Therefore, they are vital circuits
F
used in computers for number addition.
C
Figure 2.18: Logic circuit Construction of half adder
This simple addition consists of four
5. Design a combinational circuit with
possible operations which are:
three input A, B, and C and three
outputs X, Y, Z, when the binary 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and

LY
input is 0, 1, 2, 3 the binary output is 1 + 1 = 10.
too greater than the input, when the The first three operations result in a single-
binary input is 4, 5, 6, 7, the binary

N
digit sum while the fourth operation results
output is three less than the input. in a two-digit sum. A carry is the higher

O
(a) Construct a truth table for that significant bit in this operation. As a result,
scenario. the first three operations carry ‘0’ whereas
(b) Derive the Boolean expression for the fourth produces a carry of ‘1’. Table
the output.
(c) Simplify the Boolean expression
SE
2.15 shows the truth table for the Boolean
realisation of the binary addition.
for output obtained in part (b).
U
Table Input
2.15: Half adder truth table
Output
(d) Draw a logic circuit for that
simplified expression in part (c). A B Sum(S) Carry (C)
0 0 0 0
E

Construction of half and full adder 0 1 1 0


Concept of half and full adder
N

1 0 1 0
An adder is a digital circuit that adds binary
1 1 0 1
LI

values together. Adders are used in many


computers and other types of processors
to execute a variety of computations such
N

From the truth table, you obtain the


as calculating address table indices in
Boolean expression for S and C as follows:
the ALU. There are two types of adders,
O

namely half adder and full adder. A half S  AB  AB  A  B and C = AB


adder is a logic circuit that adds two binary
The Boolean expressions show that
R

digits together. Half adder has two outputs


which are the Sum (S) and Carry (C). This sum and carry are equivalent to XOR
and AND gate, respectively. The logic
FO

limitation of half adder can be overcome


using a full adder. The full adder is the circuit for the half adder is illustrated in
logic circuit with a condition to add a Figure 2.19 which is simplified using the
carry. Therefore, it adds three binary digits XOR gate as shown in Figure 2.20.

114
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 114 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
From the truth table, you obtain the
A A
B
A.B Boolean expression for sum (S) and
S=A.B+A.B
carry ( C2 ) as follows:
A A.B
B B S = ABC1 + A BC1 + ABC1 + AB C1

C=A.B S = ABC1 + ABC1 + ABC1 + ABC1

S = C1 ( AB + AB) + C1 ( A B + AB )
Figure 2.19: Half adder logic circuit

LY
A S = C1 ( A B + AB ) + C1 ( A B + AB )
S=A ⊕ B
B
S  C1 ( A  B)  C1 ( A  B )

N
A
C=A.B
S  C1  ( A  B ) and C2 = AB + AC1 + BC1

O
B
The Boolean expressions show that
Figure 2.20: Half adder logic circuit using
sum (S) and carry (C) are equivalent
XOR and AND gate

Construction of full adder


SE
to XOR ( S  C1  A  B ) and (
C2 = AB + AC1 + BC1 ) gate. The logic
A full adder adds three input bits. There circuit for the full adder is illustrated in
U
are three inputs and two outputs on this Figure 2.21.
cicuit. The two significant bits to be added A
B S
are represented by two inputs while the C1
E

third input represents the carry from the


previous significant position. Table 2.16
N

shows the truth table for the full adder.


C2
LI

Table 2.16: Full adder truth table


Input Output
N

A B C1 Sum(S) C2 Figure 2.21: Full adder logic circuit using


0 0 0 0 0
O

three inputs XOR, OR and three


0 0 1 1 0 AND gates

0 1 0 1 0
The Boolean expression for a carry out
R

0 1 1 0 1 (C2) can be simplified using XOR as


1 0 0 1 0
FO

follows:
1 0 1 0 1
C2 = AB + AC1 + BC1
1 1 0 0 1
1 1 1 1 1 C2 = AB + AC1 ( B + B) + BC1 ( A + A)

115
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 115 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

C2 = AB + AC1 B + ABC1 + AC1 B + BC1 A Chapter Summary

C2 = AB(1 + C1 + C1 ) + AC1 B + BC1 A 1. Signals are classified into two


groups: analogue signals and digital
C2 = AB(1 + C1 + C1 ) + C1 ( AB + AB) signals.
C2 = AB + C1 ( AB + AB) 2. The analogue quantity is the signal
that varies in continuous time
C2  AB  C1 ( A  B) values.

LY
3. The digital quantity is the one that
The full adder can be simplified using the changes in a discrete value in one
two half adders, as shown in Figure 2.22. of the two possibilities such as ones

N
Half Adder
Half Adder and zeros.
C1

O
A S 4. By considering the base of a
B number, number systems are
classified as binary, octal, decimal,
C2
SE
and hexadecimal.
5. Number conversion is the operation
Figure 2.22: Full adder logic circuit using two that changes a number from one
U
half adders and OR gate
base to another such as:
(a) Decimal to binary
Exercise 2.11 conversion
E

Answer the following questions. (b) Decimal to octal conversion


N

1. Define the following terms: (c) Decimal to hexadecimal


conversion
LI

(a) Half adder


(b) Full adder (d) Binary to decimal conversion
N

2. Explain why adders are important (e) Binary to Octal conversion


in a computer? (f) Binary to hexadecimal
O

3. Draw a logic circuit of the conversion


following: (g) Octal to decimal conversion
R

(a) Half adder (h) Hexadecimal to decimal


(b) Full adder conversion
FO

4. Draw the truth table of the half (i) Octal to binary conversion
adder and determine its Boolean (j) Octal to hexadecimal
expression. conversion

116
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 116 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
(k) Hexadecimal to binary (a) The OR sum inverted version
conversion of DeMorgan’s theorem states
(l) Hexadecimal to octal conversion that the complement of two
or more variables connected
6. Binary arithmetic uses the basic
by the OR operator is equal to
arithmetic operations of addition,
the complement of individual
subtraction, multiplication, and
variables connected by AND
division.
operator.

LY
7. One’s complement of a binary
A + B = A.B and
number is calculated by replacing
all 1’s with 0’s and all 0’s with 1’s. A + B + C = A.B.C

N
8. Two’s complement of a binary (b) The AND product inverted
number is calculated by adding 1 version of DeMorgan’s

O
to the one’s complement. theorem states that the
9. Data coding is the representation complement of two or more
of characters using a combination
of binary number patterns
SE variables connected by AND
operator is equal to the
complement of individual
10. The digital computer uses binary variables linked together by
U
numbers for data manipulation and OR operator.
representation.
AB = A + B and
11. Boolean algebra is a way of
ABC = A + B + C
E

representing the relationship


between the inputs and outputs of 15. A logic gate is an electronic circuit
N

a logic circuit. that involves two or more binary


LI

input signals and one binary output


12. Boolean algebra has three basic
signal.
operations: OR, AND, and NOT.
N

The OR and AND gates are linked 16. The basic logic gates include OR,
with addition and multiplication AND, NOT, NAND, NOR, and
O

logic operations. XOR gates.


13. A truth table is a table used to 17. A logic circuit is the combination
R

represent the Boolean expression of two or more logic gates.


of a given logic circuit. 18. A half adder is a logic circuit that
FO

14. DeMorgan’s theorems are very adds two binary digits together.
useful relationships in simplifying 19. The full adder is the logic circuit
Boolean algebra. with a condition to add a carry.

117
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 117 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Revision Exercise 2 (c) 241.12516 (d) 45 A116


(e) AC116
1. Differentiate between analogue
10. Convert the following hexadecimal
quantity and digital quantity.
numbers into octal numbers:
2. Explain what is meant by the term
(a) 3FA16 (b) 4 A116
sampling.
(c) 3 AF 5.12516 (d) 256.14516
3. Explain the process of converting
(e) 643116
an analogue signal into a digital

LY
signal. 11. Convert the following octal
4. Convert the following decimal numbers into decimal numbers:
numbers into binary numbers: (a) 2538 (b) 6538

N
(a) 52410 (b) 351410 (c) 424.1458 (d) 241.258

O
(c) 614.4510 (d) 535.12510 12. Perform the following binary
5. Convert the following decimal additions:
numbers into octal numbers: (a) 111 + 110 (b) 1101 + 1010
(a) 64510
(c) 574.4510
(b) 461410
(d) 764.12510
SE(c) 110011 + 110110
(d) 111101 + 110110
6. Convert the following decimal 13. Perform the following binary
U
numbers into hexadecimal numbers: subtractions:
(a) 125410 (b) 62310 (a) 1111  1100 (b) 1001  1000
(c) 11010011  10011001
E

(c) 174.22510 (d) 264.62510


14. Perform the following binary
7. Convert the following binary
N

multiplications:
numbers into decimal numbers:
(a) 110111 (b) 11110 1011
(a) 111012 (b) 11101012
LI

(c) 1001111 (d) 110011001


(c) 101010.1012 (d) 1010101.0012 15. Perform the following binary
N

(e) 10101102 divisions:


(a) 1110  10 (b) 11110  11
O

8. Convert the following octal


numbers into decimal numbers: (c) 11001.10  1101
(a) 518 (b) 16728 16. With an example, explain the
R

following terms:
(c) 435.1458
(a) data coding (b) mantissa
FO

9. Convert the following hexadecimal (c) exponent


numbers into decimal numbers:
17. Describe any three (3) popular
(a) 25116 (b) 515.2516 coding schemes.

118
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 118 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Two: Data representation


DO NOT DUPLICATE
18. Establish BCD representation of following expressions:
the decimal number 259. (a) B + A(C + DE ) (b) ( AB + C ) B
19. Describe the use of BCD number 28. Explain the term logic gate and give
representation. two examples.
20. Differentiate between signed and 29. Explain three benefits of using a
unsigned integers. logic circuit that uses few gates.
21. Explain why Boolean algebra is 30. Construct the truth table of the half
important in the digital system. adder and determine its Boolean

LY
22. Using laws of Boolean algebra, expression.
simplify the following expressions. 31. Explain gates with the aid of an
example for OR, NOR, AND,
(a) AB + AB + BC + AC

N
NAND gates.
(b) A + AB + C + BC 32. Given the Boolean expression

O
(c) A + AB Y = AB + ABC + ABC + AB
(d) ABC + AC + ABC (a) Draw the logic circuit of the
23. Explain the truth table as used in
Boolean logic.
SE Boolean expression
(b) Simplify the Boolean
expression
24. Use the truth table to prove the
U
following: (c) Draw the logic circuit of the
(a) A + B( A + B) + A( A + B) = A + B simplified Boolean expression.
33. From the following Boolean
(b) A.B + AB = ( A + B).( A + B)
E

expression, simplify and then draw


25. Create the truth table of the a logic circuit for the simplified
N

expression, x = A + B + C expression.
26. Given Table 2.17, determine the (a) Y = A( B + AB) + AC
LI

Boolean expression:
(b) Y = ( A + B)( A + B)
Table 2.17: Truth table for A,B, and Y
N

(c) Y = ABC + ABC + ABC + ABC


A B Y 34. Differentiate between half adder
O

0 0 0 and full adder.


0 1 1 35. Draw the truth table of a full adder.
R

1 0 1 36. Determine the Boolean expression


1 1 0 for sum (S) and carry (C ) of the
FO

half adder.
37. Draw the logic circuit for half adder.
27. Use DeMorgan’s theorem and laws
of Boolean algebra to simplify the 38. Draw the logic circuit for full adder.

119
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 119 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Chapter
Three Problem solving

Introduction

LY
We face different problems in our daily life. Some of these problems are simple
to solve, and others are very complex. All of these need a systematic approach
to come up with a solution. Such a step-by-step routine of arriving at the

N
solution enables computer programmers to develop programs to solve different
problems in our societies. In this chapter, you will learn about the concept

O
of problem-solving, steps of solving a problem, and algorithm representation.
The competencies developed from this chapter will enable learners to develop
algorithms for solving various daily life problems using computer programs.
SE
U
Think about the following:

Sylivia is a software engineer. Among the duties she performs in an organisation


E

she works for, include programming. Sylivia was caught in her conversation
saying: “…everyday, I arrive at my office early and use my laptop for coding the
N

programs for the IT department projects”. Among the skills which are inevitable
for a good programmer is data structure and algorithms. At the end of the year,
LI

the CEO of an organisation provided a gift to a good programmer of a year in IT


department. Sylivia was not a winner who received a gift from the CEO.
N
O

The concept of problem solving Broadcasting Corporation (TBC) channel


on your TV, and you want to shift to another
It is required to solve problems at some channel, you will need to do something,
point in our daily lives. Activities such
R

such as push the channel number on your


as paying school fees, making payments remote to transfer to that channel. This is
FO

using mobile money, buying various items an example of problem-solving. A group


from a shop, or withdrawing money from of students in a class may decide to go
a bank account are tasks that need problem on a study tour and choose to share the
solving. If you are watching the Tanzania cost. Calculating overall expenses and

120
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 120 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
the amount each person must to spend a considerable amount of time analysing a
contribute to the study tour problem, planning for solution before implementing.
is also a form of problem Applying appropriate problem solving technique is
solving. essential in programming development in order to
meet user and system requirements.
The problem is a kind of
obstacle to accomplishing Problem solving process
your goal, and that problem
solving is a method of To successfully instruct a computer, you must

LY
removing that obstacle thoroughly understand the problem to be solved. Also,
through a series of activities. you should be able to plan a technique for solving it
The process taken to arrive in the form of a set of consecutive steps. Instructing

N
at a feasible solution may the computer to solve the problem becomes relatively
vary from one to another. easier after it is well-defined and a strategy for solving

O
Problem solving in computer it has been created. Generally, the process of solving a
science, can be defined as problem is shown in Figure 3.1. This problem solving
the process of identifying a process is detailed as follows:
problem, developing a set of
procedures (steps) to solve
SE 1. Identify
and define
the identified problem and the problem
U
implementing the proposed
steps to create a computer
program. 5. Implement 2. Generate
E

the possible
solution solutions
Importance of problem
N

Problem
solving in programming solving
process
LI

To be a good problem solver


and a good programmer,
you need to follow good
N

problem solving techniques.


4. Decide
O

Applying problem solving on a


techniques is very important 3. Evaluate
solution
alternatives
before developing computer
R

programs. This is because it


is much easier to discover Figure 3.1: Problem solving process
FO

errors in a program that is


well analysed rather than Identify and define the problem
the one that is not. For this This stage involves understanding and interpreting
reason, it is recommended a problem. It would be helpful if you could describe

121
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 121 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Decide on a solution
Computer Science

the problem you are trying to solve. Break


your problem down into manageable After you have come up with solutions
smaller pieces/parts and refine it at each and alternatives to the problem, you need
stage. You should check whether the to explore the strengths and weaknesses of
problem you are trying to solve is relevant each option while forecasting outcomes.
before attempting to develop an algorithm Several influencing factors can be used to
to solve it. help you determine whether to take it or
leave it out. Criteria must be set to help
Generate possible solutions you select the best one. Sometimes pure

LY
At this stage, think and ask yourself this facts dictate which ideas will work and
question: what could be an alternative which one will not. In some situations,
solution to the problem? Make a list of feelings and intuitions decide the solution.

N
several feasible solutions that you believe Try to shortlist and refine the shortlisted
will adequately solve the problem. You solution as few options as possible. Lastly,

O
can review the possible solutions and then you need to have one or two expected
select a single solution favouring the many solutions for implementation from the
problem-solving possibilities provided. whole list.
Having various options can significantly
improve the value of your perfect solution.
SE
Implement the solution
Different alternative solutions to the After selecting the best solution, it is
U
problem must be generated before the necessary to consider how it might
last evaluation. Once you have decided be implemented. Providing insight
on the “what”, it creates a foundation for into funding potential problems with
E

establishing the structure for analysing implementing the solution, and the time
options by evaluating each solution. frame of implementing the solution
N

are essential for any workable solution


Evaluate alternatives to a problem. Not all solutions can be
LI

After gathering several alternatives, you implemented. Finally, you need to develop
will need to examine them to choose an action plan to implement and execute
N

the best one. The best option is the one the solution process in this stage.
that is agreed upon with the team, that
O

solves the problem, and which is simple Programming process


to implement in your situation using The problem solving process in the
R

available resources. When evaluating previous section applies to every work


alternatives, do not be biased because in life. It also assumes that you have
FO

this can lead you to discarding the best already known a number of existing
alternative and opting for the worst solutions to choose from, in order to
alternative. At this stage, try to narrow select the best solution to solve the
down the options to just one. existing problem. Sometimes you may

122
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 122 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
be required to propose your own solution, 8. Go to the library or visit the internet
creating it from the scratch. The process of and find the procedure or process
developing or creating your own solution of solving a problem
involves sequential steps.
9. Document your findings.
In programming context, these steps are 10. Compare your approaches or
summarised to fit in the perspective of procedures in (7) and (9) above.
developing a system or program. These
steps, which are commonly known as Algorithm representation

LY
five steps in a programming process,
are: defining and analysing the problem,
Concept of algorithm
designing or planning the solution, coding In your daily life, you perform activities

N
the program, testing and debugging the by following steps. Examples of these
program, and documenting the program. activities include getting ready for

O
These steps will be discussed in detail in exercise, making breakfast, riding a
Chapter Six of this book. bicycle, wearing shoes, and washing
utensils. To complete each of these

Activity 3.1 SE
activities, you follow a sequence of steps.
For example, the following are the steps
required to ride a bicycle:
Activity for solving various problems
(a) Remove the bicycle from the stand;
U
1. Think of problems from your
(b) Sit on the seat of the bicycle;
school, home or in your society.
(c) Start peddling;
2. Choose any three problems from (d) Use breaks whenever needed; and
E

the identified ones. (e) Stop on reaching the destination.


3. Study them carefully and identify
N

the possible solutions for your Thus, from the above scenario, a set
chosen problems. of procedures required to perform a
LI

4. Analyse and evaluate the given task (such as five steps above)
possibilities and opt for one solution or to solve a problem is known as an
N

that you think is the best to solve algorithm. An algorithm is a set of steps
each problem. that generate a predictable sequence of
O

5. Plan how you can address each basic computational processes leading
problem. to a solution of the given problem. It is a
R

method of representing the systematic and


6. What are the common procedures
logical procedure for solving a problem.
undertaken to solve the problems
FO

Before developing an algorithm for


from your study above?
solving a given problem, think of what
7. Summarise your observations using
will be the output when such algorithm
a diagram.
is executed.

123
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 123 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Importance of algorithm That is, once presented, it should


The following are the importance of always provide the same result
algorithm: for any language used to write the
(a) An algorithm is essential in enhancing program.
a computer program according to the (f) Fitness: an algorithm must be
available resources; composed of finite number of steps.
(b) It enables you to solve a problem That is, for all different cases, the
written algorithm should provide
through better approaches;
the results within a finite number
(c) It saves for the best program

LY
of steps.
speed and desired minor memory
(g) Termination: the algorithm must
consumption; and
terminate. That is, it should not go
(d) It emphasises solving problems most

N
into infinite loop.
straightforwardly.

O
Qualities of a good algorithm
Characteristics of a suitable algorithm
(a) Memory utilisation: the best
(a) Well defined input: an algorithm algorithm is the one that will ensure
requires some input values. Such
input values can be zero or more,
but only finite number of inputs are
SE
that a program consumes the least
amount of memory.
(b) Efficiency: the best algorithm is
required.
U
the one that enables a computer
(b) Well defined output: the algorithm program to produce results while
must give the output (one or more) using less amount of processing
once executed. The output produced power in a short time.
E

should have a specific relationship (c) Cost-effective: the best algorithm


with the input.
N

is the one that is simple,


(c) Unambiguity: the algorithms straightforward, and produced
LI

instructions should be clear, precise using minimal cost.


and well communicated. (d) Accuracy: the best algorithm is
the one that may provide more
N

(d) Effectiveness: each instruction in


an algorithm should be adequate. accurate results than other existing
algorithms.
O

That is an algorithm should be


designed in such a way that it
correctly achieves its purpose and Recommendations for writing a
suitable computer algorithm
R

does what it was exactly intended


to be done in a finite length of time. The following are recommendations for
FO

(e) Programming language writing a good algorithm:


independence: the algorithm should (a) The instruction in the algorithms
not depend on any particular should be clear and precise to the
programs for its implementation. programmer;

124
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 124 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
(b) Consider writing algorithms in a examples of algorithms in our daily lives
sequence; include cooking, assembling something
(c) Avoid infinite repetitions of like a computer, steps to power a computer,
instruction; sorting students’ test or examination
(d) Phrases or words used should look papers alphabetically, and finding the
like typical English language; shortest pathway to somewhere. Other
(e) Make sure that the algorithms will examples are building a house, wearing
finally terminate; and shoes, and putting on garments.
(f) The results expected should

LY
From the examples in the previous
be obtained after the algorithm paragraph, you can write an algorithm
terminates. to make a cup of tea. The following is
an example of algorithm for making a

N
Uses of algorithm cup of tea:
(a) prepare teabag, cup, kettle, water,

O
The use of an algorithm aims at increasing
reliability, accuracy, and efficiency of sugar and teaspoons;
obtaining solutions. Algorithms are helpful (b) put the teabag in a cup;
for small and complicated problems.

Construction of algorithms
SE(c) fill the tea kettle with water;
(d) boil the water in the kettle;
(e) pour the boiled water into the cup;
(f) add sugar to the cup;
U
Think about the following: (g) stir the tea using a teaspoon;
(h) remove the tea bag from a cup; and
Have you tried to think about why (i) drink the tea.
E

you take a particular route to school You can use the same example to write
or the market? Have you ever cooked
N

an algorithm that prompts the user to


ugali or made a cup of tea? Identify add sugar and milk.
LI

the materials or actions you regard as


input, process and output in cooking Steps to construct an algorithm
N

ugali or making cup of tea. Step 1: Identify detailed information on


the problem
O

Identifying detailed information


Examples of algorithm construction about the problem is a
In our daily lives, we use algorithms significant step in writing an
R

knowingly or unknowingly. We perform algorithm. Before constructing


activities using defined steps, making or developing an algorithm,
FO

some decisions, selecting items, arranging you must first obtain detailed
things in a given order, and classifying information about the problem
things using a given criterion. All these you want to solve. This step will
are examples of algorithms. Some of the help to enhance understanding

125
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 125 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

of the problem and verification Step 5: Develop an entire organisation


of the steps that will be used in of the algorithm
solving the problem. Develop a fundamental
Step 2: Analyse the problem structure of the problem solving
The precise analysis of the methodology and describe the
problem involves data that must approach step-by-step clearly.
be acquired, processed, and Step 6: Develop, improve and refine
retrieved to generate effective After developing an algorithm,
results.

LY
try to enhance the explanation
Step 3: Decide on the approach for to intensify its readability and
solving a problem user-friendliness. Then improve
Deciding which approach to and refine the algorithm for well

N
problem solving is an essential, understanding and efficient
but it is the most challenging usage.

O
step in writing an algorithm. In
this stage, you need to develop Activity 3.2
a problem-solving approach
to help construct the model
that will help solve the given
SE
Algorithms related to day-to-day
real life
problem. Consider experience 1. From your experience in daily
U
and practice in selecting an activities, outline two activities
excellent approach. Try to write which are examples of algorithms.
and read several algorithms that Give reasons to support your
E

will enhance your understanding. choice.


Step 4: Review the approach and better 2. Write the algorithm steps for each
N

alternative activity in (1).


The best algorithm must comprise
LI

the best approach to solving


Exercise 3.1
a problem that reduces the
N

coding efforts and decreases the Answer the following questions:


program’s time and complication.
O

1. Describe a problem solving process.


For that reason, when you think of
a problem-solving approach, try 2. Why is problem solving important
to think about a better alternative in our daily lives?
R

for producing the best results. 3. Identify one problem in the school
This will assist you in creating setting and develop a plan to solve it.
FO

an advanced programming logic. 4. Explain the meaning of algorithm.


Review the approach to ensure
5. Assume that studying algorithms
that it solves the problem.
seems to be complicated and

126
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 126 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
nonsense to one of your friends Types of flowcharts
in your class. Collect the pieces Flowcharts can be classified into two
of evidence on the uses and categories: Program flowchart and System
importance of algorithms that will flowchart.
assist you in convincing him or her Program flowcharts act like mirrors
to appraise and change his or her of computer programs in terms of
way of thinking. flowcharting symbols. They contain the
6. What would you consider to steps of solving a problem unit for a
ensure that your algorithm gains specific result.

LY
acceptance.
System flowcharts contain the solutions
7. Write an algorithm for withdrawing of many problem units closely related
money from your bank account

N
to each other and interact to achieve a
using an ATM card. goal. In this section, you will mainly focus

O
8. Write an algorithm to calculate the on program flowcharts. The program
area of a square. flowchart is the most convenient tool in
program development for the following

Representation of algorithm using


SE
reasons:
First, any error or omission can be more
easily detected from a program flowchart
flow chart than from a program because a program
U
flowchart is a pictorial representation of
Meaning of a flowchart the logic of a program.
A flowchart is an illustrative representation Second, a program flowchart can be
that shows the sequence of operations followed easily and quickly. Third, it
E

that must be followed to solve a problem. serves as a type of documentation which


may be of great help in the future program
N

It can be defined as a diagrammatic


modification.
representation of an algorithm. When
LI

formulating computer solutions, Uses of flowcharts


flowcharts are usually drawn in the early Flowcharts can be used in our daily
N

stages. A flowchart is constructed using lives. The following are some of the
different types of boxes and symbols. uses of flowcharts:
O

(a) To communicate ideas and solutions


to problems.
The flowchart uses a series of blocks and
(b) To document both simple and
R

arrows, each representing a particular step


complex processes as it eases
in an algorithm. One of the significances of understanding of the process itself.
FO

a flowchart is that it is helpful in detailed (c) To inform others on how a process


representations of complicated programs. is accomplished, it enables
It is also beneficial in understanding the understanding of the logic of a
logic of complex and extensive problems. process.

127
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 127 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

(d) They help to clarify how things are Disadvantages of flowcharts


currently working and how they Although a flowchart is a convenient tool
could be enhanced. for problem solving skills acquisition,
(e) They help to find the main elements there are a few limitations to use it.
of a process when drawing clear lines (a) Alterations and modifications: the
between the ends and the starting of flowchart may require redrawing if
the subsequent procedure. alterations are required.
(f) To stimulate communication among (b) Reproduction: as the flowchart
members and establish a common symbols cannot be typed,
reproduction of the flowchart

LY
understanding of the process.
Flowcharts also expose steps that becomes a problem.
are redundant or misplaced. (c) The essentials of what is done can
be easily lost in the technical details
(g) To help team members to identify

N
of how it is done.
who provides inputs or resources to
(d) Complex logic: sometimes, the
whom, to establish essential areas

O
program logic is quite complicated.
for monitoring or data gathering, to
In this case, the flowchart becomes
identify areas for improvement or
challenging.
increased efficiency, and to make
assumptions about causes. SE
Rules for drawing flowcharts
The following six rules should be followed
Advantages of flowcharts
when creating program flowcharts:
U
(a) Practical analysis: the problems can
(a) Standard symbols only should
be more effectively analysed with
be used in program flowcharts as
the use of flowcharts.
shown in Table 3.1.
(b) Efficient coding: flowcharts act
E

(b) The program logic should indicate


as guides or blueprints during
the flow from top to bottom and left
N

system analysis and program


to right.
development phase. You can easily
(c) Each symbol used in a program
LI

convert flowcharts into code in any


flowchart should contain only one
programming language.
entry point and one exit point,
(c) Proper documentation: program
N

except the decision symbol. This is


flowcharts serve as good program
known as the single rule.
O

documentation which is required for


(d) The operations shown within a
various purposes.
symbol of a program flowchart
(d) Communication: flowcharts are
should be expressed independently
R

a more effective technique for


of any particular programming
explaining the logic of a system to
language.
FO

all concerned.
(e) All decision branches should be
(e) Efficient maintenance: flowcharts
labelled clearly.
help in doing maintenance when the
(f) All components of a flowchart
developed program stop working.
should be connected with arrows.

128
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 128 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
Table 3.1: Symbols and various shapes of flowcharts

S/N Description Symbol


1. Process symbol:
This is a step for process. The step is written inside
the box. Usually, only one arrow goes out of the box.
This indicates any type of internal operation inside the
Processor or Memory

LY
2. Flowlines symbol:
An arrow shows direction of flow from one step or
decision to another

N
3. Decision symbol:
This is a diamond shaped symbol used in a flowchart

O
to indicate a point at which a decision has to be made
and a branch to one or two more alternative points is

SE
possible. Always the decision symbol has two exits.
One is labelled YES or TRUE and the other NO or
FALSE. The decision is based on the question. The
question is written inside the symbol. More than one
U
arrows go out of the diamond, each arrow showing the
direction which a process takes for a given answer.
4. Delay or wait symbol:
E

This is used to depicts any waiting period that is part


of a process.
N

5. Connector symbol
LI

This is represented by a circle and a letter or digit. It


specifies a link to another page or another flowchart
N

when a complex flowchart is to be drawn with various


directions of flow lines. The same symbol on the other
O

page indicates that the flow continues there.


6. Input or output symbol:
R

This is used for both input (read) and output (write) to


denote any function of an I/O device
FO

7. Printed Document:
This specifies if input or output from the process is in
form of printed document

129
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 129 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

8 Terminal symbols:
These are alternative for start and end points. They
always begin and end the flowcharts. Start symbol
can have only one flow line but no entering flowline.
The stop symbol can have an entering flow line but
no exit.

These are few symbols which are Step 5: Draw a flowchart as shown in

LY
commonly used. But, you may find Figure 3.2.
more other symbols depending on the
complexity of the system you are analysing Start

N
and need to construct a flowchart.

O
Steps for drawing a flowchart Input N1, N2
There are various steps in drawing a
flowchart depending on the nature of the
problem. SE SUM = N1 + N2
Example 1
U
Draw a flowchart for a program that
will help to calculate the sum of any Output SUM
two numbers entered by the user.
E

The following are the steps for


End/Stop
N

drawing a flowchart for program that


will calculate the sum of any two
LI

Figure 3.2: Flow chart for sum of two


numbers: numbers
Step 1: Identify the inputs (two
N

numbers, for example, N1


Example 2
and N2),
O

Step 2: Define the processes or Write an algorithm to find the square of


actions, i.e. adding or a number and draw a flowchart.
calculating the sum of the Before developing the algorithm, you
R

two numbers. should first identify the input, process


and output. In this case, input will be the
FO

Step 3: Identify the output. Output


is the SUM. number whose square is required. The
process will be to multiply the number
Step 4: Identify the standard symbols
by itself to get its square, and the output
used in the problem.

130
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 130 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
will be the square of the number. The instructions that a computer must follow in
following is the algorithm to find the a particular order to solve a given problem.
square of a number: Pseudocode is a non-formal language that
Step 1: Identify input. Input here is helps programmers to write algorithms.
a number to be entered in the It is a type of structured English/Swahili
‘Num’ used to specify an algorithm. It is neither
Step 2: Define process or action. Action compiled nor executed by a computer, and
here is to multiply where you there are no accurate formatting or syntax
compute Num * Num which is rules for writing them. Thus, pseudocode

LY
a product as output for Square. is neither an algorithm nor a program. It
Step 3: Determine or identify output. is an abstract form of a program that does
The output here is to Print not use any graphical representation other

N
Square. than words and phrases.

O
The flowchart will be as shown in
Figure 3.3. The importance of pseudocode
The pseudocodes are easy to read,
Start
SE
understand, and modify. Pseudocode
helps review the steps to confirm that
the expected implementation will achieve
Input Num
U
the desired output.

Advantages and disadvantages of


E

Square = Num * Num pseudocodes


Advantages of pseudocodes
N

The following are the advantages of a


Print Square pseudocode:
LI

(a) It can be easily modified, unlike


flowcharts.
N

Stop (b) It can be read and understood easily.


O

Figure 3.3: Flowchart to compute square (c) It is easier to convert the pseudocodes
of two numbers to a programming language than
flowcharts.
R

Representation of algorithm using (d) It is helpful in structured design.


pseudocode
FO

(e) It can be easily written in any word


Meaning of pseudocode processor application software
Pseudocode is a representation of algorithm
that contains a detailed description of

131
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 131 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Disadvantages of pseudocodes pseudocodes. As a result, we can


The following are the disadvantages of have different pseudocodes from one
pseudocode: problem.
(a) It is more difficult for a beginner to
follow the logic or write pseudocodes In pseudocode, keywords are used to
than a flowchart; indicate common input, processing
(b) It is not easy to interpret the operations and output. Remember, they
pseudocode for a novice programmer; can be written entirely in uppercase or
and start with a capital letter. The commonly

LY
(c) There is no standard way of writing used keyword as described in Table 3.2.

N
Table 3.2: Standard keywords in pseudocodes

Item Keyword Description

O
1. START/BEGIN This is used whenever you start your
pseudocode.

2. INPUT
SE
This is data retrieved from the user
through an input device
U
3. READ / GET This is the input used when reading data
from a file
E

4. PRINT, DISPLAY, SHOW This will show your output to a screen or


any output device
N

5. COMPUTE, CALCULATE, This is used to calculate the results of an


LI

DETERMINE expression
N

6. SET It is used to initialise values or assign a


value to a variable
O

7. INCREMENT It is used when you want to increase the


value of a variable by a given value
R

8. DECREMENT This keyword is meant to reduce the


value of a variable by a particular value
FO

9. END Used to indicate the endpoint of the


program or a process

132
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 132 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
Rules for writing pseudocodes SET Min=num3
(a) Only one statement should be written PRINT Min
for each line, where each statement END
should represent a single action.
(b) The input, output and process
(e) Pseudocode should show clearly
statements must be clearly stated
the start and stop of executable
using English like language
statements and control structures.
keywords such as READ, PRINT,
WRITE, DISPLAY, RETURN. For (f) The statement should be short, clear

LY
example, and readable.
START Example 1
READ a, b, c

N
Suppose you are given a task to add and
c = a+b
find average of two numbers entered

O
PRINT c by the user. Write a pseudocode to
END calculate the sum and average of the
(c) Each initial keyword should be two numbers and display output on
capitalised. For example, the
pseudocodes to calculate the area
SEthe screen.

Procedures:
of a triangle.
(a) From the problem, think about what
U
START
will be your input. For example, let
READ base, height, area the two numbers be X and Y.
COMPUTE: (b) Identify the processes in this case
E

area=0.5*base*height by adding the two numbers X and


Y and dividing the sum by 2 to get
N

PRINT area
average.
END
(c) Identify the outputs, in this case,
LI

(d) Show indentation for each as SUM and AVERAGE, and the
structure hierarchy (selection and pseudocode for calculating the sum
N

loop) structures. For example, the and average will be as follows:


pseudocodes to find the minimum
O

of the three numbers. START


PRINT “Enter two numbers.”
BEGIN
INPUT X, Y
R

READ num1, num2 and num3 SUM = X+Y


SET Min=num1 AVERAGE = SUM/2
FO

If (num2<num1) PRINT SUM


SET Min=Num2 PRINT AVERAGE
If (num3<Min) END

133
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 133 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Example 2
Computer Science

START
Write an algorithm that will display READ num1, num2
the sum of two numbers entered by a COMPUTE Result = num1 + num2

user using pseudocode and then draw PRINT Result


END
a flowchart.
The flowchart for this algorithm is
Procedures: illustrated in Figure 3.4.
(a) In this case, you have to think Start

LY
of the inputs to the program, the
two numbers: the first and second Read num1,num2
numbers.

N
(b) The second thing is the actions Result=num1+num2

O
of processes to be performed by
the program, which is adding/ Print Result
computing (RESULT) and
displaying the output (PRINT) and
the pseudocode for the sum of two
SE Stop

Figure 3.4: Flowchart to display the sum


numbers will be as follows: of two numbers
U
Comparison between flowchart and pseudocode
Table 3.3 shows the comparison between flowchart` and pseudocode Algorithim
E

Table 3.3: Comparison between flowchart and pseudocode


N

Flowchart Pseudocodes
1. A flowchart is a diagrammatic A method of representing the step-by-
LI

representation of an algorithm. It step logical procedure for solving a


is constructed using different types problem.
N

of boxes and symbols.


2. The flowchart employs a series of It contains detailed English descriptions,
O

blocks and arrows, each of which each step representing a particular


represents a particular step in an operation leading to the solution of the
algorithm. problem.
R

3. Flowcharts are useful for detailed Pseudocodes are particularly useful for
FO

representations of complicated minor problems.


programs.
4. For complex programs, Flowcharts For complex programs, algorithms prove
prove to be adequate. to be inadequate.

134
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 134 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
Control structures in flowcharts A good example is adding numbers or
and pseudocode any action with a series of steps before
The control structure is dedicated to termination. The following example
decision-making issues. Selection is a illustrates the flowchart using sequential
logic structure used to implement this control structure for a program to add
decision-making process. A condition two numbers as shown in Figure 3.6.
is evaluated to determine whether it is
Start
true or false. If it is true, a course of
action is prescribed; if it is determined

LY
to be false, an alternative path of action Input N
is suggested. A control structure is just
a portion of the code or statements
Input M

N
that support given decisions based on
analysis of the variable. There are three

O
basic types of control structures which Sum = N + M
flowcharts and pseudocodes operations
employ. These are:
(a) Sequence control structure.
(b) Selection control structure.
SE Output Sum

(c) Iteration control structure. END


U
Figure 3.6: Example of sequential control
Control structures in flowcharts structure
In drawing flowcharts, control structures
Selection control structure in flowcharts
E

can be used to represent control of the


process flow in terms of sequence, selection The selection control structure is used
N

and iteration as shown in Figure 3.5. to decide on a program. The selection


Iteration control structure makes the best paths
Sequence Selection
LI

between the two or more options


T F given in the logic of the program. One
N

T condition is evaluated first and then


F flows into one of two or more paths.
O

Once the conditional execution is


finished, it will rejoin before leaving the
structure. It uses IF….THEN or IF….
R

Figure 3.5: Control structures


THEN ….ELSE or a CASE structure in
Sequence control structure in flowcharts pseudocodes and program.
FO

The computer reads an instruction from IF … THEN


a program file line by line sequentially, IF….THEN structure executes the
starting from the first line. Then executes process if the condition is true, and if
the tasks that are arranged sequentially. it is not true, it skips the process. The

135
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 135 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

diamond-shaped box in flowcharts


represents the decision or condition.
The syntax for IF…THEN : True Condition False
IF (Condition) THEN
Statement
Statement 1 Statement 2
END IF;
And its flowchart is represented as
shown in Figure 3.7:

LY
Figure 3.8: Example of IF-THEN-ELSE
YES

N
Condition selection

O
IF…. THEN …. ELSE IF
You can introduce this IF statement if
Statement(s) NO you want to select an action from several
SE
alternatives. This statement introduce
the additional conditions. If condition1
is false the Else if executes another
condition. In this form of IF statement
U
more than one Else if can be used. All
Figure 3.7: Example of IF-THEN selection
conditions in the statement are evaluated
one after another from top to bottom,
E

IF…. THEN …. ELSE when one of them is true then it will be


If the condition is true, it executes executed. If all conditions are false, the
N

process 1; if the condition is false, sequence in Else clause is executed.


it will perform the second process The syntax for IF…THEN…ELSE IF :
LI

(process 2). In this case, process 1 or IF (condition1) THEN


process 2 will only be implemented
N

depending on the given condition. sequence_of_statements1


The syntax of If…..THEN…..ELSE is ELSE IF (condition2) THEN
O

shown as follows: sequence_of_statements2


IF (condition) THEN
ELSE
R

Statement 1
ELSE sequence_of_statements3
FO

Statement 2 END IF;


ENDIF; And its flowchart is represented as in
And its flowchart is represented as Figure 3.9:
shown in Figure 3.8:

136
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 136 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
some balance on their mobile. However,
such calls are usually terminated when
there no balance on their mobile phone
Yes
If condition 1 Statement 1 account. The case can be represented by
a flowchart in Figure 3.10:
No

Yes
If condition 2 Statement 2

LY
No Loop
Condition
Yes
If condition 3 Statement 3
True

N
False
Statement (s)
No

O
(Loop body)
Statement

Stop
SE Figure 3.10: WHILE-Loop control structure
Figure 3.9: Example of IF-THEN-ELSE IF
U
selection For the case of the DO…. WHILE it
checks the condition for the loop at the
Iteration control structure in flowcharts bottom. Therefore, the loop’s body is
The term iteration means repetition executed at least once regardless of the
E

or looping. Sometimes, a procedure loop as shown in Figure 3.11.


N

should be performed repeatedly. All


procedures should be constructed to be
LI

repeated as many times as needed. This


control structure gives loops in the logic
once one or more instructions may be Statement (s)
N

performed several times or depending True (Loop body)


on some conditions. ”WHILE” and
O

“DO …. WHILE” is commonly used in


iteration or looping. It loops up to the
conditions that becomes TRUE. Loop
R

Condition
WHILE….. loop is usually used when
FO

False
the condition has been met before the
statement inside the loop is performed.
For example, the mobile phone users
will make as many calls if they have Figure 3.11: DO --- WHILE control structure

137
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 137 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Examples of the flowchart for various


problems Start
The following examples illustrate the
various problems using control structures.
Enter marks

Example 1
Sequential structure procedure for Yes
is marks>50
No
calculating area of a triangle as shown

LY
in Figure 3.12.

Display “Pass” Display “Fail”


Start

N
End

O
Read Figure 3.13: Example of iteration control
base and height structure

Compute
SE Example 3
Flowchart for both iteration and
U
Area of triangle = 0.5 * base*height
selection structure procedures as shown
in Figure 3.14. This example is about
finding the factorial of a given number
E

Print
Area of triangle Start
N

READ num 1
LI

I=1
Stop New_fact=1
N

Figure 3.12: Example of sequential control False


Is I<num1
O

structure True
New_fact=new_fact*i
Print
New_fact
Example 2
R

I=I+1
Selection procedures for evaluation
FO

of student score to determine the pass


End
or fail of the student in an exam is as
Figure 3.14: Example of both iteration and
shown in Figure 3.13.
selection control structure

138
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 138 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
Example 4 (b) Please choose one of the activities
in (a) above
Example iteration control structure
for counting numbers from 1 to 5 as (c) Identify the inputs, process, and
shown in Figure 3.15. output elements.
(d) Identify the standard symbols for
Start
(c) above.
(e) Present it using a flowchart.
Set count

LY
equal to 1 (f) Has the decision made before or
count = 1 after it been evaluated?

N
Is no Exercise 3.2
count ≤ 5?

O
yes Answer the following questions:
1. Explain the meaning of flowchart
Print count’s
value SE as used in computer science.
2. Describe the types of flowcharts.
3. Give three advantages and
U
Increment disadvantages of flowcharts.
count’s value
count = count+1 4. Describe any four basic symbols
used to draw flowcharts.
E

5. Write an algorithm and draw a


Stop flowchart to accept numbers until
N

the user enters 0 and then finds their


Figure 3.15: Iteration control structure for
average.
LI

counting number
6. Develop a flowchart to show how
N

the profit or loss can be obtained.


Activity 3.3 7. Draw a flowchart representing a
O

set of activities you perform when


Flowcharts related to day-to-day you wake up daily.
real lives
8. Tell whether the flowchart in (7)
R

(a) Think about numerous activities above is sequential, selection,


in our daily lives which involve iterative, or all of them.
FO

individuals making the selection of 9. Think of any activity you perform


one course of action and presenting
daily in life that is iterative and
one of them using a flowchart.
draw its flowchart.

139
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 139 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Control structures in pseudocode The flowchart for this algorithm is


In writing pseudocode, precise instructions illustrated in Figure 3.16.
as statements will be referred. It will be
assumed that the order of execution of Start
the statements is from top to bottom.
The writing varies when using control
structures and functions. The following Read num1,num2
examples demonstrate the use of

LY
pseudocode in sequence, selection and
iteration control structures: Result=num1*num2

N
The use of pseudocode in sequence
control structure Print Result

O
Example 1
Stop
Write a pseudocode and its
corresponding flowchart for a program
to find the product of two numbers
SE
Figure 3.16: Flowchart for product of two
numbers to demonstrate
sequence control structure
entered by the user.
U
Procedures:
The use of pseudocode in selection
(a) In this case, you have to think of the
control structure
inputs to the program, that is, the
E

two numbers, the first and second Example 2


N

numbers.
Write the pseudocode that will decide
(b) The second thing is the actions students with marks greater than 45 as
LI

of processes to be performed by pass; otherwise, display fail.


the program, which is computing
N

The determined condition is ‘If a


(RESULT) and displaying the student’s grade is greater than or equal
results (PRINT) and the pseudocode
O

to 45’:
will be as follows: START
READ marks
START
R

IF marks >=45
INPUT num1, num2 PRINT “passed”
ELSE
FO

COMPUTE Result = num1 * num2


PRINT “failed”
PRINT Result ENDIF
END END

140
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 140 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
The use of pseudocode in iteration control structure.
Example 3
Write the pseudocode to calculate the average score of the class.
Procedures:
(a) In this case, you need to initialise Counter (to keep track of number of students)
and Sum to 0
(b) Identify number of students (Num) in a class

LY
(c) Use loop like While to get marks, add marks to the Sum
(d) Increment the Counter and loop
(e) Compute Average and display it.
The pseudocode will be as follows:

N
START

O
Sum = 0
Counter = 0
READ Num



WHILE Counter < Num
READ Marks
SE
COMPUTE Sum = Sum + Marks
COMPUTE Counter = Counter + 1
U
ENDWHILE
COMPUTE Average = Sum / Num
PRINT Average
E

END
N

Example 4
LI

Write the pseudocode that will identify and display the age of parents of students
who have age below 45 years or more than it.
N

Procedure:
Step 1: Think of the entry to the program, which is the input value. In this case, it
O

is the age which will be stored in variable ‘age’. INPUT will be parents
inputs their age.
R

Step 2: Introduce the condition and actions of processes to be performed by the


program.
FO

Insert the first condition which is to check if the age is less than 45.
If the value is less than 45 then the action required will be to print
the output comment. Otherwise, the else comment will be printed. The
following is a condition:

141
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 141 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

READ age
IF age<45 THEN
OUTPUT ‘My age is less than 45’
ELSE
OUTPUT ‘My age is greater than 45’
OUTPUT ‘My age is:’ age
ENDIF

Step 3: Present the pseudocode:

LY
START
IF age<45 THEN

N
PRINT ‘My age is less than 45’
ELSE

O
PRINT ‘My age is greater than 45’
PRINT ‘My age is:’ age
END

Creating flowcharts from pseudocode


SE
The algorithm written using pseudocode can be transformed into a flowchart without
U
altering its intended meaning and output. The following example illustrates how a
pseudocode can be transformed into flowchart:
E

Example 5
The flowchart for the algorithm will
Write an algorithm by using
N

be as shown in Figure 3.17.


pseudocode and flowchart to find the
largest and smallest numbers between
LI

Start
A and B.
Read A, B
N

Procedure:
The pseudocode for the above problem BIG=A No Yes BIG=B
O

A < B? SMALL=A
is as follows: SMALL=B
START
READ A, B Write BIG, SMALL
R

IF A is less than B THEN


BIG=B SMALL = A Stop
ELSE
FO

BIG=A SMALL = B
ENDIF Figure 3.17: Flowchart to display the big
DISPLAY BIG, SMALL and small numbers
END

142
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 142 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
Activity 3.4 4. List down the rules for writing
pseudocode.
Pseudocodes related to day-to-day
5. Write a pseudocode for program
real lives
that will output the cuberoot of
1. Think about a tour of your friend
any number input until the number
to visit your new home place. The
input is zero.
place is new to him/her.
2. List down step by step instructions 6. Using Loop control structure, write
the pseudocode to calculate the sum

LY
that you will give to a friend to
reach your place. and average of numbers.
3. You might need to know some 7. Write a pseudocode to print out

N
information such as transport to each character typed at a keyboard
help you direct your friend. until the character t is reached.

O
4. Use the information above to write 8. It is required to digitize the process
a pseudocode and flowchart.
of doing examination marking and

Exercise 3.3
SE disseminating the result whereby all
task should be done online. Develop
the algorithms to accomplish these
Answer the following questions:
U
operations by using pseudocode.
1. What is pseudocode?
9. Prepare a pseudocode and flowchart
2. Explain why pseudocodes are for converting temperature
said to be preferred by many
E

Fahrenheit into Celsius. The inputs


programmers over flowcharts. to the algorithm are temperature in
N

3. Describe the advantages and Fahrenheit and the expected output


disadvantages of pseudocode. is temperature in Celsius.
LI

Chapter Summary
N
O

1. An algorithm is a step-by-step procedure designed to perform an operation that


will lead to the desired result if followed correctly.
2. Algorithms have a definite beginning, an end, and a finite number of steps.
R

3. A good algorithm is precise, unique and limited; receives input and produces
FO

an output.
4. Algorithms are represented using flowcharts and pseudocodes. A flowchart is a
diagram that represents the algorithm graphically using boxes of various kinds
in an order connected by arrows.

143
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 143 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

5. An algorithm, where all the steps are executed one after, the other is said to
run in sequence. Decision-making involves selecting one of the alternatives
based on the outcome of a condition.
6. An algorithm may have a particular set of steps repeated in a finite number of
times such an algorithm is said to be iterative.
7. There can be more than one approaches to solving a problem, and hence we
can have more than one algorithms for a particular situation. The choice of an
algorithm should be made based on time and space complexity.

LY
8. Several keywords are often used to indicate common input, output, and processing
operations: Input: READ, GET, OBTAIN; Output: DISPLAY, PRINT, SHOW;
Compute: COMPUTE, CALCULATE; Initialise: SET, INIT; Add or reduce

N
one: INCREMENT, BUMP or DECREMENT

O
Revision Exercise 3 8. Write the pseudocode to print all

1. Explain the meaning of flowchart


as used in computer science.
SEmultiples of 4 between 12 and 32
(including both 12 and 32).
9. Write an algorithm using
pseudocode and flowchart that
U
2. Describe the types of flowcharts.
performs the following: Ask a user
3. Give three advantages and to enter a number. If the number is
disadvantages of flowcharts. between 5 and 14, write the word
E

4. Describe any four basic symbols AT PRIMARY SCHOOL. If the


used to draw flowcharts. number is between 15 and 22, write
N

the comment “AT SECONDARY


5. Write an algorithm that accepts
SCHOOL”. If the number is
LI

four numbers as input and find the


between 23 and 30, write the
largest and smallest of them by word “IN UNIVERSITY”. If the
N

using pseudocode and flowchart. number is above 30 and less than


6. Write an algorithm to find greater 60, write “WORK HARD” else,
O

number between two different write “ENJOY YOUR LIFE”.


numbers entered by the user in 10. Assume your school has a shop
R

algorithm. Use pseudocode and which sells different stationaries,


flowchart to present your answer. and the head of your school chose
FO

you as a shopkeeper. Draw a


7. Give an example of a loop that is
flowchart to show how the profit
to be executed a certain number of
or loss for a sale of goods obtained
times.
at the shop.

144
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 144 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Three: Problem solving


DO NOT DUPLICATE
11. Write pseudocode that reads two the students; her marks of three
numbers, divides one by another, subjects were corrected to 52, 75,
and displays the quotient. and 91. She introduced you to her
class master to plan and develop a
12. Write pseudocode and flowchart
flowchart that will be used to solve
that will perform the following:
the problem. Sambayeti asked you
(a) Read the marks of three subjects to:
out of 100: Computer Science, (a) Draw a flow chart to calculate
Biology and Chemistry.

LY
the average score of Amina.
(b) Calculate the average and (b) Draw a flowchart assisting
display it. in deciding the students who

N
met the criteria to proceed to
13. Most form four candidates seek
form six if only those with an
admission to private schools after

O
average of 60 will be allowed
their examination results. Some
to move to their next year.
private schools give them other
(c) Draw a flowchart if a new
exams as the criteria to admit only
those who pass their exams to fill
the available places. As a computer
SE policy requires that students
with <= 45 to automatically
repeat a year while those with
science student, you have been
U
average marks of 45 and 60 to
consulted by the director of XYZ
repeat their exams.
schools to develop a flowchart
15. What are the names and the use of
that will later be used to create a
the following symbols?
E

program to help students to search


schools.
N

(a) (b)
14. Sambayeti is a class master of form
LI

five PCB students at Kenyana high


school. He usually gets complaints (c) (d)
N

from some of his students about


the wrong computation of their
O

marks which leads to bad grades. (e)


Your friend Amina was one of
R
FO

145
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 145 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Chapter
Four C++ programming

Introduction

LY
The purpose of using computers is to simplify solving problems that are difficult
to tackle using traditional means. However, the computer cannot work without
programs. Programs provide interactions between people and computer

N
systems. Programs also enable the computer to perform work efficiently
and accurately. This chapter introduces you the principles of computer

O
programming and how to program using a C++ programming language. The
competency developed in this chapter will help you to create programs which

SE
have the potential of solving different problems in the society.
U
Think about the following:

(a) Scripting language used by software which instruct advanced medical equipment
E

such as MRI machines; and language used to develop computer games.


(b) How you can simplify the exercise of getting a National Identity Card for all
N

Tanzanians.
LI

(c) How the payment system for electrical bills can be automated such that after
buying electricity, you do not need to enter code numbers into a LUKU meter
manually.
N
O

Introduction to programming what to do and how to do it. In order to


languages create computer programs, you need a
R

Computer program is a set of instructions special language to instruct the computer


that guide a computer hardware to because it cannot understand normal
FO

accomplish a specific task. The act human languages such as English and
of creating a program is known as Swahili. Languages used to program the
programming. When you write a computer computer are known as programming
program, you are instructing the computer languages.

146
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 146 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
There are many types of programming follow a number of steps that are related
languages such as C, C++, C#, Java, to problem solving. These steps comprise
JavaScript, Python, Ruby, and Visual defining and analysing the problem,
Basics. Programmers use programming
designing or planning the solution, coding
language to construct programs which
are later commanded by a user to the program, testing and debugging the
accomplish a certain task. Before program and documenting as described
creating programs, programmers should in Chapter 3.

LY
Important terms used in programming language
Source code
A source code, also known as codes, is a collection of computer instructions written

N
by a programmer in a high-level or intermediate programming language. It may
include comments to aid with reasoning and maintenance of a program. The source

O
code may be written in C++, Java, Python, PHP and other languages. A source code
is machine dependent. An example of a source code in C++ is:
void main()
{
cout << “What is your name?”;
SE
}
U
Object code
An object code is a machine-readable code in a binary format (0s and 1s) that is
E

obtained after converting source code. The object code is also known as machine
code because it can only be read and understood by the processor. The following is
N

an example of oject code.


LI

Source code Object code (Just an example)


void main() 011101001010
à
N

{ 10100101001
cout << “The year 2022?” 01011100110
O

} 11001001010

Translators
R

Translators are programming language processors required to change a program


into the machine-readable languages. There are three main categories of translators
FO

namely assemblers, interpreters and compilers.

Assemblers
Assemblers are programming language processors required to convert programs

147
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 147 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
designed by assembly language into the machine codes which a computer can
Computer Science

execute easily.
Source code in Assembly Object code
assembly language

Interpreters
An interpreter is a type of translator which translates source code into object (machine)
code in the order of one statement at a time. This is to say, it does not translate the
whole program written in high level language at once. Such a translation occurs for

LY
a program that requires a small memory size. Otherwise, much time will be needed
to translate a program that requires large memory size. Examples of programming
languages that use interpreters are Perl, Ruby, Python, and PHP.

N
Source code in high Interpreter Object code
level language

O
Compilers
A compiler is used to convert a whole program written in higher level language into
SE
object (machine) code at a time, which can be understood by a computer hardware.
For that case, the compiler uses less time in compilation compared with interpreters.
Compilers involve the stage of compiling, linking with a system library and executing
U
a program. Examples of compilers are Dev, Boland, Visual C++.

Source code in high Complier Object code


level language
E
N

Background to computer They are not portable; hence, they are not
programming languages easy to be transferred from one computer
LI

Historically, computer programming to another. The reason for importability


is due to the fact that only the same
languages have passed through five (5)
N

processor of a particular manufacturer


generations. These generations can be
that a language was designed for can read
divided into two levels of programming
O

the codes written in that computer for


languages: Low-level programming processor to translate. It is not possible
languages and High-level programming for the same codes to be read in another
R

languages. type of a processor. These languages


are machine dependent, and they do not
FO

Low-level programming languages require any compiler to translate them to


Low level programming languages are machine codes. Examples of low level
characterised by little effort to translate programming languages include machine
programs into machine readable forms. languages and assembly languages.

148
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 148 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Advantages of low-level programming High-level programming languages
languages High-level languages are machine
(a) Programs designed by using low-
independent. This means that, the
level memory require less memory
execution of the program designed by high-
to be executed. For that case, they
run fast. level language does not interfere with the
normal operation of the computer system.
(b) Low-level languages do not need
compilers or interpreters to change Unlike low-level languages, high-level
into machine readable form. languages are closely related to human

LY
(c) Since a low-level language is closely languages and not machine language.
related to a machine language, it Examples of high-level programming
provides direct interaction with the languages include Pascal, Fortran,

N
internal memory of the computer. COBOL, C, C++, Java, JavaScript, Visual
(d) Low-level programming languages Basics and Python.

O
provide a conducive environment
for utilising a processor. Types of high-level languages
(e) There is direct communication
between hardware parts and low-
level programming languages.
SE
High-level programming languages can be
categorized into eight (8) types as follows:

Commercial languages
U
Disadvantages of low-level These are programming languages used
programming languages for commercial purposes such as COBOL
(a) Low-level languages need high (Common Business Oriented Language).
E

expertise in programming to design


a program.
N

Scientific languages
(b) The programs created with low-level These are programming languages
LI

language are not portable simply used for engineering and scientific
because they cannot be transferred purpose, such as FORTRAN (FORmula
N

from one hardware or software to


TRANslation).
another.
O

(c) Low-level programming languages Special-purpose languages


have challenging environment for
These are programming languages
developing and executing programs.
R

intended to be used for a specific purpose


(d) Using and learning low-level
languages is not easy compared to such as air traffic control and space
FO

high-level languages. technology. Examples include Ada, and


(e) It is complicated to debug errors in database language Structured Query
low-level languages Language (SQL).

149
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 149 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Command languages for the operating inheritance. Examples of object-oriented
Computer Science

system programming languages are C++, C#,


These are programming languages created Java, JavaScript, VisualBasic.Net and
to communicate with the operating Python.
system and control operations within
the computer system. An example of Multi-purpose languages
command languages, for operating system These are programming languages
is Shell language within UNIX operating required to perform different tasks.
system. Examples include C, C++, Java, JavaScript

LY
and Python.
Scripting languages
These are programming languages that do Advantages of high-level
not need to be translated into machine code

N
programming languages
before running. This means, compilation (a) High-level languages provide an
is not required to execute scripting

O
easy way to recognise programs
languages. Most scripting languages are prone to errors.
used to design and activate web pages.
(b) High-level languages are machine
Examples of scripting languages are
JavaScript, VBScript, PHP, Perl, Python
and Ruby.
SEindependent, and they are portable
programming languages that can
easily be transferred from one device
to another.
U
Procedural programming languages
(c) High-level languages provide
These programming languages divide a conducive environment for
a program into blocks of codes known developing, executing, and
E

as structured programs. They design maintaining a program.


a program in a sequence of steps or (d) High-level languages provide an
N

procedures made by a systematic easy way to learn and use them.


arrangement of functions, commands, and
LI

(e) Since high-level languages run on


variables to accomplish a particular task. different platforms, they are widely
Examples of procedural programming used for programming.
N

languages are Pascal, BASIC, C,


FORTRAN and COBOL. Disadvantages of high-level
O

programming languages
Object-Oriented programming language (a) The program which is developed
R

These are programming languages made by by high-level languages must be


many functional blocks known as objects. interpreted or compiled to change
FO

Each object contains instructions similar it into machine-readable form.


to procedural programming. Object- (b) They are not fast as they require time
oriented programming is characterised to change a program from a source
by polymorphism, encapsulation and code to an object code.

150
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 150 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
(c) They overload the processor by using First generation computer
several typed statements, hence, programming (Machine language)
slowing the computer’s processing Instructions in a machine language are
speed. written by using binary codes or digits,
(d) They need enough memory to be including 0 and 1. Machine language
maintained and executed. Since high- involves simple operations such as
addition or subtraction of numbers. Since
level languages are not practiced in
the computer understands binary codes,
machine codes, they have no direct
a program which is written in a machine

LY
interaction with the hardware device.
language does not need further translation.
For that case, a program which is written
Generations of programming in machine languages can be easily
languages

N
executed by the computer. However, it
In generations of programming languages, is challenging to read and understand the

O
low level languages are grouped in two program written in a machine language
generations namely first generation and because one must have programming
second generation, while, high-level knowledge of machine instructions.
languages can be grouped into three
generations, namely third, fourth and
SE
An example of a program written in a
machine language is represented in Table
fifth generation. Therefore, there are 4.1. The program adds two numbers stored
U
five generations of the programming in locations 0 and 1, and places the result
languages as follows: in location 2.
E

Table 4.1: A program to add two numbers


Location of Machine Instruction
N

Instruction Function code Operand address


LI

0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0
N

2 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
O

Second generation computer programming (Assembly language)


Assembly language involves a set of symbolic operations called mnemonics.
R

Mnemonics are codes made up of two or three letters such as LDN, STA and JPU.
Normally, features of the assembly language differ from one computer to another. A
FO

program written in assembly language should be translated from the source program
to the machine code which is known as object code. The program which is required
to translate assembly language into the machine codes is known as assembler. An
example of a program written in assembly language is represented in Table 4.2.

151
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 151 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Table 4.2: A program to add two numbers using assembly language
Computer Science

Program Meaning of codes


1. MOVESTACK INDEX 1. Save the current base address of the stack in
index register.
2. PUSH FIRST 2. Push the first number on the stack.
3. PUSH SECON 3. Push the second number on the stack.
4. INC STACK 4. Make space on the stack for the third number.
5. JSR OAA 5. Jump to subroutine which orders and adds.

LY
6. POP TOTAL 6. Remove the total from the stack.
7. POP SECON 7. Remove the second number from the stack.
8. POP FIRST 8. Remove the first number from the stack.

N

Third generation programming languages

O
Third generation languages involve programming languages that can divide a
program into subprograms known as procedures. Sometimes third generation
languages are called structural or procedural languages. A structural programming
SE
language is simple, readable and easily recognised by a human being. Structural
programming languages apply few and simple control structures compared with
other high-level languages. Examples of third generation languages are Pascal,
U
FORTRAN, COBOL, BASIC, Ada and C.

Program Example 1:
E

Adding two numbers using Pascal language


The following program example adds two numbers written in Pascal language.
N

Program addition (input, output);


LI

uses crt;
Var
x, y, z: integer;
N

begin
writeln (‘Enter first number:’);
readln(x);
O

writeln (‘Enter second number:’);


readln(y);
z: =x+y;
Writeln (‘The total is:’, z);
R

readln;
end.
FO

Output:

152
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 152 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Program Example 2: Fourth generation programming
languages
Adding two numbers using C language
Fourth generation languages are closely
The following program example
adds two numbers in C programming related to human languages. They involve
language. a graphical user interface in collaboration
with event-driven which is determined
#include <stdio.h> by actions of the user such as pressing
int main() {
keyboard keys and mouse clicks. Fourth

LY
int i, j, k; languages include dropping menus and
printf(“Enter two integers: “); forms, which provide easy interaction to
scanf(“%d %d”, &i, &j); the human being. The fourth-generation
languages can be used to design websites

N
// calculating sum
k = i + j; and databases. Examples of fourth

O
printf(“%d + %d = %d”, i, j, k); generation languages are Python, Ruby,
return 0; SQL, PHP, JavaScript, Visual Basics
} and C++. Figure 4.1 represents a simple
Output:
SE
calculator program that was designed
by using Visual Basics programming
language.
U
E
N
LI
N
O
R
FO

Figure 4.1: A simple calculator program designed by using Visual Basic 6

153
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 153 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Fifth generation programming
Computer Science

Exercise 4.1
languages
Fifth-generation languages are Answer the following questions.
advanced languages that do not need 1. Explain five differences between
human interaction to accomplish tasks. Interpreters and Compilers.
The programs designed by using fifth
2. Why is source code referred to as
generation language apply constraints
machine independent?
of the program to solve problems
3. Why did early computers perform
instead of an algorithm developed by the

LY
well with interpreters?
programmer. These languages provide
many automated features including 4. What are the disadvantages of
an application generator which stops assembly language?

N
programmers from typing several codes 5. Explain four differences between
like in other programming languages. high-level languages and low-level

O
Examples of the fifth generation languages languages.
are Mercury, Prolog and OPS5.

Activity 4.1
SE
Introduction to C++
programming language
Analysis of the programming C++ programming language is a high-
U
languages level language extended from the C
programming language. It contains both
Assume that you have been given the imperative (procedural) and object-
following programming languages:
E

oriented programming language features.


C, Perl, Python, JavaScript, machine
Examples of imperative features are
N

language, assembly language, and


records while that of object-oriented
Java:
programming features are classes. C++
LI

(a) Group them into low-level and programming is a compile-based language


high-level languages. that uses different compilers to develop
N

(b) Which criteria have guided and maintain programs. It is a case-


you to make the two groups of sensitive language like Python, Ruby,
O

programming languages? Java, Swift, and Verilog. This makes C++


(c) In which languages will you need differ from other programming languages
R

to use translators? such as Visual Basics, and SQL. The C++


programming language is also a platform-
(d) In which languages will you need
FO

dependent, which means that the source


to use compilers? code written should be compiled in every
(e) In which languages will you need platform This C++ characteristic does not
to use interpreters? apply to other languages like Java.

154
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 154 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Structure of C++ program
Consider the following simple C++ program to display text “Introduction to C++
programming” .

Program Example 3:

Simple C++ program to display text “Introduction to C++ programming”

#include<iostream>

LY
using namespace std;
int main()
{
// Display text Introduction to C++ program

N
cout<<”Introduction to C++ program”<<endl;
system(“PAUSE”);

O
return 0;
}

Description of each line of codes in a program


SE
U
Table 4.3 shows the application of each line from the given C++ programs as
presented in program example 3.

Table 4.3: Defining the structure of the C++ program


E

Line Description
N

#include<iostream> It is a preprocessor directive that tells the compiler to


LI

include iostream, to support input and output operation.


N.B: - Sometime iostream is known as header file
because it is included at the head of a program.
N

using namespace std; This alerts the compiler to find the names in the standard
O

library, for a example, “cout” and “cin” are defined in the


standard library.
int main() The main function “main()” defines the body of the
R

program to which a program execution takes place. The


FO

statements within the function should be enclosed by


curl brackets”{}.” Every statement in the main function
of the C++ program should end with a semicolon “;” as
the statement terminator.

155
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 155 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

// This is double forward slash. Any text written after these


slashes is ignored by a compiler because it stands as a
comment.
N.B:- Comments are not the line of codes; hence, they
are not compiled. While double slashes “//” stands, as a
line comment, the enclosed lines with the star “/*…….*/”
stand as a paragraph comment.
cout<<”Introduction “cout” represents console output that sends a message

LY
to to the compiler to display text “Introduction to C++
C++ program”<<endl; program.”
“<<” stand as insertion operator which send string of texts

N
to the console. A text should be enclosed by quotation
marks.“endl” represents end line sending a message to the

O
console to output a new line and ensure the text displayed.
return 0 Located at the end of the main function responsible to
exit the program

Environment setup for C++ program


SE
U
Before you create a C++ program, you must install C++ Compiler. The compiler is
a software that enables a program to be created to communicate with the computer
systems. There are many compilers that can be used in C++ programming, which
include Dev C++, Boland C++, and Visual C++. Other compilers are available
E

online. All examples in this book were prepared using Dev C++.
N

Installation of Dev C++ Compiler


LI

The following are steps to install Dev C++ compiler (Based on Version 5.11):
Step 1: Using any search engine, download a complete version of Dev C++
N

depending on your operating system by clicking the button “Download”


as shown in Figure 4.2.
O
R
FO

Figure 4.2: Downloading of Dev C++

156
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 156 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Step 2: Install Dev C++ into your computer by double clicking downloaded
executable file.
Step 3: Choose a language, then click “OK” to install Dev C++ as shown in
Figure 4.3.

LY
N
O
Figure 4.3: Choose language to install
SE
Step 4: Read and click “I Agree” button to accept the terms of the agreement as
shown in Figure 4.4.
U
E
N
LI
N
O
R
FO

Figure 4.4: Terms of agreement dialog box

157
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 157 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 5: Choose features you want to install within Dev C++ as shown in Figure 4.5
Computer Science

LY
N
O
SE
Figure 4.5: Components of Dev C++

Step 6: Locate the folder to install Dev C++ by clicking the button “Browse” then
U
click “Install” button as shown in Figure 4.6
E
N
LI
N
O
R
FO

Figure 4.6: Selecting the folder to install

158
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 158 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Step 7: Wait for the installation of Dev C++ as shown in Figure 4.7

LY
N
O
Figure 4.7: Installation process

SE
Step 8: Finish your installation by clicking the button “Finish” as shown in Figure
4.8
U
E
N
LI
N
O
R

Figure 4.8: Finish installation- Finishing set up


FO

Developing C++ programs using Dev C++


Opening Dev C++ compiler
The following are the steps to open the Dev C++ compiler.

159
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 159 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 1: Click the Dev C++ icon to open the following dialog box, as shown in
Computer Science

Figure 4.9. Select language to ‘English (Original)’ and click ‘Next’.

LY
N
O
SE
Figure 4.9: Opening of Dev C++

Step 2: Click the “Next” button followed by “Ok” to open the dialog box
U
Step 3: Click the “file” button followed by “Ok” to open the content pane in Figure
4.10
E
N
LI
N
O
R
FO

Figure 4.10: Content pane

Writing of C++ program in the content pane of the compiler


Type C++ program on the content pane as shown in Figure 4.11

160
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 160 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE

LY
N
Figure 4.11: C++ codes within the content pane

O
Saving a C++ program

SE
From the coding window of C++ program, click File followed by Save As to save
the C++ program. Then, the dialog box to choose a folder for saving a program will
be displayed as shown in Figure 4.12. Type Introduction.cpp in the file name, then
click Save to save your file.
U
E
N
LI
N
O
R
FO

Figure 4.12: Saving a C++ program

161
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 161 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
After saving a program as “Introduction.cpp” the content title will change to
Computer Science

Introduction.cpp as shown in Figure 4.13.

Content title

LY
N
O
Figure 4.13: Title change to “Introduction.cpp”

Compiling a C++ program


It is important to compile your
program not only to change source
SE
code to object code, but also to find
U
errors in the program. Compile
your program by clicking the Figure 4.14: The output from a console window
“Execute” tab from the tool bar,
then click “Compile.” If there is Note: When the output terminates after
E

any error the compiler will display running the program, add “system
(“PAUSE”) to the codes to stop the
N

the error for correction. Otherwise,


the next step of running a program execution window from terminating.
LI

will follow. Program Example 4:


Adding two numbers
N

Running a C++ program


Running a program involves The following is a C++ program that adds
O

copying a program to the RAM. two numbers.


The message is sent to the computer
#include<iostream>
to prepare the environment for
R

using namespace std;


operating a program. Run your int main()
C++ program by clicking the {
FO

“Execute” tab, then click “Run.” cout<< 5+6<<endl;


return 0;
Figure 4.14 shows the output after }
running the program.
The output of the program above is 11.

162
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 162 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Program Example 5:

Finding Average
The following is a C++ program that finds the average of 50, 70, 100 and 80.

#include<iostream>
using namespace std;
int main()
{

LY
//Find average marks of 50, 70, 100 and 80
cout<<”Average of the marks is “<<(50+70+100+80)/4<<endl;
return 0;
}

N
The output will be average of the marks which is 75.

O
Activity 4.2

Installation of Borland C++ SE


Step 1: Download the complete version of Borland C++ Compiler.
U
Step 2: Copy the folder of Borland in the C drive.
Step 3: Write each step to install Borland C++ Compiler in your computer.

Activity 4.3
E
N

Comparison of Dev C++ and Borland C++ in installation process and usage
Step 1: Install both Borland and Dev C++ compiler on your computer.
LI

Step 2: Compare the installation procedures of both compilers.


N

Step 3: Type the following program to each compiler:


O

#include<iostream>
using namespace std;
int main()
R

{
cout<<”Find the value of x”<<endl;
FO

cout<<”5x/8+1/8=x-1”<<endl;
return 0;
}

163
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 163 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Step 4: Compile the program in each compiler before saving the program. Will
the compilation take place? If yes or not, explain why?
Step 5: Now save the program using the names Findvalue_borland and Findvalue_
Dev for C++ Borland and Dev programs respectively.
Step 6: Compile and run the programs in both compilers.
Step 7: Compare the results to both compilers.
Step 8: Identify the folder where the files Findvalue_borland.cpp and Findvalue_
Dev.cpp have been stored.

LY
Step 9: Identify the location where the g++ has been stored.

N
After comparing the installation of both compilers above, and having seen the
results, now use the following activity to write a program which will be compiled

O
using command prompts on windows.

Activity 4.4
SE
Designing a C++ program using command prompt on Windows
In order to write a program using command prompt, use the following steps.
U
Step 1: On the search box in the task bar, type ‘Control panel’ and click to open
it. The window will show up as seen in Figure 4.15.
E
N
LI
N
O
R

Figure 4.15: Openning the Control panel


FO

Step 2: Click the ‘System and Security’ as in Figure 4.15 to go to open ‘system’.
The window shown in Figure 4.16 will be displayed.

164
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 164 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE

LY
N
O
SE
Figure 4.16: System and security window

Step 3: Click ‘Advanced system settings’ as shown in Figure 4.17 to go to system


properties.
U
E
N
LI
N
O
R
FO

Figure 4.17: System window display

165
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 165 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 4: Click the “Advanced” tab on ‘System Properties’ dialog box in Figure
Computer Science

4.18 , then select ‘Environment Variables’ to open it. The window will
display as shown in Figure 4.19.

LY
N
O
SE
Figure 4.18: System properties display
U
Step 5: Select ‘Path’ as shown in Figure 4.19 and click the ‘Edit environment
variable ’. The dialog box will display as in Figure 4.20.
E
N
LI
N
O
R
FO

Figure 4.19: Environment variables

166
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 166 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Step 6: Add c:\dev-cpp\bin\ g++ into “Edit environment variable” dialog box as
shown in Figure 4.20.

LY
N
O
SE
Figure 4.20: Environment variables-Editing path
U
Note: dev-cpp is the file name
Step 7: Type C++ program on a notepad or any text editor program. Use the
following sub-steps to open command prompt.
E

(a) Type Run in search box by clicking “RUN”


(b) Write “cmd” then click “OK”
N

(c) Type “g++ sourcefile_name.c -o outputfile.exe”


LI

If the C++ program file named “introduction” is stored within “dev- cpp” folder,
you will type c:\dev-cpp>g++ introduction.cpp –o welcome, then click “ok” to
N

display the output.


O

Errors in computer programming << “Hello, World! \n”; instead of cout


When writing a computer program, << “Hello, World!\n”;. once you do
R

you may make errors such as typing a that, the compiler will complain. Once
keyword wrongly, or you may forget an error has happened, you have failed
FO

to declare a variable within a program, to correctly adhere to the rules of writing


or initialise a variable with a wrong a computer program according to the
value. For example, you may write cot language rules, and the compiler finds it.

167
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 167 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
If the compiler finds one or more errors printing the value of a variable without
Computer Science

during the compilation phase, it will not declaring it, and missing semicolon (;).
translate the program to machine code, The following C++ program illustrates
and as a result, such a program will not syntax errors.
run. However, once you fix such an
error, and then compile the program, it Program Example 6:
will run successfully.
Syntax error
There are four common errors that may

LY
occur when someone write a computer #include <iostream>
program. These are syntax errors, semantic using namespace std;
int main()
errors, logical errors, and run-time errors.
{

N
int a = 10;
Syntax errors int b = 15;

O
A syntax error is a faulty construct that cout << “ “<< (a, b) // semicolon
does not conform to the rules of the missed
programming language. It is defined as return 0;
a mistake in the spelling, punctuation or
order of words in a program. These errors
SE
}

Error message:
are also called compile-time errors. They
error: expected ‘;’ before ‘}`
U
normally happen when the programmer
fails to follow language syntax rules in
the course of writing program. Examples Semantic errors
E

of syntax errors are misspelling words A semantic error is an error that relates
using a variable that has not been declared to the meaning of the code, particularly
N

and mismatched parentheses or braces, If a mistaken idea of how the compiler


you compile a program that has a syntax interprets the code. Semantic errors are
LI

error, the compiler will not run. Instead, typically syntactically valid, but they are
the compiler will tell you at what line a inconsistent in their meaning or they are
N

trouble is. Usually, the error can indicate invalid such as attempting to divide a
at the exact line where such a syntax error number by zero. Semantic errors happen
O

belongs, or the line just before it. In case when the statements written in the program
the problem is incorrectly nested braces, cannot be well interpreted by the compiler.
R

the actual error may be at the beginning of Sometimes these will cause your program
the nested block. Once you fix the error, to crash, such as in the case of division by
FO

and compile again, the program will zero: Semantic errors are problems with
successfully run. The three most frequent a program that runs without producing
syntax errors that novice programmers error messages, but it does not do the right
commit include: missing parenthesis (}), thing. For example, an expression may

168
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 168 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
not be evaluated in the order you expect, carefully looking at its output. In order
but yielding an incorrect result. to avoid logical errors, the programmer
must plan the solution clearly before
Program Example 7: writing the program. Once the error
occurs, the programmer must test the
Semantic error program and find any logic errors.
The following example of the C++
program illustrates a semantic error Program Example 8:

LY
Logical error
#include <iostream>
using namespace std; The following example of the C++
int main() program illustrates a logical error.

N
{
int a, b, c; #include <iostream>

O
a + b = c; //semantic error using namespace std;
return 0; // A C++ program to illustrate // logical
} error int main ()

Error: value required as left operand


of assignment
SE {
int i = 0;
// logical error : a semicolon after loop
for(i = 0; i < 3; i++);
{
U
a + b = c; //semantic error cout << “loop “;
continue;
}
return 0;
E

Logic errors }
Logic errors are constructs that can be
N

translated into a running program, but Error:


the resulting program does not perform No output
LI

the intended action. The logical errors


may occur even if the program is
N

syntactically correct and does something. Run-time error


However, the output of the program will Run-time errors are the types of errors
O

be different from what was intended by that occur during program execution
the writer of the program. Example of a (run-time) after successful compilation
R

logical error is when a program uses a of the program. Division by zero is one
wrong formula, or assigns wrong value of the most common run-time errors. In
FO

to the code assignment statements. this type of errors, the compiler does not
Under this situation, the compiler cannot directly point to the line where the error
find the error, and it must be flushed out occurs. Run-time errors are also called
when the program runs by testing it and “bugs”. Before a program is released to

169
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 169 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
the market, commercial software are normally checked to examine the process of
Computer Science

bugs during the debugging process

Program Example 9:
Run-time error
Example of the C++ program to illustrate the run-time error

#include <iostream>

LY
using namespace std;
int main()
{
int x = 10;

N
int div = x/0;
// wrong logic number is divided by 0,

O
// so this program abnormally terminates div = x/0;
cout << “result = “<< div;
return o;
}
SE
Note:
U
Run-time errors are hard to trace because the compiler does not point to the line
at which the error occurs.
### Error
E

In the given example, there is Division by zero error. This is an example of run-
N

time error i.e. errors occurring while running the program


LI

Exercise 4.2
N

Answer the following questions.


O

1. Study the following C++ program:

include<iostream>;
R

using namespace std;


int main
FO

{
cout<<Read and enjoy C++ programming<<endl;
return 0;
}

170
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 170 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
(a) Identify all errors in the program.
(b) Correct errors before running the program.
(c) Run the program and display the results.
2. (a) What is “comment” as applied in C++ programming?
(b) Why is it necessary to use “comments” in a C++ program?
3. Describe five (5) characteristics of a good program.
4. Will the following lines of code in (a) and (b) print the same thing? Explain
why or why not.

LY
(a) cout << 5 << ‘\n’;
(b) cout << “5” << ‘\n’;

N
5. Will the following lines of code print the same thing? Explain why or why not.
(a) cout << y<< ‘\n’;

O
(b) cout << “y” << ‘\n’;

Data types
Fundamentals of data types
SE
C++ programming language supports various types of data. Each data type defines
U
its memory size, and improves the running speed of the program. C++ programming
language provides different types of data based on numeric values, Boolean values,
and characters under a specific range of values. C++ programming language is based
on three categories of data types as shown in Figure 4.21: built-in or primary data
E

types, user-defined data types, and derived data types.


N

Data types
LI
N
O

Built-in/primary Derived User defined

Figure 4.21: Fundamental data types in C++


R

Built-in or primary data types


FO

Built-in or primary data types are pre-defined data types that can be applied directly
without creating them. Built-in data types include Integer, Character, Float, and
Bool data types.

171
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 171 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Integer data types
Computer Science

Integer data types involve whole number. Integer data types include, signed integer,
unsigned integer¸ short integer, unsigned short integer, and long integer. Table 4.4
shows the classification of integer data types with their storage size and range.

Table 4.4: Integer Data types


Type Storage size Range
Integer 4 byte -2,147,483,648 to 2,147,483,647

LY
Unsigned integer 4 byte 0 to 4,294,967,295
Short integer 2 bytes -32,768 to 32,767
Unsigned short integer 2 bytes 0 to 65,535

N
Long integer 4 bytes -2,147,483,648 to 2,147,483,647

O
Unsigned long integer 4 byte 0 to 4,294,967,295

Character data types


SE
Character data types comprise alphabetical data. These include char, signed char and
unsigned char. The classification of character data types with their storage size and
range of storing data is represented in Table 4.5.
U
Table 4.5: Character data types

Type Storage size Range


E

Char 1 byte -128 to 127 or 0 to 255


Signed char 1 byte -128 to 127
N

Unsigned char 1 byte 0 to 255


LI

Float data types


N

Float data types are based on decimal numbers. Float data types include float, double
and long double. Table 4.6 represents float data types with their storage size and
O

range.

Table 4.6: Float data types


R

Type Storage size Range


FO

Float 4 bytes ±3.4E-38 to ±3.4E38


Double 8 bytes ±1.7E-308 to ±1.7E308
Long double 8 bytes ±1.7E-308 to ±1.7E308

172
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 172 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Bool data types primary data types. Derived data
The bool data type has only two values, types are array, function, pointer, and
namely true and false. True and false are reference.
also called the logical (Boolean) values.
The central purpose of this data type is User-defined data type
to manipulate logical expressions. Use These are data types defined by the user.
this data type for simple flags that track Such data types can determine the state
true/false conditions. of the data, whether public, private,
or protected. User-defined data type

LY
Derived data types includes structure, union, enumeration,
These are data types derived from and classes.

N
Activity 4.5

O
Identifying data types from a program
You are given the following C++ program:

#include<iostream>
#include<iomanip>
SE
U
using namespace std;
void printMonth(int year,int month);
void printMonthTitle(int year, int month);
void printMonthName(int month);
E

void printMonthBody(int year, int month);


int getStartDay(int year, int month);
N

int getTotalNumberOfDays(int year, int month);


int getNumberOfDaysInMonth(int year, int month);
LI

bool isLeapYear(int year);


int main()
N

{
int year, month;
O

cout<<”Enter full year: “;


cin>>year;
cout<<”Enter month in number between 1 and 12: “;
R

cin>>month;
cout<<endl;
FO

printMonth(year, month);
cout<<endl;
cout<<endl;
return 0;
}

173
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 173 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

(a) Identify all data types applied in a program.


(b) Write the role of each data type you have identified in (a).
(c) Type the program on the Dev C++ text editor.
(d) Compile the program.
(e) Identify errors obtained after compiling the program.
(f) State the errors obtained after compiling the program.

LY
Exercise 4.3
Answer the following questions.

N
1. What is data type?
2. Explain four examples of built-in data types.

O
3. Differentiate between user-defined and derived data types.
4. What is wrong with the following program?

#include <iostream.h>
SE
using namespace std; /
U
int main()
{
int y = 0;
E

cout << “xy= “ << y << endl;


return 0;
N

}
LI

5. Compile and run the following program; thereafter, explain the output.
N

#include <iostream>
O

using namespace std;


int main()
{
cout << “Size of char: “ << sizeof(char) << “ byte” << endl;
R

cout << “Size of integer: “ << sizeof(int) << “ bytes” << endl;
cout << “Size of float: “ << sizeof(float) << “ bytes” << endl;
FO

cout << “Size of double: “ << sizeof(double) << “ bytes” << endl;
return 0;
}

174
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 174 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
6. Examine the following C++ code and answer the questions that follows.

string str1;
string str2;
char ch;
cin >> str1;
str2 = str1;
cin >> ch;
str2[0] = ch;

LY
cout << str1 << “ –> “ << str2 << endl;

Questions.

N
(a) What is the output if the input is Akilimali J?
(b) What is the output if the input is Salome A?

O
(c) What is the output if the input is Abas H?
7. Write a program that asks the user to enter the length of the sides of a triangle
and outputs the shape of the triangle. SE
8. What is the difference between the character ‘n’ and the character ‘\n’?
U
Variables and constants used to store data or information within
a computer program. They are called
Variables
variables simply because their values
E

Consider you have been told to store the can be changed. Usually, variables store
number 5 and number 2 respectively in the data of a specific data type; this means,
N

computer memory. Then, you are asked to store a value into variable, you need
to add 1 to the first number and store the
LI

to know its data type. Each variable in a


results to the memory. Afterward, you program needs an identifier (unique name)
subtract the second number from the result to differentiate it from other variables.
N

you have obtained. To the computer, the For example, from the given scenario x, y
and “result” stands as variable identifiers.
O

same process can be conducted as follows:


x=5;
Rules for naming variables in C++
y=2;
R

programming
x=x+1 (a) Commas and blank spaces are not
FO

result=x - y; required in the variable name


(b) The first character must be an
A variable is a name that defines a specific alphabet or underscore, but not a
location in the computer memory. It is number.

175
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 175 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
(c) Variables should not be too long. Example of variable initialization is int
Computer Science

Make sure it does not exceed eight i = 56;


characters
(d) Special symbols such as $, &, and # Scope of variables in C++
are not allowed within the variable programming
names, and Based on their scopes, variables in C++
(e) Combination of numbers, alphabets, can be classified into three types. These
and underscores are allowed in the are local, global, and static variables.
variable names.

LY
Local variables
Variable declaration Local variables are declared within the
Since variables represent a certain function block or inside the compound

N
type of data; then, if you want to use a statement.
variable in a program, you are supposed

O
to define its name and data type. That Program Example 10:
system of expressing variables is known
as variable declaration. It is a call to the Variable declaration
compiler to prepare a memory size for
a variable in relation to its data type.
To declare a variable, use the following
SE
The following program demonstrates
variable declaration in in C++.

syntax: datatype variableName.


U
function ()
Example of variable declaration: {
int x; int a;
E

double area;
char t; double b;
N

x, area and t represent variable name, }


while int, double and char represent data
types.
LI

Note: If two or more variables are of Variables a and b are defined within the
N

the same data type, they can be block of function, and they can only
grouped as datatype variable1, be accessed inside that block. Hence,
O

variable2, ……., variablen;. For a and b represent local variables.


example, int x, y, z;
R

Initialising variables Global variables


Initializing variables involve the use of Global variables are declared before the
FO

the equal sign “=” to assign value to the main function main(). Such variables
variable. The following syntax is used to can be applied to any function within
initialise variable: datatype variable = the program. Global variables are also
value;. known as external variables.

176
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 176 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Program Example 11:

Global variable declaration


The following example demonstrates the use of global variables in C++ program.
int x=5, y=2;
main()
{
fun();
}
fun()

LY
{
int sum;
sum = x + y;
}

N
Variables x and y in this program are global variables because they have been

O
declared before the main function, main(), and they are also used within the function.

Static variables
SE
Static variables are types of variables declared only once within a function, but they
are used in a whole program. The keyword “static” is used to declare static variables.
Example:
U
static int i, j;
static float a, b;
static char name;
E

Program Example 12:


N

Finding the area of the rectangle


The following is an example of a C++ program that finds the area of the rectangle.
LI

The output is shown in Figure 4.22


N

#include<iostream>
using namespace std;
int main()
O

{
int l, w; //Declaration of length (l) and width (w)as integers data type
double area; //Declaration of area as double data type
cout<<”Enter a length in metres: “;
R

cin>>l; //Read value of length entered by the user


cout<<”Enter a width in metres: “;
FO

cin>>w; //Read value of width entered by the user


area=l*w;
cout<<”The area of the rectangle is “<<area<<”square metres”<<endl;
return 0;
}

177
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 177 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Output:

Figure 4. 22: Output of the program

LY
The following is an activity of the program
Exercise 4.4
that uses C++ programming. Learn
through it on data types and variables.

N
Answer the following questions.
1. What is the advantage of data type
Activity 4.6

O
in a variable declaration?
Data type and variable in a program 2. Give the output of the following
code fragment:
Examine the following C++ program,
and then answer the questions that
follow:
SE
int x;
x = ‘B’;
#include<iostream> cout << x << ‘\n’;
U
using namespace std;
int main()
3. (a) What is the meaning of the
{ scope of variables?
char ch; (b) With examples, describe two
E

cout<<”Enter lower case alphabet: “;


types of scopes of variables as
cin>>ch;
applied in C++ programming.
N

ch=ch-32;
cout<<”\nThe uppercase alphabet is “<<ch; 4. Write a C++ program that reads
cout<<endl; two numbers entered by the user
LI

return 0;}
from the keyboard, calculates their
(a) Type the program on any C++ text sum, and displays the result on the
N

editor program. screen.


(b) Compile and run the program to
O

5. Are these identifiers valid or not?


display an output. Explain.
(c) Re-type the program to produce the (a) a2 (b) 3adk
R

same output without using variable (c) darasa 1 (d) a_126


and data type. (e) sum-total (f) sum total
FO

(d) Compare the two programs and


(g) sumtotal (h) While
explain how difficult it is to practice
(i) Private (j) Public
this program without using variable
and data type. (k) $16 (l) xTwo

178
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 178 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Constants
During program execution, a value may change. To avoid this change, you can use
constants. The constant represents a value whose data cannot change during program
execution. An example of the constant is Pi = 3.14; you do not need to retype it if
you want to use it more than once; instead, you can declare it as a constant.
The syntax required to declare constant is const datatype constantName = value;
Example of constant declaration:
const int averageMarks = 50;

LY
const double bankRate = 0.15;

Program Example 13:

N
A C++ program that uses constant

O
The following program demonstrates an example of a C++ program that uses
constant. The program computes the area of the circle, and it displays the output
on the screen. The output is shown in Figure 4.23

#include<iostream>
using namespace std;
SE
int main()
U
{
const double PI = 3.142; //declare PI as a constant
double radius, area;
E

cout<<”Enter a radius: “;
N

cin>>radius;
area = PI*radius*radius; //compute the area
LI

cout<<”The area of the circle is “<<area<<endl; //display the output


N

return 0;
}
O

Output:
R
FO

Figure 4.23: Output of the program

179
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 179 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Exercise 4.5
Answer the following questions.
1. Write a C++ program that will enable customers to know the Value-Added Tax
to be paid for any purchase price of the commodity. The VAT rate of 18.2%
should be declared as a constant, and the formula should be ( VAT  18.2% 
Purchase prices).
2. Differentiate the terms variable and constant as applied in C++ programming
3. Create a C++ program that prompts a user to enter a radius of the sphere. The

LY
program should calculate and display the volume of the sphere as output. (Hint:
4
The formula for calculating volume of sphere is r 3 , r represents radius of
3

N
the sphere). Use Table 4.7 in your declaration.
Table 4.7: Declaration

O
Data name Data type Declaration type
Pie (  ) =3.1415926 Double Constant
Radius
Volume
Float
Double
SE
Variable
Variable
U
4. (a) What are the benefits of using 5. Consider the following program:
constants in a C++ program? #include <iostream.h>
(b) What is wrong in the following using namespace std;
int main()
E

C++ program? Explain.


{
int a;
N

int b;
#include<iostream> a=2;
LI

#define PI = 3.142; b=5;


a=b;
N

using namespace std;


int main() b=4;
cout << “a= “ << a << endl;
O

{
cout << “b= “ << b<< endl;
double temp = PI*5;
return 0;
cout<<temp<<endl;
}
R

return 0;
} (a) What is the output of this
program?
FO

(b) Using a diagram, illustrate


how memory changes during
variable assignment.

180
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 180 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Input and output streams (>>) to read data from the source/
The tendency of reading and writing keyboard to the program. Output stream,
data in the C++ programming language as shown in Figure 4.25, uses insertion
is controlled by the input and output operator (<<) to display a program to
streams. Input and output streams enable the screen/destination. The object of the
a user to interact with the program by output stream required to display data is
displaying output on the screen and called “cout” while “cin” is used by the
getting the user’s input through the input stream to accept or read data. The
keyboard. Input stream, as shown in objects “cout” and “cin” are declared

LY
Figure 4.24, uses extraction operator within the header file “iostream.”

N
Reading data from the source
Source Program

O
Figure 4.24: Input stream

Displaying data to destination/screen


Program
SE
Figure 4.25: Output stream
Destination
U
Note: The insertion and extraction operators can be used more than once in one
stream of data. This signifies that, you can use more than one insertion
operator to display different data using one output stream. You can also use
E

more than one extraction operators to request more than one data from the
user.
N

For example: cout<< “Ashura is”<< age<< “years old”<<endl;


LI

cin>>firstNumber>>secondNumber;

The input stream “cin” will process the data entered when the user presses the
N

RETURN key. The weakness of input stream “cin” is that it cannot hold blank
O

space characters. The function “getline” can be used instead of “cin” to solve this
problem.
R

Program Example 14:


FO

The use of “cin” and “cout” commands


The following example demonstrates the uses of “cin” and “cout” commands in
a C++ program. The output is shown in Figure 4.26.

181
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 181 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

int main()
{
int a, b;
cout<< “enter first and second number”;
cin>>a>>b;
cout<< “The product is ”<<a*b<<endl;
}

LY
Output:

N
O
Figure 4.26: Output of cin and cout commands

The following program examples is for ‘getline’ command which is used to solve
SE
the problem in which ‘cin’ cannot hold blank space characters.

Program Example 15:


U
The use of “getline”
The following example demonstrates the use of “getline” commands in a C++
program. The output is shown in Figure 4.27.
E

#include<iostream>
N

#include<string>
using namespace std;
LI

int main()
{
string myname;
N

cout<<”What is your name? “;


getline(cin, myname);
cout<<”Hello “<<myname<<endl;
O

return 0;
}
R

Output:
FO

Figure 4.27: Output of the ‘getline’ command

182
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 182 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Operators, expressions and (e) Increment and decrement operators
assignments (f) Compound assignment operators
(g) Short-hand assignment operator
Operators
Once you have an idea of variables and Arithmetic operators
constants, you can decide to operate them Arithmetic operators include arithmetic
in different ways. For that case, the C++ operations such as addition, subtraction,
programming language introduces signs multiplication, and division. Table 4.8
or symbols used to link, join, or conduct shows arithmetic operators and their
two or more data operations. Operators

LY
meanings.
are required by the operands to conduct
operations. There are binary operators that Table 4.8: Arithmetic operators
involve two operands and unary operators
Operator Meaning

N
that involve only one operand.
+ Addition

O
Types of operators – Subtraction
C++ programming languages use different * Multiplication
types of operators depending on the / Division
operation to be conducted. Such operators
include:
(a) Arithmetic operators
SE % Modulo division
Note: Modulo division is the division
that gives the remainder after one
U
(b) Assignment operators
(c) Relational operators integer divide another integer.
(d) Logical operators Example 7%4 = 3.
E

Program Example 16:


N

Demonstration of Modulo division


The following C++ example program demonstrates how to change seconds into
LI

minutes, hours and seconds. The output is shown in Figure 4.28.


#include<iostream>
N

using namespace std;


int main()
O

{
int sec, min, hrs;
cout<<”Enter seconds: “;
cin>>sec;
R

min = sec/60;
hrs = min/60;
FO

int remainSeconds = sec%60;


cout<<sec<<” seconds is “<<hrs<<” hours, “<<min<<” minutes
and “<<remainSeconds<<” seconds”<<endl;
return 0;
}

183
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 183 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Output:

Figure 4.28: Output of the program

Assignment operators
Assignment operators are responsible for assigning value to the variable. The value

LY
assigned can either be constant, variable or expressions. The syntax used to assign
value to the variable is variable = value; for example x=10; or y=a+1. The assignment
operations always take the value from right to left. This means that, if two variables

N
a and b are assigned as a = b, then, the value of a will be replaced by the value of
b and not otherwise.

O
Program Example 17:
Assignment operations in C++
SE
The following example demonstrates the assignment operations in C++
programming. The output is shown in Figure 4.29.
U
#include<iostream>
using namespace std;
int main()
{
E

int a, b;
a=34;
N

b=22;
a=b;
LI

b=7;
cout<<”a = “<<a<<endl;
cout<<”b = “<<b<<endl;
N

return 0;
}
O

Output:
R
FO

Figure 4.29: Output of the program

The output of the given program in Figure 4.29 shows that variable a assigned
value of b, which is 22, and variable b replaced its value with 7.

184
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 184 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Compound assignment operators
If you want to change the value of the variable by conducting an operation on the
value currently stored in the variable, you can use compound assignment operators.
Table 4.9 shows compound assignment operators and their respective meanings.

Table 4.9: Compound assignment operators

Operator Example Meaning


+= a + =b a = a +b

LY
= a – =b a=a–b
*= a*=b a = a*b
/= a/=b a = a/b

N
%= a%=b a = a%b

O
Program Example 18:

Compound assignment operators SE


The following example demonstrates the use of compound operators. The output
is shown in Figure 4.30.
U
#include<iostream>
using namespace std;
E

int main()
N

{
int x, y = 5;
LI

x = y;
x+=8;
cout<<”The value of x is “<<x<<endl;
N

return 0;
}
O

Output:
R
FO

Figure 4.30: Output of the program

185
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 185 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Increment and decrement operators
Computer Science

Increment (++) and decrement (--) operators are unary operators that can add or
subtract one to the variable. The increment operators add one to the variable while
decrements subtract one. The increments and decrements operators can be written
before variable as prefixes and after a variable as the suffixes. The increment and
decrement operators are mainly used to iterate integers and floating data types. Table
4.10 shows increment and decrement operators and their meaning.

Table 4.10: Increment and decrement operators

LY
Operator Meaning Explanation
++i Pre increment Increment by 1 and then conduct operation
- -i Pre decrement Decrement by 1 and then conduct operation

N
i++ Post increment Conduct operation and then increment by 1

O
i-- Post decrement Conduct operation and then decrement by 1

Program Example 19: Relational operators

Increment and decrement operators


SESometimes, in programming, we
need to compare two values to
The following example demonstrates the use of know if they are equal or not,
U
increment and decrement operators. The output greater than or less than. The
is shown in Figure 4.31.
values can either be variables,
#include<iostream> constants or expressions. C++
E

using namespace std; programming language evaluates


int main() the comparison between two
N

{ values using relational operators.


int x = 25;
LI

Relational operators can help


cout<<”x++ = “<<x++<<endl;
cout<<”x-- = “<<x--<<endl; you in making the decision.
N

cout<<”++x = “<<++x<<endl; You can use relational operators


cout<<”--x = “<<--x<<endl;
to compare the height of two
return 0;
O

} trees, the ages of two students


or the prices of two items.
Output: Usually, the result obtained after
R

evaluating relational operators


is either true or false. Table 4.11
FO

shows relational operators, their


meaning, examples and return
Figure 4.31: Output of the program values.

186
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 186 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Table 4.11: Relational operators

Operator Meaning Example Evaluation Return value


< less than 16 < 20 True 1
<= less than or equal to 10 < = 10 True 1
> greater than 5 > 11 False 0
>= greater than or equal to 45 > = 28 True 1
== equal to 6==7 False 0

LY
!= is not equal to 8! = 8 False 0

Program Example 20:

N
Use of relational operators

O
The following program demonstrates the use of relational operators. The output
of the program is shown in Figure 4.32.

#include <iostream>
using namespace std;
int main()
{
SE
bool result;
U
cout<<”Condition : Return value”<<endl;
result = (5 == 5);
cout<<”5==5”<<” : “<< result<<endl;
E

result = (8>13);
cout<<”8>13”<<” : “<< result<<endl;
N

result = (22<=12);
LI

cout<<”22<=12”<<” : “<< result<<endl;


result = (15!=17);
cout<<”15!=17”<<” : “<< result<<endl;
N

return 0;
}
O

Output:
R
FO

Figure 4.32: Output of the program

187
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 187 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Logical operators
Computer Science

A relational operator involves only one condition at a time; to combine two or more
conditions, you can use logical operators. Logical operators include, !, | | and &&
operator. Table 4.12 shows logical operators, their meaning, examples and return values.

Table 4.12: Logical operators


Operator Meaning Example Return value
! Logical NOT 45! = 67 1
| | Logical OR (6 > 3) | | (8! = 8) 1

LY
&& Logical AND (5 < = 3) && (9 > = 5) 0
Logical NOT operator “!” involves only one value. It performs the Boolean

N
operation by reversing the value of the expression to be operated. If the value of
the expression is true, it changes that value to false. Otherwise, if the expression is

O
false, it changes that value to true. Logical OR operator “| |”is used to conclude a set
of the conditions. If either of the condition is true, then the statements are executed.
Logical AND operator “&&” is used to make a conclusion from the conditions

SE
where the execution takes place when all conditions are true.

Program Example 21:


The operation of logical operators
U
The following C++ program example demonstrates the operation of logical
operators. The output is shown in Figure 4.33.
#include <iostream>
E

using namespace std;


int main()
N

{
bool answer;
cout<<”Condition : Return value”<<endl;
LI

answer = ((9>2)&&(17>2));
cout<<”(9>2)&&(17>2)”<<” : “<< answer<<endl;
answer = ((8>13)||(5!=3));
N

cout<<”(8>13)||(5!=3)”<<” : “<< answer<<endl;


answer = ((15!=20)&&(27>30));
cout<<”(15!=20)&&(27>30)”<<” : “<< answer<<endl;
O

return 0;
}
R

Output
FO

Figure 4.33: Output of the program

188
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 188 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Mathematical expressions in C++ programming
Like other languages, the C++ programming language provides rules through
which different data, including variables, constants and operators, can be combined.
Such an interconnection of data is known as expression. During programming, the
arithmetic expression should be translated into C++ expression so that a compiler
can understand what is programmed.
 2x 1 
For example, the expression 10    can be translated into C++ expression as
10*( (2*x)/3 – 1/3).  3 3

LY
Operator precedence in mathematical expressions
Levels of precedence between operators, both in arithmetic expression and C++

N
expressions, remain the same. That level starts from the operation enclosed by
brackets, followed by arithmetic operators out of the brackets. Priority is given to

O
division and multiplication, followed by addition and subtraction. If the expression
includes several arithmetic operators of the same type the operation will be conducted
from left to right.

Operator precedence in C++


SE
U
Table 4.13 illustrates the level of precedence of the operators in C++
Table 4.13: Operator Precedence in C++
Priority Operators
E

Highest (,)
Priority ++, -- (as postfix), new, (type),typeof, sizeof
N

++, -- (as prefix), +, - (unary), !, ~


LI

*, /, %
+ (string concatenation)
N

+, -
<<, >>
O

<, >, <=, >=, is, as


= =, !=
R

&, ^, |
FO

You can use some of the symbols obtained in Table 4.13 to write mathematical
expressions in the following activity.

189
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 189 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Activity 4.7
Writing mathematical expression using C++ programs
Practice on how to write mathematical expressions in C++ programs by following
the steps below:
Step 1: Type the following expression in (a) word processor and (b) C++ text
editor. Compare the arithmetic operation typed in both (a) and (b).
5x  1 7  4 5  2x 

LY
z  (a  2b  c)(y  5)  10  
6 x x y  1 
Step 2: If x=1, y= 2, a = 3, b = 5 and c=6, use a calculator to find the value of z.

N
Step 3: Write a C++ program to find the value of z using the values given in step 2.
Step 4: Comment on the results obtained in step 2 and step 3.

O
Exercise 4.6

Answer the following questions.


SE
program will prompt the user to
enter two points (x1, y1) and (x2,
y2). Then, a program will find and
1. Write a C++ program that can enable display a slope. Use the formula:
U
a user to convert Fahrenheit to y –y
Slope= 2 1
Centigrade degree. Use the formula, x 2 –x1
Centigrade=5/9 (Fahrenheit-32). 4. What are the functions of “cout”
E

2. Write the following program on and “cin” in writing a C++ program?


C++ text editor; then, display the
N

5. Using output stream “cout” , write


output. a C++ program that displays the
LI

following table as shown in Figure


#include<iostream>
4.34:
N

using namespace std;


int main()
O

{
cout<<”2%3 = “<<2%3;
R

return 0;
}
FO

Figure 4.34: Output


3. Write a C++ program that enables
the user to calculate the gradient 6. Construct a C++ program that takes
(slope) of the straight line. A a character as an input from the

190
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 190 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
languages: Sequential, selection
keyboard and converts it into a capital letter
or decision, and iteration or
or small letter depending on its form. A
looping control structure.
program should check the validity of the
entered character and display a message
“The entered character is not an alphabetical Sequential control
letter” if the input is not a letter. structure
7. Give the output of the given program Sequential control structure
explains step-by-step the

LY
#include <iostream> execution of data within
using namespace std; a program. It defines how
int main() data is executed sequentially

N
by considering the order
{ provided by the program. The

O
program conducts different
cout << “1 + 5 = “ << 1 + 5 << endl;
series of data flow from top
cout << “13 + 89 = “ << 13 + 89 << endl;
to down by creating data link
cout << “30 - 20 = “ << 30 - 20 << endl;
cout << “4 - 90 = “ << 46 - 90 << endl;
SE and dependency. Sequential
structure controls data reading,
cout << “2 * 7 = “ << 2 * 7 << endl; writing, arithmetic calculation,
U
cout << “5 / 2 = “ << 5 / 2 << endl; assignment of variables, etc.
Figure 4.35 shows a flow chart
cout << “21 / 7 = “ << 21 / 7 << endl;
of a sequence control structure.
E

cout << “35 % 6 = “ << 35 % 6 << endl;


cout << “4 % 6 = “ << 4 % 6 << endl;
N

return 0;
Statement 1
LI

}
N

Statement 2
Control structures
O

If there is any repetition or condition made


within the program, the order of execution should
Statement 3
R

change based on condition and repetition. Control


structure shows how execution of data flow within
FO

a program step-by-step. It also simplifies ways of


solving problems within a program by avoiding
Figure 4.35: Sequential control
typing many lines of code. There are three types structure
of control structures used in C++ programming

191
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 191 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Selection control structure IF….THEN displays the result of the
Computer Science

C++ programming language uses selection given option when the condition is true.
or decision control structure to fulfill a Otherwise, the program will stop to
certain condition. This occurs when the execute. This means within IF…THEN
sequence of instructions is determined statement, other options are ignored.
through the condition. In a selection The following is the syntax of IF….
control structure, execution takes place THEN statement.
when the condition is satisfied whereby
If(condition)

LY
one side is executed when the condition
is true, and another side is executed when {
the condition is false. Consider a program statements;
}

N
to register citizens for presidential voting.
The program will prompt a citizen to enter Figure 4.34 shows the execution flowchart

O
their ages and then check if the age is of IF….THEN statement.
greater than 18. Then registration form
will open; otherwise, the form will not
open. SE YES Condition
There are two types of decision
U
control structure, namely If statement,
and Switch-case statement in C++
programming language. Statement(s)
E

NO
If statement
N

If statement is the type of decision control


structure used to test the logical flow
LI

of statement execution and determine


whether it is true or false. If statement
N

involves IF…THEN, IF …ELSE and


Figure 4.36: IF…THEN flowchart
O

Nested IF statement.

IF….THEN The following code shows how you can


R

write a program to find average pass


If there is only one option to be tested
in your program, you can use IF….. mark of the students to join form five
FO

THEN statement to test your condition. PMC by using ‘If…Then’ .

192
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 192 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Program Example 22:
Using ‘If …Then’

#include<iostream>
using namespace std;
int main()
{
int averageMark;

LY
cout<<”Enter marks of the student: “;
cin>>averageMark;
if(averageMark>=70)
{

N
cout<<”You have been selected to join form 5 PMC”<<endl;
}
return 0;

O
}

Output:
SE
U
Figure 4.37: Output of program for marks
E

IF…..ELSE statement
N

If you have two options to test in C++ programming, IF…THEN statement is not a
good choice to use. Instead, you can use IF…ELSE statement. IF…ELSE statement
LI

specifies two decision-making statements where one is true and the other is false.
It carries a logical test among two options and selects one option that correlates to
N

the condition. The application example of IF…..ELSE statement is to set condition


when you need to make choice among the people by considering their gender, either
O

male or female. The syntax of if..else statement is given as:


if(condition)
{
R

statement(s); // this block will execute when condition is true.


}
FO

else
{
statement(s); // this block will execute when condition is false
}

193
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 193 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Figure 4.38 shows the execution flowchart of IF….ELSE statement.
Computer Science

True Condition False

True statement(s) False statement(s)

LY
N
O
Figure 4.38: If…else flowchart

You can learn from the following program examples on how to use the ‘If else ’ to
write the program. SE
Program Example 23:
U
Using ‘if ...else’ to write a program
The following C++ program enables a user to select form five students according
E

to their average marks. The output is shown in Figure 4.39.


N

#include<iostream>
using namespace std;
LI

int main()
{
int marks;
N

cout<<”Enter marks of the student: “;


cin>>marks;
O

if(marks>=50)
{
cout<<”You have been selected to join form five”<<endl;
}
R

else
{
FO

cout<<”You are not selected”<<endl;


}
return 0;
}

194
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 194 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Output:

Figure 4.39: Output of the program

Note: If there is only one statement within the if block, using braces is an option.

LY
For example, in the program IF…ELSE statement can be written as:
if(marks>=50)
cout<<”You have selected to join form 5”<<endl;

N
else

O
cout<<”You are not selected”<<endl;

Nested if statement
SE
When a condition statement involves more than two options, more if…else should
be added within another if…else condition. Such condition statements that include
two or more if ….else statements are known as Nested if statement. The application
U
example of Nested if statement is during the match: a team can win, lose or draw
depending on its score. The syntax of the nested if statement.
If (condition 1)
{
E

// this block will execute when condition 1 is true.


statement 1
N

}
else if (condition 2)
LI

{
//this block will execute when condition 2 is true.
N

statement 2;
}
else if (condition 3)
O

{
//this block will execute when condition 3 is true.
statement 3;
R

}
else
FO

{
//this block will execute if no any condition is true.
default-statements;
}

195
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 195 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Figure 4.40 shows the execution flowchart of Nested if statement.
Computer Science

True False
Condition 1

Statement 1
True Condition 2 False

True False
Statement 2 Condition 3

LY
Statement 3 Default statement

N
O
Figure 4.40: Nested if …..flow chart

SE
In order to practice on the use of Nested if….to write a program, learn from the
program example that follows.

Program Example 24:


U
The use of Nested if statement
The following program example demonstrates the use of Nested if statement.
E

The program enables users to know the type of the game through the number of
players. The output of the program is given in Figure 4.41.
N

#include<iostream>
using namespace std;
LI

int main()
{
int n;
N

cout<<” Choose 5, 6, 9 or 11 players to know type of the game “<<endl;


cout<<”Enter number of players to know type of the game: “;
cin>>n;
O

if(n==11)
cout<<”Football”<<endl;
else if(n==5)
cout<<”Basketball”<<endl;
R

else if(n==6)
cout<<”Volleyball”<<endl;
else if(n==9)
FO

cout<<”Baseball”<<endl;
else
cout<<”Wrong choice”<<endl;
return 0;
}

196
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 196 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Output:

Figure 4.41: Output of the program

LY
Exercise 4.7 #include <iostream>
Using namespace std;
Answer the following questions. int main()

N
1. Identify errors made in the {
following program int input;

O
cin >> input;
if (marks > = 60) if (input < 11) {
Grade = ‘D’; if (input != 6)
else if (marks > = 70)
Grade = ‘C’;
else if (marks > = 80)
SE
cout << “wow “;
else
Grade = ‘B’; input++;
U
else if (marks > = 90) }
Grade = ‘A’; else {
else
if (input == 18)
Grade = ‘F’;
E

input += 11;
2. Use if statement to create a else
N

C++ program that allows the cout << “Oyaaa!”;


user to enter five numbers. }
LI

Then, the program arranges cout << input << ‘\n’;


the number from the smallest }
N

to the largest number. What will the program print if the user
3. Write the program that enters the following numbers as inputs?
O

prompts the user to enter a (a) 4, (b) 20, (c) 6, (d) 18, (e) -6
month and year. The program 5. Write a C++ program that requests six
should display the number of
R

integer values from the user. The program


days of that month as output. should give the message to the user as
FO

4. Study the following C++ follows: if any of the values entered are
program that prints one line duplicates, the message output should read
of the text, then answer the “DUPLICATE VALUES”; otherwise, it
questions which follow: prints “ALL ARE UNIQUE VALUES”.

197
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 197 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Switch case statement
Computer Science

If you have many options in a condition statement, you need more if…else statement
within nested...if statement. Overusing if…else for more options makes a program
very difficult to design. For that case, to reduce lines of codes, C++ programming
language introduces a switch-case statement to solve this problem. The syntax of the
Switch case statement is shown as follows:
switch(variable)
{
case 1: statement 1;
break;

LY
case 2: statement 2;
break;
case 3: statement 3;

N
break;
default: default statement

O
break;
}
Figure 4.42 shows the execution flowchart of the switch case statement.
SE
True
U
case 1 statement 1

False
True
E

case 2 statement 2
N

False
LI

True
case 3 statement 3
N

False
O

default statement
R

Figure 4.42: A flowchart for a Switch case statement


FO

Note:
It is a good practice in programming to write cases in sequential order and end with
default case, but it is not a must to follow that order.
The switch expression should be enclosed in brackets.

198
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 198 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
The following C++ program enables users to know the type of the game through the
number of players using switch case statement. The output of the program is shown
in Figure 4.43.

#include<iostream>
using namespace std;
int main()
{
int n;

LY
cout<<”Enter number of players to know type of the game: “;
cin>>n;
switch(n)
{

N
case 5:
cout<<”Basketball”<<endl;
break;

O
case 6:
cout<<”Volleyball”<<endl;
break;
case 9:
cout<<”Baseball”<<endl;
break;
SE
case 11:
cout<<”Football”<<endl;
U
break;
default:
cout<<”Select 5, 6, 9 and 11 only”<<endl;
}
E

return 0;
}
N

Output:
LI
N
O

Figure 4.43: Output of the program

Exercise 4.8
R

Answer the following questions.


FO

1. What is the function of “break” keyword in a switch-case statement?


2. Describe the advantages of using a switch-case statement over if statement?
3. Which data types are required for the switch variables?

199
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 199 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
4. Rewrite the following if statement languages uses looping or iteration control
Computer Science

by using the switch-case statement. structure. Looping control manages


Then, draw a flowchart of the given repeated executions in a program. The
switch-case statement. loop contains two parts: the body of the
loop and the control statement. The control
If (k==1) statement tests the condition provided, and
m+=5; it allows the repeated execution of the
else if (k==2)
m+=10; statements within the loop body. There
else if (k==3) are three types of looping or iteration
m+=16; used in the C++ programming language;

LY
else if (k==4)
m+=34; these are: While loop, Do while loop and
For loop.
5. Considers the following code

N
While loop
fragment.
The while loop allows a program to test

O
int x;
cin >> x; the conditions first before performing
switch (x + 3) { the execution. If the condition is true, the
case 5: loop is executed according to the loop
cout << x << ‘\n’;
break;
case 10:
SE
body. Otherwise, the loop terminates.
The syntax of the while loop is given as:
while (loop condition)
cout << x - 3 << ‘\n’;
U
break; {
case 20: Statement (s);
cout << x + 3 << ‘\n’; }
E

break; Figure 4.44 shows the execution


}
flowchart of the while loop.
N

Determine the output of the above


program when the user enters 3, 7, 9,
LI

19 and 22 respectively.
N

Iteration or Looping control Loop


structure condition
O

Suppose you are required to type a


text “C++ programming” ten times, True False
you will type the code cout<< “C++
R

Statement (s)
programming”<<endl; ten times which (loop body)
is very tedious. Also, consider you are a
FO

teacher and you want to find the average


marks of each student for a class of 100
students. To avoid repetition of performing
the same task, C++ programming Figure 4.44: A flowchart of a While loop

200
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 200 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Program Example 25:
Finding the Greatest Common Factor (GCF) of two numbers
The following C++ program finds Greatest Common Factor (GCF) of two numbers.
The output is shown in Figure 4.45.

#include<iostream>
using namespace std;
int main()

LY
{
int n1, n2;
cout<<”Enter first number: “;
cin>>n1;

N
cout<<”Enter second number: “;
cin>>n2;

O
int gcf=1, x=2;
while(x<=n1&&x<=n2)
{
if(n1%x==0&&n2%x==0)
gcf=x;
x++;
SE
}
U
cout<<”The greatest common factor (GCF) for “<<n1<<” and
“<<n2<<” is “<<gcf;
return 0;
}
E
N

Output:
LI
N
O

Figure 4.45: Output of the program


R

Do-while loop
The do-while loop allows execution of the statement at least once, and then, it
FO

evaluates the loop. If the loop condition is true, the execution continues until the
condition becomes false. The do-while loop terminates when the loop condition is
not met. Do-while loop is useful where the loop body needs to be executed before the

201
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 201 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
loop condition is tested. For example,
Computer Science

Program Example 26:


when you look for your favorite food at
the restaurant. First, you will go, and if The use of do-while loop
the food is attractive, you will continue
The following C++ program
to go. Otherwise, you will quit to another demonstrates the use of do…while loop.
restaurant. The syntax of the do-while The output is shown in Figure 4.47.
loop is given as:
do {
// The statement will be executed #include<iostream>

LY
once even if the condition is using namespace std;
int main()
false. {
Statement(s); int sum = 0;

N
} int i = 0;
while(loop condition);

O
do
Figure 4.46 shows the execution flowchart {
of the do-while loop. sum+=i;
cout<<”Enter an integer: “;
SE
}
cin>>i;

while(i!=0);
cout<<”The sum is “<<sum<<endl;
U
return 0;
Statement (s) }
(loop body)
True
E

Output:
N

Loop
LI

condition
N

False
O

Figure 4. 46: do-while loop flowchart Figure 4.47: Output of the program
R
FO

202
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 202 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Table 4.14 shows the difference between while...loop and do-while...loop
statements.
Table 4.14: Difference between while...loop statements and do-while…..loop statements

While loop Do-while loop


Test the condition before execution; Body execution takes place once before
if the condition is true, the execution testing the condition. Then, if the
continues until the condition becomes condition is true, the execution continues
false. otherwise, the execution stops.

LY
Testing of the loop body occurs at the Testing of the loop body occurs at the
top. bottom.
The loop stops execution if the condition Loop is executed at least once even

N
is false. though the condition is false

O
For loop Table 4.15: Body parts of ‘for….loop’
For loop is a predetermined type of loop.
It allows a user to enter the required
number of iterations to be done before
SE
Part Function
Initialisation It initialises a variable
counter
looping. For example, the program will It tests the loop condition
U
Condition
prompt a teacher to enter the number of Increment/ It provides an increment
students before calculating their average decrement or decrement variable
marks to prepare the number of iterations. counter.
E

For loop contain variables that control


how many times the loop execution can Figure 4.48 shows the execution flowchart
N

occur. Unlike other control structures, of the for loop.


LI

for...loop contains three body features:


initialisation, condition, and increment/
decrement counter. The syntax of for… Initialization
N

loop is give as : Increment/


Decrement
O

for (initialisation; condition ;


increment/decrement counter) Loop body
{
R

loop body True


Condition
}
FO

False
Table 4.15 shows the function of each
body part of the for…loop
Figure 4.48: A flowchart of “for loop”

203
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 203 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Program Example 27:

Finding the sum of numbers using for loop

The following C++ program computes the sum of 10 positive integers using for
loop. The output is shown in Figure 4.49.

#include<iostream>
using namespace std;

LY
int main()
{
int i, sum=0;

N
for(i=1; i<=10; i++)
{

O
sum=sum+i;
}
cout<<”The sum of 10 numbers is: “<<sum<<endl;
return 0;

Output:
} SE
U

Figure 4.49: Output of the program


E
N

Activity 4.8
LI

displays total marks and average


marks for each student, using:
Difference between the ‘while loop,
N

do….while loop and for…loop’ i. while…..loop


ii. do-while…loop
O

(a) Write three C++ programs to


iii. for.... loop
display students’ results. Each
(b) Compare the results generated from
program prompts a user to enter
R

each loop
the number of students in the class
(c) Comment on the results obtained
FO

and the marks of five (5) subjects


from each loop.
for each student. Then, the program

204
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 204 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Exercise 4.9 either to solve factorial or exponent
of the number using a switch case
Answer the following questions. statement.
1. Write a C++ program that displays 4. Write a C++ program to display
the Pascal triangle, as shown in even numbers, odd numbers, or
Figure 4.50, when a user enters prime numbers which lie within a
the power of expansion. range entered by the user.
5. What is printed by the following

LY
code fragment?
int x = 0;
do {

N
cout << x << “ “;
x++;

O
Figure 4. 50: Output of the program } while (x < 10);
cout << ‘\n’;
2. Use for loop to write a C++ program
which outputs the multiplication
table as shown in Figure 4.51:
SE
Functions
Concept of functions
U
In programming, you can sometimes
find the same instruction is applied
repeatedly throughout the main
E

program. The instruction does not iterate


the solution according to the condition
N

like what is happening within the loop.


Still, it is used repeatedly through the
LI

program according to the user tasks. To


avoid retyping such instructions many
N

times within the main program, you can


use a function. A function is a block of
Figure 4.51: Output of the program
O

code in a program which run only when


3. Create a simple calculator using it is called. For example, a program has
a block of code that calculates interest
R

C++ programming language to


solve the factorial of a number of money deposited by one customer
in a bank. We do not want to rewrite
FO

and read an exponent when the


user enters the base and power of the same instructions, if we wish to
a particular exponent. A calculator compute the interest of another person
should allow the user to choose who also deposited money in the bank.
Alternatively, we would rather move to
205
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 205 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
a ‘code section’ that calculates interest User-defined function
Computer Science

and then return to where you left off. A user-defined function is the type of
function designed by a programmer
Advantages of functions
according to the user’s requirement.
(a) Using functions facilitates the reuse
Programmers use the function to break
of the codes in writing computer
down large programs to simplify
programs
debugging, testing, and maintenance of
(b) The use of functions help to improve the program. A user-defined function that
the program’s readability because it returns value is called ‘returning function’.

LY
reduces the complexity of the main The function that does not return value is
function called ‘void function’.
(c) Functions help you to focus on just

N
that part of the program and construct Elements of user-defined function
it, debug it, and perfect it. User-defined function contains three

O
(d) Different people can work on elements: function definition, function
different functions concurrently. call and function prototype.
The following is the syntax of typing a
function:
returnValueType functionName (list
SE
Function definition
Function definition specifies all
of parameters) characteristics and elements required in a
U
{ user-defined function. Function definition
//Function body; includes function header and function
} body. Function header includes data type
E

or returns type, function name, and a list of


Types of functions parameters. On the contrary, function body
N

There are two types of functions applied involves all executable statements within
in C++ programming, namely user-
LI

it. Figure 4.53 shows the components of


defined function and built-in/pre-defined function definition.
function as shown in Figure 4.52.
N

int sum (int x, int y)


O

Function header
Functions {
R

sum = x + y;
cout<< “The total is”<<sum>>endl;
FO

Built-in User-defined
Functions Functions }
Function body
Figure 4.52: Types of functions Figure 4.53: Components of function definition

206
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 206 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Note: Parameters are values which need a function. Formal parameters are variables
to be passed into the function. They in the function heading.
create a link or communication
Function call
between the defined function and
the main function. The following If you want to use a defined function within
is the structure of the program to the main function, you have to call that
function. During calling the function, you
represent function parameters.
have to specify the name of the function,
funct1(x,y)
return value and parameters if they are
{ included within the function. There

LY
// function body are different ways of calling a function
…………… depending on whether the function returns
} a value or not.

N
main()
Returning value function
{

O
For the function which returns a value,
funct1(a,b); //function calling
the function will be treated as a value.
}
To call it, you have to define its data type
Where a, b are the actual parameters and x,
y are formal parameters. Actual parameters
are variables or expressions listed in call to
SE
and variable. Example of the calling
function with the integer data type is int
total = sum(10,20);
U
Program Example 28:
Using function to find a maximum number
E

The following example demonstrates a C++ program that uses function call to find
maximum number of the two numbers. The output is shown in Figure 4.54.
N

#include<iostream>
using namespace std;
LI

int maximum(int x, int y)


{
int answer;
N

if (x>y)
answer=x;
else
O

answer = y;
return answer;
}
int main()
R

{
int a, b;
cout<<”Enter two number to find which is maximum”<<endl;
FO

cin>>a>>b;
int t = maximum(a,b); //function call
cout<<”The maximum between “<<a<<” and “<<b<<” is “<<t;
return 0;
}

207
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 207 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Output:

Figure 4.54: Output of the program

Function that does not return value (Void function)

LY
A void function is a function that does not return any value. To call such a function,
you will define function name without data type or variable.
Program Example 29:

N
Changing marks grade using void function

O
The following example demonstrates a C++ program that changes marks to grade
using void function. The output is shown in Figure 4.55.
#include<iostream>
using namespace std;
void grade(double marks)
{
SE
if (marks>80)
U
cout<<’A’;
else if (marks>60)
cout<<’B’;
else if (marks>40)
cout<<’C’;
E

else if (marks>20)
cout<<’D’;
N

else
cout<<’F’;
}
LI

int main()
{
cout<<”Enter marks: “;
N

double marks;
cin>>marks;
O

cout<<”The grade is “;
grade(marks); // function call
return 0;
}
R

Output:
FO

Figure 4.55: Output of the program

208
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 208 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Note: There are two ways to call functions which are function call by value (pass
by value) and function call by reference (pass by reference).
(a) Call by value involves copying the values of actual parameters into the
formal parameters.
(b) Call by reference involves copying the address of the arguments into
actual parameters within the function.

Program examples 30 and 31 demonstrate call by value and call by reference.

LY
Program Example 30:

N
Finding the cube of the number using function

O
The following example demonstrates a C++ program that finds cube of the
number. The output is shown in Figure 4.56.

#include<iostream>
using namespace std;
int cube(int x)
SE
{
U
x=x*x*x;
return x;

}
int main()
E

{
int a;
N

cout<<”Enter number to find its cube “;


cin>>a;
LI

cout<<”Cube of “<<a<<” is “<<cube(a);// call by value


}
N

Output:
O
R

Figure 4.56: Output of the program


FO

You can use the following program example to learn on program that interchange
values which are entered by a user.

209
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 209 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Program Example 31:


A program to interchange value entered by the user
The following example demonstrates a C++ program that interchanges value
entered by the user. The output is shown in Figure 4.57.
#include<iostream>
using namespace std;
void increment(int &m)
{

LY
m++;
cout<<”The address of m is “<<&m<<endl;
cout<<”m inside the function is “<<m<<endl;
}

N
int main()
{
int x = 1;

O
cout<<”The address of x is “<<&x<<endl;
cout<<”Before the call, x is “<<x<<endl;
increment(x); //call by reference

}
return 0; SE
cout<<”After the call, x is “<<x<<endl;

Output:
U
E
N

Figure 4. 57: Output of the program


LI

Function prototype Built-in function


Before calling any function into the Built-in functions are functions stored
N

main function, it should be defined. This within standard library files. Such
is possible through writing function functions comprise mathematical, string
O

definition or function prototype. Function manipulation, conversions, and console-


prototype is the function header without based I/O function. The application of
function body. The function body will
R

the built-in function should involve their


be given, but the function should be
header files. For example, <cmath> for
introduced by writing its prototype. A
FO

function prototype contains return type, the mathematical functions and <cctype>
name, and parameters usually terminated for character manipulation. Table 4.16
by a semicolon. An example of a function shows some of the built-in function and
prototype is: int average (int n1, int n2); their application.

210
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 210 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Table 4.16: Built-in function

Built-function Application Header Example


sqrt (x) Find the square root of x <cmath> sqrt (x)
abs (x) Find absolute of x <cmath> abs (x)
exp (x) Find the natural exponent of x <cmath> exp (x)
pow(x, y) Find x power y <cmath> pow(x, y)
tolower(x) Convert character to lower case <cctype> tolower(x)
toupper(x) Convert character to upper case. <cctype> toupper(x)

LY
Returns true if x is uppercase
isupper(x) <cctype> isupper(x)
letter, otherwise it returns false.
Returns true if x is lowercase

N
islower(x) <cctype> islower(x)
letter, otherwise it returns false.
isPrime Returns true if x is prime numbr,

O
<cmath> isPrime
otherwise it returns false.
Casting
SE
C++ provides the use of casting technique to avoid implicit type conversion. Casting
is used to do data type conversion from one data type to another through the use of a
cast operator. The cast operator is also called type conversion or type casting.
U
Program Example 32:
Casting
The following C++ program demonstrates the use of casting . The output is shown
E

in 4.58
N

#include<iostream>
using namespace std;
LI

int main()
{
float l, w; //Declaration of length and width as integers data type
N

double area; //Declaration of area as double data type


/* This program asks you to enter length and with in float,and
displays the results in (i) float and (ii) integer
O

*/
cout<<”Enter a length in metres using float : “;
cin>>l; //Read value of length entered by the user
cout<<”Enter a width in metres using float: “;
R

cin>>w; //Read value of length entered by the user


area = l * w;
cout<<”The area of the rectangle in float (before casting) is “<<area<<” square metres”<<endl;
FO

//use casting int(area) to get area in integer


cout<<”The area of the rectangle (after casting) is “<<int(area)<<” square metres”<<endl;
return 0;
}

211
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 211 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Output:

Figure 4.58: The program demonstrating the use of casting in C++

LY
The following program example will help you to learn how to write a program
that changes, letter case using built-in function. Follow the commands properly and

N
practice them.

O
Program Example 33:
A C++ program to change letter case using built-in function

SE
The following example demonstrates a C++ program that changes letter case
using built-in function. The output is shown in Figure 4.59.

#include<iostream>
U
#include<cctype>
using namespace std;
int main()
{
char ch;
E

cout<<”Enter a character: “;
cin>>ch;
N

cout<<”You have entered: “<<ch<<endl;


cout<<endl;
if(islower(ch))
LI

{
cout<<”It is lowercase letter “<<endl;
cout<<”Its equivalent uppercase letter is “<<static_cast<char>(toupper(ch))<<endl;
N

}
else if(isupper(ch))
O

{
cout<<”It is an uppercase letter “<<endl;
cout<<”Its equivalent lowercase letter is “<<static_cast<char>(tolower(ch))<<endl;
}
R

if(isdigit(ch))
{
FO

cout<<”It is digit character “<<endl;


}
return 0;
}

212
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 212 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Output:

Figure 4.59: Output of the program

LY
Note: - A function“static_cast<char>( )” enable to translate the value within the
function tolower() and toupper( ) into character.

N
O
Activity 4.9 (b) Write a C++ program to
demonstrate how parameters
Understanding the application of are passed by value and by
some of the Built-in function
(a) Search on the internet built-in
SE reference.
2. (a) Differentiate between a
functions which are used to function prototype and
U
(i) Change character into a function header
number using ASCII system (b) Write a C++ program to show
(ii) Round decimal number into the application of the function
E

the whole number prototype.


N

(iii) Solve modulus division by 3. Create a C++ program that will


returning remainders after the prompt a user to enter the range of
LI

user divides two numbers. the number and choose to display


(b) Write header files of each function either an even, odd or a prime
N

(c) Write a C++ program to show the number. Then, the program will
application of each function. display selected types of number
O

according to the range entered by


Exercise 4.10 the user.
R

Example:
Answer the following questions.
FO

Enter range of the number: 5


1. (a) What is the difference between
Enter type of the number: prime
passing parameters by value
and by reference? Output: 2, 3, 5, 7, 11.

213
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 213 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Arrays and strings
Computer Science

Note: Use “isPrime” built-in


function to display prime Arrays
numbers. Suppose you are required to create a
4. Write a C++ program that can help program that can help a teacher to read
WAMO bank to calculate the total the marks of 50 students. To accomplish
amount of money (A) gained by this task you will have to declare 50
the customer after “n” number of variables with each variable storing one
years. Given, the interest rate “R” mark of a student. Such a plan is entirely

LY
provided by the bank is 12%. The difficult because you may not remember
program will prompt the user to and track names of variables. To solve
enter the amount of money (P) such problem, you can store all marks
of 50 students using a single declaration

N
invested by the customer and then
display the result on the computer of a variable. A typical data structure

O
screen. Hint: Use the formula, to help you achieve this is known as
A = P(1 + R ) n , Use function pow an array. Figure 4.60 shows a structure
(a, b) for ab. of array to solve a problem of creating
SE
numerous declarations.

Index number assigned


automatically, after being
U
initialised by programmer. Index
Name of the array number starts from zero (0)

float marks_one = 45 marks [0] 45


E

float marks_two = 67 marks [1] 67


float marks_three = 78 marks [2] 78
N

float marks_four =33.4 marks [3] 33.4


float marks_five = 56.7
LI

marks [4] 56.7


float marks_six = 12.3 12.3
marks [5]
float marks_seven =79.5 79.5
N

marks [6]
float marks_eight = 44.1 44.1
marks [7]
float marks_nine =90
O

....
……..
marks [48] 65.8
float marks_fortynine = 65.8
marks [49] 66
float marks_fifty = 66
R
FO

Figure 4.60: A structure of array

An array is a collection of elements of the same data types that can be stored in a
fixed size, placed in a contiguous memory location, and that can be individually
referenced. An array should be specified by its name and index. Instead of declaring

214
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 214 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
each variable separately, an array is Examples of declared array are:
used. Each index must be within square int a[5];
brackets. Array can be classified into double sum[7];
two types: One dimensional array and
Initialisation of one dimensional array
Multidimensional array.
Array initialisation means introducing
One dimensional array values to the arrays. The following is the
One dimensional array is the type of syntax of array initialisation:
array that involve one array name and dataType arrayName[arraySize] =

LY
only one subscript. {value0, value1, value3, …….., valuek}
Declaration of one-dimensional array Example: int marks[5] = {10, 35, 77,
An array can be declared using the syntax: 98, 100};

N
dataType arrayName[arraySize]; The given example of initialisation can
where:

O
also be defined as:
(a) dataType represents the data type int marks[5];
of all elements; marks[0] = 10;
(b) arraySize must be an integer greater
than zero; and
(c) arrayName must be a character or
SEmarks[1] = 35;
marks[2] = 77;
marks[3] = 98;
marks[4] = 100;
U
any word to represent an array.

Program Example 34:


E

Using array to print the sum of integers


The following C++ program uses array to print the sum of five integers. The
N

output of the program is shown in figure 4.61.


LI

#include<iostream>
#include<conio.h>
N

using namespace std;


int main()
{
O

int a[5], sum = 0, i;


cout<<”Enter 5 integers to store in array”<<endl;
for(i=0; i<5; i++)
R

{
cin>>a[i];
sum = sum+a[i];
FO

}
cout<<”The sum of the given numbers is: “<<sum<<endl;
return 0;
}

215
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 215 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Output:

Figure 4.61: Output of the program

LY
Multidimensional array
One dimensional array represents linear data structure. In order to represent

N
n-dimensional structure you are required to use multidimensional array. For example,
we use two dimensional array to describe a matrix or table.

O
Declaration of two – dimensional array
The syntax to declare two-dimensional array is given as
dataType arrayName[row size][column size]; SE
An example of a two-dimensional array is int matrix[3][3]; The array contains three
elements in a row and four elements in a column. Such an array can be tabulated as
U
shown in Table 4.17:

Table 4.17: Two-dimensional array


E

matrix[0][0] matrix[0][1] matrix[0][2]


matrix[1][0] matrix[1][1] matrix[1][2]
N

matrix[2][0] matrix[2][1] matrix[2][2]


LI

Initialisation of two-dimensional array


Initialise two dimensional arrays by listing all elements horizontally or arranging
N

members according to the feature of the array then enclosed them by curl brackets.
Here is the syntax for initialising two dimensional arrays,
O

dataType arrayName[row size][column size] = {list of values};


Example: int matrix[1][6] = {0,2, 7, 8, 9, 5}
R

or
int matrix[3][2]=
FO

{
{0,2},
{7,8},
{9, 5},
};
216
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 216 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Program Example 35:
Activity 4.10
Two-dimensional array
Filling number in the table
The following C++ program
Consider a box of 9  9 grid divided
demonstrates an example of a two-
into 3 3 small boxes as shown in
dimensional array. The output is shown
Table 4.18.
in figure 4.62.

LY
Table 4.18: Sudoku tables
#include<iostream>
6 9 4 1
#include<iomanip>
using namespace std; 7 1 5 9 6

N
int main() 5
{

O
int i, j, matrix[3][3]; 2 7 8 9
for(i=0; i<3; i++) 6 2 4
for(j=0; j<3; j++)
6 9 8

{
matrix[i][j]=i*3+j+1;
cout<<”Display an array: “<<endl;
for(i=0; i<3; i++)
SE 8
4
3
7
for(j=0; j<3; j++)
U
5
cout<<setw(2)<<matrix[i][j];
cout<<endl;
} (a) Fill all blanks where each row and
return 0; column should complete number 1
E

} to 9 without repeating any number.


N

(b) Write a C++ program using array


Output: that prompts a user to fill the box.
LI

The program should prompt the


user to enter the given number to
N

each box and display the completely


filled table.
O

Exercise 4.11
Figure 4.62: Output of the program
R

Answer all the questions.


Note: A function setw(2) creates a
FO

1. Define the following terms:


gap of 2 size between two
numbers as it is displayed in (a) Array
the output. (b) Two-dimensional array

217
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 217 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

2. Write a C++ program using array 4. Consider the declaration:


that allows a teacher to enter the int majumuisho[10][20];
number of students and their Write the C++ program that prints
marks. Then, the program should
all the elements in majumuisho.
find average class marks and use
It is required that all elements in
a “function” to state a grade class
the same row should appear on the
mark. Apply Table 4.19 to display
the grade class marks of students. same line, and each successive row
should appear on its own line.

LY
Table 4.19: Grade pass mark 5. Consider the declaration int
AVERAGE CLASS GRADE mayah[50][100][100][25];. How
MARK many elements does mayah hold?

N
81 – 100 A

O
61 –80 B String
41 – 60 C
A string can be defined as a collection
21 – 40 D of characters. It is a one-dimensional
0 – 20

3. Use a multi-dimensional array to


F SE
array made by characters. A string
should be terminated by a null character
create a C++ program that asks represented by ‘/0’. Termination of the
U
a student to enter the order and string is essential to make the function
elements of the matrix. Then, the know the end of the string.
program should display a matrix
E

and its transpose as represented in Declaration of a string


Figure 4.63.
N

String can be declared as


char stringName[stringSize] ;
LI

Initialisation of the string


N

Initialisation of the a string is done by


introducing the string value to the string.
O

Example of string initialisation is:


char name[ ] = {‘J’,‘U’,‘M’,‘A’,‘/0’};.
R

String standard function


FO

C++ programming language provides


different string standard library handling
functions. Some of the string library
Figure 4.63: Output of the program
functions are represented in Table 4.20.

218
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 218 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Table 4.20: String library function
Library function Application
strlen( ) Find length of the string
strcpy( ) Copy one string to another
strcat( ) Combine two strings
strcmp( ) Compare characters of two string

String operation

LY
Reading and writing in a C++ program are controlled by ‘cin’ and ‘cout’. While ‘cin’
reads a string in a program, ‘cout’ is responsible to write that string to the console
window.

N
Program Example 36:

O
Using character to demonstrate string function

The following is an example of a C++ to displays name and age. The output is
shown in 4.64.

#include <iostream>
SE
using namespace std;
U
int main()
{
char name[10];
int age;
E

cout<<”Enter your first name and age:”<<endl;


cin>> name>>age;
N

cout<<”You entered: “<<name<<” “<<age<<endl;


}
LI

Output:
N
O
R
FO

Figure 4.64: Output of the program

219
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 219 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
The following are some examples which use the string operations strcpy( ), strcat( ),
Computer Science

strlen( ), strcmp( ), strchr( ), and strstr( ).


strcpy( )
The following program example shows the use of a string function for copy.
Program Example 37:
Using Strcpy( ) string function
Taking the string s1 and s2 in strcpy(s1,s2). This string function of C++ will copy

LY
the string s2 into string s1.

#include <iostream>
#include <cstring>

N
using namespace std;
int main()

O
{
char string1[]=”Hujambo”;
char string2[]=”Mwananzengo”;
strcpy(string1, string2);
SE
cout << “The result of strcpy is : “ <<string1 << ‘\n’;
}
U
Output: The value of string2 (Mwananzengo) will be copied to string1 (Hujambo)
and string2 value will display (Mwananzengo) as shown in Figure 4.63.
E
N
LI

Figure 4.65: Output of string2


N

strcat( )
O

The following program example shows the use of the string function for concatenation.

Program Example 38:


R

Using strcat( ) string function


FO

Taking the string s1 and s2 in strcat(s1,s2). This string function of C++ will
concatenate the string s2 at the end of string s1.

220
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 220 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char string1[]=”Hujambo”;
char string2[]=”Mwananzengo”;
strcat(string1, string2);
cout << “The result of strcat is : “ <<string1 << ‘\n’;
}

LY
Output: The value of string2 (Mwananzengo) will be concatenated to string1
(Hujambo) and string2 value will be printed as shown in Figure 4.66.

N
O
SE
Figure 4.66: Output of string concatenation

strlen( )
U
The following program example shows the use of the string function for calculating
length of a string.
E

Program Example 39:


N

Using strlen( ) string function


LI

Taking the string s1 in strlen(s1), this string function of C++ will calculate and
return the length of string s1.
N

#include <iostream>
O

#include <cstring>
using namespace std;
int main()
R

{
FO

char string1[]=”Mzalendo madhubuti wa nchi yake”;


cout << “The result of strlen is : “ <<strlen(string1)<< ‘\n’;
}

221
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 221 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Output: The length of string1 will be as shown in Figure 4.67.

Figure 4.67: Output of string length function

strcmp( )

LY
The following program example shows the use of the string function which compares
the two string values and returns 0 if the two strings are the same; returns -1 if the
value of string1<string2, and 1 when string1>string2.

N
This function is used in a scenario where it is required to enter your name and
password to login to a particular website. In such cases, at the administrator side , it

O
is needed to build and script functions that will check and compare the input string
(login details) with the string stored in the data base of the site.

Program Example 40:


Using strcmp( ) string function
SE
U
Taking the string s1 and s2 in strcmp(s1, s2), this string function of C++ will
compare the string s1 and s2 and return 0, -1 or 1
#include <iostream>
#include <cstring>
E

using namespace std;


int main()
N

{
char string1[]=”Hujambo”;
char string2[]=”Mwananzengo”;
LI

cout << “The result of strcmp is : “ <<strcmp(string1, string2) <<


‘\n’;
N

Output: The result will be -1 as shown in Figure 4.68. Find the result when you
O

put char string1[]= “Mwananzengo” and char string2[]= “Hujambo”,


and when you put char string1[]= “Mwananzengo” and char string2[]=
“Mwananzengo”.
R
FO

Figure 4.68: Output of string compare function

222
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 222 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
Activity 4.11 Chapter Summary

Applying string library function in 1. Programming languages provide a


C++ program set of rules that guide the computer
to solve different problems.
Write a C++ program to show
Examples of programming
application of string library functions.
In your program include the following languages includes C, C++, C#,
functions: JavaScript, Visual Basics, etc.

LY
(a) strlen( ) 2. A translator is the language
(b)strcopy( ) processor required to change the
(c) strcat( ) program to the machine-readable

N
(d) strcmp( ) languages. Examples of translators

O
(e) strchr( ) are assemblers, interpreters and
(f) strstr( ). compilers.
3. Assemblers are required to convert

Exercise 4.12
SE programs designed by assembly
language to the machine codes
where a computer can execute
U
Answer the following questions. easily.
1. Differentiate between string and 4. Interpreter is the type of translators
array. which executes one line of the
E

2. Why do we use the null character codes at a time followed by the


‘/0’ in string initialisation?
N

next line of codes.


3. Write a program that displays the
5. Compiler is used to convert a
LI

statement “C++ programming


language”. whole program at a time into
machine codes where computer can
N

4. Can we declare an array to hold the


mixture of both and doubles and understand. Examples of compilers
O

ints? Explain. are Dev C++, Boland, Visual C++,


5. Explain what will happen if you etc.
attempt to access an element of an 6. Source code is a program written
R

array using a negative index? within an editor before being


FO

executed to machine language.


7. Object code is the machine-readable
code obtained after translating a

223
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 223 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

source code using a compiler or (b) High-level languages which


interpreter. include COBOL, Ada,
8. Programming languages passed FORTRAN BASIC, C, Python,
through five generations: Ruby, SQL, PHP, JavaScript
(a) First generation based on and Visual Basics, etc.
machine languages 10. The structure of the C++ program
(b) Second generation based on comprises
(a) header files “<include

LY
assembly languages
iostream>”
(c) Third generation based on (b) standard library “using
structural or procedural namespace std”

N
languages. Examples of third (c) main function “int main()”
generation languages are

O
(d) Main function body with exit
COBOL, Ada, FORTRAN
code “return 0”
BASIC and C.
11. You can compile a C++ program
(d) Fourth generation based on
graphical user interface and
SEusing Dev C++, Bloodshed, or
Visual C++
event driven. Examples of
12. Data types define types of data used
U
fourth generation languages
in C++ program
are Python, Ruby, SQL, PHP,
13. C++ has various data types used in
JavaScript and Visual Basics.
programming including:
E

(e) Fifth generation involves


(a) Built in data types (including
automated features including
N

fundamental data types:


application generator, which
characters, integers and floats)
LI

stops programmers from


typing a number of codes (b) Derived data types
N

like in other programming (c) User defined data types


languages. Examples of fifth 14. Variables can be defined as
O

generation languages are identifiers used to represent


Mercury, Prolog and OPS5. certain data or information in a
R

9. There are two levels of programming C++ program. Example of variable


languages: declaration is int x = 2;
FO

(a) Low-level languages which 15. Types of variables are local


include machines languages variables, global variables and
and assembly languages static variables.

224
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 224 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
16. Constants are values that cannot 23. Types of decision control structures
change during program execution. are if condition statement and
An example of the declared switch case statement
constants is int pi=3.14; 24. Iteration control structure involves
17. In C++ programming, “cout” is a while loop, do-while loop, and
used to display data to the screen for-loop.
as an output stream command while 25. Functions are set of instructions
“cin” is used to read data from the

LY
required to perform repeated tasks
keyboard to the computer as an
in a C++ program.
input stream command.
26. Syntax of writing function

N
18. Operators are signs as a result of in C++ program is dataType
operations to the operands. functionName(list of parameters);

O
19. Types of operators include 27. Elements of function include
arithmetic operators, assignment function definition, function calling
operators, compound assignment
operators, increment and decrement
operators (prefix and postfix),
SE and function prototype.
28. Parameters provide data
communication between the calling
relational operators, and logical
U
operators. function and called function.

20. Expressions in C++ programs 29. Arrays are a collection of the same
represent data such as variables, data stored under the same name.
E

constants interconnected with 30. There are two types of arrays:


N

operators. (a) One dimensional array,


21. Control structure explains line-by- example int a[5];
LI

line execution flow control and the (b) Multi-dimensional array


relationship of the data within a
N

example int arr[2][3][4];


program. It provides simple ways of
31. A string can be defined as a
solving problems within a program
O

one-dimensional array made by


by avoiding repeating typing the
characters. An example of the
codes.
R

declared string is char greatings[


22. Types of control structure include ] = {‘H’,‘E’,‘L’,‘L’,‘O’,‘/0’};.
FO

sequential, selection or Decision


and iteration or looping

225
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 225 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Revision Exercise 4 13. Write three versions of the hello.


cpp program that has a logic error.
Answer the following questions. 14. How do you discover syntax errors?
1. Discuss features of good
15. Read the following C++ program
programming languages. and answer the question that follow:
2. What software is required to
translate the source program into #include<iostream>
a machine program? using namespace std;

LY
int main()
3. Which programming language uses {
mnemonic to represent machine int num, temp, sum;
language instructions? cout<<”Enter a positive integer: “;

N
cin>>num;
4. Give five (5) features of a suitable cout<<endl;
programming language. temp=num;

O
5. Differentiate between executable sum=0;
do
file and any other file. {
6. Why do we need a compiler and
not an interpreter in a high-level
language?
SE
sum=sum+num%10;
num=num/10;
}
while(num>0)
7. Distinguish between compilers, cout<<”sum is: “<<sum<<endl;
U
interpreters, and assemblers as system(“PAUSE”);
return 0;
illustrated in the C++ program. }
8. Describe five generations of
E

computer programming languages. (a) What are the functions of the


9. State three advantages of the high- line #include<iostream>and
N

level over low-level programming system(“PAUSE”);


LI

languages. (b) Write an error made from this


10. Discuss the benefits of using program.
N

compiler over interpreter in high-


16. With examples, give the meaning
level programming languages.
of the following terms as applied
O

11. With an example in each in the C++ program


case, differentiate Procedural
(a) Reserved word
Programming languages from
R

(b) Keyword word


Object-Oriented Programming
(c) Constants
(OOP) languages.
FO

(d) Identifiers
12. Write four versions of the
17. Why do we need to state data type
hellowWorld.cpp program that have
when declaring variables in a C++
different syntax errors.
program?

226
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 226 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
18. How will you guarantee that a (a) IF……THEN statements
variable’s value can never be (b) IF... THEN ... ELSE statements
changed after its initialisation? 27. Write a C++ program to find all
19. How can you ensure that a variable’s roots of a quadratic equations. The
value can never be changed after its program should prompt a user to
initialisation? enter the coefficient and then,
20. Define the term variable as applied display roots. The program should
in C++ programming language. also be able to test the type of the
root displayed and state whether

LY
21. Explain why should we declare
those roots are real distinct,
variables before using them in a
identical or imaginary.
C++ program?

N
22. If a = 7, y = 4, z = 3, and u= 2, Note: For any quadratic equation
evaluate each of the following ax 2  bx  c  0 , if

O
statements, if possible. If it is not b 2  4ac , the root is real distinct
possible, state the reason.
b 2  4ac , the root is real identical
(a) (a + z) % y (b) (a + y % u
(c) (y + u) % a (d) (a + y) *u
(e) (a % y) % z (f) (y% z) % a
SE b 2  4ac , the root is imaginary
28. (a) Define the term nested loop
(b) Explain rules governing nested
U
(g) (a *z) % y (h) ((a *y) *u) *z
loop
23. Evaluate the following expressions. 29. Explain why do we use a function
(a) 15 / 3 (b) 17 - 12 / 4 * 2 in programming?
E

(c) 34 % 7 (d) 3 - 7% 7 30. Use a function named “largest”


(e) 18.0 / 4 (f) 20 - 5 / 2.0 to create a C++ program that
N

(g) 13 + 5 % 2 - 3 determines the largest number


(h) 1570 + 3.0 * 2.0 / 5.0 from a set of 10 numbers.
LI

24. Write the syntax of the following 31. What is a function? By using the
concept of function, write a C++
N

C++ statements:
program that prompts the user
(a) Switch case statement to input three integer values and
O

(b) Variable declaration and find the greatest value of the three
initialisation. values.
25. Differentiate between while loop
R

32. Write a C++ program that finds


and do-while loop as applied in
the reverse of number entered by
FO

C++ programming.
the user. When the number entered
26. In what circumstances would is ‘5261’ then the reverse value
you choose to use the following should be ‘1625’.
statements:

227
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 227 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

33. Given the declaration orodha [100]; the customer account by the amount
(a) What expression represents the withdrawn and the service charges,
very first element of orodha? if any.
(b) What expression represents the 36. Mr. Mbilimbi Kapilimposi is a
very last element of orodha? professor at the University of
(c) Write the code fragment that Dodoma (UDOM). Currently he
prints out the contents of teaches Nuclear Physics course
orodha? at the College of Natural and
(d) Is the expression list[3.0] legal

LY
Mathematical Science at UDOM.
or illegal? He has heard that you are the
34. Differentiate between string
computer programmer. Assume that
and character as applied in C++

N
Professor Mbilimbi has presented to
programming language.
you the list of the name of students

O
35. The NMB ATM allows a customer
in his class and their test scores
to withdraw a maximum of Tshs
for processing Nuclear atomic
1,000,000/= per day. If a customer
course. He asks you to design an
withdraws more than Tshs
335,000/= the service charge is 6%
of the amount over Tshs 335,000/=.
SEalgorithm that does the following:
(i) Calculates the average test
If the customer does not have scores, (ii)Determines and prints
U
sufficient money in the account, the the names of all the students whose
ATM informs the customer about test scores are below the average
the insufficient fund and gives the test score, (iii) Determines the
E

option to withdraw the money for highest test score; and (iv) prints
a service charge of Tshs 1250/=. If the names of all the students whose
N

there is no balance in the account or test scores are the same as the
if the account balance is negative, highest test score. You are now
LI

the customer will not be allowed required to accomplish this work.


withdraw any money from the (Hint:-You must divide this problem
N

ATM. If the amount to be withdrawn into subproblems as follows: The


exceeds Tshs 1,000,000/= , the first subproblem determines the
O

ATM informs the customer about average test score. The second
the maximum amount that can be subproblem determines and prints
withdrawn. Write an algorithm
R

the names of all the students whose


that allows the customer to enter test scores are below the average
FO

the amount to be withdrawn. The test score. The third subproblem


algorithm should check the total determines the highest test score.
amount in the account, dispense the The fourth subproblem prints the
money to the customer, and debit names of all the students whose test

228
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 228 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Four: C++ programming


DO NOT DUPLICATE
scores are the same as the highest month entered by the user and
test score. The main algorithm translate them into days.
combines the solutions of the (c) Use if…then statement to help a
subproblems.) system to know the number of days
37. Write a general syntax of pseudo for each month, where:-
code for each types of selection (i) January, March, May, July, August,
control structure October and December has 31 days
38. Draw a general syntax / formal (ii) April, June, September and

LY
of the flowchart for each types of November has 30 days.
iteration control structure. (iii) February has 29 days for leap year
39. Write a C++ program to display the and 28 days for an ordinary year.

N
following patterns: (d) Use isLeapYear( ) built-in function
to help a system identify the leap

O
year(with 366 days) made by 29
February.

(a) (a)
(b)
(a) (b)
(b) (c)

40. Create a calendar using a C++


SE (e) Make your program displays
(c)months’ calendar
(d)
after 1800.
for all years(d)
dated

(i) Example of the snapshot from the


U
programming language. A program
will prompt a user to enter a year leap year, 2012 is shown in Figure
followed by a month in a number. 4.68.
Then, the calendar will be displayed
E

as shown in Figure 4.67.


N
LI

Figure 4.70: Snapshot of the year 2012


N

(ii) Example of the snapshot from the


ordinary year, 1991 as shown in
O

Figure 4.69: Output of the program


Figure 4.69.
Hints:
(a) Use Switch case statement to
R

change the month entered by the


user in a number form to the name
FO

as it is displayed from the given


snapshot.
(b) Use function to read the year and Figure 4.71: Snapshot of ordinary year 1991

229
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 229 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Chapter
Five Website development

Introduction

LY
In today’s modern digital age, website is one of the ICT instruments that promote
achievements in several online activities. Websites are commonly used for

N
online activities including business settings, e-commerce, portals, blogs, and
social media, among others. In order to use them, websites must be designed,

O
developed, and published. In this chapter you will learn about the concept of
websites as well as their structures and how to design them. You will also learn
about how to develop and publish websites. The competencies developed in this
SE
chapter will enable you to create and publish websites.
U
Ask yourself the following:
E

(a) On how you can upload data to your website in the Internet.
(b) On how you can make your developed website to be accessible by users through
N

the Internet.
LI

Concept of website name. Websites are typically authored or


written in HTML, and they are viewed
N

A webpage is a document written in a


Hypertext Markup Language (HTML) using a web browser on the Internet or
O

and can be viewed in a web browser. intranet. The intranet is a local or restricted
Usually, the webpage has a unique communication network, especially a
Uniform Resource Locator (URL) to private network, used by an organization
R

enable its accessibility. Multiple web to share information and other computing
pages are usually contained within a single resources securely. Most websites are
FO

website. The website is a collection of designed for public use, although some
interlinked webpages that may be publicly websites exist for private (internal) use
or privately accessed with a single domain within an organisation.

230
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 230 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Types of websites 1) Static page Web browser

There are two main types of websites: is requested


by browser
static and dynamic websites. Static
websites have fixed contents. They Request Response
display the same content for each
user from time to time and they Web server 3) Web
2) Web server
are exclusively written in HTML. server
send page
One of its properties is that static finds page
website is faster to load. Figure 5.1

LY
shows an example of a static website
architecture. Figure 5.1: Architecture of static website

N
Dynamic websites combine advanced programming and databases in addition to
HTML to offer user interaction and modify content for the same and different users.

O
Dynamic website have content that may keep on changing as a result of interaction.
The dynamic website is relatively slow to load. Figure 5.2 shows an architecture of
a dynamic website.
Storage, logging and
retrieval of data
Store and Share
HTML pages SE Viewing and interaction
with HTML pages

Text
U
Database

Client/Web
Database
E

Web Server Server


Server
Figure 5.2: Architecture of dynamic website
N

The following, as shown in Figure 5.3 are the differences between static websites
LI

and dynamic websites:


N

e
ebsite I am a static websit
ic w
I am a dynam (a) Static webpage are simple HTML written pages,
O

all the data is static in nature and it does not get


(a) Its pages are written in complex
changed until users change it manually.
language such as CGI, AJAX,
ASP, and ASP.NET. (b) In static websites, all the data are static, and they
R

(b) Its content keep on changing. do not require interpretation.


(c) Wepages interpret the data. (c) Static webpage are written in simple languages.
HTML, JavaScript, and CSS are commonly
FO

(d) They take more time to load.


(e) Dynamic websites interact with used languages.
database. (d) Since the data is static, static webpages load faster.
(e) Static webpages have no interaction with database.

Figure 5.3: Differences between static and dynamic websites

231
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 231 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Generally, websites are used for various purposes including presenting, sharing or
Computer Science

displaying information online. Figure 5.4 shows an example of a website that can be
accessed using URL ( https://www.ikulu.go.tz).

LY
N
O
SE
Figure 5.4: An example of a website
Source: Ikulu Web portal (2022)

Activity 5.1
U
these web browsers include Hypertext
Transfer Protocol Secure (HTTPS) and
Exploration of static and dynamic File Transfer Protocol (FTP). There are
websites many web browsers in use. The most
E

common web browsers are Google


Using an internet search, visit various
N

Chrome, Microsoft Edge, Opera, Mozilla


webpages and analyse the features of Firefox and Safari as shown in Figure 5.5.
static and dynamic websites. Present
LI

the differences of the types of websites


Mozilla Firefox
that you have explored. Google chrome
N

Google chrome Mozilla Firefox


O

Web browsers
A web browser is a software that allows Safari
R

a user to find, access, and view websites.


Web browsers (or just browsers) convert Safari
FO

HTML and Extensible Markup Language


(XML) into a human-readable format and Microsoft Edge
Microsoft Edge
Opera
Opera
display it. Other protocols supported by
Figure 5.5: Commonly used web browsers

232
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 232 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Web content that you view in web To access a website, you must go through
browsers is provided by a remote the following steps:
computer server known as web server. Step 1: You must know a URL of
the website that you want to
Web server access. For example, a URL
A server refers to computer hardware for website of the Tanzania
or software or both. A web server Revenue Authority (TRA) is
stores, processes, and handles requests https://tra.go.tz/.
from web browsers installed on a Step 2: Open a web browser of your

LY
client computer. The web server uses choice, preferably from a
Hypertext Transfer Protocol (HTTP) desktop of your computer as
and Hypertext Transfer Protocol Secure shown in Figure 5.7.

N
(HTTPS) to communicate texts, images,
audios, and videos to web browsers.

O
The working principle of websites is
guided by client-server architecture
where browsers are regarded as clients,
and web servers are regarded as servers.
SE Figure 5.7: Opening a Google chrome
web browser
The server can handle multiple requests
U
from clients simultaneously. Figure 5.6 Step 3: The web browser will open as
shows how the web server responds shown in Figure 5.8.
to HTTP/HTTPS requests from client
browsers.
E
N

est
P S requ
HTT response Client 1
LI

PS Figure 5.8: After opening a Google chrome


HTT
web browser
N

request Step 4: Next, type the URL (tra.go.tz)


HTTPS se
respon at the address bar as shown in
HTTPS
O

Client 2 Figure 5.9 and then press the


HTT
HTT PS
PS r request Enter key.
Web server espo
nse
R
FO

Client 3

Figure 5.6: Websever handling of web requests


and responses in websites Figure 5.9: A typed URL address in the
address bar

233
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 233 25/12/2022 03:44


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 5: The TRA website will be displayed as shown in Figure 5.10.
Computer Science

LY
N
O
SE
Figure 5.10: TRA’s website
U
Step 6: To open a particular webpage, for example, a “Contacts” webpage, click on
its link as shown in Figure 5.11.
E
N
LI
N
O
R

Figure 5.11: Using a link to open a webpage


FO

Step 7: After clicking, a specific webpage that displays content about TRA contacts
will be opened as shown in Figure 5.12.

234
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 234 25/12/2022 03:44


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE

LY
N
O
Figure 5.12: A ‘contact us’ webpage

Advantages and disadvantages of a


SE
4. Websites enable entertainment
website through online games, movies and
U
The use of the website by business music.
organizations and individuals has many 5. Websites are used for marketing
benefits. Although websites are beneficial, and advertisements of products and
E

they still have disadvantages as well. As services.


a developer and user of a website, it is 6. Websites are used for banking services
N

essential to understand the advantages and employment possibilities.


and disadvantages of websites. Disadvantages of websites
LI

1. Websites cost money to develop


Advantages of websites and host. In hosting, you have to
N

1. Websites give you unlimited access pay annual fees as costs of domain
to worldwide information without registration, hosting domain name
O

limits of geographic location. and hosting website contents.


2. Websites help to bridge culture 2. Websites jeopardize the privacy of
R

among several countries and users. While some websites collect


continents in the world. users’ information through accepting
FO

3. Through websites, users can learn cookies and filling out standard
quickly the lifestyles, dressing, forms, it is unguaranteed whether
language, norms and foods of other owners of those websites will protect
nationals, among others. users’ privacy.

235
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 235 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
3. Some of the information posted on website’s overall aesthetic. Website
Computer Science

websites might not be appropriate. design frequently begins on paper, much


Some information may misinform like other ways of designing physical
users while other data may be structures such as houses and bridges. The
targeted to downgrade the morals paperwork website design is transformed
of the society. into computational form by coding.
4. Websites may be used to deceive Coding utilises a range of tools. After
users and defraud money from the developer has completed coding,
people. For example, through and a customer has been satisfied, the

LY
websites, users may be asked to website becomes ready for hosting and
provide bank details which are later use. Development of website starts with
used to debit their accounts without designing its structure.

N
their consent.
5. Some websites expose children The design of a website structure

O
to vulnerabilities. For example, determines how efficient and effective
websites displaying pornographic that website will become. Given that a
content create immediate and long- website comprises numerous separate
term effects on children. SE
web pages, those pages must be linked
and related. The website comprising
multiple interlinked webpages that are
Exercise 5.1
U
properly structured improves experience
of customers (visitors) who visit your
Answer the following questions.
website. Like a book or newspaper, the
1. Describe the differences between a website includes sections and subsections
E

webpage and a website. How are that must all be connected to portray the
they related?
N

full significance of website creation.


2. Explain the role of a Uniform
Resource Locator (URL).
LI

There are many types of website or


3. Differentiate between HTTP and webpage structures including hierarchical,
sequential, and database models. The
N

HTTPS.
4. Present ways through which hierarchical model is a famous website
O

websites are useful. structure that displays a tree structure by


beginning with a parent page. This page is
also known as a home page. The sequential
R

design stresses sequential access to many


Website design
web pages. This implies that you have to
FO

Website design is part of the process navigate through a predefined progression


of developing a website. That design of webpages. For example, if you are on
concentrates on the layout, contents webpage two (2), to reach webpage five
to be displayed, user interface and the (5), you must first go through webpage

236
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 236 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
three (3) and then webpage four (4). The database Website structure
model comprises dynamic websites that pull content The website structure refers to
from a database, mainly through searching. This the way your website is laid up.
section will introduce you to the hierarchical The sort of website structure
website structure that is widely used. you utilize is determined by how
content is displayed and where
The structure of most web pages is built on a it is placed. The structure of a
hierarchical architecture as shown in Figure 5.13. website might be hierarchical,
They have a portion at the top of the page that sequential, database-driven, or

LY
displays the organization’s emblem, name and hybrid.
a header with menus (links). A footer appears Audience awareness
typically beneath the webpage and provides

N
You must be mindful of your
numerous links such as copyright, contacts, and audience as a website designer.
terms and conditions.

O
What type of audience do
you want to attract with your
website content? Varied
SE groups of individuals usually
have different preferences
regarding how website content
is communicated. Elders,
U
kids, teens, students, sports
enthusiasts, religious and artist
lovers have various passions. It
E

is unlikely that the same design


will work for all groups.
N

Figure 5.13: Structure of webpage


LI

The panel on the left side of the webpage mainly Content purpose
displays menus. The panel on the right-hand Although a website may
N

side mainly shows news and adverts. Finally, the serve various purposes, the
section in the middle part is used to display the most common ones include
O

main content. to promote an organization’s


brand, gather information,
and sell products. In addition
Factors to considered in website design
R

to giving news, a well-


When creating a website, there are various factors to
designed website establishes
consider. Observing such factors while developing
FO

the company’s credibility


websites will ensure that your website is of high with consumers and investors.
quality to attract and retain users. The following Websites are also used to collect
factors are very important in designing websites. various types of information

237
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 237 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
from visitors. In online business, such as e-commerce, websites are used to sell products
Computer Science

and services. So, before you start building a website, figure out what it’s for because
it will determine what kind of content to present and how the site should be laid up.

Sitemap
A sitemap, like other maps, shows how your website is organized. It lays out how
your content will be divided into subjects and subtopics. The sitemap directs the user
to where certain information on the website may be found, even if that information
is difficult to find. Figure 5.14 depicts an example of a design of a site map.

LY
Home page

N
Administration Departments Combinations

O
Adv. Maths Physics PCB PCM

Typically, the sitemap begins with the


SE
Figure 5.14: An example of a sitemap for a high school website

a search engine to enable users find


U
home page. Search engines use that quickly what they need. Additionally,
sitemap to collect links to diverse online if there is more information, it may be
content when they explore the Internet. necessary to categorise it to improve
usability.
E

Clarity
A website design should accomplish Accessibility
N

content clarity, displaying what a visitor Most web browsers should be able to
LI

(consumer) could require and where visit a well-designed website. You must
they can acquire it quickly on your site. test your website on multiple browsers
With too much overlapping content, a to check how it displays, and if the
N

sophisticated website may confuse clients, display is horrible, you must improve it.
The website must accommodate persons
O

causing visitors to become dissatisfied.


Any comprehensive website with few with impairments as a critical aspect of
distractions, on the other hand, establishes accessibility.
R

a degree of clarity.
Mobility friendly
FO

Usability Nowadays, people use portable devices


Your website visitors should be able to such as smartphones, tablets, desktop
navigate it. Depending on the quantity of and laptop computers to visit websites.
published content, a website may require Therefore, the website design should

238
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 238 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
address how online information will be HTML
displayed on those portable devices.
Concept of HTML
Loading time HTML stands for Hypertext Markup
Expectedly, good websites should load in a Language. It is a standard or primary
matter of seconds. Visitors will be irritated language for creating websites. A web
by a website with images that have not page’s basic structure of HTML document
been optimised to load quickly. In the end, consists of three key components: html,
visitors will choose to quit your website,
head, and body. These components are

LY
making the reason for being useless.
enclosed with <tagName> as opening
tag and </tagName> as closing tag.
Activity 5.2

N
These tags are commands which instruct
Observation of a poorly designed web browsers on how they should

O
website display webpage content. Figure 5.15 is
Use the following steps to observe an example of the basic structure of a
poorly designed websites: webpage with HTML tags.
1. Visit the following websites:
(a) www.websitesthatsuck.com
SE <html>
(b) www.worstoftheweb.com
U
<head>
2. Write down your views about these
websites. </head>
3. From each website, choose two
E

features of quality webpage design <body>


Contains actual content
and identify aspects that indicate a
N

poor design. </body>


</html>
LI

4. Open four (4) websites of any


Regional Commissioner’s Office
in Tanzania and compare their
N

Figure 5.15: A basic structure of HTML


design qualities. The URL of document
those websites may be obtained
O

by searching a name of a region There are two types of tags in HTML:


in a search engine. Alternatively, paired tags and empty tags. Paired tags
R

you can use the following have an opening tag and its corresponding
domain structure: “www.<name closing tag. However, the empty tag has
FO

of region>.go.tz. For example,


the opening tag only. Figure 5.16 shows
www.mbeya.go.tz will open
paired tag and empty tag.
the website of Mbeya Regional
Commissioner’s Office.

239
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 239 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
Figure 5.16: An example of paired and empty tags in HTML

Apart from tags, HTML uses elements and attributes in creating a webpage. HTML

N
tags indicate the beginning and the end of an HTML element. These tags usually
begin with the “<” sign and conclude with the “>” sign. Therefore, something

O
between these signs, such as “< > “ is called a tag. This is an example, <b> , (tag
to bold text.). HTML element refers to a start tag, element content and an end tag.

SE
HTML attributes are used to define a specific feature of an HTML element in greater
depth, and they are usually found in starting tags as shown in Figure 5.17.
U
HTML attribute
Element contents
HTML tag
E

HTML element
N

Figure 5.17: Illustration of HTML tag, element and attribute


LI

HTML editors
N

An HTML editor is a program that is used to write HTML codes. There are many
O

types of HTML editors such as Notepad, Tiny, Atom, Sublime, Visual studio code,
Vim, Dreamweaver, Froala, Kamodo Edit and Brackets.io. As an HTML novice, you
should choose a simple HTML editor since it allows you to learn from the ground
R

up by typing each HTML code by hand. The Notepad is one of the simple editors.
FO

Steps on how to open a notepad


To open a Notepad in Windows Operating Systems (for example Windows 10), you
must follow the following steps:

240
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 240 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Step 1: Click on the windows search bar and type “Notepad” as shown in Figure 5.18.

Figure 5.18: Searching a Notepad program in the windows search bar

LY
Step 2: Click a Notepad App to open the notepad application as shown in Figure
5.19.

N
O
2
Click here

SE
U
E

Figure 5.19: Opening a notepad editor for HTML


N

Step 3: The notepad application will be opened as shown in Figure 5.20.


LI
N
O
R
FO

Figure 5.20: The notepad editor

241
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 241 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Parts of HTML
Computer Science

HTML, head, title, and body are the most critical components of HTML documents
as shown in Figure 5.21. The HTML tells web browsers that the content they are
receiving is of the HTML type. A webpage usually features a head section that
provides machine-readable data (metadata). Metadata comprises of titles, style
sheets and scripts. The body part is a segment where you write or compose content
for displaying on a webpage.

LY
N
O
SE
U
Figure 5.21: Basic parts of HTML written on a Notepad editor
E

Creating and saving HTML files


N

After opening an editor and knowing the essential parts of HTML, the next stage is
to create a simple HTML webpage and save it. Use the following steps to create and
LI

save the HTML file


Step 1: Create a webpage as indicated in Figure 5.22.
N
O
R
FO

Figure 5.22: An HTML webpage

242
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 242 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Step 2: While on the Notepad, to save the webpage, click on File àSave As and
select Desktop as a place where you keep your HTML file.
Step 3: Write the name of your HTML file. This example uses “MyFirstpage.html”.
The file must end with an html extension (.html) as shown in Figure 5.23.
Step 4: To finish saving your file, click “Save” as shown in Figure 5.23.

LY
N
O
SE
U
Figure 5.23: Saving a webpage

Step 5: After saving, if you are using the Google Chrome web browser, your HTML
E

file will look as shown in Figure 5.24.


N
LI
N

Figure 5.24: An iconic view of HTML document in a browser


O

Step 6: To open it double-click the HTML you have saved. The webpage will be
displayed as shown in Figure 5.25.
R
FO

Title of your webpage


Content displayed

Figure 5.25: A webpage view

243
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 243 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
HTML in website development It is good practice to employ background
Computer Science

and font colours while constructing


Paragraphs, background, and font
webpages. The default background
colours
colour for the first HTML webpage you
You cannot just add spaces or even blank generated in Figure 5.25 was white.
lines between paragraphs as it is done in On top of that, red, black, green, blue,
word processing software. The browser and other colours may be used as the
automatically removes those extra background colour. A colour is chosen
spaces. Furthermore, browsers display depending on personal preference and

LY
text differently depending on the size the target audience. Furthermore, text
may also come in a variety of colours.
of the monitor (screen); thus, different
Figure 5.26 demonstrates how to create
screen sizes provide different results.
a webpage that contains non-default

N
HTML employs the paragraph tag to colours for a background and different
direct how online content is presented. paragraphs and font colours.

O
SE
U
E
N
LI

Figure 5.26: A webpage with paragraphs, background and font colours


N

The output of HTML code in Figure 5.26 is shown in Figure 5.27.


O
R
FO

Figure 5.27: An output of an HTML code on paragraphs, background and font colours

244
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 244 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Tables and headings (d) The “<th> </th>” creates table
The creation of web pages may involve heading.
displaying information in tabular forms,
especially when you want to display Additionally, inside the table, the tag
information in rows and columns. “<th> </th>” may specify a heading cell.
Information such as examination results By default, the tag aligns content of the
is usually presented in tabular form. heading cell to the center and displays it
The basic structure of HTML table is in bold.
made up of four HTML tags which are

LY
“<table> </table>”, “<tr> </tr>”, “<th> In creating a webpage, you may need
</th>, and “<td> </td>”. Each tag is to write texts that appear as subject
explained as follows: headings. To do this, you have to use

N
HTML tags for heading. The <h1>, <h2>,
(a) The “<table> </table>” tag instructs
<h3>, <h4>, <h5> and h6> tags create
browsers to display a table;

O
HTML headings. The <h1> designates
(b) The “<tr> </tr>” tag creates a table
the most essential heading while <h6>
row; and
represents the least important heading
(c) The “<td> </td>” creates table data. SE
as shown in Figure 5.28.
U
E
N
LI
N
O
R
FO

Figure 5.28: An HTML code for headings and table

245
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 245 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
The output of HTML code in Figure 5.28 is shown in Figure 5.29.
Computer Science

LY
N
O
SE
Figure 5.29: An output of an HTML code on tables and headings

Forms (c) <button>: used to command an


U
Some websites are used to gather action, such as sending or submitting
information from visitors. Therefore, data.
internet users must fill out the form(s)
E

like how you would fill out a paper form The input element comprises of many
when applying to open a bank account. attributes including text, checkbox, radio
N

Similarly, HTML provides a tag that and submit button. Each of these attributes
allows you to build forms. The HTML
LI

is briefly described as follows:


form is generally defined according to
1. Text: this provides an input field
the following syntax.
N

where the user enters data.


<form> 2. Check box: this enables a user to pick
<!--form elements-->
O

more than one or all options out of


</form>
all options available.
3. Radio button: unlike the check box,
R

The HTML form has many elements.


Some of these elements are: the radio button enables a user to
pick one option out of all options
FO

(a) <label>: used to define a caption in


HTML form. available.
(b) <input>: used to collect data entered 4. Submit button: this allows a user to
by user (visitor). send or submit the data entered.

246
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 246 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
To show how a form may contain these elements, study the HTML code in Figure
5.30. This figure depicts a form that is used to collect information about surname,
food someone likes and regions where that person have visited in the past.

LY
N
O
SE
U
Figure 5.30: An HTML code for a form

The output resulting from the HTML form code in Figure 5.30 is shown in Figure
5.31.
E
N
LI
N
O
R
FO

Figure 5.31: An HTML form

247
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 247 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Activity 5.3
An HTML form for recording customer’s details
After completing form six, you decide to do a business. You open a shop to sell
fruits. To keep in contact with your customers, you opt to use a website. Now,
create an HTML form that will help you record your customers’ details and their
preferences. The page should be structured as shown in Figure 5.32.

LY
N
O
SE
U
E
N
LI
N
O
R
FO

Figure 5.32: An HTML page for activity 5.3

248
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 248 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
1. <b> will bold your texts;
Activity 5.4
2. <i> will make your texts italic;
Writing HTML codes 3. <mark> will highlight your texts
(default color is yellow);
Write HTML codes to create a form
with three elements: name, gender, 4. <small> will reduce the size of
and a submit button. Both gender your texts;
items should be radio buttons, and 5. <del> will delete (strike through)
one of them should be checked. The texts;

LY
background of the form should be pink. 6. <ins> will insist texts by
underlining them;
7. <sub> will create a small letter
Text formatting

N
or text just below a line of text
HTML text formatting is comparable
(subscript); and

O
to how text formatting is done in word
processing application software. The 8. <sup> will create a small letter
following formatting elements organize or text just above a line of text
or present your texts in the following way: SE (superscript).

The HTML code in Figure 5.33 shows how text formatting elements are used.
U
E
N
LI
N
O

Figure 5.33: A text formatting in HTML


R
FO

249
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 249 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
The output of HTML code in Figure 5.33 is shown be a visual representation
Computer Science

in Figure 5.34. of a bridge; in this instance,


the image represents the
bridge. The use of images in
websites has both advantages
and disadvantages.

Advantages of using
images in websites

LY
The use of images in websites
has many advantages, such
as:

N
1. Websites that use images
attract more visitors.

O
2. Images create a near
to reality of actual
SE
Figure 5.34: The output of HTML code on text formatting
products and services
offered through websites
that sell products and
services.
U
Images and lists 3. I m a g e s enhance
Images may be added to the HTML webpage to make communication because
it more informative. The image must be embedded in a picture speaks a
E

HTML code. The <img> tag is used to embed the thousand words.
image. The <img> tag is empty and has no closing
N

4. Images create attraction


tag, but it includes attributes. The two attributes to your website because
LI

are “src” which refers to a path where an image is they show up in search
stored, and; “alt” which specifies an alternative results generated
description to the image. Alternative texts appear
N

by search engines.
when you put a mouse over an image. The <img>
The search engine
O

tag has the following syntax: <img src=”path to a


understand images by
file” alt=”alternative texts”>.
relying on ‘alt’ text that
describes the image.
R

Images in websites
An image is simply a visual representation of 5. Uses of images increase
FO

something. It might be a photograph of a person or dwell time. Dwell time


any other object, a case in which the image symbolizes refers to an actual length
that individual or object. In website development, an of time spent by a visitor
image must be in an electronic (digital) form. It may on your website.

250
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 250 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Disadvantages of using images on 3. JPG/JPEG –Joint Photographic
websites Experts Groups
1. Your images may stay on Internet It is a popular image format for usage
–denying a right to be forgotten. in web content. JPEG images are
2. Some people may misuse your “lossy” because shrinking the file
vision –for example, by editing and size reduces the image quality. JPEG
correlating to negative connotations supports up to 24-bit colours and a
(reflections). maximum image size of 64Kx64K
3. Most images on websites can be pixels. The JPG and JPEG file

LY
downloaded for the use of what the formats are the same.
owner did not intend. 4. GIF –Graphics Interchange Format
Due to its small size and mobility,

N
Types of images and the right resolution this format is mostly used for online
graphics. It has a semi-transparent
There are many types of image formats.

O
background and may be animated. It
The common image format in use include:
is a lossless picture format because
1. TIFF (.tif, .tiff)
no information is lost when the
TIFF or Tagged Image File Format is
known for not losing image quality.
It uses lossless compression while
SE image is compressed. It is ideal
for web distribution of icons and
pictures because of the small file
maintaining the original image data.
U
size and lossless format.
TIFF files are typically large in size
because no information is lost when
Dimensions of images
images are saved. For this reason,
Images have dimensions, particularly
E

TIFF files are not suitable for usage


on web because of their large sizes. height and width. These dimensions
N

However, they are excellent for are expressed using either pixels or
high-resolution prints, professional percentages. A pixel stands for picture
LI

publications, and archival copies. element and is abbreviated as “px”.


The pixel is the smallest unit of data
N

2. PNG - Portable Network Graphics in an image. Pixels are represented by


This format is more suitable for squares and they are arranged in a two-
O

use on websites but undesirable dimensional grid. Such pixels consist of


for printing. PNGs are known for small squares that make up the image.
their high-quality (lossless) images;
R

however, excessive use of larger file Image resolution refers to a level of


sizes on web pages slows download details in an image and equates to the
FO

speed. The PNG file format is also number of pixels available in one (1)
used to store web images and inch. Image resolution is expressed in
other graphics with transparent Dot Per Inch (DPI) or Pixels Per Inch
backgrounds. (PPI). Resolution may also be expressed

251
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 251 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
in the width and heights of an image. For speed. To achieve this, many strategies
Computer Science

example, the image with 400 px (width) are put in place including:
and 300 px (height) contains 120000 1. Compression and optimization of
(400 x 300) pixels of the image in total. images: this entails compressing and
The higher the resolution, the higher the optimizing images while retaining a
quality of the image. You can resize an certain degree of quality.
image in pixels or percentages. Usually, 2. Enabling browser caching: this
the original image file size is counted strategy provides the means to store
to be 100%. For example, resizing that some images in a client’s browser

LY
image to 70% means you are reducing so that when another webpage is
the size of that image. In contrast, loaded, the existing images are used
resizing your image to 120% means you rather than having to retrieve them

N
are increasing the size of your image. from the web server.
3. Using lightweight image formats:

O
Effect of emerging quality and graphics
this strategy uses image formats like
on download speed
PNG and JPEG that are lightweight
The use of images on web pages affects
the download speed. When compared to
text, images take longer to download.
SE
and suitable for web use.

Lists in websites
On the contrary, having a web page A webpage’s items may be organised
U
without images limits how effectively you using lists. There are three types of lists
may communicate with your audience. that can be used: ordered, unordered and
Images assist visitors to a web page in description list. The ordered list is usually
E

comprehending the information being numbered whereas the unordered list is


given to them. Customers will bounce if represented using bullets. The description
N

a page takes too long to load, rendering list is used to create a list of items and their
your website ineffective. In this regard, a descriptions. The syntax for the ordered,
LI

compromise must be struck between the unordered, and description lists is shown
picture and graphic quality, and download in Figure 5.35.
N
O
R
FO

Figure 5.35: The syntax for ordered, unordered lists and description lists

252
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 252 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Towards applying the syntax, Figure 5.36 presents HTML codes that create the
ordered, unordered, and description lists.

The path to a file where an


image is stored. The path
must include a file format
such as JPG

Ordered list

LY
Unordered list

N
O
SE Description list
U
Figure 5.36: An HTML code for images and lists
E

The HTML code output from Figure 5.36 Linking HTML pages
is shown in Figure 5.37.
N

Linking webpages means creating


a connection between one page and
LI

another. Webpage links help the user


(visitor) to seamlessly switch among
N

different webpages in a website. The


following is a syntax for creating links
O

in webpage: <a href = “url”>Text


describing a link </a>. As an example,
to show how to create links, three HTML
R

files are created, namely: OrderedList.


FO

html and UnorderedList.html as shown


in Figure 5.38 and TypeList.html in
Figure 5.39. The output of HTML code
Figure 5.37: An output of HTML code on
images and lists in Figure 5.39 is shown in Figure 5.40.

253
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 253 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
Figure 5.38: HTML code for an ordered list and unordered list webpages

N
O
SE
U
Figure 5.39: An HTML code containing links to other web pages
E
N
LI
N
O

Figure 5.40: An output of HTML code in Figure 5.39

Activity 5.4
R

Creation of HTML webpage.


FO

Create an HTML webpage that displays an output similar to that shown in Figure
5.41. You may add other regions, agricultural products grown and districts
available in each region that you have added.

254
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 254 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE

LY
N
O
SE
U
E
N
LI
N

Figure 5.41: Output of HTML code


O

Exercise 5.2 3. Explain the use of the following


tags in HTML:
Answer all questions
R

(a) <tr> (b) <td> (c) <th>


1. Explain the meaning of an HTML 4. Create an HTML page that has the
FO

link and the role it serves in following features:


websites.
(a) the title of a page should read
2. Give five (5) examples of HTML
“Home page”;
tag elements.

255
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 255 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
2. It is easier to maintain: with CSS, you can
Computer Science

(b) the background colour


change the style in one part of the webpage
should be grey;
(usually in a head section), but the effect
(c) place the name of your will occur in every area where you used
school at the top of the that style in a webpage.
page in the large text;
3. Compatibility: CSS is compatible with most
(d) below the name of your browsers and computer hardware.
school, put a motto
4. Improved speed: website developers
statement for your school
utilise a few lines of code to improve site

LY
in a reduced text size;
performance, and hence shortening the
(e) add subject combinations download time.
(abbreviations), which
5. Consistent design: as far as styles are

N
your school offers; and
placed in a specific section and reused,
(f) below each combination, there is consistency in how the webpage

O
use an unordered list to is designed.
write subjects (in full
6. Search engine optimisation: CSS has a
name) that constitute the
combination. Use different
text colours for each
SE
small number of lines of code and a simple
structure. In this situation, search engines
go through a CSS-based page much more
subject.
quickly.
U
Cascading Style Sheets
The Cascading Style Sheets Structure of CSS
E

(CSS) is a language designed The CSS consists of a selector and declaration.


to enable the creation of styles The selector is an affected component while the
N

in HTML. The CSS is used to declaration comprises what is done to affect the
change colour, font style, font selector. The CSS structure is exemplified in
LI

size and space between web Figure 5.42.


content. You may create a style
N

in the heading and reuse it


multiple times within a whole
O

webpage.
The use of CSS offers many
R

benefits such as:


1. Time-saving: you do not
FO

need to create a style


repeatedly; instead, you
make it once and reuse it
Figure 5.42: A basic CSS structure
to save time.

256
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 256 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
The CSS essential elements include body colour, font style, font size and background
colour. Figure 5.43 shows how to create CSS style for these CSS essential elements
in which y1, y2, y3, q1, and q2 are selectors.

Background of a webpage set


to powderblue colour

Setting up colours of text

LY
Setting up font
colour and font
family of texts

N
O
SE
U
Figure 5.43: CSS code in HTML
Exercise 5.3
Answer the following questions.
E

1. Can this HTML code be executed? <img .src = “mount_klm.png” alt = “Mount
N

Kilimanjaro” />. Explain your answer.


2. Define declaration block.
LI

3. Explain the meaning and role of a CSS selector.


4. Build a webpage in HTML that:
N

a) uses CSS to set the background colour of a webpage to “MediumSeaGreen”


O

colour;
b) uses a CSS style named style1. Style1 sets the colour to “red”, font family
to “verdana”, and font size of 200%;
R

c) uses a style named style2. Style2 set the colour to “red”, font family to
“courier”, and font size of 120%; and
FO

d) After creating those CSS styles, write two paragraphs in HTML code.
Use style1 to format the first paragraph and style2 to format the second
paragraph.

257
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 257 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Introduction to JavaScript
Computer Science

You may have previously encountered situations when you fill out an online form
and immediately receive warnings, for example, for mistakes you made when
entering data in a form. Similarly, it is usual for certain websites to demand a user
to generate a password with a minimum of, for instance, eight characters. In other
circumstances, if you forget to fill in a field, you will be alerted that a certain field
is blank. These few illustrations demonstrate dynamic characteristics of websites
where content of webpage changes.

LY
You learnt in previous sections that websites may be static or dynamic. Dynamic
websites have content that change whilst a user is still on the same webpage.
Dynamic characteristics of webpages may occur in browsers (client-side) or as a

N
result from web server (server-side) as shown in Figure 5.44.

O
Client-side
Client-side script
Server-side
SE
Enabled by
JavaScript

� Executes (runs) in browser


� Change content in browsers JavaScript codes Stores JavaScript, CSS
and HTML
� Reduce workload on server
U
Uses PHP, Python and
Enabled by PHP,

Results from database Ruby to generate


Python, Ruby

Results from web server content from database


� Browser receives dynamic
results
E

� More workload on server


N

Figure 5.44: Client-side and server-side scripts


LI

Small programs that are downloaded as an outcome of result generated by a


from a web server and transmitted web server from database as shown in
N

to browsers are known as client-side Figure 5.44. The web server receives
scripts. These scripts execute (run) requests from users for information
O

in browsers to alter HTML pages whose corresponding data is stored in


dynamically. Client-side scripts database. The web server uses server-
R

minimise server processing overhead by side scripts to manipulate data and send
allowing users to read and write HTML results to browsers. These results make
FO

components in their browsers. JavaScript the HTML page to change its content,
is a popular example of client-side hence dynamic webpages. Examples of
scripting language. Besides JavaScript, server-side scripts include PHP, Python,
content of the HTML page can change and Ruby which run on the web server.

258
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 258 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
JavaScript plays a significant typed since the data type is not determined before
part in website design, ensuring the declaration or usage. In terms of memory usage,
that the website is appealing Java needs more memory compared to JavaScript.
and comprehensive. Most of Moreover, Java code must be compiled whereas
the websites today use HTML, JavaScript code is all in text.
CSS and JavaScript.
Importance of JavaScript in webpages
Java and JavaScript JavaScript is important in websites for a variety
Scripting language means of reasons. JavaScript enables HTML pages

LY
a lightweight programming to change content in user’s browsers without a
language. JavaScript is a need to communicate and retrieve data from a
scripting language, embedded web server. In this case, the use of JavaScript

N
in an HTML page to enable reduces processing overload that would have
interactivity on webpages. It been incurred by the web server. Being a loosely

O
is an interpreted rather than typed language, JavaScript is even easier to learn.
compiled language. JavaScript In a broader context, JavaScript is used to do
is mostly used to produce
dynamic content for websites. In
doing that, JavaScript handles it
SE
many things including:
1. validating user’s input –such as validating
correctness of passwords and emails;
without a need to communicate 2. creating cookies – cookies identify your
U
to a web server. computer when you connect to the internet,
with the aim of assisting websites to track
Java, on the other hand, is an your visits and activities;
object-oriented programming
E

3. reacting to events – this enables reaction to


language with a virtual machine events such as clicking on submit or reset
N

platform that allows you to button; and


compile and run applications. 4. detecting browsers – determining which web
LI

This programming language browser is being used.


is machine independent. This
N

means that, once compiled, it


Syntax of JavaScript
can run on the most of machines.
The syntax for JavaScript is shown in the
O

Whereas Java is a standalone


language, JavaScript cannot following script tag.
stand on its own. It must be <script language=”javascript” type=”text/javascript”>
R

embedded in HTML. Java is Your JavaScript code goes here


also a highly typed language </script>
FO

because the data type of a


variable is determined before There are two arguments in this script: language
declaring or using it. On the and type. The language attribute specifies
contrary, JavaScript is loosely the scripting language, which by default, is

259
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 259 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
“javascript”. The language attribute may be left out, yet the JavaScript code will run.
Computer Science

The type attribute should be set to “text/javascript” to show the scripting language
in use.

The next issue concerns the placement of JavaScript code in HTML. JavaScript may
be placed in the head or body section of an HTML page. The following examples
demonstrate two placement methods of JavaScript.

Script placed in the head section Script placed in the body section
<html> <html>

LY
<head> <head> </head>
<script type=”text/javascript”> <body>
JavaScript code <script type=”text/javascript”>

N
</script> JavaScript code
</head> </script>

O
<body> Body content
Body content </body>
</body> </html>
</html>
SE
JavaScript code is written in the same way as other programming languages. In
JavaScript, the statement is terminated by a semicolon. Simply use a double forward
U
slash if you need to add a comment. Figure 5.45 shows how to write a simple
JavaScript code embedded in the HTML code.
E
N
LI
N
O

Figure 5.45: A simple JavaScript code embedded in HTML

The output of JavaScript code written in Figure 5.45 is shown in Figure 5.46.
R
FO

Figure 5.46: An output of JavaScript code

260
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 260 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
JavaScript in web development
Variables
There are three (3) main ways to declare variables. These ways are indicated as
follows:
1. Using a keyword var –this is a common way to declare a varible. The following
are examples of declarations that use the keyword var:
var age; //declaration
age =18; //assignment

LY
var age =21; //declaration and assignment

2. Using a keyword let. The following are examples of declarations that use the

N
keyword let:

O
let greetings; //declaration
greetings =“Hello, good day”; //assignment
let month =“January has 30 days”; //declaration and assignment
SE
3. Using a keyword const. The following are examples of declarations that use
the keyword const:
U
const surname; //declaration
surname =“Kajumulo”; //assignment
const firstname =“Alex”; //declaration and assignment
E
N

JavaScript, like most other programming languages, is case sensitive. As a result, you
must make sure that keywords, variables, function names, and other identifiers are
LI

utilized consistently throughout the program, just as they were written. Furthermore,
the language features reserved words that cannot be used as identifiers.
N

Output in JavaScript
O

There are many ways to output in JavaScript. These ways are described as follows:
1. window.alert(): this function generate an alert box with some text inside it and
R

an OK button. After a specific occurrence, the alert box is triggered, and the
webpage becomes inactive until the alert box is removed by clicking the OK
FO

button. The method has the following syntax: window.alert(). The JavaScript
code in Figure 5.47 shows how to use the window.alert function.

261
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 261 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
N
Figure 5.47: A JavaScript to display output using an alert method

O
The output of JavaScript in Figure 5.47 is shown in Figure 5.48.

SE
U
Figure 5.48: An output of JavaScript code from Figure 5.47

2. document.write(): this approach tests and displays the output within the body
E

of the text. The JavaScript code that uses document.write function is shown in
N

Figure 5.49. This method has the following syntax: document.write().


LI
N
O
R
FO

Figure 5.49: A JavaScript to display output using a document.write method

262
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 262 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
The output of JavaScript in Figure 5.49 is shown in Figure 5.50.

Figure 5.50: An output of JavaScript code from Figure 5.49

3. innerHTML: it is responsible for defining and writing the HTML content. The
innerHTML file enables you to edit and customize HTML files. The innerHTML
has the following syntax: document.getElementById (id). The JavaScript code
in Figure 4.46 shows how to use innerHTML function.

LY
N
O
SE
U
Figure 5.51: A JavaScript code for the innerHTML function

The output of JavaScript code in Figure 5.51 is shown in Figure 5.52.


E
N
LI
N
O

(a) (b)

Figure 5.52: An output of JavaScript innerHTML function in Figure 5.51


R

4. console.log(): this method sends information to the browser’s console. It is a


FO

strong method that creates thorough results. The log function takes an argument
that contains the data you wish to display. The console log has the following
syntax: console.log(). The JavaScript code in Figure 5.53 shows how to use
console.log function.

263
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 263 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
Figure 5.53: A JavaScript code console.log function

N
O
SE
Figure 5.54: An output of JavaScript console.log function in Figure 5.53

If you cannot see the output similar to that shown in Figure 5.54, do the following.
U
For example, if you are using a Google chrome browser, go to the Console tab in
chrome’s developer tools, then select “More tools”. Open “Developer Tools” and
then click on “Console”. You may be required to enable JavaScript if it was not
enabled in your browser.
E

Array methods
N

An array is a collection of elements of the same kind that are stored in


LI

consecutive memory locations and may be accessed separately using an index that
is unique to each element. Arrays in JavaScript may be created or declared in many
N

ways, including:
1. Use of array literal: the syntax for declaring arrays using literal has the form: <variable
O

keyword> variable name =[“element 1”, “element 2”, …, “element n”].


a. For example: var combinations = [“PCB”, “PCM”, “EGM”, “CBG”];
R

2. Use of new keyword: the syntax for declaring arrays using new keyword has the form:
<variable keyword> variable name =[“element 1”, “element 2”, …, “element n”].
FO

For example: var combinations = new Array(“element 1”, “element 2”, …, “element
n”);
Figure 5.55 shows how to use both array syntaxes in JavaScript.

264
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 264 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE

LY
N
Figure 5.55: Arrays in JavaScript

O
The output of JavaScript code in Figure 5.55 is shown in Figure 5.56.

SE
Figure 5.56: An output of JavaScript array
U
Loops
Like other programming languages, JavaScript uses loops to iterate a code segment.
E

This sections presents three types of loops, namely: for loop, while loop and do-
N

while loop.
1. The for loop: the for loop has the following syntax:
LI

for (initialization; condition; increment)


{
code segment to be iterated
N

}
O

2. The while loop: the while loop has the following syntax:
while (condition)
{
R

code segment to be iterated


}
FO

3. The do-while loop: the do loop has the following syntax:


{
code segment to be iterated
} while (condition)

265
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 265 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
The JavaScript code in Figure 5.57 shows how to create the for loop, while loop and
Computer Science

do while loop.

LY
N
O
SE
Figure 5.57: For loop, while loop and do-while loop in JavaScript
U
The output of JavaScript code in Figure 5.57 is shown in Figure 5.58.
E
N
LI
N
O

Figure 5.58: An output generated from loops in Figure 5.57


R

Conditional statements
FO

Conditional statements enable program flow to execute one of the alternatives, among
many. These conditional statements are similar to those used in other programming
languages. In this section, the following conditional statements will be covered.

266
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 266 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
1. If condition: a condition is evaluated, if that condition is true, then a related
code segment get executed. If it is false, nothing happens. If condition has
the following syntax:
if(condition expression)
{
// code segment to be executed if condition evaluates to true
}

2. If … else condition: this is similar to if condition, except that, always there

LY
is a code statement to be executed if the condition is true or false. The if …
else condition has the following syntax:
if(condition expression)
{

N
// code segment to be executed if condition is true
}

O
else
{
//code segment to be executed if a condition is false
} SE
Figure 5.59 shows how to write JavaScript condition expressions that use if
… else statements. The output of this code will be “5 is not less than -11”.
U
E
N
LI
N
O
R
FO

Figure 5. 59: If … else condition expressions

3. If …else if condition: this is similar to if … else condition except that instead


of one condition expression, there exists many conditions to evaluate. The

267
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 267 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
syntax of if … else if condition has the following syntax:
Computer Science

{
// code segment to be executed if condition is true
}
else if (condition expression)
{
//code segment to be executed if a condition is true
}
……..
else

LY
{
//code segment to be executed if a condition is false
}

N
Figure 5.60 shows an example of JavaScript code for else …if else condition
expressions.

O
SE
U
E
N
LI

Figure 5.60: A JavaScript code for else …if else condition expressions
N

The output of the code in Figure 5.60 is shown in Figure 5.61.


12 is poor
O

45 is good
27 is satifactory
39 is satifactory
R

45 is good
77 is very good
90 is exellent
FO

Figure 5.61: An output of the JavaScript code in Figure 5.60

4. Switch statement. This condition expression eliminates the need to write


multiple if .. else if statements in a code segment. It has the following syntax:

268
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 268 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
switch (expression or literal value)
{
case condition 1: code segment
break;
case condition 2: code segment
break;
...
case condition n: code segment
break;
default: code segment
}

LY
The following code segment illustrates how to write switch statement in JavaScript.
The output of this code varies depending on which day the code has been executed.

N
<html>
<head><title> Switch Satement </title></head>

O
<body>
<script type=”text/javascript”>
var d = new Date(); //obtains date of current day


Saturday
{
SE
switch(d.getDay()) //d.getDay() obtains day number (0 to 6)
//0 is Sunday, 1 is Monday, ..., 6 is

case 0:
U
document.write(“This day is Sunday”);
break;
case 1:
document.write(“This day is Monday.”);
break;
E

case 2:
document.write(“This day is Tuesday.”);
N

break;
case 3:
document.write(“This day is Wednesday.”);
LI

break;
case 4:
document.write(“This day is Thursday.”);
N

break;
case 5:
O

document.write(“This day is Friday.”);


break;
case 6:
document.write(“This day is Saturday.”);
R

break;
default:
document.write(“This day does not exists in a week.”);
FO

break;
}
</script>
</body>
</html>

269
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 269 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

JavaScript pop messages


JavaScript has global functions for displaying messages to users. These messages
serve different purposes. In this section you will learn three (3) pop up messages
(also known as JavaScript message boxes).
1. Alert box: the alert box method shows the user a message that needs their
attention. The alert box ensures that a user receives specific information. To
proceed, the user must click “OK” when an alert box appears. Figure 5.62 (a)
shows JavaScript code for an alert box. Its output is shown in Figure 5.62 (b).

LY
N
O
(a) (b)
Figure 5.62: The JavaScript code for alert box and its output
SE
2. Confirm box: this is a pop-up box that asks for a permission or consent from
a user before proceeding to the next stage. To proceed, the user has to either
U
agree or reject the consent asked. Figure 5.63 shows JavaScript code for a
confirm box.
E
N
LI
N
O
R
FO

Figure 5.63: The JavaScript code for confirm box

270
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 270 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
The output of the code in Figure 5.63 is shown in Figure 5.64. The output in part b
and c will depend on options selected by a user.

(a) (b) (c)

Figure 5.64: The output of JavaScript code in Figure 5.63

3. Prompt box: This tells a browser to show a dialog box, in which a user is offered

LY
with an option to type something as a response to a question or request. The
user can type something and press Ok button or just press the cancel button.
The prompt box waits until the user submits the content or dismisses the dialog.

N
Figure 5.65 shows JavaScript code for prompt box.

O
SE
U
E
N
LI

Figure 5.65: A JavaScript code for prompt box


N

The output of JavaScript code in Figure 5.65 are presented in Figure 5.66 as shown
O

in part (b) and (c) will depend on what options selected by a user in (a).
R
FO

(b) (c)
(a)
Figure 5.66: The output of JavaScript code in Figure 5.65

271
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 271 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Validation of HTML forms
Computer Science

JavaScript can be used to validate the data entered in HTML form. Figure 5.67
shows how to validate inputs to a form.

LY
N
O
SE
U
Figure 5.67: A JavaScript code to validate inputs

One of the output from JavaScript code in Figure 5.67 is shown in Figure 5.68.
E
N
LI
N
O

Figure 5.68: An output for validation of a form


R

Activity 5.5
FO

Validating user’s input.


Design a form that when a field name is empty, the function alerts a message and
returns false to prevent the form from being submitted

272
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 272 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
The following steps can guide you.
Step 1: Create an HTML body.
<html>
<head>
<title>Validation of HTML Form</title>
</head>
<body>
</body>
</html>

LY
Step 2: Create an HTML form in the body. Ensure the identifier of a function in the
form is the same as the name of a function used to validate the form in step 3.

N
<html>
<head>

O
<title>Validation of HTML Form</title>
</head>
<body>
SE
<h2>JavaScript Validation</h2>
<form name=”myForm” action=” “ onsubmit=”return validateForm()”
method=”post”>
U
Enter Surname: <input type=”text” name=”fname”><br><br>
<input type=”submit” value=”Submit”>
</form>
E

</body>
N

</html>
LI

Step 3: Create a function for validating the HTML form.


<script>
N

function validateForm()
{
O

let x = document.forms[“myForm”][“fname”].value;
if (x == “”)
{
R

alert(“Name must be filled out”);


FO

return false;
}
}
</script>

273
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 273 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 4: Place the JavaScript code from step 3 into HTML code in step 2. Ensure
Computer Science

that you place the code in the head section.


<html>
<head><title>Validation of HTML Forms</title></head>
<script>
function validateForm()
{

let x = document.forms[“myForm”][“fname”].value;

LY
if (x == “”)
{
alert(“Name must be filled out”);
return false;

N
}
}

O
</script>
</head>
<body>
<h2>JavaScript Validation</h2>
SE
<form name=”myForm” action=” “ onsubmit=”return validateForm()”
method=”post”>
Name: <input type=”text” name=”fname”><br><br>
<input type=”submit” value=”Submit”>
U
</form>
</body>
</html>
E

Step 5: Run the program and test if it can validate user’s input.
N
LI

Exercise 5.4 Note:


a) The heading of your page
Answer the following questions.
N

should be “My first JavaScript


1. Create JavaScript page which can page webpage” with blue
O

load prompt box which asks a user colour and aligned center.
to enter a number. After entering the
b) The background colour of your
number, a script provides a message
page should be gray.
R

through an alert box to inform the


2. Write JavaScript that will prompt the
user about status of that number
FO

user to enter a number, then to find


entered (if it is positive or negative).
factorial of that number and display
Ensure that the JavaScript provides
its answer using an alert box. The
appropriate message for each
script should be able to check first if
category of possible inputs.

274
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 274 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
the entered value is a number or not. Note: Set page background color
You may use the webpage layout to pink.
shown in Figure 5.69.
b) Use JavaScript codes to
validate inputs to the form
created in part (a) for cases
when the user does not fill
any text box. If any of the text

LY
boxes is not filled, an alert box
Figure 5.69: A sample layout of a webpage with a message “Fill all details”
should be displayed. Make the

N
3. Answer the following questions:
password text box contains at
a) Use HTML codes to design

O
least six characters, otherwise,
the following registration form
shown in Figure 5.70. an alert box “Password must
be at least 6 characters long”
SE should be displayed.

4. Use HTML codes to design the


U
form shown in Figure 5.71. Then,
use JavaScript codes to activate the
form to find volume of the sphere
E

Figure 5. 70: A registration form when a user enters the radius.


N
LI
N
O
R
FO

Figure 5.71: A JavaScript code to find volume of a sphere

4 3
Note: The formula to get volume of the sphere is πr
3

275
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 275 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Activity 5.6

Online tutorials for further learning.


Use an internet search to do the following as explained below.
To learn more about HTML, CSS and JavaScript use online tutorials through
following steps to help you achieve this task:
1. While connected to the Internet, use a search engine to find online tutorials.
You may use various phrases to search such as “online tutorials for HTML”,

LY
“online tutorials for CSS”, “online tutorials for JavaScript” and others.
2. From the search results, click a link of your choice to open a website that offers
online tutorials.

N
3. Find what you are looking for from that website and learn further on how to
create websites.

O
Introduction to application programing interface
SE
An Application Programming Interface (API) consists of protocols, routines, functions
or instructions that programmers use to make it easier for different software services
to communicate with one another. Among other uses, the API is used to intermediate
U
web applications and databases as shown in Figure 5.72.

Request
E

Internet API
Response
N

Web application Database


Web browser
in a web browser
LI

Figure 5.72: A structure on how API works

Once you have already created a website PHP


N

and database, usually the next task is to PHP stands for Hypertext Preprocessor is
connect the database and the website to
O

an open source, interpreted, and object-


make it possible to enter and retrieve data
oriented scripting language that can be
from the database. This data is entered
executed at the server-side. PHP is well
R

through HTML forms and displayed in


suited for web development. Therefore,
HTML pages.
it is used to develop applications that
FO

In the next sections, you are going to execute on the server to generate dynamic
learn how to use PHP language to insert webpages (web applications). The syntax
and retrieve data from MySQL database. for PHP is <?php your code ?> .

276
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 276 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
It is an interpreted language, which content pulled from a database. The scope
means it does not need to be compiled, of this book does not include a detailed
and it is quicker than scripting languages study of the PHP programming language.
like ASP and JSP. PHP is a server-side
programming language that is used to Using PHP to insert data into database
control the dynamic content of a website.
The “Insert” command is used to insert
It is simple to understand and can be
new records in a database table. Note that
incorporated into HTML.
the database management system used in

LY
With that little background, the purpose is this example is MySQL, this will create
to introduce you to PHP because you will a database by using a software known as
be using it to allow a user to interact with Cross-Platform Apache MYSQL PHP and

N
a database. The language enables you to Perl (XAMPP). The following codes are
create dynamic webpages with dynamic used to insert the data in the database:

O
<?php
// php code to Insert data into mysql database from input text
if(isset($_POST[‘insert’]))
{
$hostname = “localhost”;
$username = “root”;
SE
$password = “”;
U
$databaseName = “student”;
// get values form input text and number
$fname = $_POST[‘fname’];
$lname = $_POST[‘lname’];
$age = $_POST[‘age’];
E

// connect to mysql database using mysqli


$connect = mysqli_connect($hostname, $username, $password, $databaseName);
N

// mysql query to insert data


$query = “INSERT INTO users (fname, lname, age) VALUES (‘ $fname ‘ ,’ $lname ‘, ‘ $age
‘)”;
LI

$result = mysqli_query($connect, $query);


mysqli_close($connect);
}
N

?>
<html>
O

<head><title> Inserting data using PHP </title></head>


<body>
<form method=”post”>
<input type=”text” name=”fname” required placeholder=”First Name”><br><br>
R

<input type=”text” name=”lname” required placeholder=”Last Name”><br><br>


<input type=”number” name=”age” required placeholder=”Age” min=”10” max-
FO

=”100”><br><br>
<input type=”submit” name=”insert” value=”Add Data To Database”>
</form>
</body>
</html>

277
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 277 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
The way you save PHP file differs slightly from how you were saving HTML files.
Computer Science

PHP files are server-side script, therefore, they must be saved in a web server. The
web server will execute them and send results (output) to a browser. Assuming that
you have already installed the XAMPP, illustrations in Figure 5.73 show you how
to save PHP files. XAMPP has a “htdocs” where you can save your PHP files and
HTML files as well. Steps on how to install XAMPP are described in subsequent
paragraphs.

LY
N
O
SE
U
E
N
LI

Figure 5.73: How to save PHP files


N
O
R
FO

278
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 278 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Now let us create a database in MySQL database management system, and not
the Microsoft Access that you learnt in chapter one. You will learn more about
MySQL in the Form Six book. In the present task, you are going to use XAMPP.
XAMPP is the cross-platform web server solution stack package that is free and
open-source. It consists of mainly Apache, HTTP server, MariaDB database and
PHP. The following steps can guide you to create a database.

Step 1: Search the Internet to find the XAMPP platform. Open XAMPP after
downloading it and install. After opening XAMPP you will find that

LY
Apache (the web server) and MySQL (database management system)
have not started as shown in Figure 5.74.

N
O
SE
U
E
N
LI

Figure 5.74: A XAMPP control panel before starting Apache and MySQL
N
O
R
FO

279
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 279 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 2: Run Apache and MySQL as in Figure 5.75 by clicking on their respective
Computer Science

starts.

LY
N
O
SE
Figure 5.75: Apache and MySQL started in xampp control panel

Step 3: Open your browser and type, “localhost/phpmyadmin” to open the


U
database as in Figure 5.76.
E
N
LI
N
O
R
FO

Figure 5.76: Database interface of cpanel

280
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 280 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Step 4: Click “New” to add database and name your database as shown in Figure
5.77. After writing the name of database, click on “Create”. Your database
will be created as shown on the left pane.

LY
N
O
SE
U

Figure 5.77: Creating a database in MySQL


E

Step 5: Design a simple database: your simple database should have one table
N

named as “users”. The table has four columns (attributes).


LI

(a) The first column is id. This attribute uniquely identifies every row
inserted in the table and is set to be auto-increment. It uses the integer
N

as a data type;
(b) The second is fname. This attribute stores the first name of a user. It
O

uses variable character as data type;


(c) The third column is lname. This attribute stores the last name of a user.
R

It uses variable character as data type; and


(d) The last column is age. This attribute records the age of a user. It uses
FO

integers as a data type.


Step 6: Click on your database whose name is “student”. You will be redirected to
a page for creating tables. Now, name your table (users) and enter number

281
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 281 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
of columns you have as in Figure 5.78. Your table has four (4) columns,
Computer Science

which are id, fname, lname and age. After that click on the “Go” button.

LY
N
O
Figure 5.78: Creating a table in MySQL

Step 7: Write the name of the column and its data type as shown in Figure 5.79.
SE
Two columns use variable characters as data type. So, you have to specify
its length, and in this example, you use a length of 50 characters. The id
column is used as a primary key and is set to be auto-increment, meaning
that you will not enter this data. Instead, MySQL will automatically enter
U
this data in an incremental order. In the end click “Save” as shown in
Figure 5.79.
E
N
LI
N
O
R
FO

Figure 5.79: Creating a table in MySQL

282
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 282 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
The database now is ready to accept and save the data entered. It will look like in
Figure 5.80.

LY
N
Figure 5.80: A view of table created in MySQL

O
Before inserting data, the table in the database will be empty as in Figure 5.81. You
can see if the table has data or not after clicking on a “Browse” link.

SE
U
E
N
LI

Figure 5.81: Empty table in MySQL


N

Step 8: After you have successfully created your database, next is to enter data
in the form and save it in your database. Type the following link in the
O

browser’s address bar: http://localhost/insert_Data.php. You will see the


output shown in Figure 5.82(a). Enter data as shown in Figure 5.82(b), then
click on “Add Data To Database”.
R
FO

283
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 283 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

(a) (b)

LY
Figure 5.82: An HTML form before and after entering data

Enter data as required. If you click the “Add Data To Database” button, the

N
data will be added to the database.

O
Step 9: To see if the data entered was saved in your database, go to PhPMyAdmin
panel which you used to create database and table. Click on a Browse link.
You will see the data you have entered as shown in Figure 5.83.
SE
U
E

Figure 5.83: The data inserted in the database


N

Step 10: You can continue to enter other data in the form. All that data will be
LI

recorded in your database. For example, after adding two records, the table
looks like the one in Figure 5.84.
N
O
R
FO

Figure 5.84: Two further records added in the table

284
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 284 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Using PHP to retrieve data from database
When data are inserted in the database, you can retrieve and see it in HTML files.
The PHP code responsible for this task is shown as follows.

<?php
$hostname = “localhost”;
$username = “root”;
$password = “”;
$databaseName = “student”;
$conn=mysqli_connect($hostname,$username,$password,$databaseName);

LY
if(!$conn)
{
die(‘Could not Connect MySQL database:’ .mysql_error());

N
}
$result = mysqli_query($conn,”SELECT * FROM users”);

O
?>
<!DOCTYPE html>
<html>
<head>
<title> Retrive data</title>
</head>
SE
<body>
U
<?php
if (mysqli_num_rows($result) > 0)
{
E

?>
<table border =”1”>
N

<tr>
<td><b>ID</b></td>
LI

<td><b>First Name</b></td>
<td><b>Last Name</b></td>
<td><b>Age of User</b></td>
N

</tr>
<?php
O

$i=0;
while($row = mysqli_fetch_array($result)) {
?>
R

<tr>
<td><?php echo $row[“id”]; ?></td>
FO

<td><?php echo $row[“fname”]; ?></td>


<td><?php echo $row[“lname”]; ?></td>
<td><?php echo $row[“age”]; ?></td>
</tr>

285
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 285 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
<?php
Computer Science

$i++;
}
?>
</table>
<?php
}
else
{
echo “Table users has no records”;

LY
}
?>
</body>
</html>

N
Step 1: Write this code in Notepad and save the file as using the name “retrieve_

O
Data.php”. Before saving, remember to save in the htdocs folder. That
folder is found in the Xampp folder which you created or was created
when installing XAMPP on your computer as shown in Figure 5.85.
SE
U
E
N
LI
N
O
R
FO

Figure 5.85: Saving retrieve_Data.php file

286
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 286 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Step 2: After you have successfully created your PHP file, the next step is to display
data from your database. Type the following link in the browser’s address
bar: http://localhost/retrieve_Data.php. You will see the output of data in
the users table in the database as shown in Figure 5.86 shows.

LY
Figure 5.86: Data retrieved from database

N
Activity 5.7

O
Linking HTML and database using PHP
1. Create a form as shown in Figure 5.87.
2.
3.
SE
Create a database that receives data from this form.
Register five (5) users.
4. Retrieve data that was entered in the database.
U
E
N
LI
N
O
R
FO

Figure 5.87: A form for registering users

287
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 287 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Project
Computer Science

In this project, you will create a website that can be visited by people around the
world. You must first build a fully working website before continuing with the
publication process. Create a folder in a selected drive and give it a name of your
preference. All files and images you use to develop a website should be saved in that
folder. The next steps will show you how to create such a website.

Step 1: Create a basic structure of the website by using table tags as shown in Figure
5.88. You may use same logo or replace with another logo you prefers.

LY
N
O
SE
U
E
N
LI

Figure 5.88: An HTML code for basic structure of a website


N

The output of HTML code from Figure 5.88 will be as shown in Figure 5.89.
O
R
FO

Figure 5.89: A basic structure of the website

288
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 288 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Step 2: Now you have to link different pages and change the background colour to
“#CCCCFF” color as in Figure 5.90.

LY
N
O
SE
U
Figure 5.90: An HTML code for linking webpages
E

The output of HTML code shown in Figure 5.90 will be as shown in Figure 5.91.
N
LI
N
O
R

Figure 5.91: An output of linked HTML webpages


FO

Step 3: Next, you have to add an image in a table data that displays “YYYY”. You
may also use the image that differs from the one used in this project. Note
that, not all codes for the whole website are shown in this step. Your task is

289
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 289 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
to create the HTML code and replace YYYY with your code. Your code is
Computer Science

shown in Figure 5.92.

Figure 5.92: An HTML code to add an image

The output of HTML code shown in Figure 5.92 will be as shown in Figure 5.93.

LY
N
O
SE
U
E

Figure 5.93: An image has been added to the website


N

Step 4: Add a JavaScript code to display current date and time. You will add the
JavaScript in a table data displays “XXXX”. You replace “XXXX” with
LI

your JavaScript code. Save this file by naming it as “step4.html”. That code
is shown in Figure 5.94.
N
O
R
FO

Figure 5.94: A JavaScript code that displays date and time

290
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 290 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Now your webpage can display date and time as shown in Figure 5.95.

LY
N
O
SE
Figure 5. 95: A web displaying date and time

Note: Up to this level you have achieved a basic structure of your website. The
next task is to create individual webpages that will form your website.
U
Looking on links which you created previously, there are five (5) webpages,
which are:
1. Homepage –whose HTML file is named as index.html. It is the first
E

webpage to be loaded when a visitor types an address of your website.


It is a common practice for most websites to use this file name;
N

2. About Us –whose HTML file is named as “about.html”;


3. Our Team –whose HTML file is named as “team.html”;
LI

4. Contact Us –whose HTML file is named as “contact.html”, and;


N

5. Our Projects –whose HTML file is named as “project.html”.

On top of these five (5) webpages, you will also include PHP webpages. One
O

webpage will be for inserting data and the other for retrieving information from
online MYSQL database. Remember that you already created offline MySQL
R

database under PHP section. You will use the same database.
FO

You are going to create each webpage in next steps.


Step 5: Create a home page by saving an HTML file you created in step 4 and
name it as “index.html”. To create that webpage, open a new Notepad, copy
HTML codes from a file in step 4 and paste it in a newly opened Notepad

291
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 291 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
file. Add the content to be displayed in a home page as shown in Figure
Computer Science

5.96. Add that content in a table data that displays “ZZZZ”. Save your file
as with a name “index.html”.

LY
Figure 5.96: Adding content to a home page

The output of the home page is displayed in Figure 5.97.

N
O
SE
U

Figure 5.97: An output of a home page


E

Step 6: Create a webpage for “About Us” by saving an HTML file you created in
N

step 4 and name it as “about.html”. To create that webpage, open a new


Notepad, copy HTML codes from a file in step 4 and paste it in a newly
LI

opened Notepad file. Add the content to be displayed in this webpage as


shown in Figure 5.98. Add that content in a data table that displays “ZZZZ”.
N

Save your file with a name “about.html”.


O
R
FO

Figure 5.98: Adding content to “About Us ” webpage

292
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 292 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
The webpage for ‘About us’ will display as shown in Figure 5.99.

LY
Figure 5.99: An output of “About Us” webpage

N
Step 7: Create a webpage for “Our Team” by saving an HTML file you created in

O
step 4, and name it as “team.html”. To create that webpage, open a new
Notepad, copy HTML codes from a file in step 4, and paste it in a newly

SE
opened Notepad file. Add the content to be displayed in this webpage
as shown in Figure 5.100. Add that content in a table data that displays
“ZZZZ”. Save your file with a name “team.html”.
U
E
N
LI
N
O
R
FO

Figure 5.100: Adding content to “Our Team” webpage

293
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 293 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
The webpage for ‘Our Team’ will display as shown in Figure 5.101.
Computer Science

LY
N
O
SE
Figure 5.101: The output of HTML for a“Our Team” webpage

Step 8: Create a webpage for “Contact Us” by saving an HTML file you created
U
in step 4, and name it as “contact.html”. To create that webpage, open a
new Notepad, copy HTML codes from a file in step 4, and paste in a newly
opened Notepad file. Add the content to be displayed in this webpage as
E

shown in Figure 5.102. You have to add that content in a table data that
displays “ZZZZ”. Save your file with a name “contact.html”.
N
LI
N
O
R
FO

Figure 5.102: Adding content to a“Contact Us” webpage

294
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 294 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
The webpage for a ‘Contact Us’ will display as shown in Figure 5.103.

LY
N
O
SE
U
Figure 5.103: The output of HTML for a “Contact Us” webpage
E

Step 9: Create a webpage for “Our Projects” by saving an HTML file you created
in step 4, and name it as “project.html”. To create that webpage, open a new
N

Notepad, copy HTML codes from a file in step 4, and paste in a newly opened
Notepad file. Add the content to be displayed in this webpage as shown in
LI

Figure 5.104. Add that content in a table data that displays “ZZZZ”. Save
your file with a name “project.html”.
N
O
R
FO

Figure 5.104: Adding content to ‘Our Projects’ webpage

295
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 295 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
The webpage for ‘Our Project’ will display as shown in Figure 5.105.
Computer Science

LY
N
O
SE
Figure 5.105: The output of HTML for ‘Our Projects’ webpage
U
After you have created a full website, the next task is to publish it. Upon publishing
your website, all people globally will be able to see and access it.

Website publishing
E

Internet connection
Website publishing is the process of Internet connection is required to
N

uploading content on the internet. When connect to a remotely located web server
designing a website offline, people will because you have to serve your work in
LI

not be able to see or view your website. So cloud. Internet services provider (ISP)
once you have completed to design your such as TTCL, TIGO, AIRTEL and
N

website, you may need to publish, and VODACOM can offer such services.
make it visible to the viewers. Publishing a
O

website includes uploading files, updating Web server


files and maintaining the website.
A web server is a software and hardware
R

Requirements for website that uses HTTP (HyperText Markup


Language and other protocols to
FO

publishing
respond to client requests made over
To publish a website, you need to have
the World Wide Web (www). The main
few things such as: Internet connection;
task of web server is to display website
web server; and domain name.

296
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 296 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
content through storing and website. You can also use File Transfer
delivering webpages to users. Protocol software such as Filezilla client
The web server may host single to upload the website.
or multiple sites depending on
what hosting service you have Consideration before publishing
paid for. It is like a space where website online
you put your things, you pay for There are two issues that you must address
the space according to usage. before you publish your website. These
There are different servers where

LY
are registering your domain name and
you can upload and host your signing for web hosting service.
website after paying. But also,
there are free website servers. Registering domain name

N
All you need is just to search on The process of registering for domain name

O
Internet and those hosting sites depends on the registrar you have chosen
are secure. to register your domain name. Domain
name registrar describes its own steps to
Domain name
A domain name is part of your
SE
follow to accomplish the whole process.
In this section, you will use the domain
Internet address that comes after name which is already registered to the
U
“www”. For example, in www. server Tanzania Network Information as
kilakalasps.ac.tz the domain name ‘myclassweb.sc.tz’. When your website
is .kilakalasps.ac.tz. There are is ready to be published, you may register
E

multiple domains such as .com, your domain name too through the public
.ac.tz, .org and others. organization such as Tanzania Network
N

Information Center (TzNIC).


After having these requirements,
LI

now you can upload your website. Steps for web hosting configuration in
The website can be uploaded on cPanel
N

control panel (cPanel) which is Step 1: Open the link sent to you by your
O

provided by a company where web host. In our case, the link is


you intend to host your website. https://myclassweb.sc.tz/cpanel.
The company will give you the The control panel will show
R

username and password to login up. The credentials will have to


into your account and upload the be filled in the fields shown in
FO

Figure 5.106.

297
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 297 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
N
O
Figure 5.106: Backend control panel (cPanel) provided for hosting service

SE
Step 2: Provide the Username and Password which were sent by a web host server
during domain registration that you were directed to use to access your
account created at host server. The window shown as in Figure 5.107 will
U
display after you log in.
E
N
LI
N
O
R
FO

Figure 5.107: User account backend cPanel for hosting service configuration

There are various tools available on the dashboard of a control panel


(cPanel) for customizing your website including email settings, statistics
check, database, files and others. If you are not sure with some tools in

298
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 298 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
dashboard, you better find some tutorials and user manual on how to use
cPanel for uploading website. Alternatively, you may refer to “Information
and Computer Studies” for Secondary Schools Form Three (2021) book a
Web development topic.

Step 3: Scrow down and Go to ‘File’ tab in the control panel, click the ‘File Manager’
button as shown in Figure 5.108.

LY
N
O
SE
Figure 5.108: cPanel interface for managing files and database

Step 4: After clicking the File Manager, the window shown in Figure 5.109 will
U
appear. Click the folder “public_html”.
E
N
LI
N
O
R

Figure 5.109: File manager window-opening public_html


FO

Step 5: Once you click the folder ‘public_html’, the server will be searching
directory, then you will be exposed to the window shown in Figure 5.110.
Then, click on “+Folder” to create a folder in which you will upload your
website files.

299
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 299 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
Figure 5.110: A link for creating a folder in public_html

N
Step 6: A window for creating a new folder will open up as shown in Figure 5.111.
Make sure you are creating your folder under the folder ‘public_html’ as

O
illustrated in Figure 5.111.

SE
U
E

Figure 5.111: Creating a folder in public_html


N

Step 7: After creating your folder, the window will look as shown in Figure 5.112.
LI
N
O
R
FO

Figure 5.112: A window display after creating a folder

300
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 300 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Step 8: To upload your website files, click on “computer_science” folder, then click
on upload as shown in Figure 5.113. Once the ‘File Upload’ window opens,
it will guide you to select or browse your website files which you have
prepared. These files include the index.html file which links all your files.
The index file is a file which is immediately recognized on most servers
without any need for additional configuration as default page.

LY
N
O
SE
Figure 5.113: Uploading website files

Step 9: You can upload one file after another; however, this will take time.
Alternatively, you can select, drag and drop all files together and wait for
U
them to be uploaded as shown in Figure 5.114.
E
N
LI
N
O

Figure 5.114: Options to upload website files

After uploading, the progress bar will be seen as shown in Figure 5.115.
R
FO

301
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 301 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
N
O
SE
U
E
N
LI

Figure 5.115: A successful upload of website files


N

Previewing website
O

The purpose of previewing a website is to test and check if the website you have
developed and published can be seen in the World Wide Web.
R

Step 11: Open the web browser; then, write the domain name of your website. In
this case, the registered domain name which was provided by the web
FO

host, https://myclassweb.sc.tz/computer_science/ has been written. Once


you have typed your domain name address in the web browser’s address
bar, then click go. The website that you created will be displayed. In this
case, the webpage is displayed as in Figure 5.116.

302
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 302 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE

LY
N
Figure 5.116: Output of the published webpage

O
Publishing Database on cPanel
After publishing and previewing website, now you are sure how it looks to the

SE
public. The next step is to add a simple database to a website. Remember the offline
MySQL database that you created previously. It allowed you to insert data and
retrieve information from database. You are going to make that database to be online
and allow global public to access. However, there are some steps to follow.
U
Step 12: Create two links, one for inserting data to the database and the other for
retrieving data from the database. These links will be as follows:
E

<a href=”insert_page.php”>Insert Data</a><br><br>


N

<a href=”retrieve_page.php”>Retrieve Data</a>


LI

Step 13: Place those links in the following HTML files: index.html; about.html;
team.html; contact.html and project.html. You will place those links in a
N

table data that displays “PPPP”. This means that you replace “PPPP” with
those links as shown in Figure 5.117.
O
R
FO

Figure 5.117: Adding links to a webpage

303
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 303 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Steps for web hosting configuration in cPanel
Computer Science

Step 14: Transfer all files including those you created in step 12 into htdocs folder
of the XAMPP main folder. Why transferring? The PHP files you are going
to create cannot execute in HTML browsers because they are server-side
script. Transferring them to htdocs folder implies that Apache web server
will execute them ready for HTML to display results.
Step 15: Creating insert_page.php file. Open a new Notepad file. Copy all contents
of index.html file and paste into the newly opened Notepad file. Next,

LY
embed the PHP code into this HTML code. The PHP code embedded
in this index.html file is copied from PHP file you created previously,
but with fewer changes. The following PHP code which is embedded in

N
HTML inserts data into MySQL database.

O
<html>
<head><title>Insert Data</title>
</head>
<body bgcolor =”#CCCCFF”>
<table border =”1px”>
<tr>
SE
U
<td><img src =”MwembeniLogo.png” width =”100px”></td>
<td colspan =”5”><center><h2>Mwembeni Secondary School</h2><br>
<i>Education for Our Success</i></center><br></td>
</tr>
E

<tr>
N

<td><center><a href = “index.html”>Home</a></center></td>


LI

<td><center><a href = “about.html”>About Us</a></center></td>


N

<td><center><a href = “team.html”>Our Team</a></center></td>


O

<td><center><a href = “contact.html”>Contact Us</a></center></td>

<td><center><a href = “project.html”>Our Projects</a></center></td>


R

</tr>
<tr>
FO

<td width =”15%”>


Date: <p id=”date”></p>
Time: <p id=”time”><p>

304
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 304 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
<script>
let today = new Date();
let year =today.getFullYear();
let month = today.getMonth()+1;
let day = today.getDate();
let hour=today.getHours();
let minutes=today.getMinutes();
let seconds=today.getSeconds();

LY
document.getElementById(‘date’).innerHTML=day+”/”+month+”/”+year;
document.getElementById(‘time’).innerHTML=hour+”:”+minutes+”:”+seconds;
</script>

N
</td>
<td colspan =”4”><center><img src =”tanzania students.jpg” width =”400”

O
height =”200”></center></td>
</tr>
<tr>


<td width =”15%”>
SE
<a href=”insert_page.php”>Insert Data</a><br><br>
<a href=”retrieve_page.php”>Retrieve Data</a>
U
</td>
<td colspan =”4”>
<h3>Register Users</h3>
E

<form method=”post”>
N

<input type=”text” name=”fname” required placeholder=”First


Name”><br><br>
LI

<input type=”text” name=”lname” required placeholder=”Last


Name”><br><br>
N

<input type=”number” name=”age” required placeholder=”Age”


O

min=”10” max=”100”><br><br>

<input type=”submit” name=”insert” value=”Add Data To Database”>


R

</form>
</td>
FO

</tr>
<tr>
<td colspan =”5”><p><center>&copy Mwembeni Secondary
School.</p></center></p></td>

305
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 305 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
</tr>
Computer Science

</table>
</body>
</html>
<?php
if(isset($_POST[‘insert’]))
{
$hostname = “localhost”;
$username = “root”;
$password = “”;

LY
$databaseName = “student”;
// get values form input text and number
$fname = $_POST[‘fname’];
$lname = $_POST[‘lname’];

N
$age = $_POST[‘age’];
// connect to mysql database using mysqli

O
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
// mysql query to insert data
$query = “INSERT INTO users (fname, lname, age) VALUES (‘ $fname ‘ ,’ $lname
‘, ‘ $age ‘)”;
$result = mysqli_query($connect, $query);
mysqli_close($connect);
SE
}
U
?>

Step 16: Creating “retrieve_page.php” file. Open a new Notepad file. Copy all
E

contents of “index.html” file, and paste into the newly opened Notepad
N

file. Next, embed the PHP code into this HTML code. The PHP code
embedded in this index.html file is copied from PHP file you created
LI

previously, but with fewer changes. The following PHP code which is
embedded into HTML retrieve data from MySQL database.
N

<html>
<head><title>Retrieve Data</title>
O

</head>
<body bgcolor =”#CCCCFF”>
<table border =”1px”>
R

<tr>
FO

<td><img src =”MwembeniLogo.png” width =”100px”></td>


<td colspan =”5”><center><h2>Mwembeni Secondary School</h2><br>
<i>Education for Our Success</i></center><br></td>
</tr>

306
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 306 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
<tr>

<td><center><a href = “index.html”>Home</a></center></td>


<td><center><a href = “about.html”>About Us</a></center></td>
<td><center><a href = “team.html”>Our Team</a></center></td>
<td><center><a href = “contact.html”>Contact Us</a></center></td>
<td><center><a href = “project.html”>Our Projects</a></center></td>
</tr>
<tr>

LY
<td width =”15%”>
Date: <p id=”date”></p>
Time: <p id=”time”><p>

N
<script>

O
let today = new Date();
let year =today.getFullYear();
let month = today.getMonth()+1;
let day = today.getDate();
let hour=today.getHours();
SE
let minutes=today.getMinutes();
U
let seconds=today.getSeconds();

document.getElementById(‘date’).innerHTML=day+”/”+month+”/”+year;
E

document.getElementById(‘time’).innerHTML=hour+”:”+minutes+”:”+seconds;
</script>
N

</td>
<td colspan =”4”><center><img src =”tanzania students.jpg” width =”400”
LI

height =”200”></center></td>
</tr>
<tr>
N

<td width =”15%”>


O

<a href=”insert_page.php”>Insert Data</a><br><br>


<a href=”retrieve_page.php”>Retrieve Data</a>
R

</td>
<td colspan =”4”>
FO

<?php

$hostname = “localhost”;

307
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 307 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
$username = “root”;
Computer Science

$password = “”;
$databaseName = “student”;
$conn=mysqli_connect($hostname,$username,$password,$databaseName);
if(!$conn)
{

die(‘Could not Connect MySQL database:’ .mysql_error());
}

LY
$result = mysqli_query($conn,”SELECT * FROM users”);
if (mysqli_num_rows($result) > 0) {
?>
<h3>Number of Existing Users</h3>

N
<table border =”1”>

O
<tr>
<td><b>ID</b></td>
<td><b>First Name</b></td>
<td><b>Last Name</b></td>
<td><b>Age of User</b></td>
</tr>
SE
<?php
U
$i=0;
while($row = mysqli_fetch_array($result))
{
?>
E

<tr>
<td><?php echo $row[“id”]; ?></td>
N

<td><?php echo $row[“fname”]; ?></td>


<td><?php echo $row[“lname”]; ?></td>
LI

<td><?php echo $row[“age”]; ?></td>


</tr>
N

<?php
$i++;
}
O

?>
</table>
<?php
R

}
else{
FO

echo “Table users has no records”;


}
?>

308
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 308 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
</td>
</tr>
<tr>

<td colspan =”5”><p><center>&copy Mwembeni Secondary


School.</p></center></p></td>
</tr>
</table>
</body>
</html>

LY
Step 17: Test your modified website using for example, the following link:
http://localhost/team.html. It will display an output as shown in Figure

N
5.118.

O
SE
U
E
N
LI
N
O

Figure 5.118: An offline output of “Our Team” webpage


R

Step 18: Upload all files you created under htdocs folder to Cpanel File Manager
FO

under ‘computer_science’. During that upload, you will overwrite existing


similar files. After uploading, the modified website will change its look.
Figure 5.119 shows an output of online ‘team.html’ webpage.

309
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 309 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
N
O
SE
Figure 5.119: An online output of “Our Team” webpage
U
Step 19: Now you have to upload the MYSQL database. To do so, first you have
to export your database structure and data in the SQL format. Open the
E

link: http://localhost/phpmyadmin/.
Step 20: To export, click on your “student” database, then click on “Export” as
N

shown in Figure 5.120.


LI
N
O
R
FO

Figure 5.120: First stage on exporting database

310
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 310 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Step 21: Give a name of a file to be exported; select SQL as a file format and then
click “Go” to export as shown in Figure 5.121. However, that file name
does not matter when importing the SQL file.

LY
N
O
Figure 5.121: Second stage on exporting database

Step 22: Export the SQL file. Import the file which you downloaded as shown in
SE
Figure 5.122. After specifying the file format click “Go” to export.
U
E
N
LI
N

Figure 5.122: Third stage on exporting database


O

Your exported file will be downloaded. Depending on a browser and


operating system you are using, you may find the exported file in a
“downloads” folder or other places.
R

Step 23: Go to database and click MySQL® Database Wizard as seen in Figure
FO

5.123. You will be given an option to name your database.

311
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 311 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
Figure 5.123: Opening database wizard in cPanel

N
Step 24: In the present case, name your database as “student”. According to settings

O
of Cpanel, in the present case, that name has a prefix “myclasswebsc”. So,
the full name of your database will be myclasswebsc _student as shown
in Figure 5.124.
SE
U
E
N
LI
N
O

Figure 5.124: Creating a database by using a prefix


R

Step 25: After creating the database, you have to create a user of that database as
shown in Figure 5.125. You will set the username and password. Under
FO

present case, the username is “myclasswebsc_form5student” while the


password is “Form_5!?20022@”;

312
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 312 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE

LY
N
O
SE
Figure 5.125: Creating a database by using a prefix

Step 26: Change database name, username and password in insert_page.php and
retrieve_page.php files so that access credentials in server-side script
U
match with online database credentials as shown in Figure 5.126. After
making these changes, upload insert_page.php and retrieve_page.php
files to online server in cPanel under File Manager.
E
N
LI
N
O
R

Figure 5.126: Changing database name, username and password


FO

Step 27: Adding a user to your database: you can add a user to a database you have
created as shown in Figure 5.127. Remember also to set a password for
that user.

313
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 313 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

LY
Figure 5.127: Adding a user to a database

N
Step 28: Add user access privileges: specify what users can do and what they

O
cannot do. In the present case, the user of the database was given all
privileges as shown in Figure 5.128. However, cases may differ where
the user is given limited privileges especially for security purposes.
SE
U
E
N
LI
N
O
R
FO

Figure 5.128: Setting user access privileges

314
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 314 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
Step 29: From cPanel, open the phpMyAdmin as shown in Figure 5.129. Then,
select your database and continue with Step 30.

LY
N
Figure 5.129: Opening phpMyAdmin in Cpanel

O
Step 30: Import your database: to import the database, select the SQL file that you
imported previously. Remember to use SQL as a file format as shown in
Figure 5.130 and finally click “Go”.
SE
U
E
N
LI
N
O
R
FO

Figure 5.130: Importing SQL file

315
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 315 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Step 31: If importing is successful, the output similar to that one in Figure 5.131
Computer Science

will be displayed.

LY
Figure 5.131: The SQL file imported successfully

Step 32: Your database is already imported. You can view data as shown in Figure

N
5.132.

O
SE
U
E
N
LI
N

Figure 5.132: A view of imported database, table and data


O

Step 33: Now, open the link https://myclassweb.sc.tz/computer_science. From


this home page, click on a link “Insert Data”. The following output as
seen in Figure 5.133 will be displayed.
R
FO

316
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 316 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE

LY
N
O
SE
Figure 5.133: A webpage to insert data into online database

Step 34: From a home page, click on a link “Retrieve Data”. The following output
shown in Figure 5.134 will be displayed. Note that an output displayed
U
will depend on what data you exported.
E
N
LI
N
O
R
FO

Figure 5.134: A webpage for retrieving data from an online database

In this stage you have done publishing your website, and it can be seen
by any one globally through a provided http link.

317
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 317 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Chapter Summary

1. Website is a collection of webpages.


2. Webpage is an HTML file which is accessed through internet on a browser.
3. A browser is a software designed specifically for viewing websites.
4. Examples of browsers are Google chrome, Opera and Mozilla.
5. Websites are primarily designed in HTML. However, the Cascading Style Sheet
and JavaScript further improves the websites.

LY
6. JavaScript code are client-side scripts (also known as lightweight programs)
that executes in a browser. Client-side scripts reduce processing overload to
the server.

N
7. JavaScript dynamic enables interactions to the user without a need to communicate
to a server. These scripts have many advantages including validation of user

O
inputs.
8. In terms of architectural characteristics, there are two types of websites: dynamic
SE
and static. Content on dynamic websites is always changing. Either the client
browser or the server is responsible for that change. The content of a webpage
on a static website cannot be changed once it has been loaded.
U
9. Online databases may also provide dynamic content. The content of a webpage
changes if the website is enabled, for example, to insert or get data from a
database.
10. You can make a website public so that anybody in the world can see it. You
E

may publish a database online in a similar way, allowing users to insert and
N

access data from it.


LI

Revision Exercise 5
N

1. Fill blanks with the following words: HTML, web browser, URL, Safari, sitemap,
O

Navigation, and web server. Each word should be used only once.
_________ executes on a web browser.
R

_________ identifies uniquely a web page.


_________ stores webpages.
FO

_________ is one of the specific application software that display webpages.


_________ illustrates how a website is structured.

318
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 318 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
2. What type of information is contained in the two parts of an HTML webpage?
3. How does an HTML tag differ from an HTML attribute?
4. By using examples, explain the concept of CSS and its application.
5. Discuss the features that may lead to a poorly designed website.
6. How can you generate multi-colour font on a website page using CSS, ?
7. Explain the use of “action” attribute and the difference between POST method
and GET method in HTML form.

LY
8. Create a simple HTML form that has the following form controls:
(a) Text input controls

N
(b) Check box control

O
(c) Submit and reset button
9. Briefly explain three (3) basic HTML tags which are used together with <table>
tag when creating tables.
SE
10. (a) Design a page similar to the following webpage by using basic HTML codes.
U
E
N
LI
N
O
R
FO

Hints on designing a webpage:


(i) Divide the page into three frames: top, left and right.
(ii) The size of the text “SCHOOL CALENDAR” should be 20 with

319
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 319 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

maroon font colour and magneto font type. Background color of this
frame is “grey”.
(iii) Background colour of the text “SCHOOL CALENDAR” at the table
is “purple”.
(b) Activate the months link: “January”, “February” and “March” at the top
flame so that when the user clicks, it will change the center frame as
follows:

LY
N
O
SE
U
E
N
LI
N
O
R
FO

320
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 320 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Five: Website development


DO NOT DUPLICATE
11. Create the following register form in HTML.

LY
N
O
SE
U
E
N
LI
N
O
R
FO

321
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 321 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Chapter
Six System development

Introduction

LY
Today, many activities in the world are handled by computer systems rather
than human beings. In this chapter, you will learn about the Concept of system
development, System planning, System analysis and System design. You will

N
learn about System implementation, System documentation, and System
maintenance. The competencies developed in this chapter will help you to

O
develop simple to large-scale systems to meet individual and institutional
demands such as simplified tax collection and payment services, access to
SE
health services, and access to electronic transport tickets to mention but a few.
U
Ask yourself the following questions:

1. What procedure an entrepreneur uses to build a mobile application in order to


E

compete with other large business firms?


N

2. What can be done if users of a particular system might demand for an application
LI

to be purchased or developed to replace the currently used?


N

Concept of system development To understand a system in your context,


O

as an example, take a look on your local


Basic concepts of system
transport system. Consider your transport
A system, can be defined as a collection system at your locality which comprises
R

of elements and procedures that work of elements and procedures like people,
together to accomplish a specific task. All buses, trains, motorcycles, airplanes
FO

the elements in a system are organised in or marines, transport fares, tickets and
a specific manner to achieve the system journey schedules that enable people to
goal. travel from one area to another. Another

322
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 322 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
example is football game. Have you ever up flow of communication. A computer
played football? When a football game system is thus, designed with an input
is played, it is a complete system. This device, a central processing unit, an output
system comprises of sports committee, a device and a memory unit. When these
football ground, playing teams, referees components are connected together, the
and fans. All these are commonly known computer will operate and function as a
as elements of a system. The game also complete system to input data, process
have rules which govern it (procedures) them, output information and store data
which determine how any side will and information.

LY
emerge as winner. One more example is
a computer system. This has a number of Interaction: this refers to the manner
subsystems such as Monitor, Keyboard, in which each subsystem functions and

N
CPU, and Mouse. A Computer system communicates with other components of

O
shows how these organised subsystems the system. During system development,
relate to each other, and they can work in special interfaces are designed to share data
the intended way. To achieve the intended or information between subcomponents.
objectives, these subsystems must work
together by depending on each other. The
following are the characteristics that exist
SE
You can observe a simple example
of interaction in organisations when
procurement department for purchasing
U
in all systems. must interact with operations department
for production. Marketing department
Characteristics of a System
for advertising interacts with sales, and
Organization: organisation refers to
E

accounts department that owns payroll


structure and order. This is a systematic interacts with personnel. In a computer
N

order of components working together system, the central processing unit must
to achieve specified objectives. It is the interact with the input device in order to
LI

arrangement of subsystems or elements perform a task. The RAM holds programs


in a particular structure and order that and data that the arithmetic unit uses
N

help to achieve the required objectives. for computation. This interrelationship


For example, when you design a system between these computer devices enables
O

that has a hierarchical relationship starting it to process data.


with the minister for education on top,
R

then downward to the ward education Interdependence: this refers to the


officers, it represents the organization parts of a system which depends on
FO

structure. Such an arrangement depicts one another to achieve objectives of


a system and subsystem relationship a system. This can be compared with
which describe the authority structure and a situation like a complex task which
specifies the formal top-down and bottom- is divided into a number of simple

323
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 323 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
tasks (i.e. subsystems). Each simple of a system depends on the input of
Computer Science

task performs its work and produces another part for proper functioning. In
output. The output of one task may this case, the output of one part, can be
become an input of some other tasks. a required input for another part. This
As such, a given complex problem is interdependence is very important in
finally solved. Similarly, in a system, systems operations.
the output of one subsystem may be
an input of some other subsystems. Figure 6.1 shows an organisation structure
These subsystems are coordinated and as an example of a system that works by

LY
linked together accordingly. One part interdepending on each other.

MINISTER

N
NATIONAL EDUCATION
ADVISORY COUNCIL

O
PERMANENT SECRETARY
POLICY AND PLANNING DIVISION

FINANCE AND ACCOUNTS UNIT DIRECTOR


CHIEF ACCOUNTANT
INTERNAL AUDIT UNIT
CHIEF INTERNAL AUDITOR
INFOR. AND COMMN. TECHNOLOGY UNIT
SE
ADMIN & HUMAN RESOURCE MANAGE. DIVISION

DIRECTOR
PROCUREMENT MANAGEMENT UNIT
PRINCIPAL ICT OFFICER DIRECTOR
U
GOVERNMENT COMMUNICATION UNIT
NATIONAL COMMISSION FOR UNESCO
PRINCIPAL INFORMATION OFFICER
EXECUTIVE SECRETARY
LEGAL SERVICE UNIT
E

PRINCIPAL LEGAL OFFICER FAS & PISCS


N

COMMISSIONER FOR EDUCATION OFFICE


LI

HIGHER EDUCAT SCHOOLS QUALITY


SCIENCE TECHN &
TECHNICAL AND VOC. BASIC EDUCATION SPECIAL NEEDS
DIVISION ASSURANCE INNOV DIVISION
EDUC. TRAIN. DEV. DIV DIVISION EDUC. UNIT DIVISION
N

DIRECTOR DIRECTOR DIRECTOR DIRECTOR


DIRECTOR DIRECTOR
HIGHER
O

EDUCATION TECHNICAL BASIC EDUC. PRIMARY SCHOOLS RESEARCH AND


CO-ORDINATION EDUCATION SECTION
SECTION POLICY DEV. QUALITY ASSURANCE DEVELOPMENT
DIVISION
SECTION SECTION
VOCATIONAL
HIGHER TRAINING SECTION BASIC EDUC. SECONDARY SCHOOLS
R

EDUCATION QUALITY ASSURANCE


TEACHERS
DEVELOPMENT TRAINING
DIVISION SCIENCE AND
SECTION FOLK DEVELOPMENT SECTION TECHNOLOGY
SECTION SECTION
FO

SCHOOL TEACHERS QUALITY


ASSURANCE SECTION
ACCREDITATION
SECTION

Figure 6.1: An example of organisation structure as a system

324
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 324 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Integration: this refers to the process if it happens so, the system developing
of connecting various sub systems into team will have developed unintended
a single larger system. It is concerned system. Thus, it is crucial for experts to
with how a system is tied together. This concentrate to a specified objective.
means that subsystems work together
within the system even though each Basic elements of a system
subsystem performs a unique task. Any system has three basic elements
which are input, processing and output.
These elements are common to all
Planned approach: when a system is

LY
systems. For example in educational
created, then it should work according
system: students, teachers, books
to the planned approach which is a set
and computers are the basic elements
of procedures, policies, rules, budgets,

N
or component of education system.
strategies and schedules to achieve its
Another example is a computer system
objectives.

O
which has some basic elements such as
monitor, CPU, and keyboard.
Central objective: a system should have
a central objective. This is an objective
in which the system should operate
towards achieving what it was planned
SE
Other elements of a system include control,
feedback, environment, boundaries and
interfaces. Therefore, the overall key
for. Sometimes the specified objective
U
elements of a system are shown in Figure
may become unachievable. Therefore, 6.2.
E

CONTROL
N
LI

INPUT PROCESS OUTPUT


N
O

BOUNDARIES AND
FEEDBACK INTERFACES
ENVIRONMENT
R

Figure 6.2: Key elements of a system


FO

Input: when the expected output of a system is known first, you can easily determine
what should be the input of that system. Input, is therefore, the start up component
or activity of gathering and capturing data. This data may be raw material, physical

325
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 325 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
source, knowledge or anything which standards of the output of the system.
Computer Science

will decide the nature of the output as The information obtained as a result of
per intended system goal. checking output against standard in a
system, which is used to make changes
Process: this is the activity of converting and input or processing activities is known
the inputs into useful outputs. The data as a feedback. An example of a feedback
which is processed in the computer in a customer management system could
follow the logical steps which are to be
be to improve customer services.
instructed in series.

LY
Environment: environment is the element
Output: this is the end result of a process
or procedure. Though output is largely of a system that determines how a system
must function. Environment is the source

N
reliant on input, its nature or format may
differ from the input depending on the of external elements that affect the system.

O
kind of applied process. An example in a banking system is a
national ID and macroeconomics element
Control: if you want to get the desired such as inflation.
results during any process, it is good for
you to monitor and control the input,
processing, and the output of the system.
SE
Boundaries: this shows how system
interfaces with the outside world. So,
U
In other words, the control of a system the boundaries of the system are the
is the decision maker that controls all limit of the system. Defining boundaries
activities in the system. An example of a helps to attain better concentration of
control is school environment. A School
E

the activities carried in the system. An


Management Team (SMT) is a decision example of a boundary is a teller system
N

making body which controls planning


in a bank which is restricted for the
of tasks, manages of academic matters,
customers to deposit, withdraw, and
LI

discipline students who misbehave, and


check and save accounts activities.
handles social affairs by using different
schedules. By monitoring the delivery
N

of knowledge and skills or teaching Interfaces: interface can be understood


as the interconnections and interactions
O

process as inputs, the expected output


will be good performance and behaviour between the sub-systems. They may be
of students. Control, as decision making inputs and outputs of the systems. An
R

body in this example, regulates the example is a student system in a school or


activities that affect the welfare of the college that can have various subsystems
FO

education business. such as exams, registration and payment


that might be interconnected, and they
Feedback: the output of a system interact to achieve overall goal of the
during process is checked against the set system.

326
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 326 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
which takes input and gives output. This
Activity 6.1 type of system always adapts to the
internal and environmental conditions
Searching commonly known changes, such as an organisation and
systems-1
a human being. Any organisation
By using a library or internet search, exchanges its material, manpower, money
find three commonly known systems and information with its environment.
and generate the concept of their basic Another example of an open system is
elements. Provide relevant examples. an information system which must adapt

LY
to the changing environmental conditions
such as Government electronic Payment
Activity 6.2
Gateway (GePG).

N
Searching commonly known systems-2

O
Examine how payments are made for Ask yourself the
prepaid: following question:
(a) power meter (LUKU); and
(b) TV services.
Determine the basic elements for each.
SE In what kind of system do you think
you are, as a human being? Open
system or closed system?
U
Generally, the system can be manual or
computerised. In information system A human being like many other living
point of view, a system is a collection of things, is an open system. Thus he/she
E

can exchange both matter and energy


elements (people, hardware, software,
with the surrounding environment. As
N

data) and procedures that interact to


a human being, you take in chemical
provide feedback mechanism that is
energy in form of food which you eat.
LI

needed by organisation or users to achieve The calories as a results of food are used to
their goals. do a manual work on your surroundings.
N

This manual work is done when someone


Classification of Systems
walks, talks, moves objects from one
O

Systems are classified in different ways. location to another and when breathing.
The general classification of systems is The metabolic reactions in your body
as follows:
R

accelerates the exchange of energy


inside your body and between you and
Open or closed system
FO

your environment or surroundings. This


Open System process, in natural laws, is recognized as
An open system is a system that interacts energy exchange between hot and cold
freely with its environment. It is a system objects or gas molecules.

327
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 327 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Closed system
Computer Science

Activity 6.3
A closed system is a system which has
no interactions with other systems or
does not interact with its environment. Searching for open and closed
A good example of a closed system is system
a Television. A Television is by itself By using a Library or internet search,
a closed system which controls its explore two commonly known open
sharpness and brightness automatically systems and two closed systems and
with sensors. Another example of a generate their concepts with examples.

LY
closed system is a sealed digital watch
which comprises of various components
that work collaboratively in order to Physical or abstract (Conceptual)

N
perform the specific task. In addition, a system
digital watch for example, its operation is

O
Conceptual (abstract) system are
completely isolated from its environment. non physical entities that may be a
representation or model of a real system.
Think about the
following:
SE
A good example of an abstract system
is economic theory and the theory of
relativity.
U
(a) What will happen when the
boundaries of a system change? Physical systems are tangible entities
Will the system persist as it was that may be static or dynamic in nature.
These are the concrete operational
E

from the beginning?


systems which are made up of people,
(b) Boundaries can physically change. materials, machines energy and other
N

You can change boundaries when physical things. You can touch and
you want to study a small or large
LI

feel the physical systems. In other


part of the system. way you may observe the physical
(c) If boundaries change, are plants systems which are static or dynamic in
N

going to be closed systems or open nature. For example, if you visit any
computer center, you may see desks
O

systems?
and chairs. These are static in nature.
But, the computer which you will see
Note: You can describe a system based
R

is a programmed computer, and it is a


on inputs, outputs and boundaries. dynamic system where programs, data,
FO

You can judge whether a system is and applications can change according
open or closed by observing two to the needs of users. Another example
or more parts working together to of a physical system is a Management
perform a particular function. information system. For the physical

328
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 328 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
system to be operational, it must have (KWS), decision support systems
ability to display activities or behaviour. (DSS), executive support systems (ESS)
The conceptual system on the other side and Group decision support systems
works on different ideas or concepts (GDSS). Others are computer-supported
thus displaying theoretical structures. collaborative work systems (CSCWS)
and Computer Based System which is
Activity 6.4 directly dependent on the computer for
handling business applications. Such as
Searching for Conceptual and banking system, digital library systems

LY
physical systems and railway reservation systems). Other
man made systems include manufactured
Use the environment or library or systems such as rockets, dams and trains.
internet search to study the conceptual

N
In addition, Social/human-machine/
and physical systems. Speculate two machine system is part of artificial system.

O
commonly known conceptual systems Social system is made up of people, and it
and two physical systems, generate may include social clubs and societies. In
their concept with an example for Human-Machine System, both human and
each and present.
SE
machines are involved in accomplishing
a certain task. For example, Computer
programming in artificially intelligent
Natural & Artificial systems
U
Natural systems: all the naturally robot (cobot) operated by a human is
occurring systems are called natural a human-machine system. Machine
systems. These are created by nature. System does not involve any human
Examples of natural systems are solar control. All the tasks are executed by
E

system, water system of the world and machine, for example, an autonomous
N

seasonal system. robot performance when is assigned a


particular task.
LI

Artificial system: all man made systems


are called artificial systems. Some of Activity 6.5
N

the man made systems include the


man made computerized information Searching for natural and artificial
O

systems developed for different purposes, systems


depending on the needs of humans as
Use your environment or Library or
users and the business to be performed.
R

internet search to study natural and


These information systems include artificial systems. Also, speculate two
FO

(Management Information System- commonly known natural systems and


(MIS), Transaction processing systems two artificial systems and generate
(TPS), office automation systems (OAS), their concept with an example
Expert Systems, knowledge work systems for each. Using the same laws or

329
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 329 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Temporary system is made for specified
Computer Science

principles in those system, create a


model of your own system which can time and after that it is demolished. One
work in real life. example of this system is a DJ system
which is set up for an event program and
it is disassembled after the program is
Adaptive and non-adaptive system closed.
Adaptive system is a system which
responds to the change in the environment,
Activity 6.7
in a way to improve their performance and

LY
to survive. Some examples of adaptive Searching for permanent and
systems are human beings, animals, temporary systems
Windows OS, and robotics.

N
Use your environment or library or
Non adaptive System is the system which internet search to study permanent

O
does not respond to the environment. or temporary system. In relation to
Example of non adaptive systems are this, speculate two commonly known
machines or an autocratic system of permanent systems and two temporaly
governance. SE
systems and generate their concept
with an example for each. Using
the same laws or principles in those
Activity 6.6
U
systems, create a model of your own
Searching for adaptive and non system which might work in real life.
adaptive systems
E

Use your environment or Library or Deterministic and probabilistic system


Deterministic system: it is a system
N

internet search to study adaptive and


non adaptive systems. Also, speculate which operates in a predictable manner.
LI

two commonly known adaptive The operation is executed step by step


systems and two non adaptive systems and output is certain. An example of
a deterministic system is a computer
N

and generate their concept with an


system.
example for each. Using the same
O

laws or principles in those systems,


Probabilistic system: It is a system which
create a model of your own system
operates in unpredictable manner. In
which might work in real life.
R

this system the degree of error is always


possible, and the output is uncertain. A
FO

Permanent or temporary system good example of a probabilistic system


Permanent System is a system which is weather forecasting system. In this
persists for long time, one example of case, the interaction between various
this system is a business policy. subsystems are not certain.

330
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 330 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Activity 6.8 Exercise 6.1

Exploration of deterministic and Answer the following questions.


probabilistic system 1. Describe the meaning of system and
Use your environment or library or analyse its types.
internet search to study deterministic 2. How the boundary of a system
and probabilistic system. Based on can affect the type of the system?
this, identify two commonly known Provide an example.

LY
deterministic systems and two 3. Explain with an example the
probabilistic systems and generate importance of feedback in a system.
their concept with an example for each. 4. List and describe characteristics of

N
Using the same laws or principles in a system and provide an example
for each.

O
those systems, create a model of your
own system which might work in real 5. The operations of a jet aircraft is
life. linked into an airline’s system, when

Activity 6.9
SE programmed and activated by the
pilot under certain condition, it may
possess capability. Propose the type
of systems formed by aircraft and
U
Investigating local existing system airline’s systems.
6. Explain the components of
Investigate the existing systems in information systems.
E

homes, schools or elsewhere; then,


7. Differentiate between open and
identify their key elements as well as
N

closed system and provide an


their types. Using the result of your example for each.
investigation as sample, develop a
LI

simple system model that will apply


in real life. System development
N

System development is the process


of defining, designing, testing, and
O

Integrated system implementing a new information system.


Integrated system is the combination This is to say that, systems development
R

of related subsystems to form a larger is a process of creating and maintaining


subsystem or total system. Examples information systems.
FO

of this system are airline reservation


systems, and management Information This process may include development
System (MIS). of new systems, customisation of
the existing systems and purchasing

331
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 331 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
of systems or software. In some This training is done by an organisation;
Computer Science

organisations, this process may require thus, for the use of the information
the purchasing of software package system, users will be guided on how to
that is available in the market. When use it based on the requirement specified
the software has been purchased, one in the system. Different from the off-the-
of the following may happen: adapting shelf softwares which are just purchased
directly all the functions available and people will directly use them,
in the software; change the way the information systems need users to take
organisation does business to fit the ownership of their systems which is the

LY
software; or customise the software to most important criterion for its success.
suit the organisation standards. Most In this way, system development seems
organisations choose to customise the to be challenging and risky.

N
software to ensure that it complies to
the standards of the organisation and is
Ask yourself the

O
relevant to their business purpose.
following question:

Think about the


following:
SE
Why do the systems development
seem to be challenging and risky?

Have you ever thought that, while you


U
may be able to purchase an off-the- Many system development projects are
shelf software program, you won’t never finished. If you find that they are
be able to purchase the information finished, then some of them might have
E

systems.
gone over budget. Some projects die
N

before achieving their goals. When you


are in a system development project,
The information systems are developed
LI

or purchased depending on the needs of a you may face several challenges. These
particular organisation. When purchased, challenges may be due to the fact that it is
N

the procedures to fit the business and the difficult to determine the requirements of
people or users of that system must be a system which include data, procedures,
O

constructed or adopted. This is because a communications, and processing


person cannot use the system which does requirements. The requirements always
R

not define his or her needs. The process change. These changes may occur even
to adopt a system may differ from one when the system is being developed
FO

organisation to another. Therefore, one especially when you are dealing with
must define his or her own procedures. a big system which takes long time,
In this case, people must be trained to you might find that more requirements
use the information system effectively. change. In this case, it is also difficult to

332
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 332 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
determine the schedule or budget. In order to make projection on labour costs, you
will have to estimate labour hours. The whole system project team with the project
manager may be engaged in planning for the projection of activities and associated
budget. The roles and responsibilities of a project manager and other members of a
project team are shown in Table 6.1.

Table 6.1: Roles and responsibilities of members of the project team


No Participant Role and responsibility
1. Project

LY
A person assigned by the organisation to ensure the
manager project is completed on time, within budget and delivers a
quality product that satisfies users and meet requirements.
Other roles include project monitoring and evaluation,

N
communication management, cost management, quality,

O
and risk management. The project manager is also
responsible for acquiring basic equipments.

2. Stakeholders These are people who will be directly affected positively or


SE
negatively by the systems development project. They have
knowledge of the processes involved, and their role is to
provide inputs in the project. Stakeholders include system
U
analysts, programmers, end users, business managers,
project sponsors, teammates and other key individuals.
3. Users These are people who will be interacting with the system.
E

Their role is to ensure system quality and successful


implementation by providing effective feedbacks.
N

4. System This is an expert who specialises in analysing and designing


LI

analyst of systems.
5. Programmer This is an expert whose role is to modify or develop
N

systems to satisfy user requirements. When the systems


analysis team has designed a system, then it is the role of a
O

programmer to build and modify that program.


6. Steering This is a small group of senior managers who represent
R

committee their business and other information systems organisations


team that provide a consultative support to the project.
FO

7. Project This is a key member and leader of the steering committee


sponsor who is liable to provide financial, administrative, technical
and advisory support for the project team.

333
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 333 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Participants of systems development
Computer Science

There are a number of people (participants) as shown in Figure 6.3 who are important
during the system development process.

Project sponsor

LY
Steering team

N
External companies

O
Systems analysts

System stakeholders
SE
Project manager
U
Vendors and suppliers
Technical specialists
E

Users
N
LI

Figure 6.3: Participants of the system development


N

Systems development approaches it meets customers’ needs. All these


O

As it was explained before, system activities make it an endless process.


development is a process. System SDLC has phases which need to be
development process is also known
R

followed during system development.


as System Development Life Cycle
These are requirement gathering, system
FO

(SDLC). This is because the system may


design, system development (coding),
be developed to the end point and be
system testing, documentation and system
used by customers. In addition, it may
need modifications while in use so as maintenance.

334
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 334 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
There are three main categories of system development approaches to SDLC as
shown in Figure 6.4: the predictive approach, adaptive approach. and object oriented
approach.

The System Development Life Cycle has various methodologies which can be used
during software development projects. As it was mentioned before, these include
waterfall model, agile SDLC model, Spiral Model and Scrum. Other methodologies
include Extreme Programming (XP), Unified Process (UP), iterative model,

LY
V-Model, Big Bang Model, etc. Figure 6.5 to Figure 6.10 show some of these
methodologies for system development.

N
O
SE
U
E
N
LI

Figure 6.4: Categories of System Development Life Cycle


N

Predictive SDLC approach of the system development even before


The Predictive SDLC is an approach you can go further with other phases.
O

whereby the complete output of The predictive approach is always


the project according to the plan suitable for the projects which are well
understood and they have low risk. This
R

can be predicted. This involves the


programmers to have an understanding approach is very flexible, and it does
FO

of the expected output and decide on the not allow an expert to go back to the
process to make it. In this approach, it previous phase for modification; rather,
is simple to determine the cost, scope, it allows to modify the proposed plan of
and timeline early from the beginning a system along the project progresses.

335
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 335 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
One of the SDLC model in predictive Disadvantages of Predictive SDLC
Computer Science

approach is a waterfall model, where one approach


phase completes and the project team The following are the disadvantages of
moves to the next phase of development. using the predictive SDLC approach
Other models include iterative and
V-shaped to be discussed later. 1. It is not appropriate for those projects
which are flexible and they are likely
Advantages of the Predictive SDLC to have requirements changes.
approach 2. This approach is not suitable for

LY
The following are the advantages of complex projects.
using the Predictive SDLC approach. 3. This approach may cause the
1. The guidelines and brief workflow organisation to incur extra cost due

N
which have been prepared to lead to delay of the project completion
the project make it easier for the caused by identified bugs during the

O
developers to work within a proposed testing phase of the project.
budget and timeframe.
4. It requires a smart planning. If a
2. Every stage in the predictive SDLC is
scheduled a period of its completion
together with deliverables so as to
SE
good job is not done in each phase,
it may lead to the failure of the entire
project.
help the team to function and monitor
U
the whole system development 5. It requires much efforts to integrate
project easily. individual components of a larger
3. It is easy to understand and follow system.
E

the project plan provided that each


phase starts when another phase is This predictive approach has a number
N

completed. of methodologies or models such as


LI

4. It allows organizations to predict Waterfall, iterative and V-Shaped as


the expected project budget and indicated in Figure 6.4.
timelines.
N

5. Predictive SDLC approach can Waterfall Model


O

develop the system quicker than This model is known to be the oldest
using the adaptive approach.
model in software development, it is
6. It is easy to manage risks because
R

sometimes called traditional model.


problems are identified at the first
Although this system development
iterations.
FO

technique evolved many years ago, it


7. It is incremental and the model can
remains a popular system development
be tested piece by piece until the
project is completed. method. In waterfall model, the outcome

336
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 336 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
of each phase is called a deliverable or end product, which flows into the next
phase. It has several stages that are followed during system development, as they
are shown in Figure 6.5.

Waterfall Model
Requirement Analysis

LY
System Design

Development

N
O
Testing

SE Deployment

Maintenance
U
Figure 6.5: Waterfall SDLC Model for software development
E

Advantages of Waterfall Model 2. The system will be used only if the


last stage is achieved
N

1. The model is user friendly and


understandable 3. There is a high risk of using waterfall
model and the end result is not
LI

2. Each phase has a clear end product


and process review certain.
4. It is not more suitable for complex
N

3. System development goes one phase


and Object-Oriented projects.
after another.
5. The model is not suitable for long-
O

4. It is suitable for small projects with term system development projects.


clear and unambiguous requirements 6. It is difficult to assess the progress
R

5. Key points can be determined easily of a particular stage while it is still


in development cycle in development.
FO

7. It is not possible, in some of the


Disadvantages of Waterfall Model systems, to completely specify the
1. It does not emphasize interactivity requirements before the start of the
among the phases next phase.

337
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 337 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Iterative Model each iteration, developers build few features
Computer Science

The iterative model is the first. Figure 6.6 shows stages for iterative model.
implementation of the system
development life cycle of which In this case, it is not necessary for Iterative model
to have full requirements before commencing
the development of a system
the project. In this model, creating a system may
starts with the focus on some
start with the requirements of one functional
initial requirements where by
feature, and others may be extended later. The
other functional features are
process of developing repeats in order to come

LY
added in the next iterations. out with new types of the product for every cycle.
Every iteration comprises the development
The iterative model is somehow of a new component of the system. When this

N
similar to a waterfall model, development is done, the component is added

O
but there is a trivial difference to the features that were created in the previous
between them. Unlike the iterations.
traditional waterfall model,
which focuses strictly on a step
by step during the development
SE
However, during the first iteration, the
development team may decide to work on for
stages, the iterative model has instance five features out of fifteen features.
U
various cycles focusing on While experts develop those features, they pass
improvement that is made for through all stages of the software development
process from the needs assessment to the
the next better iteration. A good
E

deployment and maintenance levels. When they


example which may assist you
move to the next feature, the development cycle
N

to note the difference is when


renews. The Iterative model have a lot of things
you need to develop a system
in common with agile model, but the difference
LI

that holds fifteen essential is that external customers are not much involved.
features. The planning for this
N

system in the waterfall model Requirements Analysis


and Design
during requirement analysis and
O

Initial
design phases will include all
Planning Iterative
fifteen functions. This planning Model
R

will then be implemented


during the development stage. Deployment
FO

But, in the iterative model, the


Evaluation Testing
whole process is divided into
several iterations, and during Figure 6.6: Iterative model- development stages

338
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 338 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Advantages of Iterative model Disadvantages of Iterative model
1. Some functional features can be 1. Iterative model demands more
quickly developed at the initial resources compared to waterfall
stages. model.
2. System development progress can 2. The development requires
be easily measured. continuous management in all
iterations.
3. It is easy to test and fix errors if the
3. Iterative model is not convenient
iterations become shorter. for small projects.

LY
4. Iterative model is very flexible 4. Some requirements, if not observed
because new functionalities may during initial stages, may cause
be added at any time of system fatal problem in design phases.

N
development stages. 5. It is difficult to manage the process
5. The end users or stakeholders can using this model.

O
provide feedback quickly and they 6. Risk analysis requires highly
can be included as development qualified personnel to check the
risks in the systems.
continues.

V-Shaped Model
SE
The key priorities of this model are verification and validation. In V-Shaped model,
U
verification is conducted to determine if the developed system is consistent with initial
requirements. In this model, validation is done to confirm if the product corresponds
to the needs of a client or organisation. Figure 6.7 shows the development stages for
E

V-Shaped model.
N

V-Shaped Model
LI

Business Requirements Acceptance Testing


N

System Requirements System Testing


O
Ve

n
tio

Software Design Component Testing


rifi

da
ca
R

li
Va
tio

Module Design Unit Testing


n
FO

Coding

Figure 6.7: V-Shaped SDLC model- development stages

339
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 339 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Advantages of V-Shaped SDLC model demanded by the changing needs. This
Computer Science

1. It is easy to control. approach is also incremental development


2. It is easy and simple to use. where you can develop one piece at a
time. Some of the SDLC models in
3. It is suitable for small projects which
adaptive approach include Agile Software
have clear requirements.
Development (ASD) methodology,
4. Testing activities like planning and Rapid Application Development (RAD),
test designing materialise well before Extreme Programming, Unified Process
coding (UP) and Scrum. Agile methodology is

LY
one of the most recent adaptive software
Disadvantages of V-Shaped SDLC development approaches. The Adaptive
model system development approach focuses

N
1. This model misses flexibility. on constructing and delivering small
2. It does not favour small projects. functional pieces of applications as the

O
project continue at any stage. This does
3. It is risky to use the V-Shaped model.
not wait to deliver one complete system
4. There is no early prototypes of the at the end of the project.
system which are created because
the system is developed at the phase
of implementation.
SE
Advantages of Adaptive SDLC approach
1. This approach encourages active
U
participation and interaction with
Adaptive SDLC approach the key stakeholders. This will help
Adaptive approach to the SDLC is an the project be developed basing on
approach in system development where priorities and greater accuracy.
E

the project is said to be flexible and adapt 2. It encourages different teams to


N

to the changing requirements as the exchange technical skills when


system development progresses. This a project is in progress and build
LI

approach involves making changes and conducive environments when


refinements depending on the feedback stakeholders interact together
N

received from the clients. This approach physically.


suitable for the projects that are not well
3. This approach emphasises on
O

understood, uncertain for what is desired


producing high quality systems while
and they are of high risk. This approach
maintaining technical excellence.
has a combination of both incremental
R

and iterative development. 4. Agile methodology is efficient to this


approach and encourages teamwork
FO

Adaptive SDLC approach usually among members.


has features of iterative development 5. This approach involves methodologies
which is a cyclical approach that allows such as iterative and incremental
the repetition of steps and tasks when which provide easy flow of work.

340
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 340 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Disadvantages of Adaptive SDLC This adaptive approach has a number
approach of methods such as Spiral, Extreme
1. The changes which occur often during programming, Agile methods and
development may lead to greater Prototyping are discussed as follows.
challenge to have a comprehensive
Agile Model
system documentation.
Agile Software Development Life
2. The approach require user
Cycle is the mixture of both iterative
involvement throughout the process and incremental process models.

LY
3. Lack of commitment from vendor Agile model is an iterative system
side and side of the particular development process that develops the
organisation or between organisation system in “sprint” increments lasting

N
and its clients may result to low from two weeks to two months. This
quality of the system developed. model focuses on process adaptability

O
and customer satisfaction by quicker
4. The planning of the project may
delivery of working software product.
be so uncertain due to the changes
Agile SDLC breaks down the system
expected during development
SE
into small incremental builds. These
builds are provided into iterations. The
Activity 6.10 uniqueness of Agile is when the work
U
split these iterations (sprints) like the
Exploration of system development iterative model. The team initially
projects defines what actions they will need to
perform in a particular timeframe.
E

Study your wide range environment,


N

explore and come up with the system The main difference between Agile and
development project which you may Iterative model is that the quantity of
LI

think it needs a day to day updating of work can be changed within the process.
the user requirements and then: Another distinction is that Agile
N

provides a room for team specialists


(a) Propose the SDLC approach that
to give customers knowledge of what
will best suit your selected project
O

is done. Specialists can give them


and explain why do you think the updates and familiarise them with the
selected approach is appropriate. plan. Any changes that occur during the
R

(b) Identify the methodology that you process are presented to a customer for
will use to develop the system. discussion and approval. Every stage in
FO

Agile should be analysed and accepted


(c) Judge, if the Agile methodology by customers before the next stage.
may be one of the methods. Agile stages for system development are
shown in Figure 6.8.

341
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 341 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
4. The system development project may
Computer Science

Requirements
go beyond the timeline due to the
corrections and changes done during
Test and Architecture the development process.
feedback and design 5. Agile SDLC model requires systems
analysts and users to be skilled in
agile systems development tools and
Development agile techniques.

LY
Figure 6.8: Agile SDLC Model for Spiral Model
software development
Spiral model is an adaptive approach
to SDLC which is designed to control

N
Advantages of Agile SDLC Model
risk. It combines iterative development
1. Agile methodology can allow process model with some aspects of

O
developers to be much more flexible waterfall model. It is also an approach
and responsive. that cycles repeatedly through
2. The functional requirements are
corrected during the development
process for effectiveness.
SE
development activities until a project is
complete. In spiral model, each iteration
or phase of the model must have a
specific goal that is accepted, rejected or
U
3. Project is divided into short iterations
changed by the user or client. Thus, each
4. Risk is minimal due to the flexible iteration provides feedback and inputs
changes during development process for improvements which assist the team
E

5. The first product version is released to achieve the project goal. Figure 6.9
within a short period of time. shows a diagram of spiral model. After
N

the initial planning is completed, usually


6. Agile approach allows teamwork
work begins in the first prototype.
LI

and interactions between users and


stakeholders to be inevitable.
A prototype is a preliminary working
N

model of a system developed to enable


Disadvantages of Agile SDLC Model
users to interact with it and provide
O

1. It is difficult to assess the final cost feedback for developers to understand


because of the long lasting changes. what is required. Building and using a
2. The system development team prototype enables developers and users
R

should be highly professional and to test concepts and evaluate alternatives


able to interact with clients at any
FO

before paying much attention to


time. implement the system. Prototypes can
3. New requirements may conflict with be classified as throw-away prototypes
the existing system. or working prototypes.

342
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 342 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
A throw-away prototype is a prototype that A working prototype starts with an
is used to help define the software solution, initial prototype that undergoes a
but it does not become part of the final series of iterations of demonstration,
solution. Throw-away prototypes provide feedback, and refinement and finally
a highly effective way for developers evolves into the final software solution.
to validate their understanding of how The client or users are involved in
the system should work to the clients providing continuous feedback during
or users. The feedback given during the
the development process. With each
demonstration identifies misinterpreted
iteration, the working prototype moves

LY
or unnoticed user requirements. The
further from the initial prototype and
demonstration also gives users an
opportunity to change their mind once closer to a working system that meets
the needs of its users.

N
they see the prototype system is working.
1. Determine Objectives 2. Identify Risks

O
Commutative cost progress

SE
U
Requirement Prototype 2
Operational
Prototype 1
Review plan prototype
E

concept of concept of Requirement Detailed


operation requirement
Draft
design
N

Development Verification &


plan Validation Code
LI

Verification & Integration


Test plan
Validation
N

Test
Implementation
O

4. Plan the next iteration Release 3. Development and Test

Figure 6.9: Spiral SDLC Model for software development


R

Advantages of Spiral SDLC Model


FO

1. System development process is divided into portions; if the risk is high, the
phase can be ended earlier to address the solution.
2. System development process documentation is done accurately including the
changes due to user and system requirements.

343
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 343 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
3. Changes and addition of new all part of an iteration cycle as shown in
Computer Science

functionalities can be done even at Figure 6.10.


the late stages.
4. When the prototype is done earlier, Parallel programming is an interesting
the users also get opportunity to concept used in Extreme Programming.
unveil the system fault earlier. Two programmers work on the same
task on the same computer in parallel
Disadvantages of Spiral SDLC Model programming; one drives (programs)
1. It is expensive to use spiral model. while the other navigates (watches). While

LY
2. The model demands highly skilled the motorist is focused on the individual
professionals. trees directly in front of him or her, the
onlooker reads the code strategically to

N
3. The model may be useless for small
view the forest. Throughout the procedure,
projects. the two continue to debate their thoughts.

O
4. Extreme documentation is required Unit tests are defined before code is written
for a various number of intermediate which is another important concept in XP.
stages

Extreme Programing (XP)


SE
A new system version may be built
numerous times each day. Every two
This is a software development model weeks, increments are supplied to the
U
which aims at greater software quality. customer. Every build must pass a test,
XP is an iterative technique to system and the build is only accepted if it passes
all the tests.
development in which a group of users
E

and developers immerse themselves


Advantages of XP
N

in the process. As with any other


development method, the first stage in (a) It saves money and time by focusing
on timely delivery of the finished
LI

the XP process is to identify the system


product.
requirements. User stories are brief and
N

straightforward requirements definitions (b) Because developers write extremely


provided by the customer. User stories simple codes that may be improved
O

at any time, simplicity is important.


are used by programmers to identify
project requirements, priorities, and (c) In XP, the entire process is
scope. User stories are implemented in a transparent and responsible.
R

series of iteration cycles. The planning, (d) Employee satisfaction and retention
are improved.
FO

designing, coding, and testing of one or


more features based on user stories are (e) There is constant feedback.

344
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 344 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Disadvantages of XP
(a) It prioritises coding over design while good design is crucial.
(b) Not all documentation is good.
(c) If programmers are geographically divided, XP is not a good option.

Test scenarios

Requirements

LY
Stories
Release
Customer
Release approval
Acceptance Test

N
planning

Spike

O
Iteration Small
Estimates releases

SE
Figure 6.10: Extreme programming for software development

Prototyping Model Activity 6.11


U
Prototyping is a system development
method in which a prototype is built, Selection of Agile or predictive model
tested and reworked until the final for development
E

decision is made.
Giving reasons for your answer based
Advantages of prototyping on the type of system being developed,
N

(a) It is easy to detect errors suggest the most appropriate model


LI

(b) It is easy to find missing that might be used as a basis for


functionality. development of the following system
software process model between Agile
N

(c) New requirements can be easily


accommodated. and Predictive models.
(a) Mobile application for bus booking.
O

(d) It ensure customer satisfaction.


(e) It actively involves users in (b) A system to control anti-lock
development. braking in a car.
R

Disadvantages of prototyping (c) A university accounting system that


replaces an existing system.
FO

(a) Poor documentation


(b) There may be too much variations (d) Enterprise Resource Planning
of requirements system.
(c) The model is too costful. (e) Sales tracking system.

345
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 345 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Object Oriented Approach Built-in procedures called methods can
Computer Science

Usually software/system are made to meet change an object’s characteristics in O-O


specified requirements and within the design. In a Web-based catalog store, for
alocated budget. Object oriented (O-O) example, an ORDER object might contain
approach enables the development of the a STATUS property that changes when
systems that might need rapid changes in a CUSTOMER object clicks to place,
confirm, or cancel an order. A message is
response to dynamic business needs. This
a way for one object to communicate with
approach is very suitable in developing
another object. A message asks another
systems that need continuous maintenance

LY
item to perform a specified action or
and redesign. O-O approach, in most
provide information
cases, follows the patterns of analysis
and design phases as in other SDLC. O-O approaches often follow a set of

N
analysis and design phases similar to other
O-O analysis integrates data and the software development models (SDLC),

O
processes that operate on it into something albeit there is less agreement on the
called objects, whereas structured analysis number of phases and their names than
predictive models, and O-O phases are
treats processes and data as separate
components. O-O modeling is used by
systems analysts to simulate real-world
SE
more interactive. The O-O methodology
is popular because it makes transitions to
O-O programming languages like Java,
Smalltalk, C++, Python, and Perl simple.
U
operations and procedures. As a result, a
set of software objects representing real
people, things, transactions, and events Advantages of O-O
(a) It is simple to integrate with an
E

is created. A programmer then writes a


code that creates the objects in an O-O object-oriented programming
N

programming language. An object is a language.


(b) Because code is modular and
member of a class which is a collection
LI

reusable, it can save money and time


of similar objects. Objects have features
during development.
called properties, which they inherit from
N

(c) Objects can be cloned using inherited


their class or they have on their own. properties, making them simple to
O

Example, a class called PERSON as shown maintain and expand.


in Figure 6.11, includes INSTRUCTOR
Disadvantages of O-O
and STUDENT. Because the PERSON
R

(a) Members of the development team


class has a property called Address, a
may be unfamiliar with a new
STUDENT inherits the Address property.
FO

method.
A STUDENT also has a property called
(b) In larger systems, the interaction
Major that is not shared by other members
of objects and classes may be
of the PERSON class. complicated.

346
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 346 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
PERSON Exercise 6.2
Name
Address Answer the following questions.
Social Security Number
1. What is the basic difference
between the predictive approach
and the adaptive approach?
INSTRUCTOR STUDENT 2. What is the standard type of
predictive approach called? How

LY
Name Name
Inherited Address does it work?
Address properties
Social Security
Social Security Number 3. What does incremental development
Number

N
mean?
Major
Office Location 4. Give the difference between object-

O
Office Telephone Other GPA
Date Hired properties Adviser oriented approach and predictive
approach.
Figure 6.11: Person Class- inheritance of
properties

Phases of System Development Life Cycle


SE
U
To develop a system successfully, one has to break the whole development process
into small activities known as phases. Any system development process should
have the following phases as shown in Figure 6.12: Planning, Analysis, Design,
Construction (development), Testing, Implementation, and Maintenance.
E
N

2. Analysis phase 3. Design phase


LI
N

7. Maintenance 4. Development
1. Planning Phase
O

phase phase
R
FO

6. Implementation 5. Testing phase


phase

Figure 6.12: Phases of SDLC

347
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 347 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Importance of System Development (f) Absence of one member doesn’t
Computer Science

Life Cycle break the Project


(a) Clear goal descriptions
SDLCs use paperwork to prepare
It is easy for developers to clearly know phases for developing system. Plans
the goals they expect to accomplish and start from the table, and guideline
the deliverables they are going to attain documents are prepared before actual
at the end of the proposed time. This development starts. When the process
help to minimize the wastage of time starts, everything is well documented.

LY
and other resources. The whole process involves a teamwork
to the extent that, if one member quits or
(b) Proper testing done before misses in a team, it will not threaten the

N
installation project timeline.
SDLC models provide great opportunity

O
for developers to ensure that all systems Exercise 6.3
developed are tested before being
installed. Answer the following questions.

(c) Clear stage advancement


SE
1. Differentiate between adaptive and
object-oriented approaches.
Developers can not move to a next stage 2. By providing examples for each, list
U
until the previous stage is cleared and and describe three main approaches
authorised and thereafter move ahead to System Development Life Cycle
by the team leader. (SDLC).
E

3. How do you explain system


(d) Member flexibility development life cycle? Provide
N

Since SDLCs have well-structured an example in which you can


describe the SDLC from planning
LI

documents for project goals and


methodologies, team members can to maintenance.
leave and be replaced by new members
N

without pain.
System planning
O

(e) Feedback from each stage makes This stage is also known as system
perfection investigation. It is the stage in which
R

the objectives of the system project are


All SDLC stages give feedback into one set. In this case, planning phase is the
FO

another. One stage completion helps to fundamental process of understanding


assess the move to the next stages. SDLC why system should be built, and
models can, therefore, help projects to determining how the project team will
move with iterations for improvement. go in building it. The system planning

348
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 348 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
phase usually begins with the formal start that project or not. Following an
request to the IT department, called a investigation, you may discover that the
system request, which describe problems information system is operational, but
or desired changes in an information the users may require additional training.
system or a business process. A system In some cases, a business process
request can come from the top manager, review may be more appropriate than
a planning team, a department head or an IT solution. In other circumstances,
the IT department itself. The request can you may come to the conclusion that a
be very important or quite minor. A large complete system evaluation is required.

LY
request could be for a new information The system Analysis phase is the
system or an upgrade to an existing one. next step if the development process
A modest request, on the other hand, can continues. The importance of doing

N
propose a new feature or a change to the system planning includes the following:
user interface.

O
Planning provides directions
Importance of system planning Planning helps to get clearly about
requirements, duration of the project and
The planning phase, is a time to think of
what you need to do. It is a time you are
supposed to decide whether to develop
SE
its cost. It also helps to determine the
kind of resources needed to accomplish
a new system or improve the existing the project.
U
one. System development project can
be in a high risk if it is not planned and Planning increases confidence and
scoped properly. This phase is used to reduces risk of uncertainties within
E

the project
conduct a preliminary investigation
Planning helps the client to be confident
N

in order to assess a problem. Because


the outcome of the preliminary that the set timeframe for the project
between two sides are implementable
LI

investigation will have an impact on


and that an agreement and decisions
the entire development process, it is
should be done before the start of the
N

an important step. A feasibility study,


project. Many projects, if they are
which examines anticipated costs and not well planned, face uncertainties.
O

benefits and advice an action plan based Planning helps to set strategies project
on operational technical, economic, and manager to foresee the future of the next
time aspects, is an important aspect of
R

phase or project. The plan helps to set on


the preliminary investigation. Assume how to face challenges like unexpected
FO

you’re a system analyst who receives a risks during system development. Some
request for a system upgrading, before resources may be prepared during the
you can get to a conclusion, you must planning phase to overcome the expected
first decide whether it makes sense to risks or uncertainties.

349
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 349 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Planning promotes business needs. Figure 6.13 shows the most
Computer Science

innovation common causes of system requests.


Since planning requires critical
Improved
thinking, the project manager Source
and development team can
find better approaches or Reduced Better
cost perfomance
methodology to develop a
particular system. Planning System
process forces project managers Request

LY
to think in a creative way about
the future of the project. Stronger Support for
controls new products

N
More and services
Planning helps in decision
Information
making

O
Planning can help a project Figure 6.13: Causes of system projects requests
manager and project team
to take several decisions. In
planning, objectives of the
SE
Factors affecting system projects
Every business decision a company makes, is
influenced by internal and external factors. So
system to be developed are set
likely, IT system projects are affected. The chart
U
in advance and expectations
shown in Figure 6.14 depicts the factors affecting
are made for the next phases
project execution.
or projects. The expectations
E

and objectives help the project Factors affecting Systems Projects


manager and development
N

team to make decisions. Internal factors External factors


LI

- Strategic plan - Technology


Main Reasons for requesting - Top Managers - Suppliers
system projects - User request
N

- Customers
A system request, which is a - Information
- Competitors
Technology dept
formal way of asking for IT
O

- Existing system - The economy


support, is the beginning point and data - Government
for most projects. A system
Figure 6.14: Factors affecting system projects
R

request may include additions


to a current system, bug fixes,
Overview of feasibility
FO

the replacement of an old


To determine whether it is worthwhile to move
system, or the creation of a
further, a system request must pass multiple
completely new information
tests known as feasibility studies. A feasibility
system to satisfy a company’s
study evaluates a project using four basic criteria.

350
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 350 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Operational, technical, economic, and (d) Schedule feasibility
schedule feasibility are all factors to Is it possible to complete the proposal in
consider. Sometimes a feasibility study is a reasonable amount of time?
straight forward and can be completed in
a matter of hours. However, if the request Evaluating Feasibility
includes a new system or a significant The first stage in determining feasibility
is to identify and eliminate non-feasible
modification, extensive fact-gathering
system requests. A request might be
and study is required. How much time and
realistic, for example, if it requires

LY
efforts are required for a feasibility study? hardware or software that the company
This depends on the nature of the request. had previously refused. Remember that
These crucial questions are always asked systems that aren’t currently practical

N
by the systems analyst. can be resubmitted after new hardware,
software, or expertise becomes available.

O
(a) Operation feasibility The system review committee must
Is the idea feasible in terms of operations? define priorities for the remaining items
Is it a practical solution to a problem or after rejecting requests that are not
a misleading use of an opportunity to
meet organizational objectives?
SE
possible. The highest priority is given to
projects that bring the most benefit for
the least amount of money in the shortest
U
(b) Technical feasibility amount of time. However, a variety of
factors influence project evaluation.
Is it technically feasible to implement
the proposal? Is the project equipped Steps for system planning
E

with the appropriate technical resources Step 1: Recognize the issue or


N

and personnel? for example, hardware, opportunity.


software, and skills. Step 2: Define the scope and restrictions
LI

of the project.
(c) Economic feasibility Step 3: Gather information by
N

Is the concept feasible from a financial (a) Analyzing organizational


standpoint? How much money will you charts
O

save and how much money will you spend? (b) Conducting interviews
Is there any consideration of intangible (c) Reviewing documents
R

aspects, such as customer satisfaction (d) Observing operations


or corporate image? Is the issue worth (e) Conducting a user survey.
FO

addressing, and will the request result in Step 4: Examine the project’s usability,
a profitable business venture? Are both cost, value, and timeline
information.
tangible and intangible benefits available?
Step 5: Assess the feasibility of the

351
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 351 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
project from the following System planning process
Computer Science

standpoint, namely operational, The process of system planning starts


technical, economic, and with comprehension of an idea put on
schedule.
the table. The next step is thinking of
Step 6: Inform management of your
the design, realization and coding. The
findings and recommendations.
planning of system discourse involves
the approach and the resources which
Activity 6.12
the project will use. Also the system

LY
Exploration for IT Projects request planning should mention various
standards to be used in development
The Health Department’s information such as tools, actions, strategies, and
system had quitted down by the end

N
responsibilities of each team member.
of the week. The IT team talked about

O
how to prioritize IT project requests The main purpose of planning is to
based on technical, operational, communicate with the team members
economic, and scheduling feasibility. and stakeholders the approach which
The group was asked for suggestions
by the IT manager.
SE
are to be used in developing the system.
Also it will help the project manager to
(a) Present two examples of why determine how to use the resources.
U
a project might lack technical
feasibility Some Leading Questions when
(b) Present two examples of why a planning
E

project might lack operational Some important questions that can be


feasibility asked when planning for the system
N

(c) Present two examples of why development include the following:


a project might lack economic (a) What problems does the project
LI

feasibility intend to address and solve?


(d) Present two examples of why (b) What are the main tasks to be
N

a project might lack schedule performed during development?


feasibility
O

(c) What are the resources to be used or


(e) Use your environment, internet, needed?
or library search to explore any IT (d) When will the resources be needed
R

project that needed improvement during the system development?


or quitted down and analyse how
FO

(e) What are the key functions of the


the request was implemented based system?
on operational, economic, and (f) What is the estimated time to end
scheduling feasibility. the software development project?

352
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 352 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
(g) What are the milestones, deadlines, time taken to announce the results,
deliverables, and dependencies? the management of the NECTA is
(h) Who are the stakeholders (team planning to implement an Online
members) involved in the project? Marking System (OMS). In this
(i) What are the responsibilities of each new system, the answer booklets
team member? are scanned in Dodoma. The
(j) How is the quality measured? What markers will then be given access
are the quality metrics? to the digital documents and the
OMS for online marking.

LY
Exercise 6.4 In relation to above information,
you are required to:
Answer the following questions.

N
(a) Briefly explain what is meant
1. The National Examination Council by technical feasibility.

O
of Tanzania (NECTA) holds special (b) Describe two technical issues
examinations for computer science
that are likely to be considered
students all over the country. The
in the OMS feasibility study
examination is held every six
months for some 30,000 students at
15 centres in 10 different regions.
SE (c) Briefly explain what is meant
by:
(i) operational and social
U
Present System feasibility.
Currently, all answer booklets (ii) (Economic or Financial
collected from the different Feasibility)
E

centres of the regions are sent by 2. What are required to do when


Posta Cargo courier service to you need to plan for the system
N

the Regional Education office in development?


Dodoma. In Dodoma, the booklets
LI

3. Explain the meaning of System


will be selected and sent through planning and its importance in
Postal service to different centres. systems development.
N

Once the booklets are already


4. What are the internal and external
marked, they will be returned to
O

factors that affect systems projects?


the Regional Education office in
Dodoma. The booklets will be
checked before being entered into
R

a computer system.
System analysis
Concept of system analysis
FO

Proposed System
System analysis is a phase in system
Because of the high cost of operation development where the present system
of the present system and the long
and acknowledged problems are

353
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 353 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
studied in depth and the system users
Computer Science

The deliverable of the system analysis


requirements are assessed. The primary phase is the system requirement
purpose of this stage is to help the systems specification (SRS) document that will
analyst to study the present system.To be used in the next stages of the system
understand the system, a system analyst development. Specifications document,
performs facts finding using techniques
as a result of system analysis, explains in
such as interviews, surveys, document
depth what is supposed to be done by the
review, observation and sampling. The
system. It presents a plan, system models,
results of the study will be used to come

LY
prototyping outputs, user and system
up with conclusions about the capability
specifications which will be referred
of the present system and to determine
during other stages of development. If
whether or not the project should move

N
system analysis is done improperly, other
on to the system design stage.
stages will end up to disaster.

O
The main activities conducted during
system analysis are requirements System analysis helps in disclosing all
modelling, data and process modeling,
object modeling and consideration of
SE
the functions of a system and how it
should behave. This information is also
very crucial in maintenance stage of
development strategies.
U
development when updating the system.
Importance of system analysis The output of a detailed system analysis
The overall objectives of the system can help to minimize the risk of a system
E

analysis phase is to understand the becoming outdated, if the maintenance is


proposed project, and ensure that it will done with the guide of a well conducted
N

support business requirements and build a system analysis.


LI

solid foundation for system development.


So the purpose of the system analysis The process of system analysis
phase is to build a logical model of the System analysis phase includes the four
N

new system. The first step is requirements main activities which are requirements
O

modeling, where you investigate business modeling, data and process modeling,
processes and documents and what the object modeling and consideration of
new system must do to satisfy users. development strategies (Transition to
R

Requirements modelling continues the systems design). The process of system


investigation that began during the system analysis starts with four main activities,
FO

planning phase. as shown in Figure 6.15.

354
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 354 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
during the requirement modeling
Data and process
Requirements process outlined above. Now you
modeling Modeling will utilise that data to create a
logical model of the proposed
system and a list of system needs.
Object A logical model shows what the
modeling
Systems system must perform, regardless
Requirements of how it will be physically
Document
implemented. You create a

LY
Transition to physical model that explains how
System Design the system will be built later in
the system design process. Three

N
basic tools are used in data and
Figure 6.15: Major activities of system analysis phase
process modeling: data flow

O
diagrams, a data dictionary, and
The following is the description of the stages in
process descriptions.
system analysis:

Requirement modeling:
SE Object modeling:
Object oriented analysis (O-O)
Requirements modelling is the process of fact- integrates data and the processes
U
finding to describe the current system, and the that act on the data into things
identification of new system requirement, such called objects whereas structural
as output, input, processes, performance, and analysis regards processes and
E

security. The term “output” refers to the system’s data as independent components.
electronic or printed information. Inputs are the During the system development
N

necessary data that is manually or automatically process, system analyst


entered into the system. The logical rules that are frequently uses both modeling
LI

used to transform data into useful information methodologies to gather as much


are referred to as processes. System qualities information as feasible.
N

such as speed, volume, capacity, availability, and


dependability are referred to as performance. Development Strategies
O

Hardware, software, and procedural controls that (Transition to systems design):


preserve and defend the system and its data from You will consider about several
R

internal and external threats are referred to as development options and


security. get ready to move on to the
FO

SDLC’s system design phase.


Data and process modeling: You will learn about current
You used fact finding techniques to study the software trends, acquisition
current system and establish user requirements and development options,

355
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 355 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
outsourcing, and formally documenting of the systems. He/she must be able to
Computer Science

the new system’s needs. A system understand and change people’s minds
requirement specification document, and attitude developed that has negative
which is an overall design for the new influence to his/her organisation and
system, is the final product of the system area of supervision. An analyst should
analysis process. In addition, each action be able to carefully pick points given by
in the systems analysis design phase has others without interruption for further
a goal and at least one milestone.
decision.

LY
Characteristics of a system analyst
Knowledgeable of business
Understanding of computer system and
system software A system analyst must have brief

N
understanding of business. He/she is not
A system analyst must have an
assumed to be an expert in it, but just
understanding of the computer systems.

O
In this case he/she must have knowledge to understand the client’s side and be
of the recent advancement and changes current. In this case, A system analyst
in technology. A system analyst must also should have the ability to work with
have the skills in software development. SE
various departments within his or her
organisation. People who can interact
Understanding of organisation with system analysts include store
U
To be a system analyst, one must have keeping officers, procurement officers,
knowledge of how various organisation accountants, sells personnel, Human
function and the structure of the Resource officer and others.
E

organisation. One must have knowledge


and skills on how managements and
Major tasks in solving a problem
N

departments of the organisation are related


in the work place. Problem solving is the process of defining
LI

a problem so that to determine the cause


Knowledge on the use of analytical tools of the problem and identify, prioritise,
N

A system analyst must have skills and and select alternatives for a solution in
understanding on how to use analytical order to implement it. There are several
O

tools to solve various problems that arise steps which can be passed when solving
during software development. Such a particular problem during system
tools includes decision table, decision development, steps are shown in Figure
R

tree and other tools. 6.15. These steps include defining


and analysing the problem, designing
FO

Good inter-personal communication


Any system analyst must have skills in or planning the solution, coding the
how to listen, evaluate and interpret the program, testing and debugging the
requirements or needs stated by users program, and documenting.

356
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 356 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Steps in problem solving process and What is this system or
The act of creating or developing software based program actually doing?
solution is known as programming. The five steps in
the programming process are explained as follows Designing the solution
and as shown in Figure 6.16: This process can also be
called planning the solution.
It involves devising and
formulating a solution by
writing the step-by-step

LY
procedure (developing
algorithm) that is required
to solve a problem. At this

N
stage, a large problem is

O
broken down into small and
manageable sub problems.
The step-by-step procedures,
SE also known as algorithm, can
also be applied to small sub-
problems. The algorithm is
U
refined so as it captures all
Figure 6.16: Steps for problem solving the aspects of the desired
solution.
E

Defining and analysing the problem


In designing the solution to
This step involves understanding the problem
N

completely and unambiguously by focusing on the the problem identified, you


can use the problem solving
LI

problem. This process should allow you to determine


necessary inputs, processing and output. Inputs technique to answer the
relate to what you know and outputs correspond to ‘what should be the solution’
N

what you want to obtain. question and collect or gather


the required information.
O

When defining a problem, you can put the problem You can review the problem
more clearly by asking several questions. In those identified by discussing the
R

questions you can assume the answers and note questions with the system
them aside. Some questions which may be asked development team in the
FO

include the following: What am I trying to do with basis of ‘why’, ‘how’ or


this system development? What have I done already ‘what’. You can collect
in the current system or the proposed one? What information from team
do I think the system or software should be doing? members and stakeholders

357
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 357 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
and use them to plan for a solution. the system (incorrect output). With this
Computer Science

regard, the grounds for feedback should


Such information may be for example, if be open during testing, and errors found
you want to know about ‘what’ functions will be debugged or rectified, and the
are in the system: if you have identified program will be tested again.
a problem and you do not know ‘why’ is
it so and If you do not understand ‘why’
Documenting the program
something was programmed the way it
appears. It is the process that provides materials

LY
that support the design, development and
testing of the program. Documentation
Coding the program
can involve testing of source codes,
This step is meant to express the algorithm

N
comments within source codes and
into the format that the computer can user manuals. This process should be
understand through programming

O
ongoing throughout the problem solving
languages. The algorithm will be translated phase.
into the programming language such as
C++, Java, and Python.

Testing and debugging


SE
Problem solving techniques in systems
development
There are several problem solving
U
Computer programs written in the first techniques. Examples of these techniques
place may have some imperfection and include flow charts and cause-and-effect
some few errors. Through testing, you diagrams.
E

can check if they work as desired, and if


they meet the user requirements. There Flow charts diagrams (Process
N

are some standardised methods for flowchart)


testing such as unit (component) testing, A flowchart is a picture of separate steps
LI

integration testing, system testing, and of a process in chronological order.


acceptance testing. Testing is done to This is a standard process analysis tool
N

ensure the program generates correct that can be used for different purposes,
outputs for all possible inputs. The process and can be used to describe various
O

of debugging involves correcting errors processes like systems development


and defects. process, manufacturing process or any
R

project plan. Flowchart technique has


The project manager may lead the been discussed in details in Chapter
FO

system development team to test the Three. In this section, we will discuss
program. He/she can also facilitate the other problem solving approaches, in
testing with other team members so as particular, cause-and-effect. Flowcharts
to minimize resistance for the success of can be drawn as high-level and detailed

358
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 358 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
level as shown in Figure 6.17 and 6.18.
Features that can be obtained in a flowchart include sequence of actions, materials or
services entering or leaving the process (inputs and outputs), decisions to be made,
people involved in system development project, time to be used for each step and
process measurements.

Situations that encourage the use of flow chart


(a) When developing understanding of how a process is done;

LY
(b) When there is a need to study a system development process in order to improve
it;
(c) When sharing with a team member on how a system development process is

N
done;
(d) When there is a need for communication between people involved in development

O
process like users, stakeholders, programmers, and system analysts;
(e) In documenting a system development process; and
(f) When planning a project. SE
Flowchart Examples
U
i. High level flowchart for order fulfillment process

Order Credit inventory


E

receipt check Production Shipment Billing


check
N

Figure 6. 17: Example of high level flow chart


LI
N
O
R
FO

359
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 359 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

ii. Detailed flowchart for order fulfillment process


Order
received

Enter order
in System

Credit check

LY
Is credit No Refuse
good? order
Yes
Check inventory

N
Is

O
product in No Check materials
inventory? needed

Yes Are No
materials in
inventory?

Yes
SE Order
materials

Schedule Vendor
Wait
U
production
Receive
materials
Schedule
shipment Wait
E

Inspect
materials
N

Confirn Yes Are No


delivery date materials
LI

with customer good?


Make product
N

Inspect product
O

Is
product
No good?
Yes
R

Ship product

Prepare bill
FO

Mail bill

Figure 6.18: Example of a detailed flow chart

360
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 360 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Developing Flowcharts
In creating flowcharts, several symbols are used. These symbols are shown in Table
3.1 of Chapter Three.

Activity 6.13

Create a flowchart for simple interest problem solving


Materials required: marker pens and flipchart or whiteboard
Procedure: Use the following steps to create your flowchart

LY
Step 1: Define the system process you need to diagram: ie. Calculation of Simple
interest
Step 2: Decide on the boundaries of your system process: where or when will

N
the process start? Where or when will it end? Decide the details you are
going to include in the diagram: Start at writing values of variables, ends

O
at writing final answer.

Write your Write down the


Input/Output:
answer SE values of P, R, T

Decision:
U
Is R and T in a Are you asked to
mixed number? find an amount?
E

Step 3: Write the activities that will take place in the process: writing formula,
changing fraction for time and rate, putting values in formula, multiplying
N

values, dividing values and writing ‘Amount’ formula.


LI

Write, Convert rate and Insert the values of


S.I = PRT time to improper P, R and T in the
N

100 fraction formula


O

Multiply the values Divide the Write an Amount


of PRT to get a numerator by the formula,
value of numerator denominator A = (S.I + P)
R

Step 4: Organise the activities sequentially


Step 5: When all activities are included and you are comfortable that the
FO

sequence is correct, draw arrows to show the direction of the process


(flow lines).
Result: The simple order processing system flowchart as shown in Figure 6.19

361
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 361 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Start

Write down the


values of P, R.

LY
Yes Is R and T in a No
mixed number?

N
Write, Convert rate and
PRT time to improper
S.I =

O
100 fraction

Insert the values of


P, R and T in the
formula
of PRT to get aSE
Multiply the values

value of numerator
U
Divede the
numerator by the
denominator
E

Yes
N

Are you asked to Write an Amount


find an arround? formula,
A=(S.I + P)
LI

No

Write your
N

answer
O

End
R

Figure 6.19: Example of a flow chart for solving simple interest


FO

Activity 6.14
Use the flowchart diagram to judge whether a student gets division one, or two or
three by taking student marks as input.

362
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 362 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Activity 6.15

Create a flowchart for order processing system


Use the Internet and library search to perform the following:
Step 1: Find out the staffs or corresponding departments involved in the process
or function, and list them on the page.
Step 2: List the steps in the process through brainstorming.
Step 3: Connect the steps with arrow according to their correct order.

LY
Step 4: Discuss to improve and perfect the flowchart.
Result: Present the completed flowchart

N
Cause-and-effect diagrams
Cause and effect (Fishbone) diagram is a problem-solving technique or tool used to

O
identify possible causes for a specific problem, by organising ideas into small useful
categories. Cause-and-effect (Fishbone) diagram example is shown in Figure 6.20.

Category 3 Category 2 Category 1


SE
Cause 2 Cause 2 Cause 2
U
Cause 1 Cause 1 Cause 1

Effect/problem
E

Cause 1 Cause 1 Cause 1


N

Cause 2 Cause 2 Cause 2

Category 4 Category 5 Category 6


LI

Figure 6.20: Example of cause-and-effect(Fishbone) diagram


N

Note: In the Fishborn diagram, there concerning long queues in banks,


are causes which are the main the typical main branches which are
O

objectives in the branches. These the causes, include management,


individual branches are assembled process, customer, and staff.
into different groups. For the
R

Situations that encourage the use of


manufacturing industry, some of the Fishbone diagram
FO

typical groups include machines, (a) When you want to identify the possible
methods, materials, measurements, causes for a particular problem.
environment, and people. For the (b) When a thinking of project team
Banking industry, for example, starts to sink.

363
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 363 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Fishbone basic procedure Developing a Cause-and-effect
Computer Science

(a) Agree on a problem statement (Fishbone) diagram


(effect). Write it at the center right
of the flipchart or whiteboard. Draw Activity 6.16
a box around it and draw a horizontal Create a fishbone diagram for long
arrow towards it. queues in banks
(b) Brainstorm the major groups of
Materials required: marker pens
causes of the problem. When this
and flipchart or
is hard to do, use common known

LY
whiteboard
headings like Environment, Methods,
Measurement, People (manpower), Procedure: Use the following steps
Materials, and Machines (equipment) to develop:

N
(c) Write the groups of causes in branches Step 1: Enter the problem statement
from the main arrow. in the box provided

O
(d) Brainstorm the causes of the problem Step 2: Brainstorm the major
stated by asking “Why does this categories of the problem.
Generic headings are provided
happen?” when ideas are given by
team members.
(e) Ask “Why does this happen?” to
SE
Step 3: Write the categories of causes
as branches from the main
every cause provided and generate arrow.
U
deeper levels of causes, then indicate The completed fishbone diagram is
causal relationships. shown in Figure 6.21.
E
N
LI
N
O
R
FO

Figure 6.21: Example of cause-and-effect(Fishbone) diagram for long queues in banks

364
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 364 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Information gathering methods (e) It is useful for identifying key issues
Information gathering methods include and searching for opinions.
the following:
Questionnaires
Interviewing
This method is used by analysts to
In gathering information through interview,
collect information related to system
systems analysts receive information from
from large number of users of a system.
stakeholders by interviewing them. The
success of an interview depends on the There are two types of questionnaires:

LY
skills of the analyst as an interviewer. (a) Open-ended Questionnaires – These
have questions that are easy to
This can be done in two ways: interpret. They can help to discover

N
(a) Unstructured Interview – this is done a problem and provide direction for
its solution.

O
by asking questions and receiving
(b) Closed-ended Questionnaires – These
answers from an organised session in
have questions that systems analyst
order to acquire basic information of prepare by providing options for
the system.
(b) Structured Interview − It has standard
SE responses.
Advantages of questionnaires
U
questions which are created in (a) They are very useful in identifying
advance and all users respond to the users’ interests, attitudes, feelings,
and beliefs about a particular system.
same questions in the same order
(b) They are suitable to recognise users
E

in either close (objective) or open of a system who are satisfied or not


(descriptive) format. satisfied with a particular feature of
N

the system.
(c) It is easily used to determine the
LI

Advantages of Interviewing
general opinion of the system and
(a) It is the best for collecting qualitative
provide direction.
N

information.
(d) Their reliability and confidentiality
(b) It is suitable for respondents who are high.
O

are weak in communicating through (e) They are appropriate for quantitative
writing or who have scarce time data collection.
in providing responses by filling
R

questionnaires. Document review of records, procedures,


(c) It is easy to validate information when and forms
FO

performing interview. System analysts can seek understanding


of a system capabilities and operations
(d) It is used to handle difficult themes
by passing through review of existing
or issues.
records, procedures, and forms.

365
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 365 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Advantages of document review of records, Advantages of JAD
Computer Science

procedures and forms (a) It saves time and cost that was to be
(a) It helps to understand how systems used for interviews and consultations.
operate before they are released. (b) It is useful in supporting team work.
(b) It helps in documenting operations (c) It promotes good relationships
of the systems for future reference. among employees.
(c) It is cheap to use because the researcher (d) It enhances creative development of
does not have to go physically to systems.
evaluate a system

LY
(d) It helps system analyst to understand Disadvantages of JAD
how the system operates. (a) It is difficult to achieve a goal when
(e) It describes the problem, areas that the team has differing opinions

N
have been affected and suggests
solutions. Survey

O
There are several advantages and
Observation
disadvantages of using survey as a tool
This is a method of gathering information
by seeing and observing. SE
for data collection

Advantages of Surveys
Advantages of observation method
(a) High representativeness
U
(a) It is a direct method where a system
analyst can observe directly to the Surveys provide a high level of
system or its users without asking general capability in representing a
large population. Due to the usual
E

from other people.


(b) It is used in environment where data huge number of people who answer
N

collected are in doubt of its validity. a survey, the data being gathered
(c) It produces more accurate and possess a better description of
LI

reliable data. the relative characteristics of the


(d) It does not require cooperation of general population involved in the
N

the respondent. study. As compared to other methods of


data gathering, surveys are able to
O

Joint Application Development (JAD) extract data that are near to the exact
It is a technique used to collect information attributes of the large population.
by engaging key members including
R

(b) Low costs


clients and end users of a system. JAD was
developed by IBM and it brings system When conducting surveys, you only
FO

owners, users, analysts, designers, and need to pay for the production of survey
developers together to define and design questionnaires. If you need a larger
the system by organising workshops. sample of the general population, you
can give small incentive in cash or kind.

366
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 366 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
On the contrary, other data gathering Types of Web-based Surveys
methods such as focus groups and
Computer Assisted Telephone
personal interviews require researchers
Interviews (CATI) – Phone surveys
to pay more.
(c) Convenient data gathering CATI methodology improved the
Surveys can be administered to the telephone interviewing process. It is a
participants through a variety of software that automatically supports
ways. The questionnaires can simply and leads the interviewer during data
be sent via e-mail or fax, or can be collection. Thus, they see questions on

LY
administered through the Internet. the screen followed by possible answers.
Nowadays, the online survey method
has been the most popular way of Advantages of web-based surveys
gathering data from target participants.

N
Apart from the convenience of data 1. High quality of collected data: it avoids
gathering, researchers can collect data any interviewer misinterpretation or

O
from people around the globe. incorrect question administering;
2. Time reduction: automatic callback
(d) Good statistical significance
Because of the high representativeness
brought about by the survey
method, it is often easier to
SE managed by the system. The interviewer
can also directly insert the data with
no use of paper;
find statistically significant results 3. Accuracy: being completely automated,
U
than other data gathering methods. there is no room for mistakes or unclear
Multiple variables can also be compiling;
effectively analysed using surveys. 4. Complete control on interviews
E

(e) Little or no observer subjectivity progress: you can check in real-time


completed, incomplete, and dropped
N

Surveys are ideal for scientific


research studies because they interviews.
LI

provide all the participants with


a standardised stimulus. With Computer Assisted Web Interviewing
such high reliability obtained, the
N

(CAWI) – Online surveys


researcher’s own biases are eliminated. It is said that the web revolution
O

(f) Precise results has been crucial to market research


As questions in the survey evolution. This is particularly true for the
should undergo careful scrutiny CAWI methodology.
R

and standardisation, they


provide uniform definitions to all Back in the days, with online surveys,
FO

the subjects who are to answer you could reach just around 20% of the
the questionnaires. Thus, there
population. So, it had limited purposes.
is a greater precision in terms of
Today, you reach a wide and generic
measuring the data gathered.

367
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 367 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
population such as the entire country Observations on CATI, CAWI, and
Computer Science

or a multinational corporation. A link is CAPI Surveys


sent to the respondents via email. They The CATI, CAWI, and CAPI Surveys
just follow the link to complete the have been compared. The following are
questionnaire. some of the comparisons.

The main characteristics of the CAWI CAWI methodology has several advantages,
method are: but it requires all respondents to have
1. The software autonomously sends an email account and a basic knowledge

LY
the emails and takes care of their of computers to correctly complete the
following classification. Finished questionnaire.
questionnaires are marked as

N
complete. CAPI methodology’s biggest quality is the
real face to face interaction between the
2. The respondent receives an invitation

O
respondent and interviewer. In contrast,
via email and clicks on the link to
the average number of completed
answer the questionnaire.
interviews in a working day is usually
You need to have all the email addresses
of your respondents to carry on a CAWI
SE
lower than CATI.

CATI methodology guarantees the benefits


survey. over the other two techniques above.
U
Specifically, CATI has a heterogeneous
Computer Assisted Personal Interview target and the call agent that can help the
(CAPI) – Offline personal surveys respondent during the interview. However
E

CAPI method is the technological CATI is still the most expensive method
evolution of face to face research. An because of higher costs linked to the call
N

interviewer collects the data in a face to center, the interviewers, and phone traffic.
face meeting with the respondent.
LI

Using a mobile device or PC even Exercise 6.5


N

offline, the interviewer carries on the


Answer the following questions.
interview and sends back the answers in
O

real-time. Data are immediately sent to 1. Discuss whether analysis, in the


the main server. sense discussed in this chapter,
should be performed for the
R

The face-to-face interview is often part following tasks:


of the Mystery Client research. Mystery (a) The construction of a new
FO

clients can discreetly complete their Fortran compiler for a new


tasks on their smartphone or mobile
machine with a new instruction
device.
repertoire.

368
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 368 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
(b) The planning for your next
4. Draw and briefly explain six
vacation.
symbols commonly used in a
(c) The repair of faulty software. flowchart.
(d) The acquisition of your next
5. Identify the advantages of using
car.
flowcharts.
(e) The remodelling of your
6. A telephone company has launched
kitchen.
a promotion for its airtime and
(f) The decision to get married. network bundles to its customers.

LY
(g) The reimplementation of an According to the promotion,
airline reservation system to the customers will receive a gift
exploit five supercomputers. voucher worth Tzs 500,000/= of

N
(h) A comparative study of monthly bundle expenditure if
systems analysis methods. they spend Tshs 1,500,000/= more

O
than their last month spending and
2. Analysis is a popular notion.
their last month expenditure is not
Mathematics, philosophy,
less than Tzs 1,000,000/=. Draw
psychiatry, and chemistry all have
a claim on this concept. Is there
any commonality between these
SE a flowchart showing the above
process.
notions and the notion of analysis
U
developed in this chapter?
3. Do you expect the following items System design
to be addressed during systems Concept of system design
E

analysis? The purpose of the system design phase


(a) Maintainability.
N

is to create a physical model that will


(b) Quality. satisfy all documented requirements
LI

(c) The development costs of the for the system. At this stage, you
target system. design the user interface and identify
N

(d) The execution costs of the necessary outputs, inputs and processes.
target system. In addition, you design internal and
O

(e) The programming language(s) external controls including computer-


to be used. based and manual features to guarantee
(f) The reusability of existing that the system will be reliable, accurate,
R

maintainable and secure. During the


system components.
system design phase, you also determine
FO

(g) The architecture of the


the application architecture which
implementation. programmers will use to transform the
(h) The relevance of existing logic design into program modules and
frameworks. codes. The deliverable of this phase is

369
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 369 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
the system design specification which is focuses on supporting the interactions
Computer Science

presented to management and users for between end users and their computer-
review and approval. Management and based applications. The following
users involvement is critical to avoid are the main things to be taken into
any misunderstanding about what the consideration by the interface designers:
new system will do, how it will do it, (a) Designing attractive and efficient
and how much it will cost. forms of user input and output such
as easy-to-use Internet or intranet
While the system analysis phase seeks web pages.

LY
to describe what a system should do (b) Designing methods of converting
to meet the users requirements, the human-readable documents to
system design phase stipulates how the

N
machine-readable input such as
system will accomplish the specified optical scanning of business forms.

O
objective. The designing phase provides
the technical specification to be used to It is important to design a user interface
create the system. Three things which are that is easy to use, attractive, and
insisted in system design phase include
activities on designing the user interface,
SE
efficient. When you create a user
interface, you should follow eight basic
data design, and process design. guidelines, namely design a transparent
U
interface, create an interface that is
User interface design: easy to learn and use, enhance user
User interface design is the first task productivity, make it easy for users to
E

in systems design phase of the SDLC. obtain help or correct errors, minimise
Designing the interface is extremely input data problems, provide feedback
N

important because everyone wants a to users, create an attractive layout, and


use familiar terms and images.
LI

system that is easy to learn and use.


A user interface describes how users
User interface design is frequently a
N

interact with a computer system and


consists of all the screens, menus, prototyping process where working
O

functions, output and features that affect models or prototypes of user interface
two-way communications between the methods are designed and modified with
user and the computer. User interface feedback from end users. User interface
R

design (UI design) refers to the process design produces detailed specifications
of designing various types of software for information products such as display
FO

and hardware interfaces through which screens, interactive user/computer


users interact with computers and other dialogues, audio responses, forms,
technologies. User interface design documents and reports.

370
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 370 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Importance of system design Top-down strategy
The importance includes: This is a design strategy that focuses
(a) It helps to identify data source, its on dividing the system into subsystems
nature and the type of data which is and component first. This design
obtained in the system. For example conceptualises the whole system
in salary system designing, inputs first and breaks it down into various
like attendance, leave details, subsystems. Smaller systems are
deductions may be used. treated to components that satisfy to the
(b) It helps to confirm that the system requirement of the larger system.

LY
is developed in order to satisfy the
needs of the user. Approaches for system design
The following are approaches for system
(c) It is useful to ensure the system

N
designing:
created is dynamic and will be
(a) Structured design: this is a dataflow

O
responding to the requirement
based methodology that helps in
changes.
identifying inputs and outputs of
(d) It helps to ensure the system designed the developed system.
can work and provide the required
output as stated in system and user
requirement specification.
SE
(b) Function-oriented design: this is a
method to software design where the
model is decomposed into a set of
U
(e) It enables to confirm that security intersecting units or modules where
measures of the system are fully each unit or module has clearly
adhered to. defined functions.
E

(c) Object-oriented design: this is a


Strategies for software design process of using object-oriented
N

There are two main strategies for system methodology to design a computing
design. These are bottom-up strategy system or application
LI

and top-down strategy:


Types of system design
N

Bottom-up strategy There are several types of system design.


This is a design that intends to design The following are the most commonly
O

the subsystem and the lowest level known types of system design:
components or sub components. The
R

higher level subsystems and larger Logical design


components are assumed to be constructed Logical design relates to an abstract
FO

easily and more efficiently after the lowest representation of the data flow, inputs,
level is built. and outputs of the system. It describes the
Advantage: it allow less time to be inputs (sources), outputs (destinations),
wasted when doing troubleshooting. databases (data stores), procedures (data

371
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 371 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
flows) all in a format that meets the user architecture. It describes the structure
Computer Science

requirements. and behaviour of the system. It defines


the structure and relationship between
In making the logical design of a system, various modules of system development
the system analyst specifies the user process.
needs at the level of detail that virtually
determines the information flow into Detailed design
and out of the system and the required It follows Architectural design and
data sources. Data flow diagram and, focuses on development of each module.

LY
E-R diagram modelling are used.
Conceptual data modeling design
Physical design It is a representation of organisational

N
Physical design relates to the actual data which includes all the major entities
input and output processes of the and relationships. System analysts

O
system. It focuses on how data is entered develop a conceptual data model for the
into a system, verified, processed, and current system that support the scope and
displayed as output. requirements for the proposed system.

It produces the working system by


SE
The main aim of conceptual data
defining the design specification that modeling is to capture as much meaning
U
specifies exactly what the candidate of data as possible. Most organisations
system does. It is concerned with user today use conceptual data modeling
interface design, process design, and using Entity Relatishiop (E-R) model
data design.
E

which uses special notation to represent


as much meaning about data as possible.
N

It consists of the following steps:


(a) Specifying the input or output media,
Entity relationship model design
LI

designing the database, and backup


This is a technique used in database design
procedures.
that helps to describe the relationship
N

(b) Planning system implementation.


between various entities of an organisation.
(c) Devising a test and implementation
O

plan, and specifying any new Systems design process


hardware and software. The system design processes are
(d) Updating costs, benefits, conversion
R

interdependent, highly iterative and


dates, and system constraints. recursive processes resulting in a certified
FO

set of systems, user requirements and a


Architectural design design solution that satisfies stakeholders’
This is also known as high level design expectations. There are four system design
that focuses on the design of system processes or steps in designing process:

372
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 372 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
developing stakeholder expectations, and projects to meet the stakeholder
technical requirements, logical expectations. This process identifies the
decompositions, and design solutions. “what” that should be achieved by the
system at each level to enable a successful
Stakeholder expectation definition project. Logical decomposition uses
The stakeholder expectations definition functional analysis to build a system
process is the preliminary process that architecture and to decompose top-level
form the base from which the system requirements and allocate them down to
is designed and the product is realized. the lowest desired levels of the project.

LY
This process intends to identify who the
stakeholders are and how they intend The logical decomposition process
to use the product. This process is done has two tasks, the first is to improve

N
understanding of the defined technical
with the help of use-case.
requirements and the relationships

O
among the requirements (e.g., functional,
Technical requirements definition
performance, behavioural, and temporal).
The technical requirements definition The second task is to decompose the
process changes the stakeholder
expectations into a statement of the
problem and into a complete set of
SE
parent requirements into a set of logical
decomposition models and their associated
sets of derived technical requirements for
certified technical requirements expressed.
U
input to the design solution definition
The process of requirements definition is process.
also recursive and iterative, it is used to
develop the stakeholders’ requirements, Design solution definition
E

system requirements, and lower level


The design solution definition process
system or component requirements. The
N

is used to translate the high-level


requirements explains the description of all
requirements resulting from the
inputs, outputs, and required relationships
LI

stakeholder expectations and the outputs


between inputs and outputs, including
of the logical decomposition process into
constraints, and system interactions with
N

a design solution. This involves changing


operators, maintainers, and other systems.
the defined logical decomposition models
The requirements documents organize
O

and their associated sets of derived


and communicate requirements to the
technical requirements into alternative
customer and other stakeholders and the
solutions. These alternative solutions
technical community.
R

are then analysed through detailed trade


studies that result in the selection of a
Logical decomposition
FO

preferred alternative. This preferred


Logical decomposition is the process alternative is then fully defined into a final
for creating the detailed functional design solution that satisfies the technical
requirements that enable systems requirements.

373
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 373 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
This design solution definition is used to
Computer Science

(d) Coding is not a step in system


generate the end product specifications
development life cycle.
that are used to produce the product and to
conduct product verification. This process (e) System analysis and system
may be further refined depending on design are the same phase of
whether there are additional subsystems system development life cycle.
of the end product that need to be defined 2. Discuss the importance of
or not. system analysis and design in the
development of a system.

LY
System design tools
3. Differentiate between system
There are several design tools used in analysis and system design.
systems designing. System designing
4. Define systems analyst and list

N
tools play important roles in system
duties of systems analyst.
development. The commonly known tools
5. Define systems design.

O
are system flow chart, Data flow Diagram
(DFD), Entity-Relation Diagram, Context 6. What systems analysis is not for?
Diagram, Decision Table, Decision Tree,
Unified Modelling Language (UML) and
Use Case.
SE
Data Flow Diagram
Data Flow Diagram (DFD) is a tool
Exercise 6.6 that describes the flow of data through a
U
system and processes done by it. DFD
Answer the following questions. shows a flow of data from external
entities into the system. It encompasses
1. Write True or False for the following
E

data inputs and data outputs, as well


statements.
as data storage and processing. The
N

(a) A collection of components DFD depicts the flow of data through


that work together to realize an information system, but it does not
LI

some objectives forms a depict program logic or processing


system. steps. It gives a logical model that
N

(b) System life cycle is not an demonstrates what the system does but
organisational process of not how it accomplishes it.
O

developing and maintaining a


system. DFD symbols
To describe processes, data flows, data
R

(c) In the system analysis and stores, and entities, DFDs use four basic
design terminology the system symbols from Gane and Sarson and
FO

development life cycle means Yourdon and Coad. Their symbols differ
software development life somewhat, but the underlying concept is
cycle. the same as shown in Figure 6.22.

374
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 374 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Gane and Sarson Yourdon and Coad understood, but the underlying details
1.0 1.0
and logic are hidden.
Process Process
Data flow symbol
Data store Data store A data flow is a way for moving data
External External
from one part of an information system to
Entity Entity another. In a DFD, a data flow represents
one or more data items. A data flow, for
Data Flow Data Flow
example, could be made up of a single

LY
data item, such as a Registration number,
Figure 6.22: DFDs basic symbols
or it could be made up of a collection
of data, such as class attendance with
Process symbol

N
student Registration numbers, names,
A process takes in data and outputs data and registration dates for specific

O
with different contents or form, or both. courses. Despite the fact that the DFD
To calculate overtime compensation, for does not provide the detailed contents of
example, two inputs (additional hours a data flow, the data dictionary does. A
worked and pay rate) are combined
to yield total pay. Processes can range
SE
data flow is represented by a line with a
single or double arrowhead. The name
from simple to complicated. Processes of the data flow appears above, below, or
U
in an organization include calculating beside the line. A data flow name is made
pay, calculating sales, procuring goods up of a singular noun and, if necessary,
from vendors, and so on. Business an adjective. SALARY PAYMENT and
CASH FLOW are examples of data flow
E

logic, also known as business rules, are


contained in processes and transforms names.
N

data to generate the desired results. A


process is represented by a rectangle Data store symbol
LI

with rounded corners. The process In a DFD, a data store is used to represent
name shows inside the rectangle. A data that the system stores because one
N

verb (and, if necessary, an adjective) or more processes may need to use it


is followed by a singular noun in the later. Instructors, for example, must save
O

process name, which indicates a distinct student scores on tests and assignments
function. ASSIGN COURSEWORK, throughout the semester in order to issue
final grades at the end of the semester.
R

CALCULATE GRADE, and CHECK


PAYMENT FILL ORDER are some A DFD does not show the contents of
FO

examples of process names. A process a data store in detail. Because you are
symbol is characterized as a black box only interested in a logical model, the
in DFDs because the inputs, outputs, physical qualities of a data store are
and overall functions of the process are irrelevant. Furthermore, the amount

375
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 375 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
of time data is stored is unimportant. system. Because they are data origins or
Computer Science

What matters is that a procedure needs final destinations, DFD entities are also
data access at some point in the future. known as terminators.
A flat rectangle with an open right side
and a closed left side is the symbol for a Physical and logical data flow
data store. The data store name appears diagrams
between the lines, and it is used to The focus of logical data flow diagrams
identify the data it holds. A data storage is on what happens in a specific
name is a plural name that includes a information flow: what information is

LY
transmitted, what entities receive that
noun and, if necessary, adjectives, such
information, what general processes
as PRODUCTS AND PATIENTS.
take place, and so on. A logical DFD

N
describes business operations rather than
Entity symbol
the technical components of a process or

O
An entity symbol is a rectangle that can system.
be coloured to make it appear three-
dimensional. The entity’s name appears Physical data flow diagrams, shown
inside the symbol. Only external entities
that contribute data to or receive output
from the system are shown in a DFD. A
SE
in Figure 6.23, are used to show how
events occur in a data flow. The software,
hardware, data, and people involved in
DFD depicts the system limits and how
U
an information flow are all depicted in
it interacts with the outside world. A these diagrams. The development of
customer entity or a patient entity puts the code required to implement a data
an order with an order processing system system can be aided by a thorough
E

or contributes data to a medical record physical data flow diagram.


N

Physical DFD
LI

Daily mail 1.1.1 1.1.2 1.1.3 Register


delivery Open mail Opened mail Retrieve mail Mail orders Register mail mail orders
N

orders orders
O

Logical DFD
R

1.1.1 Received
Customer order
Record customer customer order
FO

order

Figure 6.23: Physical Dataflow Diagram

376
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 376 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Data Flow Diagram levels its connections to external entities are
Levels are often used to categorise depicted in Level 0 data flow diagram,
data flow diagrams. DFDs become as shown in Figure 6.24.
progressively complex as the level
Consider the hospital management
increases, starting with the most basic,
system: to begin, let us define level 0
level 0, 1 and 2. You will need to decide
of the Hospital Management System.
which level your data flow diagram will
The DFD level 0 hospital management
be as you construct it. system is also known as the context

LY
diagram. The mechanism is designed
Level 0 DFDs to be depicted as a single process with
The most basic data flow diagrams are external partners in an abstract view. The

N
also known as context diagrams. They overall structure should be represented
give a broad overview that is easy to by a single bubble in the system. It has

O
understand, but they do not go into indicators for incoming and outgoing
great details. A single process node and data as well as input and output data.

Modified Patient Details

Patient Information
SE Diagnosis
information
U
Hospital
Administrator
0.0
Patient Patient
E

Hospital
Management Info
System
N

Employee/
Doctor
LI

Patient Diagnosis Bill


Information
N

List of Patients
O

Figure 6.24: Context diagram for hospital management system

The general process of hospital management is depicted in this data flow diagram.
R

It informs readers and programmers about the system primary users as well as
FO

the primary data that will be put into it. As you can see, as you progress through
the tiers of data flow diagrams, the connections between transactions and data get
increasingly broad and specific.

377
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 377 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Level 1 DFD DFD level 1 is broken down into sub
Computer Science

Level 1 DFDs provide a broad overview, processes, and it must be a single


but they go into greater depth than a process node from the context diagram.
context diagram. The single process The system must display or reveal
node from the context diagram is broken additional processing information at this
down into sub processes in a level 1 data level. Patients, hospital administrators,
flow diagram. Additional data flows and healthcare providers are among the
and data stores will be required as these actors who will use this system.
processes are added to the diagram as

LY
shown in Figure 6.25. Level 1 of the DFD broadens the context
terms. Furthermore, this may act as a
The level 1 data flow diagram is located reference for how the system inputs or

N
next to the context diagram. The context data are fed. The system outputs will
of the hospital management system then be communicated to you as well.

O
1.1
Patient Information
Patient Diagnosis
Bill Information
Manage
Patient
SE Patient
Information
Patient Diagnosis
U
Facilities
Information
1.2
E

Assign
Room/Facility
Patient Diagnosis
N

Patient
LI

Assignmed 1.3
Medicine
Facilities Employee/
Info
N

Patient Diagnosis Assign Doctor


Medicine
Medicine Information
O

Employee Information

1.4
R

List of Patient
Manage Employee/
FO

Doctors Assigned Department

Figure 6.25: DFD Level 1 for hospital management system

378
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 378 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Level 2 DFD
Exercise 6.7
Processes are simply broken out
into more specific sub - processes Answer all the questions.
in Level 2 DFD. DFDs may
1. Describe the Gane and Sarson symbols
theoretically go beyond level 3
used for processes, data flows, data store
although they rarely do. Level 2
and entities. Give four examples of typical
data flow diagrams are frequently names for processes, data flows, data stores
so detailed that further breaking and entities.

LY
them down is not necessary.
2. What is the relationship between a context
diagram and level 1 diagram?
The system level 2 DFD should
3. Explain DFD leveling technique.
show the basic modules as well

N
as data flow between them. 4. Draw a context diagram and level 1 DFD
that represents the registration system at

O
Because DFD level 2 is the
highest abstraction level, the your school or imaginary school.
hospital management system 5. What is the importance of DFD in systems
operations that are based on DFD
level 1 must be comprehensive.
SE
development?
6. Differentiate between logical and physical
DFD.
Guidelines for Drawing DFDs
U
7. Select any example of the system in your
(a) Construct the context context and draw its DFD that represents
diagram so that it fits on a how it works.
single page.
E

(b) In the context diagram, use


N

the name of the information System Implementation


system as the process name.
Meaning
LI

for example registration


system, The system implementation phase involves
N

(c) Give each collection of hardware and software acquisition, site


symbols a distinct name. preparation, user training and installation of the
O

system. System implementation in IT, usually


(d) Avoid crossing lines.
starts with negotiating a contract with a vendor.
Limiting the number of
In this contract, the guidelines, deadlines
symbols in any DFD is one
R

and a payment schedule for the complete


technique to attain that goal.
implementation process are negotiated.
FO

(e) Give each process a distinct Contract requirements may include. among
name and reference number. other things, the plan of system performance
(f) Obtain as much user feedback criteria, penalties due to issues and delays in
and input as possible. the implementation process, documentation,

379
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 379 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
training and issue related to vendor Because the IT department has to
Computer Science

support in case of system failures or manage and maintain only one system at
needs of updates. a time, direct cutover is usually the least
expensive way of changeover. Direct
System implementation process cutover, is however riskier than other
types of changeover. Regardless of how
Activities for making a new system
thoroughly and meticulously you test
operational includes: data conversion and
and train, some issues may surface once
porting; deployment strategy; installation the system is put into action.

LY
and configuration; and training.
(b) Parallel operations
Data conversion and porting
The concurrent operation necessitates

N
The conversion of data is a crucial step in that both the old and new information
system installation procedure. Existing systems be fully operational for a set

O
data is loaded into the new system length of time. Data is sent into both
during data conversion. Data conversion systems, and the output of the new
might take place before, during, or after system is compared to the old system’s
the operational environment is complete
depending on the system. You should
SE
corresponding output. The old system
is terminated once users, management,
create a data conversion plan as soon and the IT group are satisfied that the
U
as possible, and you should test the new system is working properly.
conversion process as soon as the test
environment is ready. The most obvious benefit of parallel
E

operation is that it reduces risk. If the


Deployment strategy new system fails, the company can fall
N

Deployment is the process of putting back on the old system as a backup


the new information system online and until the necessary improvements are
LI

retiring the old system. Deployment completed. Because the output from
can be rapid or slow depending on the both systems is compared and validated,
N

method. The four deployment methods it is considerably easier to verify that


the new system is running properly
O

are direct cutover, parallel operation,


pilot operation, and phased operation. under parallel operation than straight
cutover. Parallel operation, on the other
R

(a) Direct cutover hand, has several drawbacks. It is the


When the new system is operational, most expensive deployment strategy
FO

the direct cutover strategy causes the because both the old and new systems
deployment from the old system to the are fully operational at the same time,
new system to happen immediately. the corporation pays for both systems at
the same time.

380
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 380 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
(c) Pilot Operations and parallel operation. However, with
The pilot operation method requires phased operation, you supply a portion
installing the entire new system at a of the system to all users, but with pilot
single firm location. A new sales reporting operation, you provide the full system
system, for example, might be installed in to only a few users. A staged approach
only one branch office, or a new payroll offers the advantage of minimizing
system in just one department. In these the risk of errors or failures to the
cases, the group that is the first to adopt the implemented module. For example, if
new technology is referred to as the pilot a new production control subsystem

LY
site. During the pilot, the previous system fails, the failure may not affect the new
is still in use throughout the organisation purchasing subsystem or any other
including at the pilot site. After the system subsystem. Because you only have to

N
has proven to be successful at the pilot operate with one section of the system
location, it is typically implemented at a time, phased operation is less

O
across the remainder of the business expensive than full parallel operation.
via direct cutover. As a result, pilot A phased approach is impossible if the
operation is a hybrid of parallel and direct
cutover approaches. When opposed to
a direct cutover strategy, limiting the
SE
system cannot be simply divided into
logical modules or segments.

implementation to a pilot site reduces Training


U
the danger of system failure. It is less Whether it is software, hardware, or
expensive to run both systems for manufacturing, no system can succeed
only the pilot site than it is to run both without effective training. Users,
E

simultaneously in the whole organization. managers, and IT staff members all need
to be trained in order for an information
N

(d) Phased operations


system to be successful. People’s
You can implement the new system in
LI

understanding of the system and ability


stages or modules using the phased
to use it successfully can make or break
operation deployment approach. Instead
N

the overall system development project.


of adopting a new manufacturing system
Multimedia is a powerful training tool. You
all at once, you might install the materials
O

management subsystem first, then the can create training sessions that include
production control subsystem, and so slides, animation, and sound susing
presentation software like Microsoft
R

on. Any of the other three changeover


methods can be used to implement each PowerPoint, OpenOffice Impress, or Corel
FO

subsystem. Phased and pilot operation Presentations. You can also utilise tools
strategies are commonly confused by that record actual keystrokes and mouse
analysts. To reduce risks and expenses, movements and then replay the screens
both systems incorporate direct cutover for users to see. The following guidelines

381
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 381 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
should be kept in mind when creating a
Computer Science

(b) Educating users or consumers on


training program: the use of the new system.
(a) Group training using unique training
(c) Ownership changing to the
regimens for different groups;
organisation concerned.
(b) Determine the most effective location
for the training;
System testing
(c) Provide opportunities for students to
learn by hearing, seeing, and doing; System testing is a process of executing
and a system in order to find out if it contains

LY
(d) Draw on the experience of prior errors. System testing can include codes
trainees. inspection and execution of codes in
different conditions and environments.
Exercise 6.8

N
The process for testing a system
Answer the following questions. The following are the steps which are

O
1. Who needs to be trained before a involved during system or program
new information system is put in testing as indicated in Figure 6.26:
place?
2. Describe the four methodologies
SE
(a) Create a Test Plan.
(b) Create system test cases and test
scripts.
for system development. Which one
(c) Prepare the test data required for
U
is the most expensive in general?
this testing.
Which is the most dangerous?
(d) Execute the system test cases and
Explain your response.
script.
E

(e) Report the bugs. Re-testing the bugs


once fixed.
N

Importance of system implementation (f) Regression testing to verify the


System implementation is very important impact of the change in the code.
LI

in system development as follows: (g) Repetition of the testing cycle until


(a) Making the new system available the system is ready to be deployed.
N

to a prepared set of users. (h) Sign off from the testing team.
O

Create test Create test Create test Execution of


plan cases data test cases
R
FO

Sign off Retesting Regression Bug reporting

Figure 6.26: Process for testing a system

382
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 382 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
Types of system testing interact with the system. It is important
(i) Unit testing or component testing that prepared document must be updated
on regular basis for the right use of the
In this test, each component is tested
system.
independently. Components of the
system may be functions.
After the implementation of system,
if the system is working improperly,
(ii) Integration testing
documentation helps the administrator
In this test, two or more components, and other users to understand the flow

LY
units or modules that depend on each of data in the system; correct the flaws
other are tested. and get the system working.

(iii) System testing

N
Programmers or systems analysts
After completing integration testing, you usually create programs and system

O
perform system testing which involves documentation. Systems analysts
the entire system. In this test, the full are usually responsible for preparing
system which has been developed is documentation to help users learn the
going to be tested. The importance of
this test is to check if there are some
properties evolving after the system.
SE
system. In large organisations, a technical
support team that includes technical
writers might assist in the preparation of
U
user documentation and training materials.
(iv) Acceptance testing
In this test, the data from clients are used Advantages
to check if the system meets the users’ (a) It can reduce system downtime, cut
E

requirements.
costs, and speed up maintenance
N

tasks.
Activity 6.17
(b) It provides a clear description of
LI

Testing a program formal flow of present system and


helps to understand the type of
N

Take an example of any system or input data and how the output can
program developed in C++ subject or be produced.
O

any other, test it step-by-step from unit


(c) It provides effective and efficient
to acceptance test
way of communication between
technical and nontechnical users
R

System documentation about system.


System documentation is a process
FO

(d) It facilitates new user’s easy


of recording the information for any understand of the flow of system.
reference or operational purpose. It helps
(e) It helps the users to solve problems
users, managers, and IT staff who use or
such as troubleshooting and helps

383
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 383 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
the manager to take better final programmer, and system
Computer Science

decisions of the organisation system. identification.


(f) It provides better control of the (b) Scheduling information for printed
internal and external working of the output such as report, execution
system. frequency, and deadlines.
(c) Input files, their source, output files,
Types of documentation and their destinations.
(d) E-mail and report distribution lists.
When it comes to system documentation,
(e) Special forms required, including

LY
there are following four main
online forms.
documentation:
(f) Error and informational messages
(a) Program documentation
to operators and restart procedures.

N
(b) Operations documentation (g) Special instructions, such as security
(c) User documentation requirements.

O
(d) System documentation
User documentation
Program documentation
(a) It describes inputs, outputs, and
processing logic for all the program
SE
This includes instructions and information
to users who will interact with the system.
Such as user manuals, help guides, and
modules. tutorials. User documentation is valuable
U
(b) The program documentation process in training users and for reference purpose.
starts in the system analysis phase and It must be clear, understandable, and
continues during implementation. readily accessible to users at all levels.
E

(c) This documentation guides


programmers who construct The users, system owners, analysts, and
N

modules that are well supported by programmers, all put combined efforts
LI

internal and external comments and to develop a user’s guide.


descriptions that can be understood
and maintained easily.
N

A user documentation should include:


(a) A system overview that clearly
O

Operations documentation describes all major system features,


Operations documentation contains all capabilities, and limitations.
the information needed for processing (b) Description of source document
R

and distributing online and printed output. content, preparation, processing,


Operations documentation should be clear, and samples.
FO

concise, and available online if possible. (c) Overview of menu and data entry
It includes the following information: screen options, contents, and
(a) Program, systems analyst, processing instructions.

384
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 384 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
(d) Examples of reports that are produced screen layouts, source documents,
regularly or available at the user’s and the systems request that initiated
request, including samples. the project.
(e) Security and audit trail information. (d) Most of the system documentation is
(f) Explanation of responsibility for prepared during the system analysis
specific input, output, or processing and system design phases.
requirements. (e) During systems implementation,
(g) Procedures for requesting changes an analyst must review system
and reporting problems. documentation to verify that it is

LY
(h) Examples of exceptions and error complete, accurate, and up-to-date,
situations. and including any changes made
during the implementation process.

N
(i) Frequently asked questions (FAQs).
(j) Explanation of how to get help and

O
procedures for updating the user Importance of system
manual. documentation
The following are some importance of
System documentation
System documentation serves as
SE
system documentation.
(a) As a single source of truth it saves
the technical specifications for the time and energy
U
Information System (IS) and how the (b) Documentation is essential to quality
objectives of the IS are accomplished. and process control
Users, managers and IS owners never (c) Documentation cuts down
E

need reference system documentation. duplicative work


System documentation provides the
(d) It makes hiring and onboarding so
N

basis for understanding the technical


much easier
aspects of the IS when modifications are
LI

made. (e) A single source of truth makes


(a) It describes each program within the everyone smarter
N

IS and the entire IS itself.


(b) It describes the system’s functions, System documentation process
O

the way they are implemented, The following are various steps involved
each program’s purpose within the in the system documentation process:
entire IS with respect to the order of
R

execution, information passed to and Collection of source material: The


from programs, and overall system very first step of any documentation
FO

flow. process is to acquire the required


(c) It includes data dictionary entries, source material for preparation of
data flow diagrams, object models, document. The material is collected

385
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 385 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
including specifications, formats, screen the latest document is available to the
Computer Science

layouts and report layouts. A copy of user of the software.


the operational software is helpful for
preparing the documentation for user. Activity 6.18

Documentation plan: The documenter Using an internet search or other


is responsible for preparation of a means, get an example of a system.
documentation plan, which specifies the Find out and describe all types of
details of the work to be carried out to system documentation it has. What

LY
prepare the document. can be improved?
Review of plan: The plan as set out in
the process above is reviewed to see

N
that material acquired is correct and In the field of computer science, especially
complete. the programming part, you will always

O
be required to practice on how to write
Creation of document: The document programs. You will be required to
is prepared with the help of document understand all the steps to write programs
generator. Testing of document: The
document created is tested for usability
as required by the target audience.
SE
to ensure that you do not produce the
final incorrect output. The following are
some examples in real life programming
U
Maintain document: Once the document environments in system development that
is created and distributed, it must be adhere to programming process steps.
kept up to date with new version of the Let’s see how these steps work with
specific examples.
E

software product. It must be ensured that


N

Program Example 41:


LI

Developing a program that converts measurement


You are the receiving prefect on duty at the electronic laboratory of your school
N

which receives large quantity of wire and cable produced from Mwanambilimbi
Cable Industry Co. Ltd at Mwenge Dar es Salaam for practical purposes. Most of
O

the wire you receive is measured in meters. However, the students using laboratory
require wire measurements to be in feet. Your laboratory supervisor wants you to
R

compute the length in feet of each roll of wire or cable that you stock. Write a
program to perform this conversion.
FO

Step 1: Defining and analyzing the problem.


The problem is defined in the above scenario that you receive wire measured in
meters. You are required to convert from ‘meters’ to ‘feet’ system of measurement.

386
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 386 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
The input in defined problem is wire length in meters. The output to the defined
problem will be equivalent amount wire length in feet. Next: Understand
relationship between meters and feet, thus, one meter equals 39.37 inches and one
foot equals 12 inches. Lastly, summarise the findings as follows:

Table 6.1: Problem definition requirements

Information required Description


Inputs: Wire length in meters (wmeters)

LY
Outputs: Wire length in feet (wfeet)
Other variable: Wire length in inches (winchs)

N
Relevant formula or relations: 1 meter = 39.37 inches
1 foot = 12 inches

O
Step 2: Designing or planning the solution

SE
In this step, formulate the algorithm to solve the problem. Therefore, your program
will need to read wire length in meters, convert wire from meters to feet and
display the wire length in feet. Your algorithm, will look like this:
U
Step 2.1. Read the wire length in meters
Step 2.2. Convert the wire length from meters to feet
E

(a) Convert the wire length from meters to inches


(b) Convert the wire length from inches to feet.
N

Step 2.3. Display the wire length in feet.


LI

This algorithm can be represented in pseudocode and flowchart (Figure 6.27)


as follows:
N

START
O

READ wmeters
CONVERT winchs
R

DISPLAY wfeet
COMPUTE: winchs =wmeters*39.37
FO

COMPUTE: wfeet=winchs/12
PRINT wfeet
END

387
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 387 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Start

Read length in meter

Convert into inch

Display into feet

LY
Compute
Meter-to- inch-to-feet

N
Print feet

O
End

Step 3: Coding
SE
Figure 6.27: Flow chart to convert measurement

This step require you to write the codes of this program. The following is an
U
example of codes in C++ programming language:

#include<iostream>
using namespace std;
E

/*
N

Converts wire length from meters to feet.


The user enters the wire length in meters.
*/
LI

float convert(float wmeter)


{
N

// Helper variables
float inchmt = 39.37;
O

float inchft = 12;


float wfeet=0;
float winchs=0;
R

// Convert the wire length from meters to feet


winchs = wmeter * inchmt;
FO

wfeet = winchs / inchft;


// Return the wire length in feet
return wfeet;
}

388
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 388 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
int main()
{
float inputmeter;
cout<< “enter wire length in meters”<<endl;
cin>>inputmeter;
float outputfeet=convert(inputmeter); // call convert function
cout<< “ The wire length in feet is: “ <<outputfeet;
return 0;

LY
}

Output: The output of this coded program is shown in Figure 6.28:

N
O
SE
Figure 6. 28: Output of converting meters into feet

Step 4: Testing and debugging.


U
In this step you are required to compare the program results with the one you
computed manually or by using a calculator. Note that, programs often have
errors, they may be human error, syntactic error or semantic errors.
E

6. As a programmer, you are required


N

Exercise 6.9 to design a system that will manage


sales operations of Mjini Magharibi
LI

Answer the following questions. Enteprise limited.


1. Define system documentation and a) Identify and explain the
N

discuss its importance necessary information that you


2. Write the process of system will collect to accomplish this
O

task
documentation
b) Which techniques or methods
3. Define system requirement
you will use in gathering this
R

specification and discuss its information?


characteristics 7. Think of any system that you know,
FO

4. Discuss some of the standards for Then Draw a Data flow diagram
the system documentation. (DFD) that will show clearly the
5. With an example, describe good logical processes and all the entities
practices for system documentation. involved.

389
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 389 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
System maintenance Types of system maintenance
Computer Science

System maintenance phase involves the There are basically three types of
monitoring, evaluation and modification software maintenance. These are:
of a system to correct faults, improve (a) Corrective maintenance: corrective
performance, or familiarise the system maintenance of a software product
to an altered environment or user is necessary to rectify the bugs
requirements change. Therefore, system observed while the system is in use.
maintenance is the process of refining the
system to make sure it continues to meet (b) Adaptive maintenance: a software

LY
business needs. product might need maintenance
when the customers need the product
to run on new platforms, on new
Importance of system maintenance

N
operating systems, or when they
Necessity of Software Maintenance
need the product to interface with

O
Software maintenance is becoming an
new hardware or software.
important activity of a large number of
software organizations. This is no surprise, (c) Perfective maintenance: a software
given the rate of hardware obsolescence,
the immortality of a software product per
se, and the demand of the user community
SEproduct needs maintenance to
support the new features that
users want it to support, to change
different functionalities of the system
U
to see the existing software products
run on newer platforms, run in newer according to customer demands, or
environments, and/or with enhanced to enhance its performance of the
features. When the hardware platform is system.
E

changed, and a software product performs


N

some low-level functions, maintenance Problems associated with software


is necessary. Also, whenever the support maintenance
LI

environment of a software product Software maintenance is usually much


changes, the software product requires more expensive than what it should be,
N

rework to cope up with the new interface. and it takes more time than required.
For instance, a software product may need In software organisations, maintenance
O

to be maintained when the operating work is mostly carried out using ad hoc
system changes. Thus, every software techniques. The primary reason is that
R

product continues to evolve after its software maintenance is one of the most
development through maintenance efforts. neglected areas of software engineering.
FO

Therefore, it can be stated that software Although software maintenance is fast


maintenance is needed for functions such becoming an important area of work for
as correcting, enhancing features and many organisations, software maintenance
exporting the software to new platforms. is, in several cases, being carried out as

390
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 390 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
fire-fighting operation, rather than through Another problem associated with
systematic and planned activities. maintenance work is that the majority of
software products that need maintenance
Software maintenance has a poor image are legal products.
in industry. Therefore, an organisation
often cannot employ bright engineers System maintenance process
to carry out maintenance work. Even Maintenance process is not the same for
though maintenance suffers from a poor all systems or software being developed;
image, the work involved is often more it changes depending on the type of the

LY
challenging than development work. It system being maintained.
is therefore, necessary to thoroughly
understand someone else’s work and Figure 6.29 provides an overview of the

N
then carry out the required modifications steps that are usually used to guide the
and extensions. maintenance process.

O
Change
request
Impact
System
release
SE Change
implementation
System
analysis release
planning (Design, code, test)
U
E

Corrective Adaptive Perfective


maintenance maintenance maintenance
N

(Fault repair) (Platform (System


adoption) enhancement)
LI

Figure 6. 29: System maintenance process


N

Bug or problem fixing


Bug is a defect in a computer program or software that keeps it from performing
O

as it is designed to perform. It is an error, flaw or fault in a computer program or


system that causes it to produce an incorrect or unexpected result, or to behave in an
R

unintended way. A good example is a software crash or control flaw error.


FO

Upgrade
Software companies developers revise their programs and sell new versions
periodically. Software upgrade is the process of replacing a product with a newer
version of the same product. It is moving from one release to newer one. Example of

391
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 391 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
issues that need upgrade include security
Computer Science

Deterministic and probabilistic


fixes, new or enhanced features, better system, Integrated system.
compatibility with different devices or
5. Systems development is the
apps and software stability improvement.
process of defining, designing,
Enhancement constructing(developing), testing,
and implementing a new software
Software enhancement is the additional
application or program. It also
software functionality or software
refers to as a process of creating and
modules which are optional, but they may

LY
maintaining information systems.
be purchased or acquired by a licensee at
an additional fee to be set by a licensor. It 6. There are three approaches of
is any change in software that improves SDLC. These are predictive,

N
the basic functions of the software, for adaptive and object-oriented
example adding a new feature in the approaches.

O
existing system like GePG. 7. Predictive SDLC approach includes
Waterfall, Iterative andV-Shaped
Models. Adaptive SDLC approach
Chapter Summary

1. A system is a collection of elements


SE
includes Agile methods (Scrum,
Lean, Kanban and Extreme
and processes that interrelate to Programming) and spiral model.
U
accomplish a specific task. 8. Predictive approach to the SDLC is
2. The characteristics of any system an approach whereby the complete
include organisation, interaction, output of the project according to
E

interdependence, integration, the plan can be predicted.


planned approach and central 9. Adaptive approach to the SDLC is
N

objective. an approach in system development


LI

3. Basic elements of a system are where the project is said to be


input, processing and output. flexible and adapt to the changing
requirements as the system
N

The key elements of a system are


input, processing, output, control, development is in progress.
O

feedback, environment, boundaries 10. Phases of SDLC are planning,


and interfaces. analysis, design, construction
4. Classification of systems include (development), and testing,
R

open or closed system, Physical implementation, and maintenance.


11. Importance of SDLC are clear
FO

or Abstract (Conceptual) system,


Natural and Artificial systems, goal descriptions, proper testing
Adaptive and non-adaptive system, done before installation, clear stage
Permanent or temporary system, advancement, member flexibility,

392
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 392 25/12/2022 03:45


FOR ONLINE USE ONLY

Chapter Six: System development


DO NOT DUPLICATE
feedback from each stage makes structured design, function-oriented
perfection, absence of one member and object-oriented design.
does not break the project. 20. Types of system design include
12. System analysis is the phase of logical design, physical design,
system development where the architectural design, detailed design,
present system and acknowledged conceptual data modeling design
problems are studied in depth and and entity relationship model design.
the system users requirements are 21. The system implementation phase

LY
assessed. involves hardware and software
13. The steps for system analysis are acquisition, site preparation, user
preliminary investigation, system training and installation of the

N
survey, determination of user system.
requirements, analysis of the system 22. Program testing is a process of

O
survey and systems analysis report. executing a system in order to find
14. Steps in problem solving process: if it contains errors or not.
generate new ideas, evaluate and
select solutions, implement and
evaluate and define the problem.
SE 23. Types of program testing: unit
testing or component testing, system
testing and acceptance testing.
15. Problem solving techniques include 24. System documentation is a process
U
flow charts and cause-and-effect of recording the information for any
diagrams. reference or operational purpose.
16. Information gathering methods 25. Types of documentation in system
E

are interview, questionnaire, design: program documentation,


system documentation, operations
N

observation, joint application


development and surveys. documentation and user
LI

17. System design is a process that documentation.


stipulates how the system will 26. System maintenance phase involves
N

accomplish the specified objective. the monitoring, evaluation and


Three things which are insisted in modification of a system to correct
O

system design phase include activities faults, improve performance, or to


on designing the user interface, data familiarise the system to an altered
design, and process design. environment or user requirements
R

change.
18. The strategies for system design are
27. Three types of software maintenance
FO

bottom-up strategy and top-down


strategy. include corrective, adaptive and
perfective.
19. Approaches for system design are

393
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 393 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Revision Exercise 6 (a) CASE tools


(b) SDKs
Section A: (c) Flowchart
Answer the following questions. (d) Prototype
1. Compare between predictive and 2. Which symbol is used to represent
adaptive SDLC method. Provide a decision in a flowchart?
an example for each. (a) Rectangle
2. Explain when to use the spiral (b) Diamond

LY
model and waterfall model. (c) Triangle
3. Describe various roles in systems (d) Circle
development. 3. Which information is intended to

N
4. Why is documentation essential be known by programmers during
to the success of any information analysis at the beginning of a

O
system? project?
5. Explain at least three types of (a) Business rules and
system documentation and outline
their importance in systems
development.
SE documents
(b) Flowcharts and processes
(c) Processes and documents
6. You are a manager in a company,
U
(d) Processes and business rules
and you are establishing a new 4. ________ spend most of their time
information system. Who might in the beginning stages of the SDLC,
you consult in order to perform an talking with end-users, gathering
E

analysis of the current information information, documenting systems,


system?
N

and proposing solutions.


7. Computer based information (a) Business analysts
LI

systems need maintenance. What (b) Project managers


might this involve?
(c) Network engineers
N

8. Discuss the characteristics of a (d) Database administrators


good system. 5. In a systems development process,
O

users are made active members of


Section B development project teams. This is
an example of:
R

Choose the correct answer from the


following questions. (a) RAD
FO

1. Which tool among the following (b) JAD


is not helpful during system (c) Waterfall
development? (d) Documentation

394
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 394 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Glossary
Prototyping: is an iterative software development approach based on
the use of software prototypes.

Glossary
Robot is an autonomous machine that performs a task without
human control.
Cobot is an artificially intelligent robot that performs tasks in
collaboration with human workers.

LY
Surrounding everything that is external to the system.
Malware is intrusive software that is designed to damage and destroy
computers and computer systems. Malware is a contraction

N
for “malicious software.” Examples of common malware
includes viruses, worms, Trojan viruses, spyware, adware,

O
and ransomware.
Imperative is a paradigm of computer programming where the
programming program describes the steps that change the state of
SE
the computer. Unlike declarative programming, which
describes “what” a program should accomplish, imperative
programming explicitly tells the computer “how” to
U
accomplish it. Programs written this way often compile to
binary executables that run more efficiently since all CPU
instructions are themselves imperative statements.
E

Explicit type C++ Explicit Conversion. When the user manually


N

conversion changes data from one type to another, this is known as


explicit conversion. This type of conversion is also known
LI

as type casting.
Implicit type also known as automatic type conversion, is carried out by
N

conversion the compiler without the need for a user-initiated action. It


takes place when an expression of more than one data type
O

is present which in such an instance type conversion takes


place to avoid data loss.
R

Uniform Resource is a mechanism used by browsers to retrieve any published


FO

Locator (URL) resource on the web. Ideally, each valid URL permits to a
resource. Resourecs can be such as web page and image.
Example of URL include https://www.tie.go.tz or www.
google.com

395
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 395 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Computer Science

Bibliography

Acqnotes (2022). Software development management. Retrieved on 12th April, 2022 from
https://acqnotes.com/acqnote/careerfields/software-development-plan
ASQ (2022). Problem solving: What is problem solving. Retrieved on 13th April, 2022 from
https://asq.org/quality-resources/problem-solving#Process
Borzemski, L., Świątek, J., & Wilimowska, Z. (2019). Information Systems Architecture and
Technology: Proceedings of 40th Anniversary International Conference on Information

LY
Systems Architecture and Technology–ISAT 2019: Part I (Vol. 1050). Springer Nature.
Brandel, M(2013). IT Gets Its Grove Back, Computerworld. Retrieved on 13th April, 2022 from

N
www.computerworld.com/s/article/9237985/IT_gets_its_groove_back?taxonomyId=14
&pageNumber=2

O
Brookshear, J. G., Smith, D., & Brylow, D. (2012). Computer science: an overview.
Cain, E (2017). 4 steps to solving any software problem. Retrieved on 13th April, 2022 from

SE
https://www.oreilly.com/content/4-steps-to-solving-any-software-problem/
Chalk, B. S., Carter, A., & Hind, R. (2017). Computer organisation and architecture: an
introduction. Bloomsbury Publishing.
U
Chaudhuri, A. B. (2020). Flowchart and Algorithm Basics: The Art of Programming.
Mercury Learning and Information.
Chemwa, G & Mburu, S. (2005). Longhorn Secondary Computer Studies. Longhorn
E

Publishers, Tanzania.
De Champeaux, D., Lea, D., & Faure, P. (1993). Object-oriented system development.
N

Addison-Wesley Longman Publishing Co., Inc.


LI

Dennis, A., Wixom, B. H., & Roth, R. M. (2008). Systems analysis and design. John wiley &
sons.
N

Dixit, J. B. (2007). Structured system analysis and design. Firewall Media.


O

Elahi, A.(2017). Computer systems. Digital design, fundamentals of computer architecture


and assembly language. New York NY: Springer Science + Business Media LLC.
Emmanuel K. Achampong (2012). Introduction to Basic Information Technology (ICT):
R

Basic ICT.
FO

Englander, I. (2009). The architecture of computer hardware, system software, and


networking . Hoboken. NJ: Wiley & Sons.
Existek. (2017). SDLC models explained: Agile, Waterfall, V-shaped, Iterative, Spiral.

396
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 396 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Floyd, T. L. (2010). Digital Fundamentals, 10/e. Pearson Education India.
French, C. S. (1996). Computer Science. Letts Educational.
Idsurvey (2021). Advantages and disadvantages of data collection methods. Retrieved on 12th

Bibliography
April, 2022 from https://www.idsurvey.com/
Intel (2010). ASCII Computer Code. Retrieved on 20th April 2022, from
https://www.intel.com
Jeyapoovan, T. (2009). Computer Programming Theory and Practice. USB Distributors,
New Delhi.

LY
Khan Academy (2022). The laws of thermodynamics. Retrieved on 20th April 2022, from
https://www.khanacademy.org/science/

N
Kendall, K. E., & Kendall, J. E. (2014). System Analysis and Design, Edisi 9. USA: Pearson
Education.

O
Lewis, J., Lane, J., Moscovitz, M., & Barker, T. (2012). Foundation Website creation with
HTML5, CSS3, and JavaScript. Springer.

SE
Liang, Y. D. (2011). Introduction to Programming with C++. Pearson Education India.
Mall, R. (2014). Fundamentals of Software Engineering, Fourth Edition. PHI Learning
Private Limited, Delhi.
U
Markovic, I (2021). How to create a software development plan for your development team.
Retrieved on 12th April 2022 from https://tms-outsource.com/blog/posts/software-
development-plan/
E

Miller, B., & Ranum, D. (2013). Problem solving with algorithms and data structures. Retrieved
N

on 12th April, 2022 from


https://Www. Cs. Auckland. Ac. Nz/.../ProblemSolvingwith
LI

AlgorithmsandDataStructures.
Miller, M. (2007). Absolute beginner’s guide to computer basics. Que Publishing.
N

Morley, D., & Parker, C. S. (2014). Understanding computers: Today and tomorrow,
O

comprehensive. Cengage Learning.


Morrison, C., Wells, D., & Ruffolo, L. (2014). Computer literacy basics: A comprehensive
guide to IC3. Cengage Learning.
R

NASA (2019). System Design Processes. Retrieved on 16th April, 2022 from,
FO

https://www.nasa.gov/seh/4-design-process
Njoroge, H. (2018). Advanced Computer Organisation_Architecture.
O’docherty, M. (2005). Object-oriented analysis & design. John Wiley & Sons.

397
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 397 25/12/2022 03:45


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Patterson, D. A., & Hennessy, J. L. (2016). Computer organization and design ARM edition:
Computer Science

the hardware software interface. Morgan kaufmann.


Preston, M (2022). System development Life Cycle Guide. Retrieved on 4th April, 2022 from
https://www.clouddefense.ai/blog/system-development-life-cycle
Sharma, M (2013). Basic Computer Course: A Freshers Guide To Modern Day Computing.
Chandigarh/New Delhi: Abhishek Publications
Sinha, P. K., & Sinha, P. (2010). Computer fundamentals. BPB publications.

LY
Sincero, S.M (2012). Advantages and Disadvantages of Surveys. Retrieved on 14th April, 2022,
from https://explorable.com/advantages-and-disadvantages-of-surveys
Stair, R., & Reynolds, G. (2017). Fundamentals of information systems. Cengage Learning.

N
Tucker, A. B. (2004). Computer science handbook. Chapman and Hall/CRC.

O
Wasson, C. S. (2005). System analysis, design, and development: Concepts, principles, and
practices (Vol. 22). John Wiley & Sons.
Weaver, P. (2004). Success in your project: a guide to student system development projects.
Pearson education. SE
West, A. W., & Prettyman, S. (2018). Practical PHP 7, MySQL 8, and MariaDB Website
Databases. Springer.
U
Widmer, N. S., & Tocci, R. J. (2007). Digital systems: Principles and applications. Prentice
Hall. Pearson Education International.
E
N
LI
N
O
R
FO

398
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 398 25/12/2022 03:46


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Appendices

APPENDIX A: CODE OF ETHICS AND PROFESSIONAL CONDUCT


The ACM Code of Ethics expresses the conscience of the computing profession, and

Appendices
it affirms an obligation of computing professionals both individually and collectively
to use their skills for the benefit of society.

1. GENERAL ETHICAL PRINCIPLES.

LY
A computing professional should...
1.1 Contribute to society and to human well-being, acknowledging that all
people are stakeholders in computing.

N
1.2 Avoid harm.
1.3 Be honest and trustworthy.

O
1.4 Be fair and take action not to discriminate.
1.5 Respect the work required to produce new ideas, inventions, creative
works, and computing artifacts.
1.6 Respect privacy.
1.7 Honor confidentiality.
SE
U
2. PROFESSIONAL RESPONSIBILITIES.
A computing professional should...
E

2.1 Strive to achieve high quality in both the processes and products of
professional work.
N

2.2 Maintain high standards of professional competence, conduct, and ethical


LI

practice.
2.3 Know and respect existing rules pertaining to professional work.
N

2.4 Accept and provide appropriate professional review.


2.5 Give comprehensive and thorough evaluations of computer systems and
O

their impacts including analysis of possible risks.


2.6 Perform work only in areas of competence.
R

2.7 Foster public awareness and understanding of computing, related


technologies, and their consequences.
FO

2.8 Access computing and communication resources only when authorised or


when compelled by the public good.
2.9 Design and implement systems that are robustly and usably secure.

399
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 399 25/12/2022 03:46


FOR ONLINE USE ONLY
DO NOT DUPLICATE
APPENDIX B: STANDARDS AND STANDARDS-MAKING BODIES
Computer Science

Principal roles in standardisation for computer science and engineering are played
by the International Standards Organization (ISO), the American National Standards
Institute (ANSI), and the Institute of Electrical and Electronics Engineers (IEEE).
These organizations are briefly described below, with pointers to their Web pages
provided for further information.

1. The International Organization for Standardization (ISO)


“ISO is a network of the national standards institutes of 147 countries, on the basis

LY
of one member per country, with a Central Secretariat in Geneva, Switzerland,
that coordinates the system. ISO is a non-governmental organization: its members
are not, as is the case in the United Nations system, delegations of national

N
governments. Nevertheless, ISO occupies a special position between the public and
private sectors. This is because, on the one hand, many of its member institutes are

O
part of the governmental structure of their countries, or they are mandated by their
governments. On the other hand, other members have their roots uniquely in the
private sector, having been set up by national partnerships of industry associations.”
SE
2. The American National Standards Institute (ANSI)
The American National Standards Institute (ANSI) is a private, non-profit organization
U
(501(c)3) that administers and coordinates the U.S. voluntary standardization and
conformity assessment system. The Institute’s mission is to enhance both the global
competitiveness of U.S. business and the U.S. quality of life by promoting and
E

facilitating voluntary consensus standards and conformity assessment systems, and


safeguarding their integrity. (See http://www.ansi.org for more details).
N

ANSI standards in computer science exist in the areas of architecture, graphics, and
LI

programming languages. The International Committee for Information Technology


Standards (INCITS) is accredited by ANSI to create and maintain standards in
N

information technology including the various areas of computer science.


O

3. Institute of Electrical and Electronics Engineers (IEEE).


IEEE is world’s largest not-for-profit organisation for electronic engineering and
R

electrical engineering with its corporate office in New York. The mission of IEEE is
advancing techology for the benefit of every human kind.
FO

400
Tanzania Institute of Education (TIE) for Advanced Secondary Schools

Computer Science Form 5.indd 400 25/12/2022 03:46


FOR ONLINE USE ONLY
DO NOT DUPLICATE
Index

A I
Algorithm 123, 395 information 1, 6, 7, 9, 10, 12, 14, 15, 18, 22, 27,

Index
Analogue quantity 69 31, 33, 37, 49, 52, 54, 61, 63, 64, 66, 67,
95, 125, 143, 175, 230, 232, 235, 236, 237,
B 238, 239, 247, 251, 252, 258, 263, 270,
290, 302, 318, 322, 325, 326, 327, 328,

LY
Big data 61, 67, 68 330, 331, 332, 345, 347, 348, 349, 350,
Binary addition 85 351, 363, 364, 365, 369, 371, 373, 374,
Binary number system 72 375, 377, 378, 379, 380, 381, 382, 383,
Binary to decimal conversion 77, 116 384, 391, 392, 393, 397

N
Binary to octal conversion 79
M

O
C Macros 60, 67
combo box 60 malware 394
Complement operation 88
computer 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 52, 62, 63,
64, 65, 66, 67, 68, 69, 70, 72, 73, 88, 89,
SE
Octal number system 72
O

93, 95, 96, 116, 117, 120, 121, 123, 124, One’s complement 88, 89, 117
U
125, 127, 131, 136, 144, 145, 146, 148, open-source 62, 278
149, 150, 151, 156, 157, 162, 167, 168,
175, 206, 214, 228, 233, 256, 259, 285,
300, 301, 308, 315, 321, 322, 325, 327, P
E

328, 329, 343, 368, 369, 385, 390, 394,


Problem solving process 121
395, 396
programming languages 18, 148, 149, 150, 151,
N

152, 153, 154, 171, 183, 191, 200, 260,


D 261, 265, 266, 345
LI

pseudocode 136, 137, 138, 139, 140, 141, 142,


Decimal number system 72 143, 144, 386
N

E R
O

electronic ii, 6, 10, 14, 65, 69, 70, 104, 107, 117, Reports 52, 59, 66
250, 321, 326, 385

S
R

F Static variables 177


FO

Flowcharts 127, 128, 131, 135, 139, 393


T
H
Troubleshooting 62, 64, 65, 67
Hexadecimal number system 72 Two’s complement 88, 91, 117

401
Student’s Book Form Five Tanzania Institute of Education (TIE)

Computer Science Form 5.indd 401 25/12/2022 03:46

You might also like