Module 3 - Learner Guide
Module 3 - Learner Guide
Module 3
Principles of computer programming
US: 14921, 14918, 14910
Further Education and Training Certificate: Information Technology: Systems
Development
SAQA 78965 - Level 4 - 175 Credits
Learner Information:
ID Number
Tel/Cell
Email Address
Organisation:
Facilitator Name:
Copyright
All rights reserved. The copyright of this document, its previous editions and any annexures thereto,
is protected and expressly reserved. No part of this document may be reproduced, stored in a
retrievable system, or transmitted, in any form or by any means, electronic, mechanical,
photocopying, recording or otherwise without the prior permission.
2
Learner Guide Introduction
The purpose of this Learner Guide is to provide learners with the necessary
knowledge and it provides a comprehensive overview of the module: Principles of
computer programming, and forms part of a series of modularised Learner
Guides that have been developed for the qualification: Further Education and
About Training Certificate: Information Technology: Systems Development - Qual ID:
78965 NQF LEVEL 4, Worth 175 Credits.
This Learner Guide has been designed to improve the skills and knowledge of
learners, and thus enabling them to effectively and efficiently complete specific
tasks.
The only way to establish whether a learner is competent and has accomplished
the Learning Outcomes is through an assessment process.
Assessment involves collecting and interpreting evidence about the learner’s
ability to perform a task.
Assessment This guide may include assessments in the form of activities, assignments, tasks or
projects, as well as workplace practical tasks. Learners are required to perform
tasks on the job to collect enough and appropriate evidence for their portfolio of
evidence, proof signed by their supervisor that the tasks were performed
successfully.
To qualify and receive credits towards the learning program, a registered assessor
Qualify will conduct an evaluation and assessment of the learner’s portfolio of evidence
and competency
3
Seek assistance and help from your facilitators, if required.
4
US: 14921, NQF Level 4 Worth 6 Credits
Learning Unit 1 Describe the types of computer systems and associated
hardware configurations
The credit value of this unit is based on a person having prior knowledge and
5
Session 1
Describe past, present and future computer hardware configurations.
SO 1
6
A networked pc is connected to other pcs in a network.
The major disadvantage of not being part of a network is not being able to accomplish any tasks that
require an internet connection such as e-mail, browsing the internet or sharing files with other users
– anything that is not locally stored on the computer’s hard drive.
A network computer is a computer that connects to one or more computers for the main purpose of
communicating.
The advantage of a network computer is that it shares resources such as software applications,
printers, disk drives and data files with the other networked computers.
A disadvantage of being a network computer is the real possibility of becoming a victim of computer
hackers, viruses or spyware. With the possibility of a real threat, it would be in your best interest to
install a virus protection and malware software.
Although, a standalone computer system has certain security advantages compared to a network
computer, it is not very effective in today’s world of technology. Data communication and
7
networking are the way of the world, requiring the need to create a highway of data through a
network computer.
I is easy and convenient to monitor users - for Users may use too much bandwidth - for example
example websites visited or documents printed - when listening to music files or watching video
this can be done using software running on the clips - preventing others from using the network
server facilities properly
Midrange computers, or midrange systems, are a class of computer systems which fall in between
mainframe computers and microcomputers.
The class emerged in the 1960s and machines were generally known at the time as minicomputers -
especially models from Digital Equipment Corporation (PDP line), Data General, Hewlett-Packard
(HP3000 line), and successors), and Sun Microsystems (SPARC Enterprise). These were widely used in
science and research as well as for business.
IBM favored the term 'midrange computer' for their comparable more business-oriented System/3,
System/34, System/32, System/36, System/38, and AS/400 ranges.
8
Since 1990s, when the client–server model of computing became predominant, computers of the
comparable class are instead universally known as servers to recognize that they usually "serve" end
users at their "client" computers. Since the client–server model was developed in Unix-like operating
systems, using this term frequently implies support of standard—rather than proprietary—protocols
and programming interfaces.
The client–server model is a distributed application structure in computing that partitions tasks or
workloads between the providers of a resource or service, called servers, and service requesters,
called clients. Often clients and servers communicate over a computer network on separate
hardware, but both client and server may reside in the same system. A server is a host that is
running one or more server programs which share their resources with clients. A client does not
share any of its resources, but requests a server's content or service function. Clients therefore
initiate communication sessions with servers which await incoming requests.
The client–server model was developed at Xerox PARC during the 1970s. It is now prevalent in
computer networks. Email, the World Wide Web, network printing are typical examples of the
model.
Description
The client–server characteristic describes the relationship of cooperating programs in an application.
The server component provides a function or service to one or many clients, which initiate requests
for such services. The model assigns one of two roles to the computers in a network: Client or
server. A server is a computer system that selectively shares its resources; a client is a computer or
computer program that initiates contact with a server in order to make use of a resource. Data,
CPUs, printers, and data storage devices are some examples of resources.
This sharing of computer resources is called time-sharing, because it allows multiple applications to
use the computer's resources at the same time.
Clients and servers exchange messages in a request-response messaging pattern: The client sends a
request, and the server returns a response. To communicate, the computers must have a common
language, and they must follow rules so that both the client and the server know what to expect.
The language and rules of communication are defined in a communications protocol. All client-
server protocols operate in the application layer.
Whether a computer is a client, a server, or both, it can serve multiple functions. For example, a
single computer can run web server and file server software at the same time to serve different data
to clients making different kinds of requests. Client software can also communicate with server
software on the same computer.[2] Communication between servers, such as to synchronize data, is
sometimes called inter-server or server-to-server communication. For years Independent Software
9
Vendors (ISVs) have created complex client server applications which combine the compute power
of the end
Users
Computer using a “client” software module to communicate with the application and database on a
server. These client server applications have tremendous advantages and are seen across all
verticals and sizes of businesses. Many of these client server applications even have hooks back into
the client “end user’s” desktop to generate reports in Excel or Access and documents such as
invoices or pick lists in Word taking advantage of the Microsoft Office software running on the end
user’s desktop. This integration makes saving, sharing, and printing the reports or documents as
simple as using any other Office application. A great concept and great value. However, as end
users want to use different devices and more and more application delivery has become web or
browser based, the restrictions of the “client” software don’t match end user’s expectations of
Cloud or web delivery. Rewriting a client server application to support web and mobile based users
can also be time consuming and expensive for ISVs.
10
Before you start using your PC, first you must configure it with all the basic set ups. Basics setups
needed for assembling a PC includes the main memory, hard disk drive, card reader, CPU, CD drive,
monitor, modem, and definitely a windows operating system.
Multi-user is a term that defines an operating system or application software that allows access by
multiple users of a computer. Time-sharing systems are multi-user systems. Most batch processing
systems for mainframe computers may also be considered "multi-user", to avoid leaving the CPU
idle while it waits for I/O operations to complete. However, the term "multitasking" is more
common in this context.
An example is a Unix server where multiple remote users have access (such as via Secure Shell) to
the Unix shell prompt at the same time. Another example uses multiple X Window sessions spread
across multiple terminals powered by a single machine - this is an example of the use of thin client.
Similar functions were also available under MP/M, Concurrent DOS, Multiuser DOS and FlexOS.
Some multi-user operating systems such as Windows versions from the Windows NT family support
simultaneous access by multiple users (for example, via Remote Desktop Connection) as well as the
ability for a user to disconnect from a local session while leaving processes running (doing work on
their behalf) while another user logs into and uses the system. The operating system provides
isolation of each user's processes from other users, while enabling them to execute concurrently.
Management systems are implicitly designed to be used by multiple users, typically one system
administrator or more and an end-user community.
The complementary term, single-user, is most commonly used when talking about an operating
system being usable only by one person at a time, or in reference to a single-user software license
agreement. Multi-user operating systems such as Unix sometimes have a single user mode or
runlevel available for emergency maintenance.
Single-user, single task - As the name implies, this operating system is designed to manage
the computer so that one user can effectively do one thing at a time. The Palm OS for Palm
handheld computers is a good example of a modern single-user, single-task operating
system.
Single-user, multi-tasking - This is the type of operating system most people use on their
desktop and laptop computers today. Microsoft's Windows and Apple's MacOS platforms
are both examples of operating systems that will let a single user have several programs in
operation at the same time. For example, it's entirely possible for a Windows user to be
writing a note in a word processor while downloading a file from the Internet while printing
the text of an e-mail message.
11
Multi-user - A multi-user operating system allows many different users to take advantage of
the computer's resources simultaneously. The operating system must make sure that the
requirements of the various users are balanced, and that each of the programs they are
using has sufficient and separate resources so that a problem with one user doesn't affect
the entire community of users. Unix, VMS and mainframe operating systems, such as MVS,
are examples of multi-user operating systems.
A multi processor is a single computing component with two or more independent actual central
processing units (called "cores"), which are the units that read and execute program instructions.
The instructions are ordinary CPU instructions such as add, move data, and branch, but the multiple
cores can run multiple instructions at the same time, increasing overall speed for programs
12
amenable to parallel computing. Manufacturers typically integrate the cores onto a single integrated
circuit die (known as a chip multiprocessor or CMP), or onto multiple dies in a single chip package.
13
If you have ever experienced a server crash or your site becoming unavailable for an extended
period of time, it is time to adopt a more highly available configuration. As the way we host data is
rapidly developing and usage volumes fluctuate, the varying needs of enterprise solutions are calling
for increased security, flexibility, availability and performance. We at Liquid Web have been
proactive in using our knowledge of the market to develop the most flexible and easily adaptable
hosting solutions available. Choose us to host your next project, and we will introduce you to high-
performance environments with on-demand scalability, reliable load balancing and an unmatched
availability – be it developing a scaled hosting model for an ongoing project, or adding features to
your server configuration as traffic increases.
High Performance Features
Clustered File Systems
Redundant Networking Devices
Dedicated Load Balancers
14
Database Clustering Options
Increased Resiliency in Application Hosting
Our High Performance Server Configurations are designed to intuitively address Failover -- the ability
to automatically access mirrored data on standby systems in the event of increased traffic or error
causing a server crash -- via full redundancy throughout scalable server clustering. The diagram on
the right is one example of how we manage the fluctuating traffic on some of the world’s most
popular websites. With multiple servers managed by a Load Balancer, we have created a solution for
applications that can’t afford even a momentary lapse in service, let alone a full-scale crash. Adding
a High Availability MySQL Cluster to manage your database services beneath a Cisco managed switch
for data intensive solutions and you will never have to recreate databases or fear losing existing data
again.
15
documents Url
company Name
There are many ways of storing this information, but a common technique is to use an XML file. Let's
create a single XML file that contains details for all of the environments.
16
Session 2
Describe categories of computer system applications.
SO 2
Learning
The description identifies categories of computer system applications.
Outcomes
The description justifies categorisation of examples.
(Assessment The description explains the performance characteristics of the categories.
Criteria)
1. Embedded Systems
2. Windows applications (also called ‘Desktop applications’)
3. Web Applications
4. Web Services
5. Console applications
Embedded Systems:
When a name, address and other information is saved in the Mobile Phone or Digital Diary, a small
computer program ‘Embedded’ into a chip in the device inside the mobile phone or digital diary
completes the task and known as Embedded Systems.
Windows applications:
Windows Applications is a form based standard Windows, Microsoft word; Paint is example to the
Windows application, and also called ‘Desktop applications’.
Web Applications:
A web site is also called ‘web Applications’. A web applications is a collection of web pages hosted on
a special computer called ‘web server’. Web server can be located anywhere and visitors can be
located anywhere .It will work through Browsers (EG. Internet Explorer, Mozilla, Netscape).
17
Web Services:
Web services are web applications that give services to other applications through the internet, for
example, Google search engine, Yahoo Search engine etc. which allows other applications to
delegate the task of searching over the internet.
Console Applications:
Console applications runs inside the command prompt i.e. DOS window, It is a light weight program
and which is used commonly for test applications.
18
Batch Processing
• Data is processed in batches.
• The batches tend to be large and of identical type.
Common examples of where batch processing occurs include the processing of bank statements,
utility bills and credit card transactions
• No user interaction is required.
• Batch processing usually takes place during the evening or on the weekends, when there is less
demand on the processor.
• Both of these facts mean that daily work can continue with little disruption.
• The main problem with batch processing is the delay in receiving the output from the data
input.
• For example, sometimes you can pay for something using a credit card, but the money is not
taken out straight away. If you aren’t aware of this and you think you have that money in
your account you might go spending the money…thus putting you into debt!
Interactive Processing
• Also known as a transactional processing system.
• Data is processed one transaction at a time.
• Any response or update must be completed before the next transaction can take place.
• Data inputs tend to be small and input interactively by the user.
• The user inputs data into the system when prompted to do so.
• Their actions are limited to what the system allows them to enter.
Real-Time Processing
• Data is processed within a given maximum time limit (usually under 4 seconds).
• The time limit will depend on a number of factors:
– User requirements
– Type of processing
– Amount to process
• It is normally assumed that data will be processed as soon as it is received.
• This could result in data being updated straight away on a database, or an action taking
place.
• A good example of real-time processing is in auto-pilot systems.
• They wouldn’t be very useful in the following example…
19
Batch Autopilot
What to do now
Create and complete the following summary table:
Processing
Response time
User interface
requirements
20
The description identifies categories of computer system applications.
General purpose application
General purpose application software is a type of software that can be used for a variety of tasks. It
is not limited to one particular function. For example a word processor could be classed as general
purpose software as it would allow a user to write a novel, create a restaurant menu or even make a
poster.
21
There are several things to consider before purchasing bespoke software, on the plus side:
Software is built for and will meet your precise needs
However, you must also consider
Software will be expensive as you have to cover all of the production costs
It may take some time to develop the software, when special purpose software could be brought
straight away
The software is more likely to be buggy as it probably won't have thousands of clients using and
testing it
Information Systems and Computer Applications
Description of the Examination
The Information Systems and Computer Applications examination covers material that is usually
taught in an introductory college-level business information systems course. Questions test
knowledge, terminology, and basic concepts about information systems as well as the application of
that knowledge. The examination does not emphasize the details of hardware design and language-
specific programming techniques. References to applications such as word processing or
spreadsheets do not require knowledge of a specific product. The focus is on concepts and
techniques applicable to a variety of products and environments. Knowledge of arithmetic and
mathematics equivalent to that of a student who has successfully completed a traditional first-year
high school algebra course is assumed.
The examination contains approximately 100 questions to be answered in 90 minutes. Some of
these are pretest questions and will not be scored. The time candidates spend on tutorials and
providing personal information is in addition to the actual testing time.
Knowledge and Skills Required
Questions on the Information Systems and Computer Applications examination require candidates
to demonstrate knowledge of the following content. The percentages next to each main topic
indicate the approximate percentage of exam questions on that topic.
Information Systems and Office Application Software in Organizations
Standard office suite tools (word processors, spreadsheets, presentation packages, end-user
database packages)
Basic user functions of a desktop operating system
Office systems (electronic mail, conferencing, cooperative work environments)
Web browsers
Internet and other online services and methods (World Wide Web, FTP, Web search engines,
Web bots)
22
Specialized systems (statistical analysis, expert systems, DSS, GIS, BI)
Electronic Data Interchange
Enterprise-wide systems (ERP, CRM, SCM)
23
Other
Command processing time
Settle time
24
US: 14918, NQF Level 3 Worth 5 Credits
Learning Unit 2
Describe the principles of Computer Programming
Open.
The credit value of this unit is based on a person having the prior knowledge
Learning and skills to:
Assumed to be Demonstrate an understanding of fundamental mathematics (at
least NQF level 3)
in Place
Demonstrate PC competency skills (End User Computing unit
standards up to Level 3).
25
Session 1
Describe problem analysis and program design techniques.
SO 1
(Assessment The description identifies different problem analysis techniques (at least 2).
The description provides an appreciation of the steps and techniques of program maintenance.
Program development can be described as a seven step process:
1. Understand the problem.
2. Plan the logic of the program.
3. Code the program using a structured high level computer language.
4. Using a compiler, translate the program into a machine language.
5. Test and debug the program.
6. Put the program into production.
7. Maintain and enhance the program.
Planning the logic of the program requires the development of algorithms. An algorithm is a finite,
ordered set of unambiguous steps that terminates with a solution to the problem. Human readable
representations such as flow charts and pseudo code are typically used to describe the steps of an
algorithm and the relationships among the steps. A flow chart is a graphical representation of the
steps and control structures used in an algorithm. A flow chart does not involve a particular
programming language, but rather uses a set of geometric symbols and flow control lines to describe
the algorithm. From a flowchart, a programmer can produce the high level code required to compile
an executable program. Initially, the standard for describing flow charts only specified the types of
shapes and lines used to produce a flow chart. The introduction of structured programming in the
1960�s and 70�s brought with it the concept of Structured Flow Charts. In addition to a standard
set of symbols, structured flow charts specify conventions for linking the symbols together into a
complete flow chart. The structured programming paradigm evolved from the mathematically
proven concept that all problems can be solved using only three types of control structures:
Sequence, Decision (or Selection),Iterative (or looping).
The definition of structured flow charts used in this document and software further defines:
26
3 types of sequential structures: Process, Input/Output, and Subroutine Call
3 types of decision structures: Single Branch, Double Branch, and Case.
4 types of iterative structures: Test at the Top, Test at the Bottom, Counting, and User Controlled
Exit.
A comment structure.
The SFC program is designed to aid the programmer in designing and presenting structured flow
charts.
The description identifies different problem analysis techniques (at least 2).
Top-down and bottom-up are both strategies of information processing and knowledge ordering,
used in a variety of fields including software, humanistic and scientific theories and management
and organization. In practice, they can be seen as a style of thinking and teaching.
A top-down approach (also known as stepwise design or deductive reasoning, and in many cases
used as a synonym of analysis or decomposition) is essentially the breaking down of a system to gain
insight into its compositional sub-systems. In a top-down approach an overview of the system is
formulated, specifying but not detailing any first-level subsystems. Each subsystem is then refined in
yet greater detail, sometimes in many additional subsystem levels, until the entire specification is
reduced to base elements. A top-down model is often specified with the assistance of "black boxes",
these make it easier to manipulate. However, black boxes may fail to elucidate elementary
mechanisms or be detailed enough to realistically validate the model. Top down approach starts
with the big picture. It breaks down from there into smaller segments.
A bottom-up approach (also known as inductive reasoning,[1] and in many cases used as a synonym
of synthesis) is the piecing together of systems to give rise to grander systems, thus making the
original systems sub-systems of the emergent system. Bottom-up processing is a type of information
processing based on incoming data from the environment to form a perception. Information enters
the eyes in one direction (input), and is then turned into an image by the brain that can be
interpreted and recognized as a perception (output). In a bottom-up approach the individual base
elements of the system are first specified in great detail. These elements are then linked together to
form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete
top-level system is formed.
27
existing components are selected and integrated into the product. An example would include
selecting a particular fastener, such as a bolt, and designing the receiving components such that the
fastener will fit properly. In a top-down approach, a custom fastener would be designed such that it
would fit properly in the receiving components.] For perspective, for a product with more restrictive
requirements (such as weight, geometry, safety, environment, etc.), such as a space-suit, a more
top-down approach is taken and almost everything is custom designed. However, when it's more
important to minimize cost and increase component availability, such as with manufacturing
equipment, a more bottom-up approach would be taken, and as many off-the-shelf components
(bolts, gears, bearings, etc.) would be selected as possible. In the latter case, the receiving housings
would be designed around the selected components.
Modularity
Modularity is designing a system that is divided into a set of functional units (named modules) that
can be composed into a larger application. A module represents a set of related concerns. It can
include a collection of related components, such as features, views, or business logic, and pieces of
infrastructure, such as services for logging or authenticating users. Modules are independent of one
another but can communicate with each other in a loosely coupled fashion. A composite application
exhibits modularity. For example, consider an online banking program. The user can access a variety
of functions, such as transferring money between accounts, paying bills, and updating personal
information from a single user interface (UI). However, behind the scenes, each of these functions is
a discrete module. These modules communicate with each other and with back-end systems such as
database servers. Application services integrate components within the different modules and
handle the communication with the user. The user sees an integrated view that looks like a single
application.
Figure 1 illustrates a design of a composite application with multiple modules.
28
Module composition
Why Choose a Modular Design?
The following scenarios describe why you might want to choose a modular design for your
application:
Simplified modules. Properly defined modules have a high internal cohesion and loose coupling
between modules. The coupling between the modules should be through well-defined
interfaces.
Developing and/or deploying modules independently. Modules can be developed, tested,
and/or deployed on independent schedules when modules are developed in a loosely coupled
way. By doing this, you can do the following:
o You can independently version modules.
o You can develop and test modules in isolation.
o You can have modules developed by different teams.
Loading modules from different locations. A Windows Presentation Foundation (WPF)
application might retrieve modules from the Web, from the file system and/or from a database.
A Silverlight application might load modules from different XAP files. However, most of the time,
the modules come from one location; for example, there is a specific folder that contains the
modules or they are in the same XAP file.
Minimizing download time. When the application is not on the user's local computer, you want
to minimize the time required to download the modules. To minimize the download time, only
29
download modules that are required to start-up the application. The rest are loaded and
initialized in the background or when they are required.
Minimizing application start-up time. To get part of the application running as fast as possible,
only load and initialize the module(s) that are required to start the application.
Loading modules based on rules. This allows you to only load modules that are applicable for a
specific role. An application might retrieve from a service the list of modules to load.
Pseudocode and flowcharts are both popular ways of representing algorithms. Pseudocode has been
chosen as the primary method of representing an algorithm because it is easy to read and write, and
allows the programmer to concentrate on the logic of the problem. Pseudocode is really structured
English. It is English that has been formalised and abbreviated to look like the high-level computer
languages. Pseudocode provides another way to represent program logic. The approach is to write
the program in a language similar to the one used for implementation but with an easily understood
shorthand for complex expressions. The idea is to represent the logic but to ignore many of the
syntactic requirements of the programming language. A pseudocode design description is thus a
mixture of human language and programming constructs. Instead of the complete logic for well-
known functions, simple statements are used. Similarly, the program flow can be represent with
traditional conditional statements, using written expressions to describe the logic. While there are
no generally accepted pseudocode notation standards, it is a good idea to use language constructs
that are similar to those in the high-level language being used. When you do, the psedocode will
look familiar at implementation time and will provide a framework for implementation. Because
pseudocode does not require the programming language details, it is generally easier and quicker to
produce than a completed source program. While there is no standard pseudocode, once you
understand one version, it is easy to understand other versions. Many programmers use
pseudocode. Abstract versions of it are used to express abstract algorithms. More language specific
versions of it are used to express design for programs in those languages. Pseudocodes supposed to
be clear enough that a human being can execute it “by hand,” without using a computer and with
30
little or no knowledge of programming languages. Pseudocode is used to represent the
algorithm. The common characteristics of pseudocode:
Statements are written in simple English
Each instructions is written on a separate line
Keywords and indentation are used to signify particular control structures
Each set of instructions is written from top to bottom, with only one entry and one exit
Groups of statements may be formed into modules, and the module given a name
Pseudocode is an English-like nonstandard language that lets you state your solution with more
precision than you can in plain English but with less precision than is required when using a formal
programming language. Pseudocode permits you to focus on the program logic without having to be
concerned just yet about the precise syntax of a particular programming language. However,
pseudocode is not executable on the computer.
Documenting the Program
Documenting is an ongoing, necessary process, although, as many programmers are, you may be
eager to pursue more exciting computer-centered activities. Documentation is a written detailed
description of the programming cycle and specific facts about the program. Typical program
documentation materials include the origin and nature of the problem, a brief narrative description
of the program, logic tools such as flowcharts and pseudocode, data-record descriptions, program
listings, and testing results. Comments in the program itself are also considered an essential part of
documentation. Many programmers document as they code. In a broader sense, program
documentation can be part of the documentation for an entire system.
The wise programmer continues to document the program throughout its design, development, and
testing. Documentation is needed to supplement human memory and to help organize program
planning. Also, documentation is critical to communicate with others who have an interest in the
program, especially other programmers who may be part of a programming team. And, since
turnover is high in the computer industry, written documentation is needed so that those who come
after you can make any necessary modifications in the program or track down any errors that you
missed.
31
Session 2
Describe different data representations used in computer programs.
SO 2
The description distinguishes between different numeric data types (at least 3).
Binary, Decimal, Hexadecimal, Octal.
Numerical Notations: Hexadecimal, Decimal, Octal, and Binary
Since most programming languages accept literal constants in the same decimal notation that we all
learned as children, it is not uncommon for a programmer to master many of the basic programming
techniques and concepts before they ever feel the need to use an alternate notation. Even assembly
languages can be used without leaving the comfort of decimal notation. While decimal notation is
appropriate for mathematical calculations, it conceals much of the underlying structure implicit in
the way data is stored and handled internally by the computer. For certain tasks, representing data
in hexadecimal or binary notation can provide deeper insights into exactly what a program is doing.
They can also help illuminate some of the limitations of numerical data types.
Getting out of our own way
Binary, hexadecimal, and octal notations are not difficult to learn. In fact, you already know the most
fundamental concepts required to use the notations. They are all inspired by the same underlying
principle that defines the decimal system, which you mastered long before you learned the
mathematics required to even casually describe it. The most difficult obstacle that many face is the
unquestioned assumption that a number is identical with its representation. To handle data flexibly,
we have to realize the when we write a combination of symbols, such as32, we are using merely a
representation of a number. There is nothing intrinsic about the number thirty-two that demands
that it be represented by those specific symbols. None of its arithmetic or algebraic properties
depend upon the visual symbols 3 and 2. The decimal notation developed because it was found to
be convenient for manipulating the symbols used to represent numbers and helped provide insight
into their mathematical relationships. It is, however, just one member of an infinite family of similar
notation systems. To help us move past this obstacle, we'll begin by taking a closer look at how
32
decimal notation is used. This discussion is not intended to be a rigorous mathematical inquiry, and
you may find other descriptions that use an entirely different approach. The goal here is merely to
highlight the salient features of the decimal system that will help us understand hexadecimal, octal,
and binary notations. For simplicity, we are going to focus only on unsigned whole integer values,
and disregard negative values and decimal points.
The Decimal System
Modern decimal notation is a positional system. To understand what this means, lets review the
basic task of counting. To count aloud, we merely recite a list of words in a specific sequence.
zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen.....
When we want to write this sequence, rather than spell out the spoken representation, we resort to
a compact notation using only ten unique symbols.
0, 1, 2 ,3 ,4, 5, 6, 7, 8, 9
At this point, we have used all ten of our symbols, so to provide a unique representation of the next
highest integer, we need more than one digit. We can rewrite our sequence as two digit values like
this:
00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 , 20, 21, 22, 23....
It may help to envision a mechanical counter like an old style odometer display. Each position
consists of a wheel with the numerals 0 through 9 printed in order on the outer circumference. As
each wheel rolls over from 9 to 0, the wheel to the left is advanced one digit. This step is often called
the carry, as in the expression "carry the one".
With two digits, we can continue with this pattern until we reach 99. After that we will need a third
digit.
000, 001, 002, 003, 004, 005, 006, 007, 008, 009,010 ... 098, 099, 100, 101, 102 ... 998, 999
Each digit occupies a position. The position at the furthest right, is position 0. The next position to
the left is position 1, and so on through each position.
The following table shows the position of the digits in the decimal number 2993.
Position 4 3 2 1 0
Digit 0 2 9 9 3
The number, or value, represented by the sequence of digits 2993, is the sum of the value of each
digit, and the value of each digit is determined by the position in which it appears.
So, with the sequence 2993 we have:
Position Digit Value
0 3 3*1=3
1 9 9* 10 = 90
33
2 9 9 * 100 = 900
3 2 2 * 1000 = 2000
3 + 90 + 900 + 2000 = 2993
You should notice that each position indicates a power of ten. In position 2, the digit was multiplied
by 102. In position 3, the digit was multiplied by 103.
Also, notice that the maximum value that can be represented by a given number of digits is one less
than a power of ten.
Number of digits Maximum Value
1 101 - 1 = 9
2 102 - 1 = 99
3 103 - 1 = 999
...
10 1010 - 1 = 9999999999
In general, the maximum value that can be represented in the decimal notation when n digits are
used is 10n-1. Since the lowest value is 0, this mean that n digits can represent 10nunique values. The
key to making this system work is the use of the symbol 0as a place holder in any position that does
not contribute to the value of the number represented. Without this place holder, expressing a
number such as 202 would be very difficult. Normally, in the decimal notation, we don't indicate the
digits on the left of a number when they are zero, so instead of 0021, we usually simply write 21.
Conceptually, though, you can imagine an infinite list of zeros preceding any number written in
decimal notation.
Binary
The binary notation works exactly the same way as the decimal notation, but instead of ten symbols,
only two symbols are used: 0 and 1. Whereas decimal is a base 10 positional notation, binary is a
base 2 positional notation.
A digit in binary, is usually referred to as a bit.
With one bit, we have two possible values:
0, 1
So, in binary, with one bit, we can count from zero to one. To count higher requires more bits. With
two bits, we can count as high as three.
Decimal: 0, 1, 2, 3
Binary: 00, 01, 10, 11
The same pattern applies here as it did in the decimal notation. When a digit in one position rolls
over from the highest numeral (1) to the lowest (0), the digit to the left increases. To avoid any
34
confusion it should be explicitly stated here that in binary notation, 10 represents the number two. It
does not represent the number ten. For years, our minds have associated the combination of
symbols 10 with the concept "ten". This association is so strong that it can be difficult to temporarily
put aside. It may help to realize that the symbols 0 and 1 are merely a convention. If we like, we
could adopt any other two symbols, such as Tand H. Let's say T represents zero, and H represents
one.
We can rewrite the above sequence this way:
Decimal: 0, 1, 2, 3
Binary: TT, TH, HT, HH
Unfortunately, when we want to express data in a binary notation that our compiler or interpreter
will understand, we must return to the conventional symbols 0 and 1. In general, with n bits, we can
represent the values 0 to 2n- 1. The total number of unique values we can represent when we
have n bits, including 0, is 2n. To convert from the binary notation to the decimal notation, we can
use the same arithmetic that we used to determine the value of a number in decimal notation.
In binary, the value of a bit is multiplied by 2position. Again, the right most position is position 0.
So the decimal notation equivalent of the binary 1101 is:
Position Bit Value
0 1 1 * 20 = 1
1 0 0 * 21 = 0
2 1 1 * 22 = 4
3 1 1 * 23 = 8
1 + 4 + 8 = 13
You should notice that value of each bit is either zero or an integral power of two. This is true
because each bit may hold only one of two states: 0 or 1. Given an eight bit binary number, the
resulting value will be the sum of one or more of the decimal values: 1 ,2 ,4, 8, 16, 32, 64, and 128.
Given a four bit value, that list is reduced to: 1,2,4, and 8.
Here is an example using the binary value 1001.
(8 * 1 ) + ( 4 * 0 ) + ( 2 * 0 ) + (1 * 1 ) = 8 + 1 = 9
So the decimal equivalent of the binary number 1001 is 9.
The key concept is that these are equivalent representations. They both signify the same number.
Why use the binary notation?
The binary notation is used to closely represent the way information in physically implemented by a
computer. Since an individual bit can only be in one of two states, designing machinery or circuitry
to manipulate bits is well understood and these designs can be aggregated to perform operations on
35
collections of bits. In fact, while a computer's memory can be visualized as a very long sequence of
individual bits, most microprocessors are not designed to perform operations on one bit at a time.
Instead, the processor's architecture defines the least number of contiguous bits which it may be
addressed and manipulated during one machine instruction. This least number of bits that a
processor may manipulate at one time is called a BYTE. In the past, the size of a BYTE varied from
one design to another, but over time, most designs have settled on a BYTE size of 8 bits. This is the
BYTE used by processors that implement the Intel x86 architecture, which is the architecture on
which most modern PC processors are based. The original version of the x86 architecture provided
means to work with a single BYTE and with a pair of bytes called a WORD. A WORD, being composed
of two BYTEs, is a 16 bit wide field. With extensions to the architecture, the ability to work directly
upon 32 bit double words (DWORD) was added, and on some machines 64 bit quadruple words
(QWORD) may be handled by a single instruction.
This gives us the following common primitive data types:
BYTE 8 bits
WORD 16 bits
DWORD 32 bits
QWORD 64 bits
At the source code level, binary notation is rarely used to represent numerical data. Decimal
notation is much more intuitive, and almost all programming languages support decimal notation
directly in source code. Binary notation is usually only used to explicitly indicate the specific bits in a
data field. The interpretation of such data is, of course, dependant on the program, but common
usages include option flags, data masks, bit patterns, packed data, etc.When binary notation is used,
the value of all bits in the data field are usually explicitly indicated, including leading zeros. So, to
specify the contents of a single BYTE in binary, all eight bits would be included in the notation. For
example, to indicate that only bit 0 and bit 4 should be "on", it might be written like this: 00010001.
The exact syntax required to specify binary notation depends on the programming language used.
Ansi C, in fact, does not specify any method for giving literal constants in binary notation.
Hexadecimal
Using binary notation can be cumbersome and prone to typing mistakes. If we wanted to specify a
16 bit value with all bits off except bit 9 in binary notation, it would look something like this (in
FreeBASIC syntax):
&b0000001000000000
If you can verify that the 1 is in the 9th position in less than ten seconds, you deserve a pat on the
back.
36
The Hexadecimal notation provides a more compact form, but it retains a visual similarity to the
underlying machine representation of a value.
Hexadecimal is a base 16 positional notation. It uses sixteen symbols.
Hexadecimal digit Binary Equivalent Decimal Equivalent
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
A 1010 10
B 1011 11
C 1100 12
D 1101 13
E 1110 14
F 1111 15
Hexadecimal notation is often abbreviated to Hex. Strictly speaking, Hex notation would refer to a
radix 6 system, but the use of such a system is so rare that you can safely assume that Hex stands for
Hexadecimal. With one hexadecimal digit, we can represent the values 0 to F (In decimal: 0 to 15. In
binary: 0000to 1111.)
Again, this is a positional notation, so the value of a hexadecimal digit is 16position.
So 0B12, in decimal notation would be:
Position Digit Value
0 2 2 * 160 = 2
1 1 1 * 161 = 16
2 B 11 * 162 = 2816
3 0 0 * 163 = 0
2+16+2816+ 0 = 2833
In practice, converting hexadecimal notation to decimal notation by hand is rare. The utility of
hexadecimal notation consists in the compact manner that it can express an equivalent value in
37
binary notation. Since sixteen is the fourth power of two, every hexadecimal digit corresponds to at
most four bits. In other words, since four bits can only represent the values 0 to 15, exactly one
hexadecimal digit is sufficient to represent a four bit binary value. An eight bit BYTE requires no
more than two hexadecimal digits. A sixteen bit WORD requires no more than four hexadecimal
digits. This pattern holds for any bit length that is a multiple of four. Since four bits is half the bit
length of a BYTE, four bits is often called a NIBBLE. So we can say that one hexadecimal digit
represents one NIBBLE.
Converting a four bit binary value to decimal is a relatively simple activity. With a little practice it can
often be done mentally. This makes converting binary to hexadecimal trivial. Here is a thirty-two bit
value generated by flipping a coin with consecutive bits shown in groups of four with a illustration of
a conversion to hexadecimal. When performed often, this becomes second nature, and the
intermediate decimal notation can usually be skipped.
Coin Tosses: HHTT THTH HHTH THHT HHHT THHT HTHH HHTT
Binary: 1100 0101 1101 0110 1110 0110 1011 1100
Decimal equivalent of each nibble: 12 5 13 6 14 6 13 12
Hexadecimal: C5D6E6DC
To convert this value to decimal by hand would be cumbersome, and the result depends on whether
or not we are using signed or unsigned integer values. In any event, the decimal equivalent is not
simply the decimal equivalent of each NIBBLE concatenated together. C5D6E6DC is not equivalent
to 1251361461312. Using a calculator to perform the conversion to an unsigned integer, we find
that C5D6E6DC is equivalent to decimal3319195356. Every two hexadecimal digits align neatly on
byte boundaries. This makes the memory layout of hexadecimal data visually obvious. However,
when viewed this way, the "endian-ness" of the system must be considered. On the x86
architecture, multi-byte values are stored in memory in the little endian format, which means that
less significant bytes are stored at lower addresses, so the value C5D6E6DC would appear in memory
when listed by byte address like this: DC, E6, D6, C5.
Hexadecimal notation also helps highlight certain prominent bit patterns.
0 all bits clear 0000
F all bits set 1111
even low bit clear xxx0
odd low bit set xxx1
<=7 high bit clear 0xxx
>=8 high bit set 1xxx
38
The last two patterns, 0xxx and 1xxx, are useful when examining signed integer data because the
hightest bit in the most significant BYTE is used as the "sign bit" and determines whether or not the
value will be regarded as a negative number.
Octal
The octal notation is a base 8 positional notation. Valid digits are 0,1,2,3,4,5,6,7.
Note particularly, that the symbol "8" is not an octal digit.
This notation was much more common before 8 bits became the de facto standard size of a BYTE.
The interesting characteristic of the octal notation is that any combination of three bits requires at
most one octal digit. Following the same method used above, we can determine that the highest
unsigned value that n octal digits can represent is 8n-1.
Numerical Notation Syntax
The lexical conventions for specifying different numerical notations differs from one programming
language to another. Some languages support more than one convention. Some languages do not
support certain notations at all. This table demonstrates the representation of the ASCII character
code for a blank space in a number of different languages.
Language Hexadecimal Decimal Octal Binary
Ansi C 0x20 32 040 N/A
FreeBASIC &h20 32 &o40 &b00100000
Gas ( GNU assembler) 0x20 32 040 0b00100000
Nasm (Netwide Assembler) 20h 32d 40o 00100000b
20x 32t 40q 00100000y
0x20 0t32 0q40 0y00100000
0h20 0d32 0o40 0b00100000
$20 32
ECMAscript (Javascript) 0x20 32 n/a n/a
Python 0x20 32 0o40 0b00100000
040
Displaying values in different notations:
39
An integer is a whole number - it has no decimal or fractional parts. Integers can be
either positive or negative.
Examples
12
45
1274
1000000
-3
-5735
Real Numbers
Any number that you could place on a number line is a real number. Real numbers include whole
numbers (integers) and numbers with decimal/fractional parts. Real numbers can
be positive or negative.
Examples
1
1.4534
946.5
-0.0003
3.142
You might see this data type referred to as 'single', 'double' or 'float'.
Currency
40
Currency refers to real numbers that are formatted in a specific way. Usually currency is shown with
a currency symbol and (usually) two decimal places.
Examples
£12.45
-£0.01
€999.00
$5500
Percentage
Percentage refers to fractional real numbers that are formatted in a specific way - out of 100, with
a percent symbol. So, the real value 0.5 would be shown as 50%, the value 0.01 would be shown
as 1% and the number 1.25 would be shown as 125%
Examples
100%
25%
1200%
-5%
Inside the computer the 50% is stored as a real number: 0.5, But when it is displayed it is
shown formatted as a percentage
Alphanumeric (Text) Data
Alphanumeric (often simply called 'text') data refers to data made up of letters (alphabet)
and numbers (numeric). Usually symbols ($%^+@, etc.) and spaces are also allowed.
Examples
41
DOG
“A little mouse”
ABC123
Text data is often input to a computer with speech marks (". . .") around it:
"MONKEY"
These tell the computer that this is text data and not some special command.
Date and Time Data
Date (and time) data is usually formatted in a specific way. The format depends upon the setup of
the computer, the software in use and the user’s preferences.
Date Examples
25/10/2007
12 Mar 2008
10-06-08
Time Examples
11am
15:00
3:00pm
17:05:45
With inputting dates particular care has to be taken if the data contains American style dates and
the computer is setup to expect international style dates (or vice-versa)...
The date 06/09/08 refers to 6th September 2008 in the international system, but would be 9th June
2008 in America! Check your computer’s settings.
42
Boolean (Logical) Data
Boolean data is sometimes called 'logical' data (or in some software, 'yes/no' data). Boolean data
can only have two values: TRUE or FALSE
Examples
TRUE
FALSE
ON
OFF
YES
NO
Note that TRUE and FALSE can also be shown as YES / NO, ON / OFF, or even graphically as tick
boxes(ticked / unticked)
Selecting Data Types
When we are presented with data to be input into a computer system, we must analyse it and
select appropriate data types for each value... e.g. For the following data, we might use the date
types shown:
Data Name
Name
Height
Date of Birth
Phone No.
Pay Rate
Tax Rate
Data Type
Text
Real
Date
Alphanumeric
Currency
43
Percentage
44
Integer data types store the numbers just like you'd expect. IDL supports integers of four different
lengths: 1, 2, 4, and 8 bytes. The shorter the word, the less memory required; the longer the word,
the larger the numbers can be. Different requirements require different compromises.
2.1. 1 byte: The Byte Data Type
The byte data type is a single byte long and always positive. Therefore, it's values run
0 255. Images are always represented in bytes. The data might not be in bytes, but the numbers
that the computer sends to the video processor card are always bytes. Video screens require lots of
memory and really quick processing speed, so bytes are ideal. You generate an array
using bytarr() for zeroed array or bindgen() for index array; you can generate a single byte variable
by saying x=3b for example. If a byte number exceeds 255 during a calculation, then it will "wrap
around"; for example, 256 wraps to 0, 257 to 1, etc.
2.2. 2 byte: Integers and Unsigned Integers
With 2 bytes, numbers that are always positive are called Unsigned Integers. They can range from
0 256 2-1, or 0 65535. You generate an array using uintarr() for zeroed array or uindgen() for
index array. How do you think unsigned integers wrap around? Normally you want the possibility of
negative numbers and you use Integers. The total number of positive integer values is 256 2 / 2 =
32768. One possible value is, of course, zero. So the number of negative and positive values differ
by one. The choice is to favor negative numbers, so integers cover the range -32768 32767. You
generate an array using intarr() or indgen(). What happens with wrap around? What if x = 5, y =
30000 and z = x * y? Check it out!
2.3. 4 bytes: Long Integers and Unsigned Long Integers
The discussion here is exactly like that for 2-byte integers, except that 256 2 becomes 256 4. What
are the limits on these numbers? See IDL help under "Data Types" and "Integer Constants" for more
information. You generate arrays using ulonarr() or ulindgen() and lonarr() or lindgen().
2.4. 8 bytes: 64-bit Long Integers and Unsigned 64-bit Long Integers
The discussion here is exactly like that for 2-byte integers, except that 256 2 become 256 8. What
are the limits on these numbers? See IDL help under "Data Types" and "Integer Constants" for more
information. You generate arrays using ulon64arr() or ul64indgen() and lon64arr() or l64indgen().
3. FLOATING DATA TYPES IN IDL
The problem with integer data types is that you can't represent anything other than integral
numbers - no fractions! Moreover, if you divide two integer numbers and the result should be
fractional, it won't be; instead, it will be rounded down (e.g., 5/3 is calculated as 1). To get around
this, the floating data type uses some of the bits to store an exponents, which may be positive or
45
negative. You throw away some of the precision of the integer representation in favor of being able
to represent a much wider range of numbers.
3.1. 4 bytes: Floats
"Floating point" means floating decimal point - it can wash all around. With Floats, the exponent
can range from about -38 -> +38 and there is about 6 digits of precision. You generate an array
using fltarr() orfindgen() and a single variable by including a decimal point (e.g., x = 3.) or using
exponential notation (e.g., x = 3e5).
3.2. 8 bytes: Double-Precision
Like Float, but the exponent can range from about -307 -> +307 and there is about 16 digits of
precision. You generate an array using dblarr() or dindgen() and a single variable by writing
something like x = 3d or x = 3d5.
4. STRINGS
Strings store characters - letters, symbols, and numbers (but numbers as characters - you can't
calculate with strings!) A string constant such as hello consists of five letters. It takes 5 bytes to
store this constant - one byte for each character. There are 256 possible characters for each of the
bytes; with 2*26 letters (smalls and caps) and 10 digits, this leaves 104 other possibilities, which are
used for things like semicolon, period and etc. You can generate an array of strings
with strarr() or sindgen() and a single string using ' ' like this: x = 'Hi there!!!'.
5. STRUCTURES
Structures are a special data type that allows variables of different types and sizes to be packaged
into one entity. This is different from an array, where every element must be the same data
type. There are two kinds of structures in IDL: an anonymous structure (a package of arbitrary
variables) and a named structure (a package of variables that conform to a template created by the
user). Structures are used
46
Logical Operators
Common Lisp provides three operators on Boolean values: and, or, and not. Of these, and and or are
also control structures because their arguments are evaluated conditionally. The
function not necessarily examines its single argument, and so is a simple function.
The logical operators are described in the following table:
Operator Usage Description
Logical expr1 &&expr2 Returns expr1 if it can be converted to false; otherwise, returns expr2.
AND Thus, when used with Boolean values, && returns true if both
(&&) operands are true; otherwise, returns false.
Logical expr1 ||expr2 Returns expr1 if it can be converted to true; otherwise, returns expr2.
OR (||) Thus, when used with Boolean values, || returns true if either operand
is true; if both are false, returns false.
Logical !expr Returns false if its single operand can be converted to true; otherwise,
NOT (!) returns true.
Fortran has five LOGICAL operators that can only be used with expressions whose results are logical
values (i.e., .TRUE. or .FALSE.). All LOGICAL operators have priorities lower
than arithmetic and relationaloperators. Therefore, if an expression involving arithmetic, relational
and logical operators, the arithmetic operators are evaluated first, followed by the relational
operators, followed by the logical operators.
These five logical operators are
.NOT. : logical not
.AND. : logical and
.OR. : logical or
.EQV. : logical equivalence
.NEQV. : logical not equivalence
47
Session 3
Describe the basic principles of Computer Programming.
SO 3
48
The selection or decision structure can be described as shown in the pseudocode The selection
structure in pseudocode.
Enter
Test a condition for true or false
On true
Take one or more actions in sequence
On false
Take none, one, or more actions in sequence
Exit
Test a condition for true or false
Once again, there is only one entry point and one exit point. The first thing that happens following
entry is that some condition is tested for true or false. If the condition is true, one or more actions
are taken in sequence and control exits the structure. If the condition is false, none, one or more
different actions are taken in sequence and control exits the structure. (Note the inclusion of the
word none here.)
The action elements may themselves be structures
Once again, each of the action elements in the sequence may be another sequence, selection, or
loop structure. Eventually all of the actions for a chosen branch will be completed in sequence and
control will exit the structure.
Sometimes no action is required on false
It is often the case that no action is required when the test returns false. In that case, control simply
exits the structure without performing any actions.
The loop structure
The loop or iteration structure can be described as shown in the pseudocode
The loop structure in pseudocode.
Enter
Test a condition for true or false
Exit on false
On true
Perform one or more actions in sequence.
Go back and test the condition again
As before, there is only one entry point and one exit point.
Perform the test and exit on false
The first thing that happens following entry is that a condition is tested for true or false.
49
If the test returns false, control simply exits the structure without taking any action at all.
Perform some actions and repeat the test on true
If the test returns true:
One or more actions are performed in sequence.
The condition is tested again.
During each iteration, if the test returns false, control exits the structure. If the test returns true, the
entire cycle is repeated.
Each action element may be another structure
Each of the action elements may be implemented by another sequence, selection, or loop structure.
Eventually all of the actions will be completed and the condition will be tested again.
Need to avoid infinite loops
Generally speaking, unless something is done in one of the actions to cause the test to eventually
return false, control will never exit the loop.
In this case, the program will be caught in what is commonly referred to as an infinite loop.
The description identifies good program documentation principles (at least 3).
Internal documentation
50
The variable declaration comments are one part of good internal documentation. Internal
documentation is the set of comments that are included within the code to help clarify algorithms.
Some students take internal documentation to mean that they should comment each line of code!
This is obviously an example of overdoing a good idea. Any programmer knows how to increment a
value in a variable; there's no reason to explain trivial operations such as that. The value of some
good internal documentation should be clear by looking at the latest version of our sample program.
Even with the good code organization and variable names, the function of this program is still not
obvious.
A critical point: Documentation and internal documentation in particular, should be written and
included in the program as the code is being written. Students tend to get in the habit of writing the
code and then tossing in some documentation only if they have time before the due date. This
makes documenting seem even more boring and tedious that it already is, and students who rush
the documentation at the last minute usually do a very mediocre job. Documentation should be
written when the code is being written, and should be typed in as the code is typed in. To
demonstrate some of these points, here's yet another version of our program, this time containing
some acceptable internal documentation:#include <stdio.h>
The trick with internal documentation is to make it easy to find while at the same time ensuring that
it's not making the code hard to read. Block comments can be partially boxed (as shown) to separate
them from the code. The use of the '*' at the start of each line of the shorter clarifying comments in
the code serves a similar purpose. There's no one right way to do this, but it does need to be done.
51
Experiment with some styles and pick one you like. One piece of advice: Don't fall in love with the
"complete box" style. Lots of students like to completely enclose the block comments within a box.
This looks great, but the right-hand wall of the box is very hard to keep lined up as you make
adjustments and additions to the comments. The "three wall" style shown above is much easier to
deal with and looks almost as good.
External documentation
In a professional programmer's shop, large projects are documented in great detail, not only with
comments in the code but with descriptions that are maintained separately from the code. In such
an environment, programmers are often asked to fix problems in code that they didn't write. Many
times, the author of the code isn't even with the company any longer. The documentation may be all
the programmer has as reference material to help him or her make the necessary
modifications. External documentation doesn't deal with details of the code. Instead, it serves as a
general description of the project, including such information as what the code does, who wrote it
and when, which common algorithms it uses, upon which other programs or libraries it is
dependent, which systems it was designed to work with, what form and source of input it requires,
the format of the output it produces, etc. Often the external documentation will include structure
charts of the outline of the program that were produced when the program was being designed. All
of this information is necessary to help other programmers understand the program. One seemingly
innocent change in a program can have unpredictable consequences on other parts of the system.
Good documentation can help prevent such problems.
In most programming classes, it is impractical for instructors to require large amounts of external
documentation for programs that are only a few hundred lines long. Instead, it is common for
instructors to require that a small amount of external documentation be included at the top of the
program in the form of a large block comment. This condensed version should include at least the
following pieces of information:
1. Your name, the course name, assignment name/number, instructor's name, and due date.
2. Description of the problem the program was written to solve.
3. Approach used to solve the problem. This should always include a brief description of the major
algorithms used, or their names if they are common algorithms.
4. The program's operational requirements: Which language system you used, special compilation
information, where the input can be located on disk, etc.
5. Required features of the assignment that you were not able to include.
52
6. Known bugs should be reported here as well. If a particular feature does not work correctly, it is
in your best interest to be honest and complete about your program's shortcomings.
The final version of the program is given at the end of this document. Look it over carefully. Do you
understand what the program does? More importantly for this discussion, do you understand how it
does it? If the indentation, identifier names, and documentation helped, then they were well worth
the time it took the programmer to put them in. Hopefully, you'll now see the value of putting such
documentation in your programs as well. Take the time to ask yourself if you think the design of the
comments is a good one; are the comments easy to find and to read? Do they distract from the code
excessively? Are there too many of them to suit you, or too few? By asking and answering questions
such as these, you will begin to develop a style of your own. When you see documentation styles
that you like, consider adopting them into your own style. Soon you'll have one you like, and as a
result you'll be more likely to use it.
There are plenty of decisions that were made in the design and documentation of this program that
can be questioned and improved on. As you gain more experience in programming, consider
revisiting this program and trying to rewrite it from scratch. Perhaps you can think of a better way to
generate the times, for example. There isn't a program in existence that can't be improved, and this
one is certainly no exception.
53
The description identifies programming quality assurance (QA) principles.
Quality Information Systems: Vital to Total Quality Management
Heightened global competition has made it imperative for organizations to deliver products - goods
and services - of consistently high quality. The principles of total quality management (TQM)
recognize that consistent product quality results from designing and executing business processes so
as to remove error and waste.
Product quality is the result of :
a. Customer focus
b. Introduction and continuous improvement of business processes and product-development
processes that reduce variations
c. Creation of a company-wide quality culture through motivation and training of all its members
d. Continuous measurement and analysis of the accomplished results.
International Standards Organization (ISO) 9000 - many companies, particularly in the manufacturing
sectors, comply with the ISO 9000 group of quality standards. Such compliance is mandatory for
those selling any of a broad range of products to the countries of the European Union. Some other
countries also require this certification. The standards aim to ensure quality of products by certifying
quality assurance during business processes, such as product design, manufacturing, delivery, and
service support. Extensive quality-oriented information processing is a prerequisite for a certification
of compliance.
Software Quality
There are many attributes of software quality. These include:
1. Effectiveness
54
2 Usability
3. Efficiency
4. Reliability
5. Maintainability
6. Understandability
7. Modifiability
8. Testability
Effectiveness Refers to the satisfaction of the user and organizational requirements as established
during an analysis of these requirements, possibly using prototyping.
Usability The ease with which the intended users can use the system, depend on the proper user-
system interface.
Efficient operation is reflected mainly in how economically hardware resources are used to satisfy
the given effectiveness requirements
Reliability Refers to the probability that the information system will operate correctly; that is,
according to specifications over a period of time. It may also be defined as the mean time between
failures. Software reliability is rooted in its freedom from defects. If a system must run on different
hardware or systems software platforms, portability should be included as a desired attribute.
Maintainability Refers to ease of understanding, modifying, and testing.
Understandability Is achieved by readable and well-commented system code and by
documentation, which includes the requirements specifications, system documentation, user
manuals, and, sometimes special maintenance documentation.
Modifiability Means that it is relatively easy to identify and change any part of the system that
requires maintenance without affecting its other parts.
Testability Is the ease with which we can demonstrate that a modification resulted in a quality
system.
The following are the principal aspects of TQM - oriented quality assurance for information systems:
1. Customer focus is achieved by involving end users in the IS development process, particularly
during its early stages when the requirements for the system are being defined. Systems prototyping
and joint application development (JAD) are the principal techniques applied to this end. Joint
55
Application Development (JAD) is an organizational technique for conducting meetings between the
prospective users of an information system and its developers.
2. The life-cycle oriented systems development, with the inclusion of prototyping, is a process that
lends itself to control, measurement, and continuous improvement. Support with CASE tools helps
to ensure product quality.
3. Software development and maintenance teams are the primary human element in ensuring
software quality.
4. The quality measurement program can assist in consistent striving for higher quality levels. Such a
program rests on the foundation of software metrics. Software matrices include techniques for
measuring the attributes of software and techniques for measuring the attributes of software
development process.
56
diagrams and the program source code. Dynamic techniques or tests involve exercising an
implementation.
Static techniques include program inspections, analysis and formal verification. Some theorists have
suggested these techniques should completely replace dynamic techniques in the verification and
validation process and that testing is not necessary, this is not a useful point of view and could be
'considered harmful'. Static techniques can only check the correspondence between a program and
its specification (verification). They cannot demonstrate that the software is operationally useful.
Although static verification techniques are becoming more widely used, program testing is still the
predominant verification and validation technique. Testing involves exercising the program using
data like the real data processed by the program. The existence of program defects or inadequacies
is inferred fromunexpected system outputs. Testing may be carried out during the implementation
phase to verify that the software behaves as intended by its designer. This later testing phase checks
conformance with the requirements and assesses the reliability of the system.
The description explains the relationship between files, records and fields.
What is a Record?
The set of data associated with a single object or person is known as a record. In the example of our
students, the data associated with each student is a record.
Here is Jess's record...
Each student has their own record just like Jess's but with different data. The data in each record
is different, but each record has the same structure. (each one has a name, d.o.b., phone, etc.) We
say that each record contains the same fields. A database is a collection of records. You can imagine
a single record being a card with one the details of one person/object written on it.
57
This is exactly how a lot of old, manual databases used to look. If you went to a public library 30
years ago, and you wanted to find a specific book, you would have to look through boxes of index
cards until you found the details of your book.
What is a Field, and What is a Field Name?
You'll see that each of our student's records contain the same items. These items are known
as fields. Each field has a field name (e.g. 'Date of Birth') Each field will contain different data in
each of the records (e.g. in Jess's record, the Phone field contains 7564356, but in Sita's record the
Phone field contains 8565634 - same field, different data values) It can be a bit confusing - what's
the difference between the field, the field name, and the data in the field?! Imagine that you were
manually filling in a record card for Jess. The card would have various labels and boxes to write in...
58
Session 4
Describe the principles used in designing a computer program.
SO 4
59
Top-down and bottom-up are both strategies of information processing and knowledge ordering, used in a
variety of fields including software, humanistic and scientific theories ( systemic), and management and
organization. In practice, they can be seen as a style of thinking and teaching.
[1]
A top-down approach (also known as stepwise design or deductive reasoning, and in many cases used as a
synonym of analysis or decomposition) is essentially the breaking down of a system to gain insight into its
compositional sub-systems. In a top-down approach an overview of the system is formulated, specifying but
not detailing any first-level subsystems. Each subsystem is then refined in yet greater detail, sometimes in
many additional subsystem levels, until the entire specification is reduced to base elements. A top-down
model is often specified with the assistance of "black boxes", these make it easier to manipulate. However,
black boxes may fail to elucidate elementary mechanisms or be detailed enough to realistically validate the
[
model. Top down approach starts with the big picture. It breaks down from there into smaller segments.
A bottom-up approach (also known as inductive reasoning, and in many cases used as a synonym of synthesis)
is the piecing together of systems to give rise to grander systems, thus making the original systems sub-
systems of the emergent system. Bottom-up processing is a type of information processing based on incoming
data from the environment to form a perception. Information enters the eyes in one direction (input), and is
then turned into an image by the brain that can be interpreted and recognized as a perception (output). In a
bottom-up approach the individual base elements of the system are first specified in great detail. These
elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in
many levels, until a complete top-level system is formed. This strategy often resembles a "seed" model,
whereby the beginnings are small but eventually grow in complexity and completeness. However, "organic
strategies" may result in a tangle of elements and subsystems, developed in isolation and subject to local
optimization as opposed to meeting a global purpose.
60
The description explains the features of a computer program that could solve a given problem.
Batch processing is execution of a series of programs ("jobs") on a computer without manual intervention.
Jobs are set up so they can be run to completion without manual intervention. So, all input data are
preselected through scripts, command-line parameters, or job control language. This is in contrast to "online"
or interactive programs which prompt the user for such input. A program takes a set of data files as input,
processes the data, and produces a set of output data files. This operating environment is termed as "batch
processing" because the input data are collected into batches of files and are processed in batches by the
program.
61
The mouse pointing device sits on your work surface and is
moved with your hand. In older mice, a ball in the bottom of
the mouse rolls on the surface as you move the mouse, and
internal rollers sense the ball movement and transmit the
information to the computer via the cord of the mouse.
The newer optical mouse does not use a rolling ball, but
instead uses a light and a small optical sensor to detect the Two-button mouse with scroll wheel
62
like a button).
Touch pad
Most laptop computers today have a touch pad pointing
device. You move the on-screen cursor by sliding your finger
along the surface of the touch pad. The buttons are located
below the pad, but most touch pads allow you to perform
“mouse clicks” by tapping on the pad itself.
Touch pads have the advantage over mice that they take up
much less room to use. They have the advantage over
trackballs (which were used on early laptops) that there are
no moving parts to get dirty and result in jumpy cursor
control.
The description explains techniques used to research problems in terms of inputs and outputs.
An actor in the Unified Modeling Language (UML) "specifies a role played by a user or any other system that
interacts with the subject. "An Actor models a type of role played by an entity that interacts with the subject
(e.g., by exchanging signals and data), but which is external to the subject. “Actors may represent roles played
by human users, external hardware, or other subjects. Note that an actor does not necessarily represent a
specific physical entity but merely a particular facet (i.e., “role”) of some entity that is relevant to the
specification of its associated use cases. Thus, a single physical instance may play the role of several different
actors and, conversely, a given actor may be played by multiple different instances. UML 2 does not permit
associations between Actors. The use of generalization/specialization relationship between actors is useful in
modeling overlapping behaviours between actors and does not violate this constraint since a generalization
relation is not a type of association. Actors interact with use cases.
So the following are the places where use case diagrams are used:
Requirement analysis and high level design.
Model the context of a system.
Reverse engineering.
63
Forward engineering.
A sequence diagram is a kind of interaction diagram that shows how processes operate with one another and
in what order. It is a construct of a Message Sequence Chart. A sequence diagram shows object interactions
arranged in time sequence. It depicts the objects and classes involved in the scenario and the sequence of
messages exchanged between the objects needed to carry out the functionality of the scenario. Sequence
diagrams are typically associated with use case realizations in the Logical View of the system under
development. Sequence diagrams are sometimes called event diagrams, event scenarios, and timing
diagrams. A sequence diagram shows, as parallel vertical lines (lifelines), different processes or objects that
live simultaneously, and, as horizontal arrows, the messages exchanged between them, in the order in which
they occur. This allows the specification of simple runtime scenarios in a graphical manner.
The description includes an evaluation of the viability of developing computer programs to solve problems
and it identifies the issues in assessing the viability.
Testing the Program
Some experts insist that a well-designed program can be written correctly the first time. In fact, they assert
that there are mathematical ways to prove that a program is correct. However, the imperfections of the world
are still with us, so most programmers get used to the idea that their newly written programs probably have a
few errors. This is a bit discouraging at first, since programmers tend to be precise, careful, detail-oriented
people who take pride in their work. Still, there are many opportunities to introduce mistakes into programs,
and you, just as those who have gone before you, will probably find several of them. Eventually, after coding
the program, you must prepare to test it on the computer. This step involves these phases:
Desk-checking. This phase, similar to proofreading, is sometimes avoided by the programmer who is looking
for a shortcut and is eager to run the program on the computer once it is written. However, with careful desk-
checking you may discover several errors and possibly save yourself time in the long run. In desk-checking you
64
simply sit down and mentally trace, or check, the logic of the program to attempt to ensure that it is error-free
and workable. Many organizations take this phase a step further with a walkthrough, a process in which a
group of programmers-your peers-review your program and offer suggestions in a collegial way.
Translating. A translator is a program that (1) checks the syntax of your program to make sure the
programming language was used correctly, giving you all the syntax-error messages, called diagnostics, and (2)
then translates your program into a form the computer can understand. A by-product of the process is that the
translator tells you if you have improperly used the programming language in some way. These types of
mistakes are called syntax errors. The translator produces descriptive error messages. For instance, if in
FORTRAN you mistakenly write N=2 *(I+J))-which has two closing parentheses instead of one-you will get a
message that says, "UNMATCHED PARENTHESES." (Different translators may provide different wording for
error messages.) Programs are most commonly translated by a compiler. A compiler translates your entire
program at one time. The translation involves your original program, called a source module, which is
transformed by a compiler into an object module. Prewritten programs from a system library may be added
during the link/load phase, which results in a load module. The load module can then be executed by the
computer.
Debugging. A term used extensively in programming, debugging means detecting, locating, and correcting
bugs (mistakes), usually by running the program. These bugs are logic errors, such as telling a computer to
repeat an operation but not telling it how to stop repeating. In this phase you run the program using test data
that you devise. You must plan the test data carefully to make sure you test every part of the program.
65
US: 14910, NQF Level 4 Worth 8 Credits
Learning Unit 3
Apply the principles of Computer Programming
Open.
The credit value of this unit is based on a person having the prior knowledge
and skills to:
Learning
demonstrate an understanding of fundamental mathematics and
Assumed to be
English (at least NQF level 2)
in Place demonstrate PC competency skills (End User Computing unit
standards)
describe the principles of Computer Programming.
66
Session 1
Operate computer programming development tools.
SO 1
The operation demonstrates the use of the editor of the development tools to produce program
source code.
A programming tool or software development tool is a program or application that software
developers use to create, debug, maintain, or otherwise support other programs and applications.
The term usually refers to relatively simple programs, that can be combined together to accomplish
a task, much as one might use multiple hand tools to fix a physical object. Sometimes called text
editor, a program that enables you to create and edit text files. There are many different types of
editors, but they all fall into two general categories: line editors: A primitive form of editor that
requires you to specify a specific line of text before you can make changes to it. screen -oriented
editors: Also called full-screen editors, these editors enable you to modify any text that appears on
the display screen by moving the cursor to the desired location.
EDITOR COMMANDS
Command Description
Ctrl-a Moves the cursor to the beginning of the current line.
[Home]
Ctrl-b Moves the cursor backwards one character.
[Left Arrow]
Ctrl-c Copys highlighted text (the current selection) to a temporary holding area.
Ctrl-d Deletes the character to the right of the cursor.
( [Delete] on Windows )
Ctrl-e Moves the cursor to the end of the current line.
[End]
Ctrl-f Find a sequence of characters. A prompt bar pops up for entering the
desired sequence of characters. An [Esc] aborts the find operation.
67
Ctrl-g Find the next occurance of a sequence of characters, specified by last FIND
or SEARCH.
The operation includes the use of the syntax checker of the tools to check for syntax errors.
In computer science, a syntax error refers to an error in the syntax of a sequence of characters or
tokens that is intended to be written in a particular programming language. For compiled languages
syntax errors occur strictly at compile-time. A program will not compile until all syntax errors are
corrected. For interpreted languages, however, not all syntax errors can be reliably detected until
run-time, and it is not necessarily simple to differentiate a syntax error from a semantic error; many
don't try at all. In 8-bit home computers that used BASIC interpreter as their primary user interface,
the SYNTAX ERROR message became somewhat notorious, as this was the response to any
command or user input the interpreter couldn't parse. A syntax error may also occur when an invalid
equation is entered into a calculator. This can be caused, for instance, by opening brackets without
closing them, or less commonly, entering several decimal points in one number.
68
E Error. The compiler will make an assumption about what you meant. You
might want to correct your program in case the compiler's assumption is not
what you intended.
W Warning. This means there might be an error, although the program is
syntactically correct.
I Information. This draws your attention to something in the source code that
you might need to be aware of. It does not mean there is an error.
You can disable reporting of errors of E-level, W-level, and I-level, using the WARNING directive.
When the Compiler has finished, the total number of errors in each category is also output. You can
disregard some levels of errors and continue working. You can:
Debug programs that have S-level, E-level, W-level, and I-level errors regardless of the setting of
the E run-time switch.
Produce object code from intermediate code that has E-level, W-level, and I-level errors, but not
S-level errors.
Run programs that have E-level, W-level, and I-level errors. If the E-level run-time switch is on,
which overrides the default setting, you can also run programs with S-level errors.
The error messages can contain variable information. This information is indicated as an item in
italics. For example:
User-name data-name not unique
will have the name of the item that is not unique in place of the text data-name.
69
The sequence of characters forming a literal in your source code does not conform to the rules
governing the construction of such names. A literal can be either nonnumeric or numeric. If numeric
it can be up to 18 digits in length, but it must not contain more than one sign character or more than
one decimal point. A nonnumeric literal can consist of any allowable character in the computer's
character set up to a maximum of 160 characters in the Procedure Division, or 2048 characters in the
Data Division. A nonnumeric literal must be enclosed in quotation marks. If you have used a
figurative constant as the literal make sure that it is referenced by an allowable reserved word (such
as ZERO) which you have spelled correctly. A figurative constant and a numeric literal must not be
enclosed in quotation marks. You might also have used the wrong class of literal for the context of
the sentence. Alternatively, if you have used the figurative constant ALL in your code, you have not
coded it in accordance with the rules governing the use of this constant. ALL must be followed by a
nonnumeric literal and not by a numeric one.
Resolution:
Revise your code to comply with the above rules.
0004 Illegal character
Your program contains a character that is not part of the COBOL language set.
Resolution:
Replace the illegal character with a valid one.
0005 User-name user-name not unique
You have given the same user-name without qualification to more than one data item or procedure-
name in your source code.
Resolution:
You must rename or qualify the duplicated data items or procedure-names to ensure that
uniqueness of reference is achieved.
70
Resolution:
Insert one at the relevant place.
0010 Word starts or is continued in wrong area of source line
The word starts either in area A when it should have started in area B, or in area B when it should
have started in area A.
0011 Reserved word missing or incorrectly used
You have either used a reserved word in a place where a user defined word is expected or you have
failed to use a reserved word where one is needed.
Resolution:
Alter the reserved word into a user defined one or insert a reserved word according to the context
of this message.
The operation uses the tool to compile the program source code produced.
User written code, standard functions, library functions.
Library Functions:
Q-Basic provides a number of functions. These inbuilt functions of Q-basic are called library
functions. These are divided into string and numeric functions. LEFT$, LEN, MID$, LCASE$ etc are the
examples of string functions and ABS, SQR, INT, VAL etc are the examples of numeric variables.
User Defined Functions:
While standard functions are pre-defined and provided for by QBasic, user-defined functions are
completely defined and customized by the programmer. User-defined functions return a single value
and are generally used to perform an operation that will be needed numerous times in a program. In
QBasic, user-defined functions are referred to as procedures; similar to SUB procedures except
function procedures return one value. Arguments may be sent into a function procedure for use in
the function operation, but the value returned by the function will not be included in the parameter
list. The value is returned in the function itself. Each user=defined function starts with BEGIN
FUNCTION FunctName (x,y,z) and ends with END FUNCTION. The code between these two lines is
executed whenever the function is invoked from main program, from another function, or SUB, or
from itself. FunctName is a name for your function (choose a descriptive one). Arguments (x,y,z) are
the variables passed to the function.The form of a function procedure is as follows:
FUNCTION name( parameter list )
REM
REM body of function
REM
71
END FUNCTION
Subroutines and functions:
A subroutine (also called a "module") is a "mini-program" inside your program. In other words, it is a
collection of commands--and can be executed anywhere in your program. To create a subroutine:
Go to the "Edit" menu Select "New Sub" Enter a name for the subroutine Type a list of commands
between SUB and END SUB. (Topic 1.1 SUB ….. END SUB statement: will provide detail information)
Functions:
Function is the same as a subroutine, except it returns a value. Also, you must leave out the CALL
command. To return a value, set a variable with the same name as the function.
Local and Global variable:
When a variable is declared within a main module or procedure without using SHARED attribute,
only code within that main module or procedure can access or change the value of that variable. This
type of variable is called as LOCAL variable. When a variable is declared with SHARED attribute in a
main module, it can be used in a procedure without passing it as parameter. Any SUB or FUNCTION
procedure within the module can use this type of variable. This type of variable which is available to
all SUB and FUNCTION procedure with the module is known as GLOBAL variable.
72
Session 2 Demonstrate an understanding of different data representations used in
SO 2 computer programs.
The demonstration applies different number conversion techniques between data types (at least
2).
There are infinite ways to represent a number. The four commonly associated with modern
computers and digital electronics are: decimal, binary, octal, and hexadecimal.
Decimal (base 10) is the way most human beings represent numbers. Decimal is sometimes
abbreviated as dec.
Decimal counting goes:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, and so on.
Binary (base 2) is the natural way most digital circuits represent and manipulate numbers. (Common
misspellings are “bianary”, “bienary”, or “binery”.) Binary numbers are sometimes represented by
preceding the value with '0b', as in 0b1011. Binary is sometimes abbreviated as bin.
Binary counting goes:
0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, and
so on.
Octal (base 8) was previously a popular choice for representing digital circuit numbers in a form that
is more compact than binary. Octal is sometimes abbreviated as oct.
Octal counting goes:
0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, and so on.
73
Hexadecimal (base 16) is currently the most popular choice for representing digital circuit numbers
in a form that is more compact than binary. (Common misspellings are “hexdecimal”, “hexidecimal”,
“hexedecimal”, or “hexodecimal”.) Hexadecimal numbers are sometimes represented by preceding
the value with '0x', as in 0x1B84. Hexadecimal is sometimes abbreviated as hex.
Hexadecimal counting goes:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, and so on.
All four number systems are equally capable of representing any number. Furthermore, a number
can be perfectly converted between the various number systems without any loss of numeric value.
Dec Hex Oct Bin
0 0 000 00000000
1 1 001 00000001
2 2 002 00000010
3 3 003 00000011
4 4 004 00000100
5 5 005 00000101
6 6 006 00000110
7 7 007 00000111
8 8 010 00001000
9 9 011 00001001
10 A 012 00001010
11 B 013 00001011
12 C 014 00001100
13 D 015 00001101
14 E 016 00001110
15 F 017 00001111
The demonstration differentiates between different internal representations of data types (in
ASCII).
Data Representation refers to the methods used internally to represent information stored in a
computer. Computers store lots of different types of information:
numbers
text
graphics of many varieties (stills, video, animation)
74
sound
At least, these all seem different to us. However, ALL types of information stored in a computer are
stored internally in the same simple format: a sequence of 0's and 1's. How can a sequence of 0's
and 1's represent things as diverse as your photograph, your favorite song, a recent movie, and your
term paper? It all depends on how we interpret the information. Computers use numeric codes to
represent all the information they store. These codes are similar to those you may have used as a
child to encrypt secret notes: let 1 stand for A, 2 stand for B, etc. With this code, any written
message can be represented numerically. The codes used by computers are a bit more sophisticated,
and they are based on the binary number system (base two) instead of the more familiar (for the
moment, at least!) decimal system. Computers use a variety of different codes. Some are used for
numbers, others for text, and still others for sound and graphics.
Memory Structure in Computer
Memory consists of bits (0 or 1)
o a single bit can represent two pieces of information
bytes (=8 bits)
o a single byte can represent 256 = 2x2x2x2x2x2x2x2 = 28 pieces of information
words (=2,4, or 8 bytes)
o a 2 byte word can represent 2562 pieces of information (approximately 65 thousand).
Byte addressable - each byte has its own address.
Binary Numbers
Normally we write numbers using digits 0 to 9. This is called base 10. However, any positive integer
(whole number) can be easily represented by a sequence of 0's and 1's. Numbers in this form are
said to be in base 2 and they are called binary numbers. Base 10 numbers use a positional system
based on powers of 10 to indicate their value. The number 123 is really 1 hundred + 2 tens + 3 ones.
The value of each position is determined by ever-higher powers of 10, read from left to right. Base 2
works the same way, just with different powers. The number 101 in base 2 is really 1 four + 0 twos +
1 one (which equals 5 in base 10).
Text
Text can be represented easily by assigning a unique numeric value for each symbol used in the text.
For example, the widely used ASCII code (American Standard Code for Information Interchange)
defines 128 different symbols (all the characters found on a standard keyboard, plus a few extra),
and assigns to each a unique numeric code between 0 and 127. In ASCII, an "A" is 65," B" is 66, "a" is
97, "b" is 98, and so forth. When you save a file as "plain text", it is stored using ASCII. ASCII format
uses 1 byte per character 1 byte gives only 256 (128 standard and 128 non-standard) possible
75
characters The code value for any character can be converted to base 2, so any written message
made up of ASCII characters can be converted to a string of 0's and 1's.
Graphics
Graphics that are displayed on a computer screen consist of pixels: the tiny "dots" of color that
collectively "paint" a graphic image on a computer screen. The pixels are organized into many rows
on the screen. In one common configuration, each row is 640 pixels long, and there are 480 such
rows. Another configuration (and the one used on the screens in the lab) is 800 pixels per row with
600 rows, which is referred to as a "resolution of 800x600." Each pixel has two properties: its
location on the screen and its color. A graphic image can be represented by a list of pixels. Imagine
all the rows of pixels on the screen laid out end to end in one long row. This gives the pixel list, and a
pixel's location in the list corresponds to its position on the screen. A pixel's color is represented by a
binary code, and consists of a certain number of bits. In a monochrome (black and white) image,
only 1 bit is needed per pixel: 0 for black, 1 for white, for example. A 16 color image requires 4 bits
per pixel. Modern display hardware allows for 24 bits per pixel, which provides an astounding array
of 16.7 million possible colors for each pixel!
The demonstration compares different logical data types (at least 3) in a language of choice (incl.
pseudo code).
Numeric Data
Numeric data simply means numbers. But, just to complicate things for you, numbers come in a
variety of different types...
Integers
An integer is a whole number - it has no decimal or fractional parts. Integers can be
either positive or negative.
Examples
12
45
1274
1000000
-3
-5735
76
Real Numbers
Any number that you could place on a number line is a real number. Real numbers include whole
numbers (integers) and numbers with decimal/fractional parts. Real numbers can
be positive or negative.
Examples
1
1.4534
946.5
-0.0003
3.142
You might see this data type referred to as 'single', 'double' or 'float'.
Currency
Currency refers to real numbers that are formatted in a specific way. Usually currency is shown with
a currency symbol and (usually) two decimal places.
Examples
£12.45
-£0.01
€999.00
$5500
77
Percentage
Percentage refers to fractional real numbers that are formatted in a specific way - out of 100, with
a percent symbol. So, the real value 0.5 would be shown as 50%, the value 0.01 would be shown
as 1% and the number 1.25 would be shown as 125%
Examples
100%
25%
1200%
-5%
Inside the computer the 50% is stored as a real number: 0.5, But when it is displayed it is
shown formatted as a percentage
Examples
DOG
“A little mouse”
ABC123
78
Text data is often input to a computer with speech marks (". . .") around it:
"MONKEY"
These tell the computer that this is text data and not some special command.
Date and Time Data
Date (and time) data is usually formatted in a specific way. The format depends upon the setup of
the computer, the software in use and the user’s preferences.
Date Examples
25/10/2007
12 Mar 2008
10-06-08
Time Examples
11am
15:00
3:00pm
17:05:45
With inputting dates particular care has to be taken if the data contains American style dates and
the computer is setup to expect international style dates (or vice-versa)...
The date 06/09/08 refers to 6th September 2008 in the international system, but would be 9th June
2008 in America! Check your computer’s settings.
79
Examples
TRUE
FALSE
ON
OFF
YES
NO
Note that TRUE and FALSE can also be shown as YES / NO, ON / OFF, or even graphically as tick
boxes(ticked / unticked)
Selecting Data Types
When we are presented with data to be input into a computer system, we must analyse it and
select appropriate data types for each value... e.g. For the following data, we might use the date
types shown:
Data Name
Name
Height
Date of Birth
Phone No.
Pay Rate
Tax Rate
Data Type
Text
Real
Date
Alphanumeric
Currency
Percentage
80
The demonstration distinguishes between different logical operators (at least 2).
And, Or, Not.
Logical operators are typically used with Boolean (logical) values; when they are, they return a
Boolean value. However, the && and ||operators actually return the value of one of the specified
operands, so if these operators are used with non-Boolean values, they may return a non-Boolean
value.
Logical Operators
Common Lisp provides three operators on Boolean values: and, or, and not. Of these, and or are also
control structures because their arguments are evaluated conditionally. The function not necessarily
examines its single argument, and so is a simple function. The logical operators are described in the
following table:
Operator Usage Description
Logical expr1 &&expr2 Returns expr1 if it can be converted to false; otherwise, returns expr2.
AND Thus, when used with Boolean values, && returns true if both
(&&) operands are true; otherwise, returns false.
Logical expr1 ||expr2 Returns expr1 if it can be converted to true; otherwise, returns expr2.
OR (||) Thus, when used with Boolean values, || returns true if either operand
is true; if both are false, returns false.
Logical !expr Returns false if its single operand can be converted to true; otherwise,
NOT (!) returns true.
Fortran has five LOGICAL operators that can only be used with expressions whose results are logical
values (i.e., .TRUE. or .FALSE.). All LOGICAL operators have priorities lower
than arithmetic and relational operators. Therefore, if an expression involving arithmetic, relational
and logical operators, the arithmetic operators are evaluated first, followed by the relational
operators, followed by the logical operators.
These five logical operators are
.NOT. : logical not
.AND. : logical and
.OR. : logical or
.EQV. : logical equivalence
.NEQV. : logical not equivalence
81
Session 3
Demonstrate an understanding of fundamental programming principles.
SO 3
(Assessment principles (at least 3), using a language of choice (incl. Pseudo code) where
Criteria) needed.
The demonstration illustrates good programming quality assurance
principles.
The demonstration illustrates the differences between the various algorithmic structures of
programming languages, using a language of choice (incl. Pseudo code).
An algorithm is the steps that a programmer will write that will become a program. It is written in a
form of structured language called Pseudocode. Once an algorithm is created using pseudocode, it is
simple to translate it into real programming code. It gives an opportunity to detect any logic errors
prior to actual coding, which is a lot more expensive and time consuming. It is used for planning the
programming. Pseudocode consists of short, English phrases used to explain specific task within a
program’s algorithm. Pseudocode should not include keywords in any specific computer languages.
It should be written as a list of consecutive phrases. You should not use flowcharting symbols but
you can draw arrows to show looping processes. Indentation can be used to show the logic in
pseudocode as well. For example, a first-year, 9th grade Visual Basic programmer should be able to
read and understand the pseudocode written by a 12th grade AP Data Structures student. In fact,
the VB programmer could take the other students pseudocode and generate a VB program based on
that pseudocode.
The programming process is a complicated one. You must first understand the program
specifications, of course. Then you need to organise your thoughts and create the program. This is a
difficult task when the program is not trivial (i.e. easy). You must break the main tasks that must be
accomplished into smaller ones in order to be able to eventually write fully developed code. Writing
pseudocode WILL save you time later during the construction & testing phase of a program’s
development.
Keep in mind that, if you have used pseudocode to write your algorithm, the coding will become
very simple.
82
Pseudocode
The sequence structure Pseudocode is an outline of a program,
We have been using the sequence structure since written in a form that can easily be
early in the course. Basically we can describe the converted into real programming
sequence structure using the pseudocode shown in statements.
Figure 1.
Figure 1. The sequence structure in pseudocode.
Enter
Perform one or more actions in sequence
Exit
Thus, the general requirement for the sequence structure is that one or more actions may be
performed in sequence after entry and before exit. There may not be any branches or loops
between the entry and the exit.
All actions must be taken in sequence.
The action elements themselves may be structures
However, it is important to note that one or more of the action elements may themselves be
sequence, selection, or loop structures. If each of the structures that make up the sequence has only
one entry point and one exit point, each such structure can be viewed as a single action element in a
sequence of actions. Obviously, the sequence structure is the simplest of the three.
The selection structure
The selection or decision structure can be described as shown in the pseudocode The selection
structure in pseudocode.
Enter
Test a condition for true or false
On true
Take one or more actions in sequence
On false
Take none, one, or more actions in sequence
Exit
Test a condition for true or false
Once again, there is only one entry point and one exit point. The first thing that happens following
entry is that some condition is tested for true or false. If the condition is true, one or more actions
are taken in sequence and control exits the structure. If the condition is false, none, one or more
83
different actions are taken in sequence and control exits the structure. (Note the inclusion of the
word none here.)
The action elements may themselves be structures
Once again, each of the action elements in the sequence may be another sequence, selection, or
loop structure. Eventually all of the actions for a chosen branch will be completed in sequence and
control will exit the structure.
Sometimes no action is required on false
It is often the case that no action is required when the test returns false. In that case, control simply
exits the structure without performing any actions.
The loop structure
The loop or iteration structure can be described as shown in the pseudocode
The loop structure in pseudocode.
Enter
Test a condition for true or false
Exit on false
On true
Perform one or more actions in sequence.
Go back and test the condition again
As before, there is only one entry point and one exit point.
Perform the test and exit on false
The first thing that happens following entry is that a condition is tested for true or false.
If the test returns false, control simply exits the structure without taking any action at all.
Perform some actions and repeat the test on true
If the test returns true:
One or more actions are performed in sequence.
The condition is tested again.
During each iteration, if the test returns false, control exits the structure. If the test returns true, the
entire cycle is repeated.
Each action element may be another structure
Each of the action elements may be implemented by another sequence, selection, or loop structure.
Eventually all of the actions will be completed and the condition will be tested again.
Need to avoid infinite loops
Generally speaking, unless something is done in one of the actions to cause the test to eventually
return false, control will never exit the loop.
84
In this case, the program will be caught in what is commonly referred to as an infinite loop.
The demonstration compares good & bad program documentation principles (at least 3), using a
language of choice (incl. Pseudo code) where needed.
Documenting the Program
Documenting is an ongoing, necessary process, although, as many programmers are, you may be
eager to pursue more exciting computer-centered activities. Documentation is a written detailed
description of the programming cycle and specific facts about the program. Typical program
documentation materials include the origin and nature of the problem, a brief narrative description
of the program, logic tools such as flowcharts and pseudocode, data-record descriptions, program
listings, and testing results. Comments in the program itself are also considered an essential part of
documentation. Many programmers document as they code. In a broader sense, program
documentation can be part of the documentation for an entire system.
The wise programmer continues to document the program throughout its design, development, and
testing. Documentation is needed to supplement human memory and to help organize program
planning. Also, documentation is critical to communicate with others who have an interest in the
85
program, especially other programmers who may be part of a programming team. And, since
turnover is high in the computer industry, written documentation is needed so that those who come
after you can make any necessary modifications in the program or track down any errors that you
missed.
International Standards Organization (ISO) 9000 - many companies, particularly in the manufacturing
sectors, comply with the ISO 9000 group of quality standards. Such compliance is mandatory for
those selling any of a broad range of products to the countries of the European Union. Some other
countries also require this certification. The standards aim to ensure quality of products by certifying
quality assurance during business processes, such as product design, manufacturing, delivery, and
86
service support. Extensive quality-oriented information processing is a prerequisite for a certification
of compliance.
Software Quality
There are many attributes of software quality. These include:
1. Effectiveness
2 Usability
3. Efficiency
4. Reliability
5. Maintainability
6. Understandability
7. Modifiability
8. Testability
Effectiveness Refers to the satisfaction of the user and organizational requirements as established
during an analysis of these requirements, possibly using prototyping.
Usability The ease with which the intended users can use the system, depend on the proper user-
system interface.
Efficient operation is reflected mainly in how economically hardware resources are used to satisfy
the given effectiveness requirements
Reliability Refers to the probability that the information system will operate correctly; that is,
according to specifications over a period of time. It may also be defined as the mean time between
failures. Software reliability is rooted in its freedom from defects. If a system must run on different
hardware or systems software platforms, portability should be included as a desired attribute.
Maintainability Refers to ease of understanding, modifying, and testing.
Understandability Is achieved by readable and well-commented system code and by
documentation, which includes the requirements specifications, system documentation, user
manuals, and, sometimes special maintenance documentation.
Modifiability Means that it is relatively easy to identify and change any part of the system that
requires maintenance without affecting its other parts.
Testability Is the ease with which we can demonstrate that a modification resulted in a quality
system.
87
Session 4
Demonstrate an understanding of high level programming language concepts.
SO 4
Types of Operators
Visual Basic provides the following types of operators:
Arithmetic Operators perform familiar calculations on numeric values, including shifting their bit
patterns.
88
Comparison Operators compare two expressions and return a Boolean value representing the
result of the comparison.
Concatenation Operators join multiple strings into a single string.
Logical and Bitwise Operators in Visual Basic combine Boolean or numeric values and return a
result of the same data type as the values.
The value elements that are combined with an operator are called operands of that operator.
Operators combined with value elements form expressions, except for the assignment operator,
which forms a statement.
The end result of an expression represents a value, which is typically of a familiar data type such
as Boolean, String, or a numeric type.
The following are examples of expressions.
5+4
' The preceding expression evaluates to 9.
15 * System.Math.Sqrt(9) + x
' The preceding expression evaluates to 45 plus the value of x.
"Concat" & "ena" & "tion"
' The preceding expression evaluates to "Concatenation".
763 < 23
' The preceding expression evaluates to False.
Several operators can perform actions in a single expression or statement, as the following example
illustrates.
VB
x = 45 + y * z ^ 2
In the preceding example, Visual Basic performs the operations in the expression on the right side of
the assignment operator (=), then assigns the resulting value to the variable x on the left. There is no
practical limit to the number of operators that can be combined into an expression, but an
understanding of Operator Precedence in Visual Basic is necessary to ensure that you get the results
you expect.
The demonstration illustrates different modular programming features and variable passing.
Modular Programming
When the complete program code started from one point and ended in another point is compiled
within a single program, the program become very complex and unmanaged which is called as linear
89
programming. In making large programs, you may need to repeat parts of the code again and again,
but not necessarily from within a loop that does only that section of code. You may also have
complex mathematical formulas that use several variables to calculate a single value. If the complex
and unmanaged program is broken into the simpler programs to perform different task, then the
program become simpler and managed which is called as modular programming. SUBs (subroutines)
and FUNCTIONS are the tools you can use to organize your code and create mini-programs within
your one QBasic program.
Advantages of Modular Programming:
The same procedure can be used more than one without rewriting, so it reduces the length of
the program.
The debugging is much easier since the programs are found in the different parts.
The procedure can be tested and debugged separately.
Due to small programs, the task of documentation is easier.
The program is much more readable than the linear program.
MODULE:
The main program or source file of the sequential program containing the entry point and the ending
point of the program and which can be separately compiled is known as module. It may contain the
SUB and FUNCTION as well as codes not directly part of the SUB and FUNCTION. The statements that
are the not the part of the SUB or FUNCTION are called module level code, for example DIM, TYPE
etc. Every program has one special module (the main module) and may consists of many supporting
modules
RTFM technique
RTFM stands for Read The Fine Manual. Make sure you take the time to find relevant documentation
for the task at hand, i.e. the documentation of the tools (not only the compiler, but also make, the
preprocessor and the linker), libraries and algorithms you are expected to use, such
90
as [CPP][GCC][MAKE]. Often you do not need to know everything in the documentation, but you do
need to be aware what documentation is relevant and what its purpose is. You should at the very
least browse through it; hopefully this will give you a feeling of deja-vu where needed, so you know
where to look.In examining documentation, you should distinguish between tutorials and reference
documentation.
print() debugging
printf debugging is our term for a debugging technique we encounter all too often. It consists of ad
hoc addition of lots of printf (C) or cerr or cout (C++) statements to track the control flow and data
values in the execution of a piece of code.
This technique has strong disadvantages:
It is very ad hoc. Code is temporarily added, to be removed as soon as the bug at hand is solved;
for the next bug, similar code is added etc. There are better ways of adding debugging
information, as you shall see shortly.
It clobbers the normal output of your program, and slows it down considerably.
ANWB debugging
`ANWB debugging' is based on a simple principle: the best way to learn things is to teach them.
In `ANWB debugging' you find a, preferably innocent and willing, bystander and explain to her how
your code works . This forces you to rethink your assumptions, and explain what is really happening;
often you find the cause of your problems this way.
91