Tie Computer Science Form Five
Tie Computer Science Form Five
Computer
Science
for Advanced Secondary Schools
LY
Student’s Book
N
Form Five
O
SE
U
E
N
LI
N
O
R
FO
i
Student’s Book Form Five Tanzania Institute of Education (TIE)
Published 2022
LY
N
O
ISBN: 978-9987-09-589-6
SE
U
Tanzania Institute of Education
P.o. Box 35094
E
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
ii
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
iii
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Glossary....................................................................................................... 395
Bibliography............................................................................................... 396
FO
Appendices.................................................................................................. 399
Index .......................................................................................................... 401
iv
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
v
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
LY
Besides, the following individuals are acknowledged:
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
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)
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
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
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
Computer organisation
FO
1
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
MODEM/ROUTER
U
(communications)
E
N
PRINTER
(output)
LI
SYSTEM UNIT
KEYBOARD AND MOUSE
(houses processing and storage
(input)
N
Computer hardware
FO
2
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
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
4
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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 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)
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
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
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
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)
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.
8
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
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
9
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
Clock Registers
N
Data bus
Control bus
Address bus Data bus External
Figure 1.17: System bus
N
components
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)
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
Note: 1KB=210 bytes, 1MB=220 bytes, 1GB=230bytes, 1TB=240 bytes, 1PB= 250 bytes
O
12
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
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
13
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
14
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
drive (SSD) is a storage device that I/O channels can access secondary
uses integrated circuit assemblies memory. The processing unit can access
O
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)
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
16
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
two main categories, namely system drivers of these devices are preinstalled
management software and system on the computer such that the operating
R
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)
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
(g) System profiling utility provides the computer can understand. Translator
detailed information about the software converts a program written
LI
(h) Network managers to check the translated program is called the object
computer network and to log events. code.
O
18
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
unnecessary files or programs that (e) They are somewhat easier to design
reside in your computer. and develop than system software.
N
O
application software.
is commonly known as end-user program
FO
19
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Activity 1.3
Answer the following questions.
N
20
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
21
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
used to surf the internet. They help as the Ribbon, Quick Access Toolbar,
and Backstage view. For the first time
LI
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
22
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Step 3: After expanding the folder, click ‘Word 2016’, the Microsoft word 2016
N
23
Student’s Book Form Five Tanzania Institute of Education (TIE)
and see its features, Figure 1.27 will appear showing the main components
of Word 2016.
LY
N
O
SE
U
E
Inserting the table of contents in the reflect the heading levels, names, and
LI
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
24
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
25
Student’s Book Form Five Tanzania Institute of Education (TIE)
LY
N
O
SE
U
Figure 1. 30: Choosing a format of table of contents
26
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
LY
N
O
SE
U
E
recipients.
LY
N
O
SE
U
E
N
LI
N
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)
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
30
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
31
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
(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
LY
N
O
Figure 1.44: Mail merge wizard-
Previewing letters-II
33
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
34
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
35
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Step 6: Check your letters to make its grid structure, which allows the user
sure they are formatted to perform several related calculations.
O
36
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
(c) Enter all data in one table or worksheet to enable a statistical program to work
O
(e) MS Excel have limitations of up to the maximum of 1,048,576 rows, for latest
versions of Excel 2016 and above.
FO
37
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
38
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
digits
= Small(A1:A10,n) Returns the nth smallest value in a data set
FO
39
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
40
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
42
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
43
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
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
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
45
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Activity 1.7
FO
46
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
48
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
49
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
50
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
51
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
52
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
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
How to create a table in the design view Step 4: If you are asked to save the table,
R
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
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
group.
LI
N
O
R
FO
55
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Step 1: Open the table or query on which you are basing the form
Step 2: Click on the Create tab (1)
O
56
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
LY
N
O
Figure 1.79: Form creation
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
57
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
58
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
LY
N
O
SE
Figure 1.83: MS Access report wizard
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
Steps to create a simple Macro as shown the right side of the screen and
in Figure 1.84: double-clicking it.
O
60
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
it step by step.
LI
MS Access with all objects (table, information and used in machine learning,
form, query and report). predictive modelling, and other advanced
R
61
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
considerations:
data from devices, transactional
(a) Write down the steps: once you have
apps, the web, and social media.
started troubleshooting, you might
N
62
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
63
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
tool for retrieving information about problems and workable solutions. The
Windows error codes. following options are beneficial in
LI
64
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
LY
N
O
SE
Figure 1.85: Microsoft Easy fix solution as an example of troubleshooting tools
U
Activity 1.12 Chapter Summary
E
Windows 10; select one tool which binary data based on the user’s
you can use to troubleshoot the requirements.
LI
65
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
66
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
analytics initiatives.
10. Describe the components of the
27. Troubleshooting is a method
CPU.
R
67
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
68
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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:
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
69
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Digital data representation has many signals into electrical impulses. The ADC
advantages over analogue data then converts electrical signals into digital
N
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
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
Exercise 2.1
Activity 2.1
N
71
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
73
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
74
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
8 × 0.992 7.936 7
8 × 0.936 7.488 7
FO
76
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
77
Student’s Book Form Five Tanzania Institute of Education (TIE)
Example 10
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
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
1110101.1012 = 117.62510
78
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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 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
79
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
Example 16
Procedure:
FO
81
Student’s Book Form Five Tanzania Institute of Education (TIE)
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 81 2 82 1 83
= 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
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
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 1162 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
0010 Example 22
{ 1001
{ 1100
{
2 B D
N
equivalent.
N
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
83
Student’s Book Form Five Tanzania Institute of Education (TIE)
Step 2: Multiply each digit with 16n where n represent the weight for each bit.
(42 6110.112213 )16 4 162 6 161 1160 116 1 2 16 2 116 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
{ 3 7 7 1 2 4
0 6 7 4
84
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
(b) 6748
(a) 81410 (b) 421410
(c) 234.148 (d) 2431.258
N
85
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
LY
0 01 1
10 01 (c) 10111101
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) 110110
U
Note: Fractional multiplication for
binary numbers is the same as 1101
decimal number multiplication. 10
E
0000
Example 28 1101
N
multiplication.
(a) 110111 (b) 1010 110
Binary division
N
11 Example 29
FO
87
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
88
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
1110
N
1 Carry
that enables the subtraction using an
0011
addition operation. The following steps
N
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)
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
Procedure:
Subtract 1010 from 1000 using 1’s Step 1: Write the numbers in their
binary equivalent.
N
complement method
15 = 01111
Procedure:
O
Add + 0101
1101 Step 3: Add two numbers.
FO
90
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Step 5: Add the two’s complement of Subtract 101011 – 111001 using 2’s
FO
91
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
(a) 5 – 6 00111
Step 1: Write each number in their Step 4: Add 2’s complement of number
N
+ 00111
Step 2: Find 1’s complement of
10011
N
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
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) 11111 (b) 11111010
bits expressed by considering their place
(c) 1101101 (d) 1101111001
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.
4 0100
5 0101
LI
6 0110
Data coding 7 0111
Concept of data coding 8 1000
N
93
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
94
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
95
Student’s Book Form Five Tanzania Institute of Education (TIE)
(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
96
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
±
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
1. Define the following terms: Logical addition uses the logical symbol
(a) data coding (b) mantissa ''+ '' which can be placed between any
O
97
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
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
Procedure:
( A + B ).( A + C ) =
N
99
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
100
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
102
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
x = AB + AB + AB
the combined Boolean
Step 3: The Boolean expression equations whose output is
LI
x = AB + AB + AB + AB - Associative law
rules of Boolean algebra.
x = ( A + A) B + A( B + B ) - Distributive law
FO
103
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
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
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
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.
Example 50 A B A B AB AB A+ B
0 0 1 1 0 1 1
Prove DeMorgan’s theorem
FO
105
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
ABC BC ABC . BC
Step 3: Using DeMorgan’s theorem expression ABC . BC will be:
LI
ABC BC A B C . B C
N
ABC BC A B C . B C
R
106
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
- Annulment law
ABC + BC = AB + AC + BC + C.1
LY
ABC + BC = AB + C ( A + 1) - Annulment law, B + 1 = 1
N
ABC + BC = AB + C - Identity law
O
and one binary output signal. These gates
Exercise 2.8
OR gate
Logic gates
FO
107
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
108
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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)
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
110
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
111
Student’s Book Form Five Tanzania Institute of Education (TIE)
Input Output
Combinational Combinati- Memory
onal Logic Elements
Logic Circuit
External inputs
LY
Figure 2.14: (a) Combinational logic circuit (b) Sequential logic circuit
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
BC
signals are connected in the logic circuit.
Y
For example, you will realise that two A
N
112
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
You can create Boolean expressions from 3. Create a logic circuit of the Boolean
expressions:
O
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
1 0 1 0
An adder is a digital circuit that adds binary
1 1 0 1
LI
114
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
0 1 0 1 0
The Boolean expression for a carry out
R
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)
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
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
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
The OR and AND gates are linked 16. The basic logic gates include OR,
with addition and multiplication AND, NOT, NAND, NOR, and
O
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)
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
multiplications:
numbers into decimal numbers:
(a) 110111 (b) 11110 1011
(a) 111012 (b) 11101012
LI
following terms:
(c) 435.1458
(a) data coding (b) mantissa
FO
118
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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, 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
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)
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:
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
120
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
121
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
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 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
123
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
124
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
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
126
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
stages. A flowchart is constructed using lives. The following are some of the
different types of boxes and symbols. uses of flowcharts:
O
127
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
5. Connector symbol
LI
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)
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
130
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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.
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
131
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
DETERMINE expression
N
132
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
133
Student’s Book Form Five Tanzania Institute of Education (TIE)
START
Write an algorithm that will display READ num1, num2
the sum of two numbers entered by a COMPUTE Result = num1 + num2
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
Flowchart Pseudocodes
1. A flowchart is a diagrammatic A method of representing the step-by-
LI
3. Flowcharts are useful for detailed Pseudocodes are particularly useful for
FO
134
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
135
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Statement 1
ELSE sequence_of_statements3
FO
136
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
Example 1
Sequential structure procedure for Yes
is marks>50
No
calculating area of a triangle as shown
LY
in Figure 3.12.
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
structure True
New_fact=new_fact*i
Print
New_fact
Example 2
R
I=I+1
Selection procedures for evaluation
FO
138
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
counting number
6. Develop a flowchart to show how
N
139
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
numbers.
Write the pseudocode that will decide
(b) The second thing is the actions students with marks greater than 45 as
LI
to 45’:
will be as follows: START
READ marks
START
R
IF marks >=45
INPUT num1, num2 PRINT “passed”
ELSE
FO
140
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
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
Example 5
The flowchart for the algorithm will
Write an algorithm by using
N
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
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
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
Chapter Summary
N
O
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)
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
144
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
(a) (b)
14. Sambayeti is a class master of form
LI
145
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
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
{ 10100101001
cout << “The year 2022?” 01011100110
O
} 11001001010
Translators
R
Assemblers
Assemblers are programming language processors required to convert programs
147
Student’s Book Form Five Tanzania Institute of Education (TIE)
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++.
Background to computer They are not portable; hence, they are not
programming languages easy to be transferred from one computer
LI
148
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
149
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
programming languages
Object-Oriented programming language (a) The program which is developed
R
150
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
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)
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
uses crt;
Var
x, y, z: integer;
N
begin
writeln (‘Enter first number:’);
readln(x);
O
readln;
end.
FO
Output:
152
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
153
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
154
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
Program Example 3:
#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;
}
Line Description
N
using namespace std; This alerts the compiler to find the names in the standard
O
155
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
online. All examples in this book were prepared using Dev C++.
N
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
156
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
157
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
158
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
159
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
160
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
161
Student’s Book Form Five Tanzania Institute of Education (TIE)
Content title
LY
N
O
Figure 4.13: Title change to “Introduction.cpp”
any error the compiler will display running the program, add “system
(“PAUSE”) to the codes to stop the
N
162
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
#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)
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
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
LY
N
O
SE
Figure 4.16: System and security window
165
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
166
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
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
167
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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 ()
Logic errors }
Logic errors are constructs that can be
N
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)
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
Exercise 4.2
N
include<iostream>;
R
{
cout<<Read and enjoy C++ programming<<endl;
return 0;
}
170
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Data types
LI
N
O
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)
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.
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
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.
172
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
{
int year, month;
O
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)
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
}
LI
5. Compile and run the following program; thereafter, explain the output.
N
#include <iostream>
O
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
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
you have obtained. To the computer, the For example, from the given scenario x, y
and “result” stands as variable identifiers.
O
programming
x=x+1 (a) Commas and blank spaces are not
FO
175
Student’s Book Form Five Tanzania Institute of Education (TIE)
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++.
double area;
char t; double b;
N
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
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
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
#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
177
Student’s Book Form Five Tanzania Institute of Education (TIE)
Output:
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
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
178
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
LY
const double bankRate = 0.15;
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
return 0;
}
O
Output:
R
FO
179
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
int b;
#include<iostream> a=2;
LI
{
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
180
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
more than one extraction operators to request more than one data from the
user.
N
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
181
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
#include<iostream>
N
#include<string>
using namespace std;
LI
int main()
{
string myname;
N
return 0;
}
R
Output:
FO
182
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
{
int sec, min, hrs;
cout<<”Enter seconds: “;
cin>>sec;
R
min = sec/60;
hrs = min/60;
FO
183
Student’s Book Form Five Tanzania Institute of Education (TIE)
Output:
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
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
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:
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
185
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
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
186
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
LY
!= is not equal to 8! = 8 False 0
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
return 0;
}
O
Output:
R
FO
187
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
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.
{
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
return 0;
}
R
Output
FO
188
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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.
Highest (,)
Priority ++, -- (as postfix), new, (type),typeof, sizeof
N
*, /, %
+ (string concatenation)
N
+, -
<<, >>
O
&, ^, |
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)
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
{
cout<<”2%3 = “<<2%3;
R
return 0;
}
FO
190
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
return 0;
Statement 1
LI
}
N
Statement 2
Control structures
O
191
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Nested IF statement.
192
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
#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
else
{
statement(s); // this block will execute when condition is false
}
193
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
#include<iostream>
using namespace std;
LI
int main()
{
int marks;
N
if(marks>=50)
{
cout<<”You have been selected to join form five”<<endl;
}
R
else
{
FO
194
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
}
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)
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.
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
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
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
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
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)
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
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
#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
Exercise 4.8
R
199
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
19 and 22 respectively.
N
Statement (s)
programming”<<endl; ten times which (loop body)
is very tedious. Also, consider you are a
FO
200
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
#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
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)
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
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
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)
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
Activity 4.8
LI
each loop
the number of students in the class
(c) Comment on the results obtained
FO
204
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
There are two types of functions applied involves all executable statements within
in C++ programming, namely user-
LI
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
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
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)
Output:
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
208
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Output:
O
R
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)
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
main function, it should be defined. This within standard library files. Such
is possible through writing function functions comprise mathematical, string
O
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
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
*/
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
211
Student’s Book Form Five Tanzania Institute of Education (TIE)
Output:
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<<”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
212
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
(c) Write a C++ program to show the number. Then, the program will
application of each function. display selected types of number
O
Example:
Answer the following questions.
FO
213
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
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
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
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.
#include<iostream>
#include<conio.h>
N
{
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)
Output:
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:
members according to the feature of the array then enclosed them by curl brackets.
Here is the syntax for initialising two dimensional arrays,
O
or
int matrix[3][2]=
FO
{
{0,2},
{7,8},
{9, 5},
};
216
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Exercise 4.11
Figure 4.62: Output of the program
R
217
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
218
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Output:
N
O
R
FO
219
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
strcat( )
O
The following program example shows the use of the string function for concatenation.
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
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
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
221
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
{
char string1[]=”Hujambo”;
char string2[]=”Mwananzengo”;
LI
Output: The result will be -1 as shown in Figure 4.68. Find the result when you
O
222
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
223
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
224
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
225
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
(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
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
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
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)
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
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
228
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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)
229
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
The following, as shown in Figure 5.3 are the differences between static websites
LI
e
ebsite I am a static websit
ic w
I am a dynam (a) Static webpage are simple HTML written pages,
O
231
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Web browsers
A web browser is a software that allows Safari
R
232
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Client 3
233
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
LY
N
O
Figure 5.12: A ‘contact us’ webpage
1. Websites give you unlimited access pay annual fees as costs of domain
to worldwide information without registration, hosting domain name
O
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)
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
HTTPS.
4. Present ways through which hierarchical model is a famous website
O
236
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
237
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
a degree of clarity.
Mobility friendly
FO
238
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
you can use the following have an opening tag and its corresponding
domain structure: “www.<name closing tag. However, the empty tag has
FO
239
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
240
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
241
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
242
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
243
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.27: An output of an HTML code on paragraphs, background and font colours
244
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
245
Student’s Book Form Five Tanzania Institute of Education (TIE)
LY
N
O
SE
Figure 5.29: An output of an HTML code on tables and headings
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
246
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
247
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
248
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
249
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
Images in websites
An image is simply a visual representation of 5. Uses of images increase
FO
250
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
However, they are excellent for are expressed using either pixels or
high-resolution prints, professional percentages. A pixel stands for picture
LI
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)
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
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
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
253
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Activity 5.4
R
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
LY
N
O
SE
U
E
N
LI
N
255
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
webpage.
The use of CSS offers many
R
256
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
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
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
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
259
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
The output of JavaScript code written in Figure 5.45 is shown in Figure 5.46.
R
FO
260
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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)
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
262
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
(a) (b)
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)
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
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
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
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
}
O
2. The while loop: the while loop has the following syntax:
while (condition)
{
R
265
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
267
Student’s Book Form Five Tanzania Institute of Education (TIE)
{
// 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
45 is good
27 is satifactory
39 is satifactory
R
45 is good
77 is very good
90 is exellent
FO
268
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
270
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
Activity 5.5
FO
272
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
function validateForm()
{
O
let x = document.forms[“myForm”][“fname”].value;
if (x == “”)
{
R
return false;
}
}
</script>
273
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
274
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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 3
Note: The formula to get volume of the sphere is πr
3
275
Student’s Book Form Five Tanzania Institute of Education (TIE)
Activity 5.6
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
and database, usually the next task is to PHP stands for Hypertext Preprocessor is
connect the database and the website to
O
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
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
?>
<html>
O
=”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)
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
278
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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)
starts.
LY
N
O
SE
Figure 5.75: Apache and MySQL started in xampp control panel
280
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
LY
N
O
SE
U
Step 5: Design a simple database: your simple database should have one table
N
(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
281
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
282
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
283
Student’s Book Form Five Tanzania Institute of Education (TIE)
(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
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
284
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
<?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
285
Student’s Book Form Five Tanzania Institute of Education (TIE)
$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
286
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
287
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
The output of HTML code from Figure 5.88 will be as shown in Figure 5.89.
O
R
FO
288
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
The output of HTML code shown in Figure 5.92 will be as shown in Figure 5.93.
LY
N
O
SE
U
E
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
290
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
291
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
N
O
SE
U
Step 6: Create a webpage for “About Us” by saving an HTML file you created in
N
292
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
293
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
294
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
295
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
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
Figure 5.106.
297
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
298
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
Step 7: After creating your folder, the window will look as shown in Figure 5.112.
LI
N
O
R
FO
300
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
LY
N
O
SE
U
E
N
LI
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
302
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
303
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
</tr>
<tr>
FO
304
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
min=”10” max=”100”><br><br>
</form>
</td>
FO
</tr>
<tr>
<td colspan =”5”><p><center>© Mwembeni Secondary
School.</p></center></p></td>
305
Student’s Book Form Five Tanzania Institute of Education (TIE)
</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
306
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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>
<td colspan =”4”>
FO
<?php
$hostname = “localhost”;
307
Student’s Book Form Five Tanzania Institute of Education (TIE)
$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
<?php
$i++;
}
O
?>
</table>
<?php
R
}
else{
FO
308
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Step 18: Upload all files you created under htdocs folder to Cpanel File Manager
FO
309
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
310
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Step 23: Go to database and click MySQL® Database Wizard as seen in Figure
FO
311
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
312
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
314
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
315
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
316
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
Chapter Summary
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
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
318
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
319
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
LY
N
O
SE
U
E
N
LI
N
O
R
FO
321
Student’s Book Form Five Tanzania Institute of Education (TIE)
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:
2. What can be done if users of a particular system might demand for an application
LI
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
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
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
323
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
324
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
BOUNDARIES AND
FEEDBACK INTERFACES
ENVIRONMENT
R
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)
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
326
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
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
327
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
You can change boundaries when physical things. You can touch and
you want to study a small or large
LI
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
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
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
329
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
330
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
331
Student’s Book Form Five Tanzania Institute of Education (TIE)
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:
systems.
gone over budget. Some projects die
N
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
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
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.
analyst of systems.
5. Programmer This is an expert whose role is to modify or develop
N
333
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
334
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
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
336
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
337
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
that holds fifteen essential is that external customers are not much involved.
features. The planning for this
N
Initial
design phases will include all
Planning Iterative
fifteen functions. This planning Model
R
338
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
n
tio
da
ca
R
li
Va
tio
Coding
339
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
340
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
(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
341
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
342
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
Test
Implementation
O
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)
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
series of iteration cycles. The planning, (d) Employee satisfaction and retention
are improved.
FO
344
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
decision is made.
Giving reasons for your answer based
Advantages of prototyping on the type of system being developed,
N
345
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
7. Maintenance 4. Development
1. Planning Phase
O
phase phase
R
FO
347
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
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
348
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
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)
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
- Customers
A system request, which is a - Information
- Competitors
Technology dept
formal way of asking for IT
O
350
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
of the project.
(c) Economic feasibility Step 3: Gather information by
N
save and how much money will you spend? (b) Conducting interviews
Is there any consideration of intangible (c) Reviewing documents
R
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)
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
352
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
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
354
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
355
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
356
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
357
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
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
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
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
359
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
Inspect product
O
Is
product
No good?
Yes
R
Ship product
Prepare bill
FO
Mail bill
360
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
Activity 6.13
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.
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
361
Student’s Book Form Five Tanzania Institute of Education (TIE)
Start
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
value of numerator
U
Divede the
numerator by the
denominator
E
Yes
N
No
Write your
N
answer
O
End
R
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
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.
Effect/problem
E
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)
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
364
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
365
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
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
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
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
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)
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.
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
368
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
(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
369
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
370
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
There are two main strategies for system methodology to design a computing
design. These are bottom-up strategy system or application
LI
the subsystem and the lowest level known types of system design:
components or sub components. The
R
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)
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.
372
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
373
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
(b) System life cycle is not an demonstrates what the system does but
organisational process of not how it accomplishes it.
O
(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
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
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
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
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)
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
Physical DFD
LI
orders orders
O
Logical DFD
R
1.1.1 Received
Customer order
Record customer customer order
FO
order
376
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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.
Patient Information
SE Diagnosis
information
U
Hospital
Administrator
0.0
Patient Patient
E
Hospital
Management Info
System
N
Employee/
Doctor
LI
List of Patients
O
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)
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
Employee Information
1.4
R
List of Patient
Manage Employee/
FO
378
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
(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)
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
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
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
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.
simultaneously in the whole organization. managers, and IT staff members all need
to be trained in order for an information
N
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
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)
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
to a prepared set of users. (h) Sign off from the testing team.
O
382
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
LY
units or modules that depend on each of data in the system; correct the flaws
other are tested. and get the system working.
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
Take an example of any system or input data and how the output can
program developed in C++ subject or be produced.
O
383
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
modules that are well supported by programmers, all put combined efforts
LI
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
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
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
385
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
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
386
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
Start
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
// Helper variables
float inchmt = 39.37;
O
388
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
LY
}
N
O
SE
Figure 6. 28: Output of converting meters into feet
task
documentation
b) Which techniques or methods
3. Define system requirement
you will use in gathering this
R
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)
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
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
390
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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)
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
392
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
change.
18. The strategies for system design are
27. Three types of software maintenance
FO
393
Student’s Book Form Five Tanzania Institute of Education (TIE)
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
394
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
as type casting.
Implicit type also known as automatic type conversion, is carried out by
N
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)
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
Dennis, A., Wixom, B. H., & Roth, R. M. (2008). Systems analysis and design. John wiley &
sons.
N
Basic ICT.
FO
396
Tanzania Institute of Education (TIE) for Advanced Secondary Schools
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
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
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)
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
Appendices
it affirms an obligation of computing professionals both individually and collectively
to use their skills for the benefit of society.
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
practice.
2.3 Know and respect existing rules pertaining to professional work.
N
399
Student’s Book Form Five Tanzania Institute of Education (TIE)
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.
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
ANSI standards in computer science exist in the areas of architecture, graphics, and
LI
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
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
E R
O
electronic ii, 6, 10, 14, 65, 69, 70, 104, 107, 117, Reports 52, 59, 66
250, 321, 326, 385
S
R
401
Student’s Book Form Five Tanzania Institute of Education (TIE)