Computer Science Handout
Computer Science Handout
Processing
Data Information
Results
Control Unit
Arithmetic
Logic Unit
1.2.2 Processing/ System Units: The task of performing operations like arithmetic and
logical operations is called processing. The Central Processing Unit (CPU) takes data and
instructions from the storage unit and makes all sorts of calculations based on the
instructions given and the type of data provided. It is then sent back to the storage unit.
This is further discuss in this section.
Central Processing Unit (CPU): A CPU is the brain of a computer. It is responsible for
all functions and processes. Regarding computing power, the CPU is the most important
element of a computer system.
The CPU is comprised of three main parts:
(a) Arithmetic Logic Unit (ALU): Executes all arithmetic and logical operations.
Arithmetic calculations like addition, subtraction, multiplication and division. Logical
operation like compare numbers, letters, or special characters
(b) Control Unit (CU): Controls and Co-ordinates computer components by performing
the following functions:
Reads the code for the next instruction to be executed.
Increments the programs counter so it points to the next instruction.
Reads whatever data the instruction requires from cells in memory.
Provides the necessary data to an ALU or register.
If the instruction requires an ALU or specialized hardware to complete,
instructs the hardware to perform the requested operation.
(c) Registers: Stores the data that is to be executed next, "very fast storage area".
1.2.3 Storage Unit: The process of saving data and instructions permanently is known as
Storage or Memory. Data has to be fed into the system before the actual processing starts.
The processing speed of Central Processing Unit (CPU) is so fast; data has to be provided to
CPU with the same speed. Therefore, the data is first stored in the storage unit for faster
access and processing. It provides space for storing data and instructions. There are four
types of memory or storage:
(a) Primary Memory
(i) RAM: Random Access Memory (RAM) is a type of primary memory scheme within the
computer system. It is responsible for storing data on a temporary basis, so that it can be
promptly accessed by the processor as and when needed. It is volatile in nature, which
means that data will be erased once power supply to the storage device is turned off. RAM
stores data randomly and the processor accesses these data randomly from the RAM
storage. RAM is considered "random access" because you can access any memory cell
directly if you know the row and column that intersect at that cell.
There are two types of RAM as it can be seen in figure 1.4, which are DRAM (Dynamic
Random Access Memory) and SRAM (Static Random Access Memory)
(ii) ROM (Read Only Memory): ROM is a permanent form of storage. ROM stays active
regardless of whether power supply to it is turned on or off. ROM devices do not allow data
stored on them to be modified.
Types of ROM
Programmable Read Only Memory (PROM): This can be programmed with a special
machine as opposed to using the expensive masks needed to produce large volumes of
roll chips. Once a PROM is programmed, its contents cannot be changed.
Erasable Programmable Read Only Memory (EPROM). This type of ROM is designed
so that its contents can be erased using ultra-violet light. Then the chip can be re-
programmed. Disadvantages of EPROM are that its contents do not last as long as
those of other types of ROM. because sunlight contains ultra-violet rays, you must
protect EPROM chips from exposure to sunlight. Figure 1.5 is a diagrammatical
example of a ROM
Figure 1.5: ROM
(iii) Cache: This is a high speed access area that can be either are served section of main
memory or a storage device memory. It is a chip-based computer component that makes
retrieving data from the computer's memory more efficient. It acts as a temporary storage
area that the computer's processor can retrieve data from easily. Most computers today
come with L3 cache or L2 cache, while older computers included only L1cache.
(iv) Registers: The CPU processes data and instructions with high speed; there is also
movement of data between various units of the computer. It is necessary to transfer the
processed data with high speed. So the CPU (esp. ALU) uses a number of special memory
units called registers. They are not part of the main memory but they temporarily store data or
information used by the ALU and passes it on as directed by the control unit.
(b) Secondary Memory: This stores data and programs permanently and it is retained
after the power is turned off.
(i). Hard Drive (HD): A hard disk is part of a unit, often called a "disk drive," "hard
drive," or "hard disk drive," that store and provides relatively quick access to large
amounts of data on an electromagnetically charged surface or set of surfaces.
Figure 1.6 (a) and (b) are examples of internal and external hard disk respectively.
Figure 1.6: (a) Internal Hard disk (b) External Hard Disk
(ii).Optical Disk: an Optical Disc Drive (ODD) is a disk drive that uses laser light as
part of the process of reading or writing data to or from optical discs. Some drives
can only read from discs, but recent drives are commonly both readers and
recorders, also called burners or writers. Compact discs, DVDs, and Blu-ray discs
are common types of optical media which can be read and recorded by such drives.
Optical drive is the generic name; drives are usually described as "CD" "DVD", or
"Bluray", followed by "drive", "writer", etc. CDs can store up to 700 megabytes
(MB) of data and DVDs can store up to 8.4 GB of data. Blu-ray discs, which are
the newest type of optical media, can store up to 50 GB of data. This storage
capacity is a clear advantage over the floppy disk storage media (a magnetic
media), which only has a capacity of 1.44 MB
(iii) Magnetic Tape: This is a magnetically coated strip of plastic on which data can be
encoded as shown in figure 1.7 • Tapes for computers are similar to tapes used to
store music. • Tape is much less expensive than other storage mediums but
commonly a much slower solution that is commonly used for backup.
Figure 1.7: Magnetic Tape
.(iv) Floppy Disk: This as shown in figure 1.8 is a soft magnetic disk. • Floppy disks are
portable. • Floppy disks are slower to access than hard disks and have less storage
capacity, but they are much less expensive. • Can store data up to 1.44MB. • Two
common sizes: 5 ¼” and 3 ½”.
Storage measurements: The basic unit used in computer data storage is called a bit (binary
digit). Computers use these little bits, which are composed of ones and zeros, to do things and
talk to other computers. All your files, for instance, must be kept in the computer as binary
files and translated into words and pictures by the software (which is also ones and zeros).
This two number system is called a “binary number system” since it has only two numbers in
it. The decimal number system in contrast has ten unique digits, zero through nine.
Computer Storage units
Bit BIT 0 or 1
Kilobyte KB 1024 bytes
Megabyte MB 1024 kilobytes
Gigabyte GB 1024 megabytes
Terabyte TB 1024 gigabytes
Petabtye PB 1024 terabyte
Exabyte EB 1024 petabyte
Yottabyte YB 1024exabyte
1.2.4 Output Unit: An output device is any piece of computer hardware equipment used to
communicate the results of data processing carried out by an information processing system
(such as a computer) which converts the electronically generated information into human-
readable form. Examples of output devices are displayed in figure 1.11.
Basic types of monitors are Cathode Ray Tube (CRT), Liquid Crystal Displays (LCD), Light-
Emitting Diode (LED). Printer types are Laser Printer, Ink Jet Printer and Dot Matrix Printer.
(ii) Accuracy: Computer provides a high degree of accuracy. For example, the computer
can accurately give the result of division of any two numbers up to 10 decimal places.
(iii) Diligence: When used for a longer period of time, the computer does not get tired or
fatigued. It can perform long and complex calculations with the same speed and
accuracy from the start till the end.
(iv) Storage Capability: Large volumes of data and information can be stored in the
computer and also retrieved whenever required. A limited amount of data can be stored,
temporarily, in the primary memory. Secondary storage devices like floppy disk and
compact disk can store a large amount of data permanently.
(v) Versatility: Computer is versatile in nature. It can perform different types of tasks with
the same ease. At one moment you can use the computer to prepare a letter document
and in the next moment you may play music or print a document. Computers have
several limitations too. Computer can only perform tasks that it has been programmed
to do.
(vi) Automation: Once a program is in the computer's memory, it can run automatically
each time it is opened. The individual has little or no instruction to give again.
(vii) Reliability: Being a machine, a computer does not suffer human traits of tiredness and
lack of concentration. It will perform the last job with the same speed and accuracy as
the first job every time even if ten billion jobs are involved.
(viii) Flexibility: It can perform any type of task once it can be reduced to logical steps.
Modern computers can be used to perform a variety of functions like on-line
processing, multi-programming, real time processing etc.
(ix) Resource and File sharing: It allows for more convenient resource sharing. This benefit
is very important, particularly for larger companies that really need to produce huge
numbers of resources to be shared to all the people. Since the technology involves
computer-based work, it is assured that the resources they wanted to get across would
be completely shared by connecting to a computer network which their audience is also
using.
(x) Communication and Information: It enhances communication and availability of
information. Networking, especially with full access to the web, allows ways of
communication that would simply be impossible before it was developed. Instant
messaging can now allow users to talk in real time and send files to other people
wherever they are in the world, which is a huge boon for businesses. Also, it allows
access to a vast amount of useful information, including traditional reference materials
and timely facts, such as news and current events
Another earlier computer is Stepped Reckoner which was invented by Gottfried Wilhelm
Leibniz in 1672. The machines that can add, subtract, multiply and divide automatically. Also
we have Jacquard Loom called a mechanical loom, invented by Joseph-Marie Jacquard in
1881. It an automatic loom controlled by punched cards. There is Arithmometer, a
mechanical calculator invented by Thomas de Colmar in 1820, The first reliable, useful and
commercially successful calculating machine. This machine could perform the four basic
mathematic functions and it was the first mass-produced calculating machine.
First Computer Programmer is Augusta Ada who wrote programs for the Analytical Engine
in 1840.
Scheutzian Calculation Engine was invented also by Per Georg Scheutz in 1843 and it was
based on Charles Babbage's difference engine which is also first printing calculator.
Tabulating Machine was also invented by Herman Hollerithin in 1890 this assist in
summarizing information and accounting. Mark 1 also known as IBM Automatic Sequence
Controlled Calculator (ASCC) was invented by Howard H. Aiken in 1943and this is the first
electro-mechanical computer. Z1 was the first programmable computer, created by Konrad
Zusein Germany from 1936 to 1938. To program the Z1, it required that the user insert punch
tape into a punch tape reader and all output was also generated through punch tape.
Atanasoff-Berry Computer (ABC) was the first electronic digital computing device
invented by Professor John Atanasoff and graduate student Clifford Berry at Iowa State
University between 1939 and 1942
A microcomputer is the smallest general purpose processing system. The older pc started 8
bit processor with speed of 3.7MB and current pc 64 bit processor with speed of 4.66 GB.
Examples: - IBM PCs, APPLE computers
Laptop: - this computer is similar to a desktop computers but the size is smaller. They are
expensive than desktop. The weight of laptop is around 3 to 5 kg. Examples of laptop brands
are HP, Dell, Lenovo, Apple, Acer etc
Notebook: - These computers are as powerful as desktop but size of these computers are
comparatively smaller than laptop and desktop. They weigh 2 to 3 kg. They are more costly
than laptop.
Palmtop (Hand held): - They are also called as personal Digital Assistant (PDA). These
computers are small in size. They can be held in hands. It is capable of doing word
processing, spreadsheets and hand writing recognition, game playing, faxing and paging.
These computers are not as powerful as desktop computers. Ex: - 3com palmV.
Wearable computer: - The size of this computer is very small so that it can be worn on the
body. It has smaller processing power. It is used in the field of medicine. For example pace
maker to correct the heart beats. Insulin meter to find the levels of insulin in the blood.
b) Minicomputer: -
A minicomputer is a medium-sized computer. That is more powerful than a microcomputer.
These computers are usually designed to serve multiple users simultaneously (Parallel
Processing). They are more expensive than microcomputers.
Examples: Digital Alpha, Sun Ultra.
c) Mainframe computers:
Computers with large storage capacities and very high speed of processing (compared to
mini- or microcomputers) are known as mainframe computers. They support a large number
of terminals for simultaneous use by a number of users like ATM transactions. They are also
used as central host computers in distributed data processing system.
Examples: - IBM 370, S/390.
d) Supercomputer: -
Supercomputers have extremely large storage capacity and computing speeds which are
many times faster than other computers. A supercomputer is measured in terms of tens of
millions Instructions per second (mips), an operation is made up of numerous instructions.
The supercomputer is mainly used for large scale numerical problems in scientific and
engineering disciplines such as Weather analysis.
Examples: - IBM Deep Blue
a) Single User: - Only one user can use the resource at any time.
b) Multi User: - A single computer shared by a number of users at any time.
c) Network: - A number of interconnected autonomous computers shared by a number
of users at any time.
What are some tips to avoid viruses and lessen their impact?
(a) Install anti-virus software from a reputable vendor. Update it and use it regularly.
(b) In addition to scanning for viruses on a regular basis, install an "on access" scanner
(included in most anti-virus software packages) and configure it to start each time you
start up your computer. This will protect your system by checking for viruses each time
you run an executable file.
(c) Use a virus scan before you open any new programs or files that may contain executable
code. This includes packaged software that you buy from the store as well as any
program you might download from the Internet.
(d) If you are a member of an online community or chat room, be very careful about
accepting files or clicking links that you find or that people send you within the
community.
(e) Make sure you back up your data (documents, bookmark files, important email
messages, etc.) on disc so that in the event of a virus infection, you do not lose valuable
work.
Antivirus Software
Antivirus software or Vaccines is a computer program that detects, prevents, and takes
action to disarm or remove malicious software programs, such as viruses and worms.
New viruses, worms, and other threats are created by cyber terrorists and discovered
every day. So updating antivirus software is periodically mandatory. List of some
examples of Anti Virus Programs are:
(a) Norton Antivirus: Norton Antivirus is the most popular and secure virus scanner for
checking boot sector records at start-up. The live update feature automatically installs
new updates for regular protection against viruses.
(b) AVG Free Edition – AVG Resident Shield provides real-time protection executions
of files and programs. It features a smart e-mail scanner, virus updates and virus vault
for secure handling of the files which are infected by viruses. The base version for
windows is Free for private and non-commercial use.
(c) McAfee VirusScan for Windows: This antivirus package detects all virus types,
including Word and Excel macros; boot-sector infections; and file, multipartite,
stealth, polymorphic, and encrypted viruses.
(d) Kaspersky Anti-Virus Personal Pro – It is a commonly used virus protection solution
offering full protection against macro- viruses and unknown viruses.
(e) ESET NOD32 Antivirus – ESET NOD32 Anti-virus is available as an anti-virus for
small businesses, individuals and for large networks.
(f) Avast! Home Edition – A free antivirus solution for scanning disk, CDs, and E-mail.
(g) Panda Antivirus Platinum – It is a complete virus protection package for home and
business users. It comes with an easy installation and automatic protection from latest
viruses.
(h) Avira - Windows and Linux antivirus, firewall, anti spam, recovery solutions against
malware infection
Law enforcement to carry out biometric mapping activities like fingerprint matching
and store forensic information.
Banking to keep client accounts details and issue cash transaction services at the
Automated Teller Machines (ATM).
CHAPTER TWO
COMPUTER SOFTWARE
2.0 Introduction
The usefulness of the computer depends on the programs that are written to manipulate it. The
physical components of the computer are called the hardware while all the other resources or parts of
the computer that are not hardware, are referred to as the Software. Software are the set of programs
that makes the computer system active. In essence, the software is the set of program or instructions
implemented on either hardware or firmware to make the computer machine usable. A Program is a
series of coded instructions showing the logical steps the computer follows to solve a given problem.
It is generally referred to as the expression of an algorithm using the constructs (rules) of a particular
computer programming language.
Utility Software
User Application Software
Language Translator
Application Packages
Library Programs
(a) Word processing software: The main purpose of this software is to produce
documents. MS-Word, Word Pad, Notepad and some other text editors are some of
the examples of word processing software.
(b) Database software: Database is a collection of related data. The purpose of this
software is to organize and manage data. The advantage of this software is that you
can change way data is stored and displayed. MS access, dBase, FoxPro, Paradox, and
Oracle are some of the examples of database software.
(c) Spreadsheet software: The spread sheet software is used to maintain budget, financial
statements, grade sheets, and sales records. The purpose of this software is organizing
numbers. It also allows the users to perform simple or complex calculations on the
numbers entered in rows and columns. Example is Microsoft Excel etc.
(d) Presentation software: This software is used to display the information in the form of
slide show. The three main functions of presentation software is editing that allows
insertion and formatting of text, including graphics in the text and executing the slide
shows. The best example for this type of application software is Microsoft
PowerPoint.
(e) Multimedia software: Media players and real players are the examples of multimedia
software. This software will allow the user to create audio and videos. The different
forms of multimedia software are audio converters, players, burners, video encoders
and decoders.
(f) Web page editors : e.g. MS FrontPage, Macromedia Dreamweaver) are used to create
Web pages
ii) Special Purpose Software Application Package: This software package performs a
single very specific type of task. Examples are Hospital Management system, Human
Resources Management, Reservation Systems, Attendance system, and Billing
An operating system (OS) is the software that manages computer hardware and software resources
and provides common services for computer programs. It can also be defined as a layer of software
that provides access to the computer resources and creates an environment with which application
programs can run. Application programs rely on the facilities provided by the operating system to
gain access to the computer system resources such as files, memory, CPU, input/output devices e.t.c.
Users usually interact with the Operating System directly by means of Operating System commands.
Programs also invoked the services of Operating System by means of Operating System calls.
Internally, operating systems vary greatly in their makeup, since they are organized along many
different lines. The design of a new operating system is a major task. It is important that the goals of
the system be well defined before the design begins. These goals form the basis for choices among
various algorithms and strategies. Because an operating system is large and complex, it must be
created piece by piece. Each of these pieces should be a well delineated portion of the system, with
carefully defined inputs, outputs, and functions. Operating system can be thought of as having three
objectives namely:
Convenience: An OS makes a computer more convenient to use (i.e. it serves as interface).
Efficiency: An OS allows the computer system resources to be used in an efficient manner (it
manages computer system resources).
Ability to evolve: An OS was constructed in such a way as to permit the effective
development, testing, and introduction of new system functions without interfering with service.
iii) Compilers: A Compiler is a computer program that accepts a source program in one high-
level language, reads and translates the entire user’s program into an equivalent program in machine
language, called the object program or object code. The stages in compilation include:
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) Code generation
For each high-level language, there are different compilers. We can therefore talk of COBOL
Compilers, FORTRAN Compilers, BASIC Compilers, etc. A Compiler also detects syntax errors,
errors that arise from the use of the language. Compilers are portable i.e. a COBOL Compiler on one
machine can run on a different machine with minimum changes. Examples of Compiler are; C, C++,
Java, Microsoft Visual Studio.
COMPUTER HARDWARE
.
3.1 The System Unit
The system unit is the main unit of a PC. It is the Computer itself while other units attached to it are
regarded as peripherals. It could be viewed as the master conductor orchestrating your PC’s
operation. It is made up of several components like the Motherboard, Processor, Buses, memory,
power supply unit, etc. This unit (system unit) has been confused over the years by novices as the
CPU. This is not true. The CPU (Central Processing Unit) or simply processor is a component within
the system unit and it is not the only thing that makes up the system unit. Hence, it will be wrong to
equate the system unit with the CPU.
1
1.2 Back of the System Unit
Battery
A small battery powers a clock to keep track of the time when the PC is turned off. It also maintains
low electricity to certain RAM chips that record which components are installed.
Expansion Slots
These long narrow connectors allow you to plug in expansion cards (also known as adapter cards),
which offer extra options not available on a basic PC.
2
ROM Chips
Read-only memory (ROM) chips have data written on them during manufacturing that tells the CPU
what to do when the PC is switched on. The data is always there, even when you switch the PC off.
RAM Chips
When a computer is switched on and running a program, RAMS (Random Access Memory) is used
for purposes such as holding the program and its data. But when the PC is switched off, anything
held in RAM is lost.
RAM chip
Central Processing Unit (CPU)
The Microprocessor, or Central Processing Unit (CPU), is the computer’s most important single
item. It does all the PC’s thinking and runs the programs (series of instructions) that you request.
3
Speaker
The speaker emits the computer’s sound output.
Motherboard
All the electronic components in a PC are mounted on a piece of fiberglass called the motherboard.
Fiberglass cannot conduct electricity, so each component is insulated from all the others. Thin lines
of metal on the surface of the fiberglass connect pins from one component to another, forming the
computer’s electrical circuits.
Components of a motherboard
Intel CPUs
The earliest PCs were equipped with a CPU from Intel Corporation called the 8088. The next
generation of PCs used CPU known by the number “80286 and were called “PC/AT” computers.
Subsequently, PCs have been supplied with more and more powerful CPUs – the 80386, the 80486,
and the more recent and impressive of all, the Intel Pentium (I, II, III, IV& M).
All these PC processors belong to a family called 80 x 86. In general, you can run the same software
on PCs containing different CPUs within this family. From the outside, the chips look different only
in sizes and number of pin-put inside, an 80486 has over one million components to the 3,500 that
were in the first 8088. Because of these differences, the latest Pentiums runs over ten times faster.
What is CPU
The CPU is certainly the most important PC component. CPU stands for Central Processing Unit.
Let us briefly study that name:
ı It is a processor, because it processes (moves and calculates) data.
ı It is central, because it is the center of PC data processing.
ı It is a unit, because it is a chip, which contains millions of transistors.
CPU Speed
The speed of a CPU is measured in megahertz (MHz). A computer has central clock that keeps all
the components in time with each other; one hertz is similar to a clock tick and megahertz is equal to
one million ticks per second. If your PC runs at 333 or 400MHz,the central clock ticks 333 or 400
million times every second. As you might imagine, the faster the clock ticks, the faster the computer
runs. Without the CPU, there would be no PC. Like all other hardware components, the CPUs are
continually undergoing further development. You can see the explosive technological development
in data processing most clearly in the development of newer and faster CPUs. The CPUs have for
years doubled their performance about every 18 months and there are no indications that this trend
will stop.
4
When we now look at all the CPUs from a broader perspective, we can see that:
The CPU history is closely tied to the companies IBM and especially Intel.
The CPUs have their roots back to Intel's chip 4004 from 1971.
The compatibility concept has been important throughout the development.
DISKS
Floppy Disks
Computers use disk to store information. Although there is a permanent hard disk that lives inside the
system unit, you can use floppy disks to store and move data easily from one PC to another. Floppy
disks come in two sizes, either 5¼ or 3½ inches in diameter.
The smaller disks are able to store more data and are also less easily damaged, because of their
thicker plastic cases. As both sizes can be either “high” or “low” capacity (or density), there are four
main varieties of disks available. High-capacity disks are more expensive, but they can store much
more information. Low-capacity disks are generally labeled DS/DD, which stands for “double
sided/double density”, while the high-capacity floppy disks are labeled DS/HD (double sided/high-
density”).
Take care to store them vertically, preferably in a special storage box. Remember too that you should
keep floppy disks away from magnetic fields, including hidden magnets such as those in telephone,
radio and television speakers, amplifiers, desk fans, and photocopiers. If you do leave floppy disks
near magnetic field, your data may become corrupted and will no longer be usable.
PERIPHERAL DEVICES
The computer peripheral devices are those devices which are attached to the system unit. The devices
are necessary to ensure that the computer is able to accept input and display the result for the user.
This section therefore discusses the input unit and the output unit.
Input Devices
1 Computer Keyboard
A Computer keyboard is identical to the conventional typewriter keyboard. However, it has more
keys than the typewriter keyboard. A computer keyboard can be a dummy type or intelligent type. A
computer keyboard is considered too be intelligent if, in addition to performing the routine functions
characteristic of a typewriter keyboard, it can initiate a series of actions for a computer to carry out
by mere pressing a key or combination of
5
two or more keys. An intelligent computer keyboard has a set of keys and when one of them is
pressed, the computer can be made to carry out a specific function. For example, the pressing of a
key may cause the computer to display a menu list from which a human being may be prompted to
select one.
The intelligent computer keyboard has four major divisions, namely: Function keys, Alphanumeric
keys, Numeric keys and Control keys. In addition to the four types of keys, there are some special or
important keys such as the following:
(a) Return or Enter key
(b) Escape key denoted by ESC
(c) Control key denoted by CTRL
(d) Alternate key denoted by ALT
(e) Delete key denoted by DEL
(f) Insert key denoted by INS
(g) Backspace key
(h) Shift key.
Function Keys
The effects of the functions keys are software package dependent. That is, they mean different
translations depending on which software package one is running on the computer. The function keys
are traditionally labeled F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11 and F12. The function keys are
often arranged to the left of the main keyboard in two columns or they are arranged in a row above
the main keyboard. In most software
packages, the function key F1 is used to run the HELP program. Word perfect, for example, uses F3
for HELP program and F1 to cancel the last command issued on the computer. The function keys F7
and F12 are used to save a text and block a section of a text respectively in word perfect. Function
keys can be programmed to carry out the functions desired by a programmer. For example the
function keys F10 may be programmed to display menus. Thus, the operations of the function keys
can be determined by the user or programmed by the software package being used at any point in
time.
Alphanumeric Keys
The Alphanumeric keys can be likened with the conventional typewriter keys. They contain
alphabetic characters, numeric characters and special characters such as comma, full stop, open
bracket, close bracket, asterisk, semicolon, colon, question mark, and soon. Usually, each key carries
a character at the lower part and another character at the upper part. The SHIFT key is used to switch
on or off the lower and upper characters by
the programmer.
6
Other cursor control keys are HOME, PAGE UP, PAGE DOWN, and END. These keys may be part
of the numeric keypad or separated from the numeric keypad. Moving the cursor around on the
screen is one of the most common tasks in an application program.
In fact, cursor movement is so important in an application such as word processing that it can usually
be accomplished by additional key-driven commands. The control keys and their functions are
documented in Table the above table.
Numeric Keypad
The numeric keypad contains a set of keys required for typing or entering number digits0, 1, 2, 3, 4,
5, 6, 7, 8, and 9 into the computer store. A numeric key is often activated by pressing the Numlock
Key. The numeric keypad is also used in combination with Alternate (Alt) key to produced extended
characters. Extended characters are characters not normally found on most keyboard. For example, to
produced the character alpha data denoted one holds down the Alt key and press 224; to produce
character beta data denoted by one holds down the Alt key and press 255 and to produce pound
sterling denoted by ‘₤’, one holds down the Alt key and press 156.
Shift Key
When the Shift key is pressed, the capital letters on the alphanumeric keys are activated. It also
serves as the activator of characters that are at the upper part of each alphanumeric key. The Shift
key has no effects on itself; its effect are realized when some other keys are pressed. Thus, if one
presses the shift key and then ‘equal’ sign key, the ‘plus’ sign which is at the upper part of the
‘equal’ sign is activated and then it appears on the screen.
CapLock Key
The CapLock Shifts all alphabetic characters into upper case (capital letters). Thus all characters
typed are in lower case (small letters) when not pressed.
7
Alternate Key (Alt)
The Alternate key can be used in combination with numeric keys to generate characters not shown on
the keyboard, that is, extended characters. For example, holding the Alt key down and pressing 228
produces the summation ( ) sign; holding the Alt key down and pressing 235 produce sign. To
restart or reboot your computer, press Alt, Ctrl and Delkeys simultaneously.
NumLock Key
The Numlock key activates the numeric keypad. Neither NumLock nor CapLock affects the function
keys.
For example, in Word Perfect word processing package, to centre a text; press Shift andF6; to print a
text, press Shift and F7.
8
Spacebar
The Spacebar is the longest key found on most keyboards. It erases characters at the cursor position
or gives blank space when pressed.
Tab Key
The Tab Key moves the cursor by five spaces to the right when pressed. The number of positions
moved depend on the software or the Tab Set by the operator. The Tab is normally pressed to insert
paragraphs during typing. In some programs, when this key is pressed in combination with shift key,
the same number of positions is moved backwards.
A mouse can be used to draw diagrams on computer screen more effectively and efficiently than the
computer keyboard. Generally, the keyboard and the mouse do complement each other. For example,
the mouse can be used to highlight an item in a menu list while the keyboard Enter Key can be
pressed to activate or evoke the command associated with the highlighted item.
A mouse is the primary input device for modern computers that feature operating systems with a
graphical user interface, such as Windows 98 or Windows XP. While keyboards obviously excel at
entering text, numbers, and symbols, your mouse is the tool you'll use to tell your computer what to
do with all the data you've entered.
9
Joysticks are almost exclusively used with game software and help the user more effectively control
the actions of computer-simulated airplanes or arcade-style games. All modern PC operating systems
(Windows 98, Windows XP, and the Macintosh) rely on an on-screen pointer to select and execute
commands. A mouse is simply an input device built to help the user control this on-screen pointer in
as natural and efficient a manner as possible.
The pointer on the screen mimics the movements of your mouse. As you move your mouse, a ball
encased in the bottom of your mouse rolls on the desk and in turn sends signals to the computer as to
which direction to move the pointer on the screen. Move the mouse side to side, or up and down, and
the on-screen pointer moves in a similar manner.
Once you have the mouse positioned to select the command or data you want to act on, you use the
mouse buttons to execute the command. The mouse controls the on-screen pointer and lets you select
program icons, manipulate property sheets, and access data.
3. Output Device
1 Printer
A printer is the computer component that lets you create copies of the information stored in your
computer on paper. The printed material is often called hard copy, to differentiate it from the data
stored on a disk, or held in the computer's memory. There are three basic types of printers available
for use with personal computers:
Laser printers. These combine a magnetic roller with powdered ink called toner to transfer high-
quality characters or images onto a page.
Inkjet printers. These have small nozzles that actually spray fast-drying ink onto the page to form
characters or images. Inkjet printers spray a fine, quick-drying ink through small nozzles to produce
characters and images on paper. Although the results are not quite as sharp as those of laser printers,
inkjet printers provide very good quality output ata lower cost.
Dot-matrix printers.
These use a print head to strike an inked ribbon against paper, like a typewriter, creating characters
out of a series of dots. Dot-matrix printers are the cheapest printers available.
They create text and images on the page by hammering several small pins against aninked ribbon.
The more pins used, the better the image--9-pin and 24-pin are common options. The 24-pin printers
produce a better quality output, but are somewhat slower than the 9-pin printers.
Print quality for dot-matrix printers is often described in terms of mode: draft mode (low resolution),
near-letter-quality mode (medium resolution), or letter-quality mode (high resolution). The speed
depends on the mode, with draft mode being the fastest.
The type of printer you choose depends on your budget and the type of output you need. For
example, if all you need to print are grocery lists, you may be happy with a dot-matrix printer. In
general, dot-matrix printers are noisier, slower, and produce a poorer quality image than do laser or
inkjet printers, but they are also less expensive. If you need to print newsletters, brochures, or
illustrated reports, you will probably want a high quality laser printer. Laser printers cost more than
other printers, but they may be worth the price because they are fast, quiet, and produce high-quality
text and graphics.
2 Monitors
10
The monitor does not do any processing itself. The monitor only displays the information that the
video card tells it to.
Monitor Sizes
The two most common monitor sizes are 15-inch and 17-inch. If you have an older, hand me down
PC or a very inexpensive starter PC, you may have a smaller 14-inch monitor.21-inch monitors are
also available but mostly used by graphics professionals.
VGA and SVGA Monitors
The two most common acronyms you will see on current monitors are VGA or SVGA. Both of these
terms generally refer to how many dots (or pixels) in each direction the monitor can display. VGA is
640x480 (width by height) and SVGA is 800x600. This measurement is called the monitor's
resolution, and more is better! Most new monitors are capable of displaying at least SVGA quality.
In fact, 1,024x768 is somewhat of a minimum to look for.
Almost any VGA or SGVA monitor made in the last few years is capable of displaying any of these
resolutions. However, it's actually the video card that determines what resolution your monitor
displays at any time. The monitor is capable of switching from one resolution to another on
command from the video card.
3 Scanners
Scanners are peripheral devices used to digitize (convert to electronic format) artwork, photographs,
text, or other items from hard copy. In a sense, a scanner works as a pair of eyes for your PC. Your
eyes see an image and translate the image into electrical impulses that travel to and are interpreted by
your brain. Similarly, a scanner captures images and converts them to digital data that travel to and
are interpreted by the computer.
A scanner works by dividing an image into microscopic rows and columns and measuring, like the
film in a camera, how much light (or lack thereof) reflects from each individual intersection of the
rows and columns. Each reflection is recorded as a dot, or picture element (pixel). After the scanner
collects information from each dot, it compiles the result into a digital file on the computer.
There are a wide variety of scanners that work in a number of different ways, but the technology
behind them is essentially the same. The following sections discuss the more popular types of
scanners available today.
Types of scanners
i. Flatbed Scanners
Flatbed scanners look and behave a lot like a photocopier. You lay the item to be scanned on a glass
plate and the scanning head passes below the glass. Flatbed scanners are very versatile: you can scan
objects in a variety of sizes and shapes, including pages from a book, without damaging the original.
While flatbed scanners are
the best choice for a wide variety of uses, if you plan to do a lot of text scanning (called OCR for
Optical Character Recognition) work, keep in mind that flatbeds only accommodate one page at a
time. Scanning multi-page documents can be a slow, tedious process, because you have to manually
remove one page and insert the next.
ii Sheetfed Scanners
Sheetfed scanners look and act more like fax machines. The page or item is fed into the machine,
scanned, then spit out on the other end . A sheetfed scanner is a good choice for large volumes of
text, but not for handling delicate original photographs. Scanning directly from a book or other three-
dimensional object is impossible.
iii Hand Scanners
Hand scanners are a low-cost alternative to their larger, more sophisticated counterparts .As their
name implies, hand scanners are manual devices you move over a flat surface just as you do your
PC's mouse. The hand scanner's advantages are many, but so are its disadvantages. Generally, hand
11
scanners work best for small, uncomplicated images such as company logos or small black-and-white
photographs. You might want a hand scanner if you do not plan to use iton a regular basis, because it
usually does not require adding internal cards to your CPU and it's easily disconnected and stored
away. Most hand scanners can only scan a four inch wide image at one time and require a steady
hand. You're usually provided with software that helps you "sew up" a series of these 4-inch, side-
by-side scans into one image, but this is obviously not as convenient as getting the full image at once.
NOTE: The system unit cannot function without the peripheral devices. The input and the output
units are very important peripheral devices that must be taken care of in setting up a computer
system.
AUXILLARY EQUIPMENT
- Air conditioner
- Voltage stabilizer
- Uninterruptible Power Supply System (UPS)
The auxiliary equipment as their name suggests are not computers but are necessary in a computing
environment in order to ensure proper functioning and smooth running of computing activities. In
this module, we shall address in some details the importance of equipment such as air conditioner,
voltage stabilizer, uninterruptible power system and line transformer in a data processing
environment.
i. Air Conditioner
12
A Computer is an electronic machine. It is, therefore, capable of generating heat. A computer is
manufactured to operate in an environment with a specific temperature range. When the temperature
of the environment in which a computer is kept falls outside the specific range, the computer may
function badly and consequently get
damaged. The free air is basically, dust laden. Dust is metallic in nature and, as such, capable of
conducting electricity. If dust is allowed to settle on a computer, particularly the electronic circuits,
the dust can bridge two circuits. The bridging of two electronic circuits may cause a serious damage
to the computer. Thus, air conditioners are needed ina computer environment to:
a. Condition the temperature
b. Prevent dust.
ii Voltage Stabilizer
A computer when switched on, takes off at a cold state, warms up and gradually gets to a hot state.
At a hot state, a computer is always roaming in an attempt to find something to do. In a situation
where the public electricity such as that of PHCN in Nigeria is cut suddenly, the computer would
suddenly be brought to a halt. The sudden power cut may cause the computer to lose the memory of
some basic house-keeping operations when power eventually returns and the computer is switched
on. The sudden power cut may also cause irreparable damages to the file the computer was
processing at the time the power was suddenly cut.
iii Line Voltage Transformer
We note that computers are built to operate within a specific range of voltages. In the United State of
America, computers are built to operate on 110V. A voltage transformer is a device meant to step up
or step down a voltage as the case may be. In Nigeria, for example, a 110V computer requires a
voltage transformer to step down the 240V to110V. Similarly, in USA, a 2409V current is connected
directly to a 110V computer, the computer power unit will blow up almost immediately.
Today, the technology has improved tremendously such that if a 240V current is connected directly
to a 110V computer, only a fuse, rather than the power unit will blowup. It is worth mentioning, too,
that there is an advanced technology today which permits a computer to operate effectively and
efficiently with the power line voltage ranging between 110V and 240V. The technology supports an
inbuilt switch which can be operated at two terminals namely: the 110V terminus and 240V
terminus. In recent times, the technology has been improved upon such that computers are
manufactured in such a way that they can sense the voltage that is adequate. Thus, if one connects a
110Vcomputer to a 240V current, the 110V computer has an in-built line transformer which
automatically steps down the 240V current to 110V.
iv Uninterruptible Power Supply System (UPS)
An Un-interruptible Power System (UPS) is an auxiliary hardware that is capable of:
(a) Converting the public electricity raw line into fine line, that is, conditioning the voltage that is
fed into the computer.
(b) Storing electrical energy when the public electricity line is life
(c) Releasing the stored electrical energy to the computer when the public electricity line is dead.
Some of the discussed hardware in this section can be clearly view in figure 3.1
13
Figure 3.1: Computer Hardware system
14
CHAPTER FOUR
ALGORITHM, FLOWCHART AND PROBLEM SOLVING
4.1 Introduction
Flowchart and algorithm are essential tools for learning programming in computer. Both help
to give detail and clarify all the steps for solving a computational problem. Flowchart is a
diagrammatic representation of how a computational problem will be solved and algorithm is
a step by step procedure of solving the problem. These essential tools for programming will
be discussed in this chapter.
4.2 Algorithm
An algorithm is a set of steps that defines how a task is performed. For example, there are
algorithms for cooking (called recipes), for finding your way through a strange city (more
commonly called Maps or directions). For example:
Task: to make a cup of tea.
Algorithm:
add water to the kettle,
boil it, add tea leaves,
add Milk and sugar, and then serve it in cup.
Before a machine such as a computer can perform a task, an algorithm for performing that
task must be discovered and represented in a form that is compatible with the machine. A
representation of an algorithm is called a program. For the convenience of machines,
programs are encoded in a manner compatible with the technology of the machine. Programs,
and the algorithms they represent, are collectively referred to as software, in contrast to the
machinery itself, which is known as hardware. The study of algorithms began as a subject in
mathematics. Indeed, the search for algorithms was a significant activity of mathematicians
long before the development of today’s computers. The goal was to find a single set of
directions that described how all problems of a particular type could be solved. One of the
best known examples of this early research is the long division algorithm for finding the
quotient of two multiple-digit numbers. Once an algorithm for performing a task has been
found, the performance of that task no longer requires an understanding of the principles on
which the algorithm is based. Instead, the performance of the task is reduced to the process of
merely following directions. The intelligence required to solve the problem at hand is
encoded in the algorithm. Capturing and conveying intelligence by means of algorithms
allows us to build machines that perform useful tasks. Consequently, the level of intelligence
displayed by machines is limited by the intelligence that can be conveyed through algorithms.
We can construct a machine to perform a task only if an algorithm exists for performing that
task. In turn, if no algorithm exists for solving a problem, then the solution of that problem
lies beyond the capabilities of machines. It is the study of algorithms that forms the core of
computer science.
An algorithm can be formerly defined as “an ordered set of unambiguous, executable
steps that defines a terminating process.” The definition requires that:
(i) The set of steps in an algorithm must be ordered. This means that the steps in an
algorithm must have a well-established structure in terms of the order of their
execution. This does not mean, however, that the steps must be executed in a
sequence consisting of a first step, followed by a second, and so on. Some
algorithms, known as parallel algorithms, contain more than one sequence of
steps, each designed to be executed by different processors in a multiprocessor
machine. In such cases the overall algorithm does not possess a single thread of
steps that conforms to the first-step, second-step scenario. Instead, the algorithm’s
structure is that of multiple threads that branch and reconnect as different
processors perform different parts of the overall task. The steps are ordered by
cause and effect.
(ii) Another requirement imposed by the definition is that the steps in an algorithm be
unambiguous. This means that during execution of an algorithm, the information
in the state of the process must be sufficient to determine uniquely and completely
the actions required by each step. In other words, the execution of each step in an
algorithm does not require creative skills. Rather, it requires only the ability to
follow directions.
(iii) The algorithm must consist of executable steps. To appreciate this condition,
consider the instruction: make a list of all the positive integers which would be
impossible to perform because there are infinitely many positive integers. Thus
any set of instructions involving this instruction would not be an algorithm.
Computer scientists use the term effective to capture the concept of being
executable. That is, to say that a step is effective means that it is doable.
(iv) It requires that an algorithm define a terminating process, which means that the
execution of an algorithm must lead to an end. There may problems whose
answers can be obtained algorithmically and problems whose answers lie beyond
the capabilities of algorithmic systems. In this context, a line is drawn between
processes that culminate with an answer and those that merely proceed forever
without producing a result.
4.3 Flowchart
The flowchart is a diagram which visually presents the flow of data through processing
systems. This means by seeing a flow chart one can know the operations performed and
the sequence of these operations in a system. Algorithms are nothing but sequence of
steps for solving problems. So a flow chart can be used for representing an algorithm. A
flowchart, will describe the operations (and in what sequence) are required to solve a
given problem. You can see a flow chart as a blueprint of a design you have made for
solving a problem.
For example suppose you are going for a picnic with your friends then you plan for the
activities you will do there. If you have a plan of activities then you know clearly when
you will do what activity. Similarly when you have a problem to solve using computer or
in other word you need to write a computer program for a problem then it will be good to
draw a flowchart prior to writing a computer program. Flowchart is drawn according to
defined rules.
START
Input A,B,C,D
Grade= (A+B+C+D)/4
YES If Grade<60
NO
STOP
Example3: Algorithm for find the greater number between two numbers.
Start
Read A,B
If A > B
Print A Print B
End
Advantages of Flowchart
(i) It is an excellent way of communicating the logic of a program
(ii) It is easy and efficient to analyze problem using flowchart
(iii) During program development cycle, the flowchart plays the role of a blueprint,
which makes program development process easier.
(iv) After successful development of a program, it needs continuous timely
maintenance during the course of its operation. The flowchart makes program or
system maintenance easier.
(v) Conversion from flowchart into any programming language code is very easy.
4.3 Operators
Programming Languages typically support a set of operators that are constructs which behave
generally like functions, but which differ syntactically or semantically from usual functions.
They are Mathematical Operators, Relational Operators and Logical Operators. Examples are
given in table 4.3 (a,b and c) in this section.
END
(a) Defining the problem: During this phase, the problem is described and fully analysed
(b) Formulating the solution: This second phase is also called the Design Stage where
you as a programmer, plan the logic of the solution
(c) Writing the program: This phase is also called the starting point of implementation,
which involves writing or coding the program
(d) Debugging and testing the program: The fourth phase consists of debugging or
removing the program errors and the program testing. This is still part of the so-called
stage of implementation
(e) Documenting the program: Documentation of the whole program is very essential in
program development after the successful testing. This involves gathering together
and organizing all the materials involved in its design.
(f) Evaluation the program: Evaluation phase is always an on-going programming
process which assures that the program continues to meet your need for example, as a
user
There are lots of terms used to describe the approaches you might take to solving a problem.
Some are listed below.
Technique Explanation
Divide & Conquer Break the problem down into smaller, solvable sub-problems
Attempting every step towards the solution (one approach that you might
Gradient
take to the U2 problem) even if it seems to move you temporarily away
Descent/Ascent
from the goal
Means-End
Setting sub-goals that lead to the solution
Analysis
Select an answer and see if it works, then select another until you happen
Trial & Error
on the solution
Brainstorming Thinking creatively and sifting through ideas for the best ones
Morphological
Looking at every possible combination of steps in pursuit of a goal
Analysis
Analogy Looking for a similar problem that has already been solved
The position of each digit in a decimal number indicates the magnitude of the quantity
represented and can be assigned a weight. The weight for whole number are positive powers of
10 that increase from right to left, beginning with 10 0 = 1
…105 104 103 102 101 100
For fractional numbers, the weights are negative powers of 10 that decrease from left to right
beginning with 10-1
102 101 100.10-1 10-2 10-3…
Decimal point
The value of a weight is determined by its position in the number. The value of a decimal
number is the sum of the digits after each digit has been multiplied by its weight.
Note: This weight is the same as what you know as T H T U (that represents Thousand,
Hundred, Tens and Unit) in Primary schools.
Example 1
Express the decimal number 47 as a sum of the value of each digit.
Solution
The digit 4 has a weight of 10, which is 101, as indicated by its position. The digit 7 has a weight
of 1, which is 100, as indicated by its position.
101 100
4 7 = (4 x 101) + (7 x 100)
= (4 x 10) + (7 x 1) = 40 + 7
Exercise: Determine the value of each digit in 939.
Example 2
Express the decimal number 568.23 as a sum of the value of each digit.
Solution
The weight of 5 is 100 = 102
The weight of 6 is 10 = 101
The weight of 8 is 1 = 100
The fractional digit 2 has a weight of 0.1 = 10 -1 while
The fractional digit 3 has a weight of 0.01 = 10-2
568.23 = (5 x 102) + (6 x 101) + (8 x 100) + (2 x 10-1) + (3 x 10-2)
= (5 x 100) + (6 x 10) + (8 x 1) + (2 x 0.1) + (3 x 0.01)
= 500 + 60 + 8 + 0.2 + 0.03
Exercise: Determine the value of each digit in 67.924
Counting in Binary
Having learnt how to count in decimal, counting in binary is easy and a comparable situation
occurs when you count in binary, except that you have only two digits called bits 0 and 1.
As you can see from table 1, four (4) bits are required to represent or count from 0 to 15. Note
that we started our decimal numbers from 0, so 0 through 15 make 16 numbers.
In general, with n bits you can count up to a number equal to 2 n – 1, so the largest decimal
number = 2n – 1 while the total number you can count is 2n, the largest decimal number that can
be counted is 2n – 1.
For instance, with 5 bits (n = 5) you can count 25 = 32. While the largest number you can count
is 25 – 1 = 32 – 1 = 31. Because counting start from 0.
Like decimal, the binary number is a weight number, the right-most bits are the LSB (Least
Significant Bit) in a binary whole number and has a weight of 20 = 1. The weight increases from
right to left by a power of two (2) for each bit. The left-most bit is the MSB (Most Significant
Bit); its weight depends on the size of the binary number.
Fractional number can also be represented in binary by placing bits to the right of the binary
point (not decimal point again since we are now dealing with binary, it is called binary point) just
as fractional digits are placed to the right of the decimal point. The left-most bit after the binary
point is the MSB in a binary fractional number and has a weight of 2 -1 = 0.5. The fractional
weight decreases from left to right by a negative power of two for each bit.
The weight structure of binary number is
2n-1 … 23 22 21 20. 2-1 2-2 2-3 … 2-n
Binary point
Where n is the number of bits from the binary point.
The second method for converting decimal to binary is the repeated division-by-2 method. This
method is familiar to you from primary school, to get the binary number for a given decimal
numbers, divide the decimal number by 2 until the quotient is 0. The remainders form the binary
number.
Example 7: Convert the following decimal number to binary, (a) 19 (b) 45
Solution:
(a)
2 19 R
2 9 1 LSB
2 4 1
2 2 0 R = Remainder
2 1 0
0 1 MSB
Read the bits from down to up to get required number 1910 = 100112
(b)
2 45 R
2 22 1 LSB
2 11 0
2 5 1 R = Remainder
2 2 1
2 1 0
0 1 MSB
4510 = 1011012
Exercise: Convert decimal number 39 to binary using successive division by 2
Repeated Multiplication by 2
Decimal fraction can be converted to binary by repeated multiplication by 2. For example, to
convert the decimal fraction 0.3125 to binary, begin by multiply 0.3125 by 2 then multiplying
each resulting fractional part of the product by 2 until the fractional product is zero or until the
desired number of decimal places is reached. The carry digits or carries, generated by the
multiplications produce the binary number. The first carry produced the MSB, and the last carry
is the LSB.
For example, convert 0.312510to binary
0.3125 x 2 = 0.625 0 …MSB
0.625 x 2 = 0.25 1
0.25 x 2 = 0.50 0
0.50 x 2 = 1.00 1 …LSB
Now the fractional parts are all zero so we stop. 0.312510 = 0.01012
Exercise: Convert each of the following decimal numbers to binary using the sum-of-weight
method:
(a) 23 (b) 57 (c) 45.5
Exercise: Convert each decimal number to binary by using the repeated division-by-2 method
(repeated multiplication-by-2 for fraction).
(a) 14 (b) 21 (c) 0.375
Binary Arithmetic
Binary arithmetic is essential in all digital computers and in many other types of digital system.
To understand digital systems, you must know the basic binary addition, subtraction,
multiplication and division.
Binary Addition
The four (4) basic rules for adding binary digits (bits) are as follows
0 + 0 = 0 sum of 0 with a carry of 0
0 + 1 = 1 sum of 1 with a carry of 0
1 + 0 = 1 sum of 1 with a carry of 0
1 + 1 = 10 sum of 0 with a carry of 1
Example 8: Add the following binary number
(a) 11 + 11 (b) 100 + 10 (c) 111 + 11 (d) 110 + 100
Solution:
(a) 1 1 3 (b) (c) 1 1 1 7
1 0 0 4
+ 1 1 ≈ +3
+ 1 0 ≈ +2 + 1 1 ≈ +3
1 10 6
1 1 0 6 101 0 10
(d) 1 1 0 6
+ 1 0 0 ≈ +4
1 0 1 0 10
Exercise: Add 1111 and 1100
Binary Subtraction
The four (4) basic rules for subtraction bits are as follows:
0–0=0
1–1=0
1–0=1
0–1=1
0 – 1 with borrow of 1 which you call 2. Remember in binary 10 – 1 = 1, not 2
When subtracting numbers, you sometimes have to borrow from the next column to the left. A
borrow is required in binary only when you try to subtract a 1 from a 0. In this case, when a 1 is
borrowed from the next column to the left, a 1 0 is created in the column being subtracted, and
the last of the four basic rules just listed must be applied.
- 0 1≈ - 1 -1 0≈ - 2
1 0 2 0 1 1
0 1 0 2
Exercise: Subtract 101 from 110
Binary Multiplication
The four (4) basic rules for multiplication bits are as follows:
0x0=0
0x1=0
1x0=0
1x1=1
This is the same as in decimal.
Example 10: Perform the following binary multiplications
(a) 1 1 x 1 1 (b) 1 0 1 x 1 1 1
Solutions
(a) 1 1 3 (b) 1 1 1 7
x 1 1 3 ≈x x 1 0 1 5 ≈x
1 1 9 1 1 1 35
+1 1 0000 Partial products
1001 +1 1 1
100011
Exercise: Multiply 1101 x 1010
Binary Division
Binary division follows the same procedure as division in decimal
11 3 110 6
10 2 10 0
10
00
Exercise: Divide 1100 by 100
0 1 0 0 1 1 0 1 1’s complement
The simplest way to obtain the 1’s complement of a binary number with a digital circuit is to
use parallel inverter (NOT circuits), as shown below for an 8-bit binary numbers.
1 0 1 0 1 0 1 0
NOT Gate
0 1 0 1 0 1 0 1
Example 13: Find the 2’s complement of 1 0 1 1 1 0 0 0 using the alternative method
Solution
1 0 1 1 1 0 0 0 Binary number
0 1 0 0 1 0 0 0 2’s complement
Note: That the circled parts remain the same while the remaining part is the 1’s complement.
The 2’s complement of a negative binary number can be realized using inverter (NOT gates) and
an adder as shown below.
1 0 1 0 1 0 1 0 ≈17010
1’s complement 0 1 0 1 0 1 0 1 1
Input bits adder
Carry in (Add 1)
To convert from 1’s or 2’s complement back to the original, true (un-complemented) binary
form, use the same procedures described previously. To go from the 1’s complement back to true
binary, reverse all the binary bits. To go from the 2’s complement from back to true binary, take
the 1’s complement of the 2’s complement number and add 1 to the LSB.
This is because the complement of a complement gives back the original un-complemented
number as you know in mathematics.
Given x, the complement of x is –x and complementing –x again gives –(-x) which equals x. So
also in logic, given x the complement is x- and complementing x- = x.
0 0 0 1 1 0 0 1
Sign bit
Magnitude bits
The decimal number -25 is expressed as 1 0 0 1 1 0 0 1
Note that the only difference between +25 and -25 is the MSB which is the sign bit because the
magnitude bits are in true binary for both positive and negative numbers.
In the sign-magnitude form, the negative number has the same magnitude bit as the
corresponding positive number but the sign bit is a 1 rather than a 0.
Example 14: Express the decimal number -39 as an 8-bit number in the sign-magnitude, 1’s
complement and 2’s complement form.
Solution: First write down the 8-bit number for +39.
00100111
In the sign-magnitude form, -39 is produce by changing the sign bit to 1 and leaving the
magnitude bits as they are which produce 10100111.
In the 1’s complement form -39 is produced by taking the 1’s complement of +39 (00100111),
this produce 11011000.
In the 2’s complement form, -39 is produced by taking the 2’s complement of +39 (00100111) as
follows:
1 1 0 1 1 0 0 0 1’s complement
+ 1
1 1 0 1 1 0 0 1 2’s complement
Exercise: Express +19 and -19 in sign-magnitude, 1’s complement and 2’s complement.
Example 15: Determine the decimal value of this signed binary numbers expressed in sign-
magnitude: 10010101
Solution
26 25 24 23 22 21 20
0 0 1 0 1 0 1
Summing the weights, we have
(0 x 26) + (0 x 25) + (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20)
= 0 + 0 + 16 + 0 + 4 + 0 + 1 = 21
The sign bit is 1 therefore, the decimal number is -21
1’s Complement
Decimal values of positive numbers in the 1’s complement form are determined by summing the
weight in all bit positions. Decimal values of negative numbers are determined by assigning a
negative value to the weight of the sign bit, sum all the weights and add 1 to the result.
Example 16: Determine the decimal values of the signed-binary number expressed in 1’s
complement: (a) 00010111 (b) 11101000
Solution
(a) The bits and their weights for the positive number are as follows:
-27 26 25 24 23 22 21 20
0 0 0 1 0 1 1 1
= 0 + 0 + 0 + 16 + 0 + 4 + 2 + 1 = +23
(b) -27 26 25 24 23 22 21 20
1 1 1 0 1 0 0 0
= -128 + 64 + 32 + 0 + 8 + 0 + 0 + 0 = -24
Adding 1 to the result we have
-24 + 1 = -23
Notice the negative (-) on the MSB of the left-most bit.
Exercise: Determine the decimal value of the 1’s complement number 11101011
2’s Complement
Decimal values of positive and negative numbers in the 2’s complement form are determined by
summing the weights in all bit position. The weight of the sign bit in a negative number is given
a negative value.
Example 17: Determine the decimal value of the sign-binary number expressed in 2’s
complement.
(a) 01010110 (b) 10101010
Solution
(a) -27 26 25 24 23 22 21 20
0 1 0 1 0 1 1 0
= 0 + 64 + 0 + 16 + 0 + 4 + 2 + 0 = +86
(b) -27 26 25 24 23 22 21 20
1 0 1 0 1 0 1 0
=-128 + 0 + 32 + 0 + 8 + 0 + 2 + 0 = -86
Note that there is no addition of 1 to the result here as in 1’s complement
Exercise: Determine the decimal value of the 2’s complement number 11010111
Example 18: Convert the decimal number 3.248 x 104to a single-precision floating-point binary
number.
Solution: Convert the decimal number to binary
3.248 x 104 = 32580 = 1111110111000002 = 1.11111011100000 x 214
The MSB will not occupy a bit position because it is always a 1. Therefore, the mantissa is the
fractional 23-bit binary number 11111011100000000000000 and the biased exponent is 14 + 127
= 141 = 100011012
The complete floating-point number is
0 10001101 11111011100000000000000
Exercise: Determine the binary value of the following floating-point binary number:
01001100010000100010100110000000
Addition
Two numbers in the addition are the addend and the subtrahends. The result is the sum, there are
four cases that can occur when two signed binary numbers are added.
1. Both numbers positive
2. Positive number with magnitude larger than negative number
3. Negative number with magnitude larger than positive number
4. Both numbers negative
Let’s take one case at a time using 8-bit signed number as example, the equivalent decimal
numbers are shown for reference.
Example 19:
0000111 7
0 0 0 0 1 0 0≈ + 4
0001011 11
The sum is positive and is therefore in true (un-complemented) binary.
Positive number with magnitude larger than negative number: Addition of a positive number and
a smaller negative number yield a positive number.
Example 20:
00001111 15
+ 1 1 1 1 1 0 1 0 ≈ + -6
Discard carry 1 00001001 9
The final carry bit that makes the total number of bits to become 9 instead of 8 bits 1’s discarded.
The sum is positive and therefore in true (un-complemented) binary.
Negative Number with Magnitude Larger than Positive Number
Addition of a positive number and larger negative number or two negative numbers yield a
negative number in 2’s complement.
Example 21:
00010000 16
+ 1 1 1 0 1 0 0 0 ≈ + -24
11111000 -8
The sum is negative and therefore is 2’s complement form
11111011 -5
+ 1 1 1 1 0 1 1 1 ≈ + -9
Discard carry 1 11110010 -14
The final carry is discarded. The sum is negative and therefore in 2’s complement form.
In a computer, the negative numbers are stored in 2’s complement form so, as you can see the
addition process is simple; add the two numbers and discard any final carry bit.
Overflow Condition
When two numbers are added and the number of bits required to represents the sum exceeds the
number of bits in the two numbers, an overflow results as indicated by an incorrect sign bit. An
overflow can occur only when both numbers are positive or both are negative. The following 8-
bit example will illustrate this condition.
Example 23:
01111101 125
0 0 1 1 1 0 1 0 ≈ + 58
10110111 183
Incorrect sign
Magnitude incorrect
In the above example, the sum of 183 requires 8 magnitude bits. Since there are seven magnitude
bits in the number (one bit is sign), there is a carry into the sign bit which produces the overflow
indication.
Subtraction
Subtraction is a special case of addition, for example subtracting +6 (the subtrahend) from +9
(the minuend) is equivalent to adding -6 to +9. Basically, the subtraction operation changes the
sign of the subtrahend and adds it to the minuend. The result of a subtraction is called the
difference.
Note: The sign of a positive or negative binary number is changed by taking its 2’s complement
For example, when you take the 2’s complement of the positive number
0 0 0 0 0 1 0 0 (+4) as the following sum-of-weight evaluation shows:
-128 + 64 + 32 + 16 + 8 + 4 = -14
Hence, to subtract two signed numbers, take the 2’s complement of the subtrahend and add.
Discard and final carry bit.
Example 25: Perform each of the following subtractions of the signed numbers
a. 0 0 0 0 1 0 0 0 – 0 0 0 0 0 0 1 1
b. 0 0 0 0 1 1 0 0 – 1 1 1 1 0 1 1 1
c. 1 1 1 0 0 1 1 1 – 0 0 0 1 0 0 1 1
d. 1 0 0 0 1 0 0 0 – 1 1 1 0 0 0 1 0
Solution: The equivalent decimal subtractions are given for reference.
a. In this case, 8 – 3 = 8 + (-3) = 5
24 Product
The multiplication operation in most computers is accomplished using addition. Now let’s see
how multiplication is done.
Direct addition and partial products are two basic methods for performing multiplication. Using
addition in the direct addition method; you add the multiplicand a number of times equal to the
multiplier. In the previous decimal example (3 x 8), three multiplicands are added 8 + 8 + 8 = 24.
The disadvantage of this approach is that it becomes very lengthy if the multiplier is a large
number. For example, 75 x 350, you must add 350 to itself 75 times. Incidentally, this is why the
term is used to mean multiply. When two binary numbers are multiplied, both numbers must be
in true (un-complemented) form. The direct addition method is illustrated below in example 26,
adding two binary numbers at a time.
The partial products method is perhaps the more common one because it reflects the way you
multiply long hand. The multiplicand is multiplied by each multiplier digit beginning with the
least significant digit. The result of the multiplication of the multiplicand by a multiplier digit is
called a partial product.
Each successive partial product is moved (shifted) one place to the left and when all the partial
products have been produced, they are added to get the final product.
Here is a decimal example
239 Multiplicand
x 123 Multiplier
The sign of the product depends on the sign of the multiplicand and the multiplier according to
the following rules.
1. If the signs are the same, the product is positive
2. If the signs are different, the product is negative
Example 27: 0 1 0 1 0 0 1 1 x 1 1 0 0 0 1 0 1
Solution:
Step 1: The sign bit of the multiplicand is 0 and the sign bit of the multiplier is 1, the sign bit of
the product will be 1 (negative)
Step 2: Take the 2’s complement of the multiplier to put it in a true form
11000101 0 0 1 1 1 0 1 1 2’s complement
Step 3 and 4: The multiplication proceeds as follows
Note that only the magnitude bits are used in these steps. The sign bits of the numbers are left out
since we know that the final product is negative (sign bit 1).
1010011
x 0111011
Exercise: Verify that the multiplication above is correct by converting the result in question 27
above to decimal number and performing the multiplication.
Division
The numbers in a division are the dividends, the divisor and the quotient. These are illustrated in
the following standard division format:
Dividend
= Quotient
Divisor
The division operation in computers is achieved using subtraction. Since subtraction is done with
an adder, division can also be done with an adder.
The result of a division is called the quotient; this is the number of times that the divisor will go
into the dividend. This means that the divisor can be subtracted from the dividend a number of
times equal to the quotient, as illustrated by dividing 21 by 7 below.
21 Dividend
7 2ndpartial remainder
0 Zero remainder
In this example, the divisor was subtracted from the divided three times before a remainder of
zero was obtained. Therefore, the quotient is 3.
The sign of the quotient depends on the sign of the dividend and the divisor according to the
following rules;
1. If the signs are the same, the quotient is positive
2. If the signs are different, the quotient is negative.
When two binary numbers are divided, both numbers must be in true (un-complemented) form
01100100 Dividend
Add 1 to quotient: 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1 = 0 0 0 0 0 0 0 1
Step 3: Subtract the divisor from the 1st partial remainder using 2’s complement addition.
01001011 1st partial remainder
+ 11100111 2’s complement divisor
00110010 Positive 2nd partial remainder
Step4: Subtract the divisor from 2 nd partial remainder using 2’s complement addition
00110010 2nd partial remainder
+11100111 2’s complement divisor
01001011 Positive 3rd partial remainder
Add 1 to quotient: 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 1 = 0 0 0 0 0 0 1 1.
Step 5: Subtract the divisor from the 3rd partial remainder using 2’s complement addition.
00011001 3rd partial remainder
+1 1 1 0 0 1 1 1 2’s complement divisor
00000000 zero remainder
Add to quotient: 0 0 0 0 0 0 1 1 + 0 0 0 0 0 0 0 1 = 0 0 0 0 0 1 0 0
(Final quotient), the process is complete.
Exercise: Verify that the process is correct by converting the result obtained in question 28
above to decimal numbers and performing the division.
Hexadecimal Numbers
The hexadecimal (HEX) number system has 16 characters; (0 through 15) it is primarily used as
a compact way of displaying or writing binary numbers because it is very easy to convert
between binary and HEX. As you are probably ware, long binary numbers are difficult to read
and write because it is easy to drop or transpose a bit. Since computers and microprocessors
understand only 1’s and 0’s, it is necessary to use these digits when you program in “machine
languages”.
The HEX numbers system has a base of sixteen (16); that is, it is composed of 16 numeric and
alphanumeric characters. Most digital systems like computers process binary data in groups that
are multiples of four bits, making the HEX number system very convenient because each HEX
digit represents a 4-bit binary numbers as shown below:
Table 2: Decimal, Binary and Hexadecimal Numbers Equivalence
We will use the subscript 16 to indicate HEX number to avoid confusion with decimal numbers;
sometimes you may see “h” following a HEX number.
Counting in Hex
How do you count in HEX once you get to F? Simply start over with another column and
continue as follows: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A, 1B, 1C, 1D, 1E, 1F, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 2A, 2B, 2C, 2D, 2E, 2F, 30…
With two HEX digits, you can count up to FF16, which is equivalent to decimal 255. To count
beyond this, three HEX digits are needed, for instance, 100 16 is decimal 256, 10116 is decimal
257, and so forth. The maximum 3-digit HEX number is FFF16 or decimal 4,095. The maximum
4-digits HEX number is FFFF16, which is equivalent to decimal 65,535.
Binary-to-Hex Conversion
To convert from binary to HEX is simple. Break the binary number into 4 part groups, starting
from the right-most bit and replace each 4-bits group with the equivalent HEX symbol.
C A 5 7 = CA5716
(b) 0 0 1 1 1 1 1 1 0 0 0 1 0 1 1 0 1 0 0 1
3 F 1 6 9 = 3F16916
Two zeros have been added in part (b) to complete a 4-bits group at the left
Note: we use the vertical lines to divide the numbers into groups of four binary digits (nibbles)
Example 30: Determine the binary number of the following HEX numbers.
(a) 10A416 (b) CF8E16 (c) 974216
Solution:
(a) 1 0 A 4
(c) 9 7 4 2
Another way to convert a HEX number to its equivalent decimal is to multiply the decimal value
of each HEX digit by its weight and then take the sum of these products. The weights of HEX
number are increasing powers of 16 (from right to left). For a 4-digit HEX number, the weights
are;
163 162 161 160
4096 256 16 1
Example 32: Convert the following HEX numbers to decimal;
(a) E516 (b) B2F816
Solution: Recall from Table 1, that letters A through F represents decimal number 10 through
15, respectively.
(a) E516 = (E x 16) + (5 x 1) = (14 x 16) + (5 x 1) = 224 + 5 = 229 10
(b) B2F816 = (B x 4096) + (2 x 256) + (F x 16) + (8 x 1)
= (11 x 4096) + (2 x 256) + (15 x 16) + (8 x 1)
= 45,056 + 512 + 240 + 8 = 45,81610
Exercise: Convert 60A16 to decimal.
Hex Addition
In HEX addition, remember that A to F represents 10 to 15 in decimal, so look at the digits in
terms of their decimal equivalent.
Example 33: Add the following HEX numbers
(a) 2316 + 1616 (b) 5816 + 2216 (c) 2B16 + 8416 (d) DF16 + AC16
Solution:
(a) (b) (c) (d) DF16
2316 5816 2B16
Hex Subtraction
Various methods exist in HEX subtraction
Method 1:
HEX Binary 2’s complement in binary 2’s complement in HEX.
Example 34:
2A 00101010 11010110 D6
Method 2:
HEX Subtraction from maximum 1’s complement in HEX +1 2’s complement in
HEX
Method 3:
HEX 0123456789ABCDEF
FEDCBA9876543210
1’s complement in HEX
Octal Numbers
Like the HEX numbers system, the octal number system provides a convenient way to express
binary numbers and codes. However, it is used less frequently than HEX in conjunction with
computers and microprocessors to express binary quantities for input and output purposes. The
octal number system is composed of eight digits which are 0 through 7.
Octal digit 0 1 2 3 4 5 6 7
Binary 000 001 010 011 100 101 110 111
To convert an octal number to a binary number, simply replace each octal digit with the
appropriate three bits.
Example 38: Convert each of the following octal numbers to binary
(a) 138 (b) 258 (c) 1408 (d) 75268
Solution:
(a) 1 3
001 011
001011
(b) 2 5
010 101
010101
(c) 1 4 0
001100000
(d) 7 5 2 6
Solution
(a) 1 1 0 1 0 1
6 5 = 658
(b) 1 0 1 1 1 1 0 0 1
5 7 1 = 5718
(c) 1 0 0 1 1 0 0 1 1 0 1 0
4 6 3 2 = 46328
(d) 0 1 1 0 1 0 0 0 0 1 0 0
3 2 0 4 = 32048
Exercise: Convert the binary number 1 0 1 0 1 0 1 0 0 0 1 1 1 1 1 0 0 1 0 to octal.
Decimal digit: 0 1 2 3 4 5 6 7 8 9
BCD: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Invalid Codes
You should realize that with four bits, sixteen numbers (0000 through 1111) can be represented
but in the 8421 code, only ten of these are used. The six code combinations that are not used;
1010, 1011, 1100, 1101, 1110 and 1111 representing decimal 10 to decimal 15 are invalid in the
8421 BCD code.
To express any decimal number in BCD, simply replace each decimal digit with the appropriate
4-bits code.
0011 0101
00110101
(b) 9 8
1001 1000
10011000
(c) 1 7 0
8 6 = 8610
(b) 0 0 1 1 0 1 0 1 0 0 0 1
3 5 1 = 35110
(c) 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 0
9 4 7 0 = 947010
Exercise: Convert the BCD codes 10000010001001110110 to decimal.
BCD Addition
BCD is a numerical code and can be used in arithmetic operation. Addition is the most important
operation because the other three operations (subtraction, division, and multiplication) can be
accomplished by the use of addition. Here is how to add two BCD numbers:
Example 42: Add the following BCD numbers
(a) 0011 + 0100 (b) 00100011 + 00010101 (c) 10000110 + 00010011
(d) 010001010000 + 010000010111
Solution: The decimal number additions are shown too.
(a)
0011 3
+ 0100 ≈ + 4
0111 7
(b)
00100011 23
+ 00010101 ≈ + 15
00111000 38
(c) 10000110 86
+ 00010011 ≈ + 13
10011001 99
(d) 010001010000 450
+ 011000010111 ≈ + 417
100001100111 867
Note: That in each case the sum in any 4-bit column does not exceed 9, and the results are valid
BCD numbers.
The Internet is a global network of computer networks utilizing a suite of protocols called the
TCP/IP (Transmission Control Protocol/Internet Protocol) that supports interconnection of a
number of different computer networks. The Internet covers large, international Wide Area
Networks (WAN’s) as well as smaller Local Area Networks (LAN’s) and individual
computers connected to the Internet worldwide. The Internet supports communication and
sharing of data, and offers a vast amount of information through a variety of services and
tools.
6.2.1 Internet versus Computer Network
The Internet has several tools and services that makes it ideal as an information resource.
Each of these features has its own merits and therefore should be utilized depending on the
type of information one needs to access.
(a) Electronic-Mail
This is the most popular service available on the Internet, e-mail as a form of correspondence
has revolutionalized the way we communicate with each other. It is a way of sending
messages from one computer to another. Its ability to send files through attachments also
factors in its popularity. It is readily available, and in most cases free of charge, this speedy
alternative to postage mail comprises the bulk of traffic on the Internet. Almost all internet
users have at least one e-mail address, and in some cases, several addresses. It has also
become the most basic form of identification on the Internet, with a lot of websites requiring
an e-mail address before offering services.
(b) Newsgroups
Newsgroups are an online forums for discussion of related topics, accessible by a newsreader.
Some newsgroups allow postings or messages from anyone, while others are moderated
(postings are screened). Several university departments have also set up newsgroups for
specific issues and class use. On the Internet, there are literarily thousands of newsgroups
covering every conceivable interest. To view and post messages to a newsgroup, you need a
news reader, a program that runs on your computer and connects you to a news server on the
Internet.
Using chat is like "talking" to other people who are online at the same time as you are.
Special software allows typed-in messages to be viewed by everyone taking part at that time.
Chats can be ongoing or scheduled for a particular time and duration. Most chats are focused
on a particular topic of interest and some involve guest experts or famous people who "talk"
to anyone joining the chat. Topics of interest are organized into “channels”, facilitating
specialized chat sessions that occur in chatrooms. More advanced forms of chat use sound
cards to allow voices and 2D or 3D characters called “avatars” to represent the participants.
Some websites have built in chatrooms enabling on-site chatting e.g. the U.S. Patriot Tactical
using SMS-to-Chat services that allows clients to start a live chat with their support team via
a simple text message.
(d) Telnet
Telnet is a client software allowing a user to login from a local desktop computer to a remote
server, the Telnet host, and use its resources. Access is usually controlled by passwords given
to each individual or group. Once access is given, the remote user can issue commands or use
the resources of the host, depending on the level of access given the user. It is mainly used by
libraries to allow access to information stored in their computers.
File Transfer Protocol or FTP is an Internet utility that allows the transfer of files from one
location to another. In order to do this, one must have an FTP program to connect to other
servers and be able to download files. These FTP programs are available both commercially
and for free, and offer various features. Most modern web browsers have built in FTP
capabilities enabling downloads through websites.
The World Wide Web (WWW or W3) was invented by Tim Berners-Lee in 1991 and further
developed at the CERN labs in Switzerland in the early 1990s. It is a vast collection of
interconnected files and programs spanning the globe and retrievable via a client-server
system utilizing HTML (Hyper Text Markup Language) enabled documents called webpages.
It is responsible for the so-called Internet boom, transforming it from a largely academic
domain into a commercial one. It has grown to encompass not only its native http protocol,
but also ftp, newsgroups, e-mails, chat and telnet. As a result of this, most people equate the
Web with the Internet. The Web is accessed by programs called browsers (e.g., Netscape
Navigator or Internet Explorer, Google Chrome, Firefox e.t.c.). These browsers enable
webpages and websites containing multimedia content and applications to be accessed
anytime, anywhere. Users navigate the Internet by following links from one document to
other documents on computers located anywhere on the globe. These links are called
hyperlinks and connect the contents of Webpages to each other as well as to other Webpages
identified by their URLs (Uniform Resource Locators).
Google is the gatekeeper to the World Wide Web and the keyholder to all the answers to your
questions. Type keywords and find the best answer possible. There’s a reason why it’s ranked
the number one website in the world, you know.
Google Drive is an easy way to drag-and-store all of your documents onto a Google account.
You can view documents anytime and anywhere with internet access. If you’re running an
online business with multiple employees, use Google Drive to share documents and pass
information.
(i) WordPress
This is a free to use blogging platform. It allow you create your own domain and have a
website running in minutes. WordPress is arguably the goto blogging website used by
millions of businesses online. It’s free and available on Linux, PC, and MAC.
(j) Ecommerce
Ihis is also known as electronic commerce or internet commerce, refers to the buying and
selling of goods or services using the internet, and the transfer of money and data to execute
these transactions. There are six basic types of e-commerce. e.g. Business-to-Business (B2B),
Business-to-Consumer (B2C), Consumer-to-Consumer (C2C), Consumer-to-Business (C2B),
Business-to-Administration (B2A) and Consumer-to-Administration (C2A). All of them
represent a different purchasing dynamic
The Internet started as a military network called ARPANET (Advanced Research Projects
Agency Network), which was involved in networking research. The research involved the
creation of standards and protocols that will support interconnection of a number of computer
networks. It also involved the creation of applications and technologies that utilize current
and emerging technologies. This process continues as the Internet grows dynamically.
The Internet later expanded to include Universities, Businesses and Individuals. However, the
Internet only started to gain popularity with the casual computer user in the 1990s, with the
creation of the World Wide Web, followed by the introduction of Mosaic, the first graphical
Web browser. Today, the Internet is also referred to as the Net, Information Superhighway,
and Cyberspace.
The following are some of the technologies that make the Internet work:
Protocols – standardized rules that define how computers communicate and exchange
data.
IP(Internet Protocol)address – unique number used to identify computers on the
Internet
Domain name – structured naming system to locate computers on the Internet
URL – uniform naming scheme that specifies unique addresses of Internet resources
Client and server – computing architecture used by most Internet services
Internet Protocols
Below are some of the Internet Protocols used by Internet tools and services;
(a) TCP/IP (Transmission Control Protocol / Internet Protocol) -The Internet is a packet-
switching network that uses TCP/IP as its core protocol. TCP/IP is a suite of protocols
that govern network addresses and the organization and packaging of the information
to be sent over the Internet. Transmission Control Protocol (TCP) handles the flow
control and recovery of packets, while Internet Protocol (IP) is responsible for
addressing and forwarding of individual packets.
(b) HTTP (Hypertext Transfer Protocol) – a protocol for accessing and transmitting
World Wide Web documents
(c) FTP (File Transfer Protocol) – a protocol for transferring files from one computer to
another
(d) Gopher Protocol – a protocol for accessing documents via Gopher menus (no longer
widely used)
(e) Telnet Protocol – a protocol that allows users to logon to a remote computer
(f) SMTP (Simple Mail Transfer Protocol) – a protocol for sending and managing
electronic mails (e-mail)
IP address
Unlike local computer networks which are centrally controlled, the Internet is decentralized
by design. Its operators can choose which Internet services to use and which services to make
available to the global Internet community. Each Internet computer, called a host, is
independent and has a unique address called the IP address. TCP/IP uses the IP address to
route packets of information from a sender to a location on the Internet. The IP address
consists of four sets of numbers ranging from 0 to 255.
Domain Names
Domain names are the alias or English- language equivalent of a computer’s IP address. The
Domain Name System (DNS) allows the use of easier to remember domain names instead of
IP addresses to locate computers on the Internet. Domain Name Resolvers scattered across
the Internet translate domain names into IP addresses
Domain Names have two parts: the first part names the host computer while the second part
identifies the top-level domain. Accordingly, there are two types of Top-Level Domains
(TLD);generic Top-Level Domains and country code Top-Level Domains. The TLD
identifies the type of host; for example a domain that ends with .edu is an educational
institution. Domain names are used in URLs and e-mail addresses.
Only a few top-level domains are currently recognized, but this is changing. Here is a
list of the domains generally accepted by all:
.ng – Nigeria
.ph – Philippines
.cn – China
.sg – Singapore
.fj – Fiji
.uk – United Kingdom
The complete list can be accessed at http://www.iana.org/cctld/cctld-whois.htm
A URL or Uniform Resource Locator is the unique address of a given webpage. Knowing the
URL allows you to locate a given webpage. Much like a house address, the URL consists of
several parts: the protocol, the domain name and the path.
• Protocol – lets the computer know how to process the information it receives
• Domain name – Internet address of the computer hosting the site and storing the documents
• Path – lets the computer know which directory and file to access
In the example http://www.amazon.com/books/children.html
• "http” - hypertext transfer protocol
• "www" - world wide web server name
• “amazon" - second-level domain name
• “com" - top-level domain name
• "books" - directory name • “children" - file name
• "html" - file type
Client-Server
The client-server model is the distributed computing architecture used by most Internet
services, generally classifying hosts on the Internet as clients and servers. Client computers
use client programs to access Internet services provided by host computers (Servers) running
server programs that provide the information or services needed. For example, web browsers
are client programs used to access information hosted by Web Servers. Each Internet service
requires a specific client program; however, most of these services can now be accessed by
simply using a web browser.
(a) Net surfing –involves scanning pages and clicking on links randomly. It is a leisurely
way of searching for information which could be highly unorganized and inefficient.
It involves browsing the links provided on the current web page being viewed, in
search of related valuable information
(b) Using a URL – quickest way to find information on the Internet but user must know
where it is located. It is quite effective but user may encounter problems in
remembering the exact URL and in finding the document if the URL has been
changed.
(c) Using search tools and services – can assist user in locating the information desired
among the vast amount of information available on the Net.
General classifications of Internet tools and services available through the World Wide Web
are
Search engines are huge databases of web page files that have been assembled automatically
by the machine over time and are the best means for searching the web. Search engines
compile their databases by employing "spiders" or "robots" ("bots") to crawl through the
Internet, usually using embedded links. They periodically search the World Wide Web and
automatically index and store the information in their database. On the downside, web pages
without links are usually missed in these searches. To circumvent this, most web authors
place tags called META tags on their web pages enabling the search engines to track them.
Search engines are different from each other since they use their own proprietary programs
for searching the Net. These softwares employ different types of indexing as well as
relevancy ranking systems, so searches using different search engines yield different results
in terms of the number of ‘hits’ (matching documents) found and in the actual documents
that comprise those hits.
Subject directories differ from search engines in that most of them are assembled manually.
Much like directories in the print media, subject directories are registries assembled by
editors who determine which sites to include and exclude in their listings. Because of this,
subject directories tend to index even less content than do search engines.
By their very nature, subject directories are more out of date compared to search engines.
Since they do not store actual pages but rather direct to them, it is not uncommon to find that
some of the addresses or search results no longer exist. Their main advantage is that they
point to top-level addresses, and thus are perfect for searching general topics as well as
looking for products and the main sites of commercial establishments.
The invisible web is so called since it refers to documents that cannot be ordinarily reached
through search engines and subject directories, and are thus ‘invisible’. It is generally
believed to comprise the bulk of the Internet with estimates ranging from 60% to as much as
90% of all content. This content is largely made up of databases, and collections of databases,
that cannot be directly accessed on the Web because they are password protected, hidden or
in formats that are not generally used or searchable. Usually very subject specific, the
invisible Web is organized by professionals or individuals who have accumulated data on
their particular interests. Search engines and subject directories usually exclude them from
main-stream searches since they generate little interest to the bulk of users, but nonetheless
they may still point to places or ‘vortals’ where they can be accessed.
Meta-search engines send your search query to several search engines simultaneously and
give you a consolidated report of their findings. They do not maintain a database of their
own. Examples are; Metacrawler – http://www.metacrawler.com, Dogpile –
http://www.dogpile.com, ProFusion – http://www.profusion.com
(e) Specialized search engines
Specialized search engines are dedicated to indexing web pages on specific topics .Examples
are;Locate mailing lists and newsgroups, The Lizt – http://www.liszt.com,Mailbase –
http://www.mailbase.ac.uk, Dejanews – http://www.dejanews.com, Google groups -
http://groups.google.com/
Others are FTP archives used to locate files on anonymous FTP sites.
Examplesare;ArchiePlex -http://archie.emnet.co.uk/form.html; Web and e-mail people finder
o Ex. – Four11 – http://people.yahoo.com; Multimedia search o Ex. - Webseek -
http://www.ctr.columbia.edu/webseek/; Virtual Reference Libraries – online dictionaries,
indexes, etc. o Ex. Research-it – http://www.iTools.com/research-it and Virtual Reference
Desks – online reference serviceso Ex – AskA+Locator -
http://www.vrd.org/locator/subject.shtml
Most, if not all of the Internet tools and services can be used through the World Wide Web.
To be able to use the search tools on the Web, one must first know how to use a browser.
Moreover, features and functions of available search tools and services vary and as such one
must be familiar with at least two or more search tools to become effective in finding
information on the Net.
Browsers
These are programs used to access the World Wide Web. A browser allows a user to access
resources on a server and displays the contents of the web in multimedia format. Examples
of browsers are Netscape Navigator, Internet Explorer, America Online, Opera, Firefox,
Safari, etc.
Using a Browser
You need to be familiar with the features of your web browser and know how to do these;
• enter a URL in the location or address bar to visit a particular web site
• open, resize, close a browser window
• locate and use the navigation tools on your browser, ie., back, reload/refresh, home, print
• identify and use hyperlinks to get around the web
• download documents and files
• use plug-ins like Adobe Acrobat or Macromedia Shockwave
Generally, there are two ways of using search tools and services
Browsing – usually applied to directories where subjects are arranged hierarchically
Keyword search – search box is provided for entering keywords to search the
database
• Simple search – search on the keywords, Type keywords in the search box, press
Enter on the keyboard, and then select from the results
• Advanced search – search can be refined using various techniques
Problem Solution
Endless links that lead to getting lost Try another search
Data traffic taking eternity to download Try it another time /site or change ISP
Too many; too few or irrelevant sites Refine or vary your search
Information overload Search with a more specific question in mind
Online resources have made an entire revolution in education, not only because they are
convenient and accessible, but because they make the entire process of teaching and learning
more interesting and memorable. There are free and paid online resources for college
students,and they usually complement one another quite well. Each student will prefer
different resources according to their subjects of interest and learning style, but there are
universally great tools that impress nearly every student who tries them.
In order to help college students locate the best online resources, the underlisted sites may be
useful;
.
CHAPTER SEVEN
Scratch is a visual programming environment that lets users create interactive, media-rich
projects. People have created a wide range of projects with Scratch, including animated stories,
games, online news shows, book reports, greeting cards, music videos, science projects, tutorials,
simulations, and sensor-driven art and music projects. The Scratch application is used to create
projects containing media and scripts. Images and sounds can be imported or created in Scratch
using a built-in paint tool and sound recorder. Programming is done by snapping together
colorful command blocks to control 2-D graphical objects called sprites moving on a background
called the stage. Scratch projects can be saved to the file system or shared on the Scratch Web
site.
When the Costumes tab is chosen, the costume editor is shown in figure 7.2
1. Click File/New to create a new project and enter a project name of Square.
2. From the Events menu, drag a when green flag clicked block to the scripts area. Your scripts
area should look like this:
3. From the Motion menu, drag a goto x: 0 y: 0 block to the scripts area and snap it to the bottom
of the when green flag clicked block. Your script should look like this:
4. Add a move 10 steps block to the bottom of your script and change the 10 to 100.
5. Click the green flag at the top right corner of the stage to run your program. Let’s look at what
happened:
The when green flag clicked block tells Scratch that the other blocks in the script are to be
executed at the start of the program — that is, when the green flag is clicked.
The go to x: 0 y: 0 block tells Scratch to move the sprite — that’s the cat, which is what
you’re writing instructions for — to the coordinates (0, 0). The stage has a coordinate system
with (0, 0) in the center, x values ranging from –240 to +240, and y values ranging from –
180 to +180.
The move 100 steps block tells Scratch to move the sprite 100 units in the direction it is
facing
3. Run your program. What happened? Nothing? Actually, the sprite moved in a square,
but so quickly that you couldn’t see it. You can fix that by adding wait 1secs blocks
from the Control menu to the stack:
4. Run your program again. Better? If your sprite is too slow, you can always change the
wait time.
(c) Repeat Loops
Look at your script. One thing that should strike you is that three blocks — move, turn, wait
— are repeated four times. Imagine if you wanted your cat to walk in a square 100 times.
You’d need 1,200 blocks! That’s insane. (Not to mention a lot of work.) Fortunately, there is
an easy way to fix this: the repeat loop.
1. Drag the four sets of move/turn/wait blocks away from the bottom of the script.
2. Drag a repeat 10 block to the bottom of your script and change the 10 to a 4.
3. Drag one set of move/turn/wait blocks inside your repeat block.
4. Now run your program. Your sprite still moves in a square, but with far fewer
commands. Repeat loops are an incredibly important programming tool. They allow you
to repeat actions without having to add extra blocks, thus saving lots of work. Use repeat
loops!
(d) More Repeat Loops
You may have noticed that the move block makes your sprite jump from one place to
another. Sometimes, this is what you want. Other times, you might want your sprite to move
smoothly across the screen. One way to do this is to make it move multiple, shorter
distances.
1. Replace the move 100 steps block with a repeat loop that moves the sprite 10 times,
moving 10 steps each time.
2. Remove the wait blocks so that the sprite doesn’t pause. (Remember, we added the wait
blocks only because the sprite moved too fast to see.)
3. Run your program and watch the sprite move more smoothly in a square.
(e) Forever Loops
What if you want to make your cat really, really dizzy? Or just want to do something
forever? There is a special kind of repeat loop for this called a forever loop, which you can
find in the Control menu.
1. Replace the repeat 4 block with a forever block.
2. Run your program and watch your cat go round and round and round and round and ...
(f) Cleanup and Save
You probably have a lot of unused blocks laying around the script area.
1. Drag the unused blocks to the blocks palette to delete them.
2. Click File/Save to save your project.
5. Inside the if-then block, add a turn counterclockwise 180 degrees block:
This script tells Scratch to check if the x position of the sprite is greater than 240 — that is,
if it is at the right edge of the stage. If so, Scratch rotates the sprite 180 degrees. If not,
nothing happens. (There is also an if-then-else block so you can do something else if the test
condition is false.)
Along with repeat loops, if-then and if-then-else statements are two of the main building
blocks of programs. Use them!
6. Run your program. Your sprite should move to the right edge of the stage, turn around, and
move to the left edge of the stage, where it gets stuck. To fix this, add blocks to rotate the
sprite 180 degrees if the x position is less than –240.
7. Run your program again. Your sprite should move endlessly between the right and left edges
of the stage.
8. To finish your program, keep your cat right side up. (You may have noticed that it is upside
down when moving left.) To do this, add a set rotation style left-right block from the Motion
menu as the first block in your script.
(b) Keyboard Commands
Let’s face it. Walking back and forth is boring. Time to make your sprite jump. To do this,
you will add blocks that move the sprite up and down 50 steps when the space bar is
pressed.
1. From the Events menu, drag a when space key pressed block to the scripts area:
An event is something that happens. The main events in Scratch are starting the program,
pressing keys, and broadcasting and receiving messages, which are used to communicate
between scripts and between sprites.
2. Beneath the key-pressed block, add blocks to move the sprite up and down 50 steps in
increments of 10 steps. You will need to use the change y by 10 block from the Motion
menu.
3. Run your program. When you press the space bar, the sprite should jump up and fall back
down.
(c) Adding More Sprites
Time to give your cat a reason to jump. Really, what cat jumps because you press a space
bar? Lightning is a much better motivator.
1. Click the Choose sprite from library icon:
2. Select the Lightning sprite and click OK. This adds a new sprite to the sprite list.
3. Add a script to hide the Lightning sprite when the program starts. You will need the hide block
from the Looks menu.
4. Add a script to make the Lightning strike the cat when the space bar is pressed. The lightning
sprite should move to the cat sprite, show itself, wait 0.1 seconds, and hide itself again. In
addition to the blocks you have already learned, you will need the go to mouse-pointer block
on the Motion menu — you will need to change mouse-pointer to Sprite1 in the drop-down
list — and the show block from the Looks menu.
5. Run your program, press the space bar, and watch the cat jump.
7.4.5 Messages
In this section, you will learn to use messages, which are used to communicate between scripts
and between sprites.
(a) Sending and Receiving Messages
1. Create a new project and name it Taking Turns.
2. Right-click Sprite1 in the sprite list and select duplicate. This will make a copy of Sprite1
named Sprite2.
3. Create a script for Sprite1 that broadcasts the message sprite 1’s turn when the program
starts. You will need the broadcast block in the Events menu. To create your message,
click the drop-down list, select new message..., and type sprite 1’s turn. Your block should
look like this:
4. Drag a when I receive block to the scripts area and set the value to sprite 1’s turn:
5. Add blocks to the when I receive script to glide to a random position, then broadcast a new
message named sprite 2’s turn. You will need the glide 1 secs to x: y: block from the
Motion menu, two pick random 1 to 10 blocks from the Operators menu, and a broadcast
block. Use the random blocks to choose an x value between –240 and 240 and a y value
between –180 and 180.
6. Click Sprite2. Create a script to receive the message sprite 2’s turn, glide to the position of
Sprite1, and broadcast the message sprite 1’s turn. To determine the position of Sprite1, use
__ of __ blocks from the Sensing menu, set as follows:
7. Run your program. Sprite1 should glide to a random position on the stage; Sprite2 should
glide to Sprite1’s position; Sprite1 should glide to a new position; and so on.
Let’s see what’s happening:
a) When the program starts, Sprite1 broadcasts the message sprite 1’s turn.
A message is like yelling into a crowd of people, “Who is supposed to wash the dishes?”
Everybody can hear it, but only those people (sprites) who have been told they are on dish
duty (have a when I receive block for the dish duty message) will respond. This could be
zero, one, many, or all people (sprites).
b) Because Sprite1 has a when I receive block for the message sprite 1’s turn, it executes the
script for that message. In this case, it randomly picks an x value between –240 and +240
and a y value between –180 and +180, then glides to the new position. After gliding, it
broadcasts the message sprite 2’s turn.
c) Because Sprite2 has a when I receive block for the message sprite 2’s turn, it executes the
script for that message. In this case, it finds the x and y coordinates of Sprite1, glides to
that position, and broadcasts the message sprite 1’s turn, starting the cycle all over again.
7.4.6 Animation
(a) Bitmap Mode
Before learning animation, you need to learn about two different ways to draw with a
computer: bitmap drawing and vector drawing. In this section, you will learn about bitmap
drawing.
1. Create a new project and name it Bitmap vs. Vector.
2. Click the Costumes tab and click Clear to delete the cat.
3. Look in the lower right hand corner and make sure you are in Bitmap Mode. If you are
not in Bitmap Mode, click Convert to bitmap.
4. Using the line tool, draw an X with a short and a long arm:
5. Now suppose you want to rotate the short line while keeping the long line in place.
Using the Select tool, select the short line:
6. Using the rotation handle (the circle at the top of the line coming out of the selection
box), rotate the short line:
What happened? Both the short line and a segment of the long line in the selection box
rotated. This is because you didn’t actually select just the short line, you selected
everything in the selection box. In bitmap mode, the computer does not understand what a
line is. Instead, it just stores a grid of dots. For example, this is what the computer stores
for a short line:
(Actually, the computer stores a grid of numbers, where each number tells the computer
what color to draw each dot in the grid. But it’s easier to think of the computer as just
storing a grid of dots.)
Because the computer just stores dots, it doesn’t understand anything about those dots.
That is, it doesn’t realize that the grid shown above is a line, or that a different grid might
show a circle or a triangle. All it sees are dots.
As a result, when you use the select tool, you can’t select a particular line in the grid. You
can only select the dots in the grid. And when you rotate the grid, you rotate all of the dots
in the grid.
(b) Vector Mode
In the section (a), you learned about bitmap drawing. In this lesson, you will learn about
vector drawing:
1. Click Costume2, clear the canvas, and check that you are in Vector Mode. If you are not
in Vector Mode, click Convert to vector.
2. Using the line tool, draw the same lopsided X you drew in the previous lesson.
3. Using the select tool, select the shorter line and rotate it:
What happened? This time, only the shorter line rotated. The reason for this is the
difference between vector graphics and bitmap graphics. In vector graphics, the computer
does not store a grid of bits. Instead, it stores information about the actual objects you
draw.
For example, for a line, it stores the endpoints of the line, as well as the fact that you are
drawing a line. For a circle, it stores the center and radius of the circle, and the fact that you
are drawing a circle.
Because vector graphics store information about individual objects — as opposed to a grid
of dots — you can select, rotate, move, and resize individual objects without affecting
other objects, even if the objects overlap.
In general, you will use vector graphics. Bitmap graphics are useful when creating objects
that can’t easily be described by equations, such as the cat sprite or a photograph.
However, they are more difficult to work with and this class is about writing programs, not
drawing pictures.
3. Click the Costumes tab, clear the canvas, make sure you are in Vector Mode, and use
the line and oval tools to draw a simple stick figure of a man walking. Make sure you
use separate lines for the body, arms, and legs. This is because we need to reposition the
arms and legs later.
Don’t spend too much time drawing. We’re learning programming, not fine art.
4. Using the Set costume center tool (the plus sign in the upper right corner of the screen),
set the center of the costume to a point on the “ground” just beneath the man’s feet:
A costume’s center is used for movement and rotation. When you tell a sprite to go to a
certain point, its center goes to that point. When you tell a sprite to rotate, it rotates
around its center.
5. Click costume2 and delete it, then make two copies of costume1. You can use the stamp
tool at the top of the screen, or right click and select duplicate.
6. Click costume2 and use the zoom controls — the plus and minus in the lower right
corner of the screen — to zoom in on your stick man. Rotate and move his arms and
legs:
8. Finally, click costume2 and duplicate it. You should now have four costumes, with
costume2 and costume 4 being identical:
2. Run your program and watch your man walk in place. If he’s moving too fast, you can
add a wait block after each costume change.
3. After you’re done, delete your forever block. We just used it to show you how
animation works.
7.4.7 Variables
Variables in computing are used to store values. You have already seen some variables. For
example, in the Back and Forth project, you used the variable to determine if the
sprite was near an edge. That is, Scratch stores values in this variables and you can use the value
in your programs. You can also define your own variables and store values in them. For
example, you could use variables to store scores in a game, store the speed of a meteor crashing
to earth (so you know how big a hole to draw when it hits), or calculate the value of y in the
equation y = 3x + 10 for a given value of x.
Variables can be shared by all sprites or used only by one sprite. is an example
of a variable used by only one sprite: it gives the current x position of that sprite. Other sprites
have their own copies of this variable. is an example of a variable shared
by all sprites — any sprite can use it.
Variables that can be used only by one sprite are called local variables. Variables that can be
used by all sprites are called global variables. As a general rule, you should use local
variables.
3. When the program starts, use ask _______ and wait in the Sensing menu to ask for a number:
4. Scratch stores the number entered by the user in the answer variable from the Sensing menu.
Use the set ______ to ____ block in the Data menu to store the answer in your number
variable:
6. To show the user what their number plus 2 is, use the say ____ for 2 secs block in the Looks
menu:
7. Run your program, enter a number, and check that the program displays the correct answer.
8. Create local variables to hold the value of the number minus 2 and times 2, set these variables,
and display their values. (Note that the multiplication operator uses an asterisk. This is
because the letter x is commonly used as a variable name; it would be confusing if it also
meant multiplication.)
9. Test your program to make sure it displays the correct values.
It is important to understand that this is a program you could not have written without variables.
Because you did not know what number the user was going to enter, you could not have
computed the value of that number plus, minus, and times 2 without using a variable.
The join operator takes two strings and joins them together. In this case, you are joining the
string “Your number plus 2 is:” and the value of the plus2 variable.
3. Change your say plus2 for 2 secs block to use the output variable:
(c) Algorithms
Most computer programs use algorithms, which are a set of instructions designed to complete a
certain task, such as tracking the flight of a rotten tomato through the air. It is usually a good idea
to think of your algorithm before you start writing your program. For example, the algorithm for
graphing the points on the line y = 3x + 10 is:
pick a starting value for x
calculate a corresponding value for y using the equation y = 3x + 10
go to (x,y)
This loop adds the numbers from 1 to the number entered by the user. It is important to
understand how it works. Remember that we already set lastValue to the number entered by the
user and initialized number to 1 and total to 0. Suppose the user entered the number 3.
The first time through the loop, number (1) is less than lastValue (3), so we go inside the loop.
The first block in the loop sets the new value of total to the old value of total (0) plus number
(1). Thus, the new value of total is 0 + 1 = 1.
The second block in the loop changes the value of number by 1. That is, it adds 1 to the
current value of number. Since the current value of number is 1, the new value is 1 + 1 = 2.
Changing the value of a variable by a fixed amount is called incrementing the variable. It is a
very common operation in loops.
The second time through the loop, number (2) is still less than lastValue (3), so we go inside.
This time, total is set to 1 (old value) + 2 (number) = 3 and number is incremented to 3.
The third time through the loop, number (3) is equal to lastValue (3), so we go inside. total
is set to 3 (old value) + 3 (number) = 6 and number is incremented to 4.
The fourth time through the loop, number (3) is greater than lastValue (3), so we stop.
6. Add blocks to display the output using the string “The sum of the numbers from 1 to n is:
m”, where n is the number entered by the user and m is the total.
7. Test your program.
Now that you’ve seen how to use a loop and variables together, write a program to ask the user
for a number (n) and display the sum of the odd numbers from 1 to n, as well as the sum of the
even numbers from 2 to n. For example, if the user entered the number 6, your program would
display 9 (which is equal to 1 + 3 + 5) and 12 (which is equal to 2 + 4 + 6).