You are on page 1of 301

E W

N
GATEWAY
TO

New Gateway to Computer Science Book - 9


Our Computer Series
COMPUTER SCIENCE
Our Computer Series

9
1. New Gateway to Computer Science-1
2. New Gateway to Computer Science-2
3. New Gateway to Computer Science-3
4. New Gateway to Computer Science-4
5. New Gateway to Computer Science-5
6. New Gateway to Computer Science-6
7. New Gateway to Computer Science-7
8. New Gateway to Computer Science-8
9. New Gateway to Computer Science-9
10. New Gateway to Computer Science-10

Price Rs. 441/-

Shubharambha Publication Pvt.Ltd.


Kathmandu Nepal
Approved by Government of Nepal, Ministry of Education, Curriculum Development
Centre, Sanothimi, Bhaktapur as an Additional Learning Material.

NEW GATEWAY
TO
COMPUTER SCIENCE
9
Authors
Dinesh Adhikari
Dilendra Prasad Bhatta
Shekhar Poudel
Laxman Adhikari

Shubharambha Publication Pvt. Ltd.


Kathmandu, Nepal
Published by:

Shubharambha Publication Pvt. Ltd.


Kathmandu, Nepal
URL: www.shubharambhapublication.com
E-mail: shubharambha.publication@gmail.com
www.facebook.com/shubharambhapublication

New Gateway to Computer Science Book-9

Authors : Dinesh Adhikari, Dilendra Prasad Bhatt,


Shekhar Poudel, Laxman Adhikari
Layout Design : Ram Malakar
Video Content : Dinesh Adhikari
Language Editor : Krishna Prasad Regmi
Copyright © : Dinesh Adhikari
Edition : 2077
ISBN : 9789937579315

© : Publisher
No part of this book may be reproduced or transmitted by means (electronic, photocopying,
recording or otherwise) without prior written permission from the publisher. Any breach of this
condition will entail legal action and prosecution.

Printed in Nepal
Preface

It has become a fundamental right of children to get computer education. It is


very essential to get basic to advance knowledge about computer education to
compete the future. Nepal government has prescribed the syllabus and course
outline for the computer education from primary to secondary level. But
students are not able to get quality education due to the lack of systematic course
book and the computer system in the school. So we have developed the complete
series of computer science.

Along with the evolution of human beings new thoughts, area of knowledge and
technology also developed together. Among the eruptions, ICT (Information and
Communication Technology) is one which has unquestionably become important
part of human beings. A person is not better than a caged pigeon if s/he is far
from computer technology in this century. New Gateway to Computer Science is
a complete package which obviously supports a lot to the students as this is one
of the most useful textbook, so far available in the market.

This book is completely prepared considering the level of the students. This text has
various salient features like it focuses on child psychology, pictorial descriptions,
practical sections, let’s Review, sufficient exercise, etc.

It is impossible to acknowledge all who have directly or indirectly encouraged


me to prepare this book on this single page. My special thanks go to the students
and teachers of different schools for their regular interactions during the
preparation of this book.

Comments and constructive suggestions are highly welcomed from the readers
and professionals to update this text book.
Dinesh Adhikari
dinesh.nayaghare@gmail.com
Content

Unit 1 Fundamental Aspect of computer..............................5-70



Lesson 1: Introduction to Computer and Its Applications areas.................6

Lesson 2: Types of Computer....................................................................15

Lesson 3: Computer System.....................................................................27

Lesson 4: Introduction to Computer Hardware........................................33

Lesson 5: Introduction to Computer Software.........................................56

Unit 2 Working with Graphics........................................73-101


Lesson 6: Introduction to Computer Graphics............................................74

Unit 3 Internet and Web Technologyi...........................102-177


Lesson 7: An introduction to Internet Technology....................................103
Lesson 8: Working with HTML................................................................112
Lesson 9: Working with CSS....................................................................149

Unit 4 Computer Programming....................................178-298


Lesson 10: General Concept of Programming.......................................179
Lesson 11: Programming Techiniques......................................................192
Lesson 12: Programming in QBASIC.....................................................209
Lesson 13: QBASIC Statements.............................................................223
Lesson 14: Program flow and Control Structures......................................235
Lesson 15: Library Functions in QBASIC................................................261
Lesson 16: Arrays in QBASIC..................................................................281
Program Writing Project ..................................................298
Specific Grid.....................................................................299
Practical Assessment........................................................300
Fundamental Aspects
of
Computer
Unit

This unit covers the following topics:

Lesson 1: Introduction to Computer and Its Applications areas


Lesson 2: Types of Computer
Lesson 3: Computer System
Lesson 4 Introduction to Computer Hardware
Lesson 5: Introduction to Computer software
Lesson Introduction to Computer and its
1 Applications Areas

Inside the Lesson

 Introduction to computer
 Defination of computer
 Characteristics of computer
 Advantages and disadvantages of computer
 Working principles of computer
 Applications area of computer

The word ‘computer’ comes from the word ‘compute’, which means, “to calculate”.
Hence, people usually consider a computer to be a calculation device that can perform
arithmetic and logical calculations at a very high speed.
Nowadays computers have become an integral part of our lives. They play a vital role in
everyone’s life; their importance is so amazing that without it we will not be able to live
the way we do. They are basic tool of human beings these days. Computers have changed
the way that people work. Computers can handle many tasks in business, education,
manufacturing and other so many fields. Computer is an electronic machine/device which
can input data, process them according to the instruction given and then give out the
meaningful information.
 The data consists of numbers, text, sound, images, animations, and video.
 The process converts numbers, text, sound, images, animations, and video (data) into
usable data, which is called information.
 The information consists of numbers, text, sound, images, animations, and video that
has been converted by the process.
 The data can be given using an input device.
 The Central Processing Unit (CPU) converts data into information.
 The information can be displayed by an output device.
 A storage device is a device for storing data and information. A basic computer
consists of four components: an input device, a CPU, output devices, and memory.

New Gateway to Computer Science Book -9


6
What is a computer?

A computer is a programmable machine. It allows the user to store information and then
‘process’ that information, or data, with the help of instructions provided by the user. It is
also an electronic device that receives data from the input devices and processes the data,
to display the correct output which is always meaningful.
The computer is also called a data processor because it can store, process, and retrieve
data whenever needed. The activity of processing data using a computer is called data
processing. Data processing consists of capturing input data, manipulating the data, and
managing output results.

Characteristics of Computer

Speed
A computer can work very fast. It takes only few seconds for calculations but humans
take hours to complete their work. It can execute millions of instructions within Nano or
Pico second or even more than that. The speed that a CPU works at is measured in hertz
(Hz). Modern processors run so fast in term of gigahertz (GHz). One gigahertz is one
billion cycle per second. The following are the speed measurement units of computer.

Unit of Speed Parts of Second


1HZ (Hertz or 1×10O Hz) 1 Second (1×10O sec)
1KHZ (Kilo Hertz or 1×103 Hz) 1 Millisecond (1×10-3 sec)
1MHZ (Mega Hertz or 1×106 Hz) 1 Microsecond (1×10-6 sec)
1GHZ (Giga Hertz or 1×109 Hz) 1 Nanosecond (1×10-9 sec)
1THZ (Tera Hertz or 1×1012 Hz) 1 Picosecond (1×10-12 sec)
1PHZ (Peta Hertz or 1×1015 Hz) 1 Femtosecond (1×10-15 sec)
1EHZ (Exa Hertz or 1×1018 Hz) 1 Attosecond (1×10-18 sec)
1ZHZ (Zetta Hertz or 1×1021 Hz) 1 Zeptosecond (1×10-21 sec)
1YHZ (Yotta Hertz or 1×1024 Hz) 1 Yoctosecond (1×10-24 sec)

Accuracy
The accuracy of results computed by a computer is very high. Due to digital
techniques the error is very less. The errors in computing may be due to logical mistakes
by a programmer or due to inaccurate data. The degree of accuracy of computer is very
high and every calculation is performed with the same accuracy but the degree of its
accuracy depends upon its design. If the input data is incorrect, the output will be incorrect
which is called GIGO (Garbage in Garbage Out).

New Gateway to Computer Science Book -9


7
Diligence Let’s Review
A computer is always free from tiredness, lack of Characteristics of computer
concentration, weakness, etc. It can work for hours  Speed
without creating any error. If millions of calculations
 Accuracy
are to be performed, a computer will perform every
calculation with the same accuracy.  Diligence
 Versatility
Versatility  Storage
Computers are very versatile machine. They can  No Intelligence
perform various activities like simple to complex. A
computer can perform completely different types of tasks. Computers are applicable in
each and every field like banking, business, education, entertainment, research and so on.
Storage
A computer has the power of storing more amounts of information or data. Any
information can be stored and recalled as per our requirement. A computer has a main
memory and auxiliary memory system. They can store large amount of data. With more
and more auxiliary storage devices, which are capable of storing huge amounts of data,
the storage capacity of a computer is virtually unlimited. The memory power of computer
depends fully upon how much data you want to store and when to lose or retrieve them
in a computer.

The following are the storage measure units of computer


Storage Unit Short Cut Bytes
1 Bytes Bytes 8 Bits
1 Kilobyte KB 1024 Bytes
1 Megabyte MB 1024 Kilobytes
1 Gigabyte GB 1024 Megabytes
1 Terabyte TB 1024 Gigabytes
1 Petabyte PB 1024 Terabytes
1 Exabyte EB 1024 Petabytes
1 Zetabyte ZB 1024 Exabyte
1 Yottabyte YB 1024 Zetabyte
1 Brontobyte BB 1024 Yottabyte

No Intelligence
Computers do not have their own intelligence. They follow a set of instructions fed into
them by manufacturer. The user knows what to do and when to perform a specific task.

New Gateway to Computer Science Book -9


8
Advantages and Disadvantages of Computer
Advantages
 The computers are always accurate and reliable with high storage capacity.
 Computers are able to perform thousands of tasks within a short period of time.
 Computers can be used to solve complex mathematical and logical operations.
 Computers are versatile device, so that we can use it everywhere.
 Computers are useful in communication among various users.
 Computer never feels tired and boring but a human being does.
Disadvantages
 A computer is a machine that has no intelligence to perform any task.
 Commuter works according to the program and instructions given to it.
 It is very risky to store data and information on the computer independently because
some electrical and electronic damages may damage the data.
 Back up is so expensive that all the people are not able to purchase the computer.
 We need dustless and temperature maintained environment to use the computer for
the best performance.
 Skilled computer users are required to operate and maintain the computer system.

Working Principles of Computers


Let’s Review
Input: Inputs are the raw data given to the
computer for processing. The computer accepts The basic working principles of the
data from the user with the help of input devices computer are:
like keyboard, mouse, light pen, microphone,  Receive input through various
etc. input devices.
Process: The computer processes the data  Process information to perform
when it gets input from the user. The processing arithmetic or logical operations.
activity of computer is done by the Central  Produce output with the help of
Processing Unit (CPU) of the computer. output devices.
 Store information on the storage
Output: The output is always meaningful. The
output devices of the computer like monitor, devices.
printer, speaker, etc. can display meaningful
information. The output devices can display the output only after processing.
Storage: This is done after displaying the information. When the result is final, we can use
storage devices for data storage. There are some primary and secondary memories with
the computer system. Generally, we use secondary memories to store data permanently.

New Gateway to Computer Science Book -9


9
Application Areas of Computer

Computer in Education
Computers are commonly used in school and college for teaching and learning activities. A
teacher can make his teaching techniques easier and interactive with the help of computer
tools. Students can also use computer as their learning tools. They can search various
topics on the internet. Teachers also can take help of the internet to do research work so
that they can collect lots of ideas and information about learning process. A teacher can
prepare a slide and demonstrate it in the class. Students also can do research work in their
various subjects that they require. Computer Based Learning (CBL) and Internet Based
Learning (IBL) are more popular these days. Because of the use of computer online and
distance learning is also possible and has been implemented in our education system.

Computer in Bank
Computers are massively used in bank these days. With
the help of computers, we can keep records of customers;
we can calculate the money; check the balance, verify the
signature, deposit and withdraw money. Online banking,
mobile banking, ATM card, Electronic Fund Transfer
system are also available because of the use of computer
at bank.

Computer for Entertainment


Entertainment is also an important part of human life.
Computers are used for listening to music, watching videos
and films, play games, online booking of film tickets,
downloading music and videos, etc. So computers play a
major role in the sector of entertainment.

Computer at Hospital
Hospitals use computers to keep the records of patients,
doctors and staff. These days, computers are used to
keep and display the duty roster of doctors. Computers
are used to check the various internal organs of human
so that it is easy to find out the health problems. X-Ray
, CT-Scan, test of heart, test of kidney, endoscopy,
ultrasound, etc. are possible to do within a second with the

New Gateway to Computer Science Book -9


10
help of computer. Computers are used in different medical units of hospital such as
ECG (Electro Cardiograph), ICU ( Intensive Care Unit), OT (Operation Theater), CAS
( Computer Aided Surgery), diagnosis of diseses, etc. So there is a great role of computer
in the medical science.

Computer in Science and Technology


Science and technology is responsible for many changes in
our lives, how we live, how we communicate and what we
can learn about the world. But some of the most profound
effects of technology are hard to articulate, or even notice.
Computers are used in all branches of science and technology.
It is almost impossible to conduct research in science and
technology without the use of computer.
Computer in Communication
Whether communication is to be internal or external, it is
important in the life of every individual. Computers can play
a significant role in communication with the use of email, fax,
videoconferencing and many more. The information cannot
be delivered to any other without the use of computer and
computing tools these days. The following are the major areas
of communication where computers are used.

Social Networking
Social networking sites like Facebook, Twitter and LinkedIn allow users to rapidly
generate content for people in their network to view. Rather than sending individual notes,
social networking provides us with a constant stream of updates and information. These
tools have taken communication a step further than email due to their ability to instantly
communicate life and status updates to an entire network of people who can respond and
comment in real time.

VOIP and Video Chat


Voice-Over-Internet-Protocol has replaced the need for
landline telephones. These lines can provide us with instant
phone communication over the Internet, and are cheaper than
fixed phone lines. They also provide us with the ability to
conduct video chats to see whom you are speaking with. VOIP
platforms also store contact details for easy accessibility and
dialling.

New Gateway to Computer Science Book -9


11
Internet and Email
The World Wide Web, Internet and Email have revolutionized the way individuals
communicate with each other. Rather than waiting days or weeks to see information,
we can now view all information at the speed of light. Email has fundamentally
transformed how people share information based on the speed and flexibility it offers.
Computers can process data at approximately 20 million bytes per second so it is easy to
download and display the text email.
Routers
Routers are the types of computers used to direct communication traffic. They are crucial
to the efficient and correct distribution of calls, emails or other internet traffic. Routers take
“packets” of electronic data and send them in the direction to connect with the intended
person. They can be used at home but are also held in central data warehouses where hubs
of traffic are routed in the same place.

Let’s Review
The following are the modern application areas of computer.
 computer in education
 computer in bank
 computer for entertainment
 computer at hospital
 computer in science and technology
 computer in communication such as social networking, video chat, internet and
email.

Expand your knowledge


What is a smart card?
A smart card looks like an ATM card or credit card in size and shape, but instead of a
magnetic strip it contains an embedded microprocessor and memory.
What can internet banking do?
 transfer money from one account to another.
 pay bills now or schedule for future payments.
 check account balance and transaction history.
 access previous account statements.
 request cheque books.
 change personal identification number.
 view currency exchange and interest rates.
 apply for credit cards and various types of loans

New Gateway to Computer Science Book -9


12
Assignment
1. Select the correct answer from the given options.
a. What is the unit of time for one trillionth of a second?
i. Picosecond ii. Nanosecond iii. Millisecond iv. Femtosecond
b. If a computer can store data of 1024 gigabytes, what is the storage unit for this?
i. 1 Petabyte ii. 1 Terabyte iii. 1 Gigabyte iv. 1 Megabyte
c. What is the act of entering raw data to the computer?
i. Process ii. Output iii. Storage iv. Input
d. Which of the following is the best example of social networking?
i. Facebook ii. Gmail iii. Web site iv. Search
e. In which application area does CBL, IBL lie?
i. Science ii. Communication iii. Education iv. Entertainment
2. Fill in the blanks with suitable words.
a. The word ‘computer’ comes from the word which means, “to …………………”.
b. Computer is an electronic machine which can input data, process them and then
give out the …………………
c. The speed that a CPU works at is measured in ………………………
d. The errors in computing may be due to ……………. mistakes by a programmer
or due to inaccurate data.
e. A computer has a main memory and ……………………. memory system to store
large amount of data.
f. The ………………. produced by the computer is always meaningful.
g. Hospitals use computers to keep the records of ………… , ……………. and staff.
h. ………………….has replaced the need for landline telephones in many instances.
3. State whether the given statements are true or false.
a. The computer is called a data processor because it can store, process, and retrieve
data whenever needed.
b. Modern processors run so fast in term of megahertz (MHz).
c. If millions of calculations are to be performed, a computer will perform every
calculation with the same accuracy.
d. It is very safe to store data and information on the computer independently.
e. If some electrical or electronic damages occur, there are no any chances of data loss
or damage.
f. The output devices of the computer like monitor, printer, speaker, etc. can store
meaningful information.
g. The input devices can display the output after processing.
h. Students can also use computer as their learning tools.

New Gateway to Computer Science Book -9


13
i. A teacher can prepare a slide and demonstrate it in the class with the help of
computer.
j. Computers are used to check various internal organs of human to find out the
health problems.
4. Write appropriate technical terms for the followings.
a. An electronic device which can input data, process them according to the
instruction given and then give out meaningful information.
b. The computer unit that converts the data into information.
c. A collection of four bits or half byte.
d. The result obtained after the data processing.
e. It takes "packets" of electronic data and sends them in the direction to connect
with the intended person.
f. It is the raw facts used in computers.
g. A speed measurement unit which is ten trillionth of a second.
h. A storage unit that is equal to 1024 terabytes.
5. Write the full form of the followings.
CPU, GHz, CBL, IBL, GIGO, ECG, OT, CAS, ICU, VOIP
6. Match the following:
One terabyte One millionth of a second
Microsecond 1024 Gigabyte
CBL, IBL Social Networking
Facebook, Twitter can be used everywhere
Versatile computer in education
7. Answer the following questions.
a. Why are computers important these days? Write in short.
b. Define computer with its two advantages and disadvantages.
c. What are the characteristics of a computer? List out them.
d. What are the various speed measurement units of the computer?
e. List out the storage measurement units of a computer.
f. Why is the computer called a versatile machine?
g. Write down the working principals of the computer.
h. What are the major application areas of the computer? List out them.
i. What is the role of the computer in education sector?
j. What is the role of the computer in health and communication sector?
Project Work
• Conduct a speech competition on the topic ‘Role of computer in education and
communication'.
• Divide a class in various groups and conduct a presentation on the following topics.
i. Characteristics of a computer
ii. Major application areas of a computer
iii. The communication mechanism of the 21st century.

New Gateway to Computer Science Book -9


14
Lesson

2 Types of Computer

Inside the Lesson

 Introduction to computers types


 Types of computer on the basis of work/ function
 Types of computer on the basis of size
 Types of computer on the basis of brand
 Types of computer on the basis of model

There are different types of computers available these days. The function of each type of
computer is to process the data and provide the users with output. However, the methods
used by these computers to process and handle the data may be different. Generally,
there are two types of computer they are general purpose computer and special purpose
computer. A general purpose computer can perform any kind of jobs with equal efficiency
simply by changing the application program stored in its main memory. A special purpose
computer is designed to perform only one special task. The program or instructions set is
permanently stored in special purpose computers.
Computers are broadly classified into the following four groups such as; on the basis of
work/function, size, brand, and model. Let’s discuss them in detail.

Types of Computer on the Basis of Work/ Function

Analog Computer
An analog computer is that computer, which is used to process
continuous data.These computers are very fast in their operation and
allow several other operations to be carried out at the same time.
However, the results produced by these computers are not accurate.
Analog computers can be used in scientific and industrial applications
such as measure the electrical current, frequency and resistance of
capacitor, etc. They perform arithmetical operation by measurable
quantities, such as mechanical movement, the rotation of gears rather
than by number. In analog computers, data are transmitted for their operation in the form

New Gateway to Computer Science Book -9


15
of continuous signals, while in digital computers in the form discrete signals. Examples
of analog computers are Thermometer, Pressure measurement device, speedometer,
frequency of signal and voltage.

Some features of analog computers are listed below.


 It is specific to particular task so we cannot use it for multiple applications.
 It works on continuous data and gives continuous output.
 It works on real time and has no storage capacity.
 It gives output in the form of graph, signals, table, etc.

Digital Computer
The digital computer is also known as the digital
information processing system. It is a type of computer that stores
and processes data in the digital form. Therefore, each type of
data are usually stored in these computers in the terms of 0 and
1. The output produced by these computers is also in the digital
form. The digital computers are also capable of processing the
analog data. However, the analog data should be first converted
to the digital form, before being processed by these computers.
Similarly, if we want the output in the analog form, the digital information produced
by these computers should be first converted to an analog form. These conversations
are generally carried out by the in-built components of digital computers. The different
hardware components of a digital computer are an Arithmetic- Logic Unit, a Control Unit
(CU), a memory unit and I/O units. IBM PC, Apple/Macintosh, etc. are the examples of
digital computers.

Some features of digital computers are listed below.


 It works on discontinuous or discrete data.
 It is applicable for general purpose.
 It is based on the digits 0 and 1.
 It is faster and it has storage section.
 It is highly accurate and reliable than analog system.

Hybrid Computer
A hybrid computer combines features of both analog and digital
computers. In this computer, some calculations are done in the analog
portion and some are done in the digital portion of the computer. The
hardware components of hybrid computers are usually the mixture

New Gateway to Computer Science Book -9


16
of analog and digital components. These features make the hybrid computers very fast,
efficient and reliable. In these computers, data are generally measured and processed
in the form of electrical signals and are stored with the help of digital components. For
example in hospital, analog devices measure patient’s heart function, temperature and
other vital signs. These measurements are converted into numbers and supplied to a digital
component in the system. This component is used to monitor the patient’s vital signs and
to send an immediate signal to the nursing station if any abnormal readings are detected.

Some features of digital computers are listed below.


 It is expensive system
 It is designed for special purpose so it is not so versatile.
 It works on discrete and continuous value.
 It has limited storage.
 It is more complex than other computer system.

Let’s Review
 Generally there are two types of computer they are general purpose computer and
special purpose computer.
 An analog computer is that computer, which is used to process continuous data.
 The digital computer is also known as the digital information processing system.
 The hardware components of hybrid computers are usually the mixture of analog
and digital components.

Types of Computer on the Basis of Size

Supercomputer
A super computer is the fastest type of computer that can
perform complex operations at a very high speed. It is the
most powerful computer in terms of performance and data
processing. It is specialized and task specific computer
used by large organizations. The super computers were first
presented in the year 1960AD by Seymour Cray at Control
Data Corporation (CDC). These computers are used in
research and for exploration purposes. The supercomputers
are very expensive and very large in size. It can be accommodated in large air-conditioned
rooms; some super computers can span an entire building. Some popular supercomputers
are IBM’s Sequoia, Fujitsu’s K, IBM’s Mira, IBM’s Super MUC, NUDT Tianhe-1A,
CRAY-3, Cyber 205, NEX SX-3, PARAM, etc.

New Gateway to Computer Science Book -9


17
The uses of supercomputers are listed below.
 Space exploration
 Earthquake studies
 Animated graphics
 Weather forecasting
 Nuclear weapons testing and energy research
 Petroleum exploration

Minicomputer
A minicomputer was first introduced in the year 1960 AD by
Digital Equipment Corporation (DEC). They were called mini
computers because they were smaller than the other computers
of those times. Minicomputers are used by small businesses and
firms. Minicomputers are also called “Midrange Computers”.
These computers are not designed for a single user. Individual
departments of a large company or organizations use mincomputers for specific purposes.
Mini computers can also be used as the web servers that can handle thousands of
transactions in a day. These computers are less expensive than mainframe computers. The
popular minicomputers are K-202, Texas Instrument TI-990, SDS-92, IBM 8000 Series,
PDP 11, VAX-7500, etc.

Mainframe Computer
A mainframe computer is a very large computer that is employed
by large business organizations for handling major applications
such as financial transactions, Enterprise Resource Planning
(ERP), industry and consumer statistics, census, etc. Mainframe
computers are not as powerful as supercomputers, but they are quite
expensive. Many large firms and government organizations use
mainframe computers to run their business operations. The Mainframe computers can be
accommodated in large air-conditioned rooms because of their size. As super-computers
are the fastest computers with large data storage capacity, Mainframe computers can also
process and store large amount of data. Banks, educational institutions and insurance
companies use mainframe computers to store data. Example of mainframe computers are
IBM 3000, VAX 8000 and CDC 66000, Fujitsu’s ICL VME, Hitachi’s Z800, etc.

Some of the special features of mainframe computers are as follows:


 The capacity of RAM of these computers lies between 128 MB and 8 GB.
 They can handle huge amount of I/O operations at the same time.

New Gateway to Computer Science Book -9


18
 They have different cabinets for primary storage, secondary storage and input
/ output units.
 A typical mainframe computer has a maximum 16 microprocessors. However,
some modern mainframe computers can have more than this.
 They are able to run multiple operating systems, so it is also called ‘virtual machines’.

Let’s Review
 A supercomputer is the most powerful computer in terms of performance and
data processing.
 Minicomputers are also called “Midrange Computers”.
 A mainframe computer is a very large computer that is used by the large
business organizations.
 Many large firms and government organizations use mainframe computers to
run their business operations.

Microcomputer
A microcomputer is a small and cheap digital computer that is
designed to be used by individuals. Desktop computers, laptops,
personal digital assistant (PDA), tablets and smartphones are
the types of microcomputers. The micro-computers are widely
used and the fastest growing computers. These computers
are the cheapest among the other types of computers. The
micro-computers are specially designed for general use. Microcomputers also include
several software programs such as operating system, system software and utility software.
The popular microcomputer manufacturing companies are IBM, Dell, Apple, Samsung,
Son, Toshiba, etc.

Types of Microcomputers
Desktop Computer
The desktop computer systems are designed to be used by
an individual at a single place. The desktop computer uses
keyboard, mouse, monitor, hard disk, peripheral devices and
system unit. These computers are very cheap and an individual
can easily purchase them for home or business use. The different
manufactures of desktop computers are Apple, IBM, Hewlett-
Packard(HP), etc.

New Gateway to Computer Science Book -9


19
Laptop Computer
Laptop computer is a portable computer that can be taken
from one place to another at any time very easily. It is also
known as notebook, notepad or mobile computer. The
laptop computer is a small size computer that incorporates
all the features of a desktop computer. These computers are
provided with a rechargeable battery that removes the need of continuous external power
supply. However, these computer systems are more expensive than desktop computers.
Different manufactures of laptop computers are Acer, Apple, Sony, HP, DEL, TOSHIBA, etc.

Hand-Held Computer
Hand-held computer is also known as Personal Digital Assistant (PDA), converged
device, palmtop or mobile device. It is a very small sized computer that can be kept in
pocket. It has a small display screen and it uses input device like an electronic stylus or
finger. The storage capacity of hand-held computers is not very large. They generally use
small cards to store data and programs instead of disk drives. Therefore, they are less
powerful as compared to the desktop and laptop computers. Different examples of hand-
held computers are Apple Newton, Casio Cassiopeia, Franklin eBook Man, Samsung, etc.

Let’s Review
 A microcomputer is a small and cheap digital computer that is designed to be
used by individuals.
 The desktop computer systems are designed to be used by an individual at a
single place.
 Laptop computer is also known as notebook, notepad or mobile computer.
 The hand-held computer is a very small sized computer that can be kept in pocket.

Types of Computer on the Basis of Brand

There are three types of computers on the basis of brand which are explained below.

IBM PC
The computers that are manufactured by IBM (International
Business Machine) are IBM PC. It is one of the leading companies
of the world manufacturing computers. IBM was established in 1924
and started manufacturing mainframe, mini and microcomputer
from 1945 onwards. IBM PC is the brand name of the first popular

New Gateway to Computer Science Book -9


20
commercial PC that was developed by the IBM corporation. In 1981, the IBM PC was
launched with the model number IBM 5150. These computers are more reliable, durable
and have better quality. IBM PC was one of the fastest desktop computers of its time. It
directly competed with the Commodore Personal Electronic Transistor (PET), Apple II
and Control Program/Monitor (CP/M). The IBM PC was equipped with an Intel 8088
processor at a speed of 4.77 MHz, 16 KB of memory extendable to 256 KB, a 160 K
floppy drive and an optional CRT colour monitor.

IBM Compatibles
The computers that are manufactured by the other computer
manufacturing companies but have the same technology and
features are known as IBM Compatibles computers. The term
compatible means “Able to exist together and work successfully”.
IBM compatible computer system is assembled form of different components developed
by different companies. It is based on IBM principle that can use standard hardware and
software designed for the IBM PC and its own additional features. Some IBM compatible
computers are AST, ALR, Sherry, etc.

Differences between IBM PC and IBM Compatible


IBM PC IBM Compatible
The computers designed as well as The computers which are designed by IBM
developed by IBM corporation are called but manufactured by companies other than
IBM PC. IBM are called IBM compatibles.
It is known as original or branded IBM. It is called assembled or duplicate IBM.
It is expensive but more reliable than It is cheaper but less reliable than IBM PC.
IBM Compatible.
It is usually used by large organization It is usually used by small organization and
which requires high security. higher security is not required.
Examples:- IBM Desktop, IBM 1401, Examples:- HP laptop, Dell notebooks, etc.
IBM laptop, etc.

Apple Macintosh
The computers that are manufactured by Apple Company
but have different architecture and configuration than
IBM Compatibles are known as Apple Macintosh. Apple
Macintosh computers were introduced by Steve Jobs and
Steve Wozniak of Apple Inc. on January 24, 1984. The first
computer was called Mac 128K. This computer has its own operating system which is
called Mac OS.

New Gateway to Computer Science Book -9


21
Types of Computer on the Basis of Model

There are three types of computers on the basis of model which we are going to discuss
below.
XT Computers (Extended Technology)
The computers having 8086 or 8088 microprocessor and processing speed of 4.77 MHz
are known as XT Computers. These computers are out-dated now because they cannot run
on latest software versions.
AT Computers (Advanced Technology)
The computers having 80286 or later versions of microprocessors are known as AT
computers. Their storage capacity as well as speed is much higher than XT computers.
Besides that they have math co-processor to support main processors to perform complex
mathematical calculations.
PS/2 Computers (Personal System 2)
IBM developed another model of computer in 1990 that have more advanced architecture
design than AT computers. They are known as PS/2 computers. They are more faster than
AT computers. Most of the laptop computers based on PS/2 model use OS/2 or UNIX
operating system and 1.44 MB floppy diskette.

Let’s Review
 The computers that are manufactured by IBM are IBM PC.
 The term compatible means “Able to exist together and work successfully”.
 Apple Macintosh computers were introduced by Steve Jobs and Steve Wozniak of
Apple Inc. on January 24, 1984.
 The three types of computer on the basis of model are XT, AT and PS/2.

Expand your knowledge


 Kathmandu University has installed the first supercomputer at IT Park, Banepa.
 The supercomputer which consists of high performance computing (HPC) servers
was donated by CERN based in Switzerland.
 There are so many Super Computers spread in almost every country in the World.
The maximum numbers of Super Computers are owned by the United States and
China.
 The first desktop hybrid computing system was the Hycomp 250, released by
Packard Bell in 1961 AD.

New Gateway to Computer Science Book -9


22
Assignment
1. Select the correct answer from the given options.
a. A computer that is used to process continuous data.
i. Analog computer ii. Digital computer iii. Super computer iv. Hybrid computer
b. Which computer is also called a digital information processing system?
i. Digital computer ii. Analog computer iii. Hybrid computer iv. None of them
c. Which of the following computer has the features of both analog and digital
computer?
i. Micro Computer ii. Mainframe computer
iii. Hybrid Computer iv. Super computer
d. Which of the following computer has complex system?
i. Hybrid computer ii. IBM computer
iii. Mainframe computer iv. Analog computer
e. Which of the following is mainframe computer?
i. IBM 3000 ii. Cyber 205 iii. IBM PC iv. All of them
f. In which computer does the capacity of RAM lie between 128 MB and 8 GB?
i. Micro computer ii. Mainframe Computer
iii. Super Computer iv. None of them
g. Which of the following is micro computer?
i. Apple and IBM ii. CDC 66000 iii. PDP 11 iv. VAX-7500
h. Which of the following is extended technology computer?
i. Having 8086 or 8088 Processor ii. Later version having 80286
iii. With windows 8 OS iv. None of them
2. Fill in the blanks with suitable words.
a. …………computer is that computer, which is used to process continuous data.
b. In …………….. computers, data are transmitted for their operation in the form of
continuous signals.

New Gateway to Computer Science Book -9


23
c. Digital computers transmitt data and operation in the form of ………………
signals.
d. The hardware components of ………… computers are usually the mixture of
analog and digital components.
e. ……………… are also called “Midrange Computers”.

f. The…………… computer systems are designed to be used by an individual at a
single place.
g. The term compatible means “……………………….”.
h. The three types of computer on the basis of model are XT, …………… and PS/2.
i. The computers having …………. or later versions of microprocessors are known
as AT Computers.
3. State whether the given statements are true or false.
a. Generally there are two types of computer. They are general purpose computer and
special purpose computer.
b. Digital computer performs arithmetical operation by measurable quantities, such
as mechanical movement, the rotation of gears rather than by number.
c. The hybrid computer is also known as the digital information processing system.
d. Supercomputers are the most powerful computers in terms of performance and
data processing.
e. A mainframe computer is a very large computer that is employed by large business
organizations.
f. A supercomputer is a small and cheap digital computer that is designed to be used
by the individuals.
g. Desktop computer is also known as notebook, notepad or mobile computer.
h. The supercomputer is a very small sized computer that can be kept in pocket.
i. The computers that are manufactured by IBM (International Business Machine)
are IBM PC.
j. The computers having 8086 or 8088 microprocessor are known as XT Computers.

New Gateway to Computer Science Book -9


24
4. Write appropriate technical terms for the followings.
a. A program that is designed to perform only one special task.
b. A computer which is used to process the continuous data.
c. The computer that can process analog data but the analog data should be first
converted to the digital form.
d. The computer that has the features of both analog and digital computer.
e. The computer which is also called a digital information processing system.
f. The computers that are able to run multiple OS and called virtual machines.
g. It is a computer which is known as PDA.
h. The computer systems that are designed to be used by an individual at a single
place.
i. The computers that are manufactured by other computer manufacturing companies
having same technology and features.
j. The computers having 80286 or later version of microprocessors.
5. Write the full form of the followings.
IBM-PC, CDC, DEC , ERP, PDA, CP/M, PET, XT, AT, PS/2
6. Match the following:
Apple / Macintosh Computer IBM compatibles
CRAY- 3 Hand-held computer
VAX 8000 Digital computer
Apple Newton Supercomputer
AST, ALR Minicomputer
PDP 11 Mainframe computer
7. Answer the following questions.
a. What are general purpose and special purpose computers?
b. What are the types of computer on the basis of work?
c. Define analog and digital computer.
d. What are the features of hybrid computer?

New Gateway to Computer Science Book -9


25
e. Write any two features of analog and digital computer.
f. What are the types of computer on the basis of size?
g. What are the uses of supercomputers? List out them.
h. What is minicomputer and mainframe computer?
i. Mention any two features of mainframe computer.
j. What are the various types of microcomputer? List out them.
k. What is microcomputer? Name some popular microcomputer manufacturing
companies.
l. Write at least two examples of super, mainframe, and minicomputer.
m. Write down the differences between IBM PC and IBM compatible computers.
n. List out the types of computers on the basis of model.
Project Work
• Divide a class in various groups and conduct a presentation on the following topics.
i. Types of computer on the basis of work
ii. Types of computer on the basis of size
iii. Types of computer on the basis of model and brand

New Gateway to Computer Science Book -9


26
Lesson

3 Computer System

Inside the Lesson

 Introduction to computer system


 Understanding computer hardware
 Understanding computer software
 Introduction to data and information
 Understanding users

A computer is the collection of parts, which are categorized on the basis of work that they
do. A computer is a system, an interrelated combination of components that performs the
basic system functions of input, processing, output, storage, and control, with a powerful
information processing tool. Computer systems include any software and peripheral
devices that are necessary to make the computer function. A computer system allows
users to input, manipulate and store data. Computer systems typically include a computer,
monitor, keyboard, mouse and other components. Without the programs, the computer
would not know how to process data that enters the system, and the data might be
discarded. It is very flexible, as it can process any task by loading a program from storage.
Computer systems can work by themselves or access other devices that are external or
connected with other computer systems.The major components of computer system are
explained below.

Understanding Computer Hardware

Computer hardware consists of the components that can be physically handled.


It refers to the physical units or machine of functional units, which makes up
the computer configuration. The function of these components is typically
divided into three main categories: input, output, and storage. Hardware may be classified
into Central Processing Units (CPU) and the peripherals. The CPU has Control Unit (CU),
Arithmetic and Logic Unit (ALU) and the Internal Memory Unit (IMU) or main memory.
The peripherals consist of the input, output and auxiliary storage units. Computer is made
up of five distinct elements which are explained below.

New Gateway to Computer Science Book -9


27
Central Processing Unit Let’s Review
This is the brain of the computer that  A computer system allows users to input,
accepts data, performs operations manipulate and store data.
on the data and sends out the result.  Computer hardware refers to the physical
Information from an input device units or machine of functional units, which
or from the computer’s memory is makes up the computer configuration.
communicated through the bus to  CPU is also known as the brain of the any
the Central Processing Unit (CPU), computer system.
which is the part of the computer that
translates commands and runs  The arithmetic operation can be addition,
programs. It consists of ALU subtraction, multiplication and division.
(Arithmetic Logic Unit), CU (Control  Control unit maintains the sequence of
Unit) and MU (Memory Unit). The operations being performed by the CPU.
CPU makes the use of the following  The main memory is also responsible for
memory sub systems for carrying holding instructions between CPU and
out its processing operations. theI/O devices.
Arithmetic Logic Unit (ALU)
The ALU is the part of the CPU that performs arithmetic operations on the data. The
arithmetic operation can be addition, subtraction, multiplication and division. The
multiplication and division operations are usually implemented by the arithmetic unit as
the repetitive process of addition and subtraction operation respectively.
Control Unit (CU)
The control unit is an important component of CPU that controls the flow of data
and information. It maintains the sequence of operations being performed by the CPU.
It fetches an instruction from the storage area, decodes the instruction and transmits the
corresponding signals to the ALU and the storage registers. Control unit guides ALU
about the operations that are to be performed and also suggests the input and output
devices to which data are to be communicated.
Memory Unit (MU)
The memory unit is referred to as the internal memory of primary memory of the computer.
It is also known as Random Access Memory (RAM). It is a temporary storage location
that holds the data only for a short period of time. Once the computer is switched off, the
data stored in the RAM gets erased. The memory space of RAM is limited and therefore
all the files cannot be stored in it. The memory space available in RAM also affects the
speed of a computer system. If the memory space is more, more number of instructions
can be copied and executed at the same time. The main memory is also responsible for
holding instructions between CPU and the I/O devices.

New Gateway to Computer Science Book -9


28
Input Unit
Input unit consists of external devices that are; components outside the
computer system. It provides information and instructions to the computer.
The devices like keyboard, mouse, light pen, joystick, scanner, microphones, Optical
Character Reader (OCR), Magnetic Ink Character Reader Recognition (MICR), bar code
reader, digitizer, touch screen and optical mark reader (OMR) are mostly used input units
of computer.
Output Unit
An output unit consists of hardware that transfers information from the
computer’s CPU to the computer user. This includes the monitor, printer, plotter
or speaker. The output unit is used to present soft and hard copy of information.
The VDU (Visual Display Unit) or monitor and printer are common output units.
There are many categories of display units available for computer. The LED
(Light Emitting Diode), LCD (Liquid Crystal Display), DVST (Direct View Storage
Tube), etc. are text and graphics display output units.
Storage Unit
Storage units provide permanent storage of information and programs for retrieval to
the computer. Storage units are one of the core components of any computing device.
They store virtually all the data and applications on a computer.The two main types of
storage units are disk drives and memory. There are several types of disk drives like hard
disk drive, floppy disk, magneto-optical, and compact disk for data storage.

Understanding Computer Software

Software is a set of instructions that tells the computer what to do and when to do it.
The computer uses this instruction to manipulate data, and enhance the proper
functioning of the hardware components. It is designed to provide the potential capabilities
of the hardware to the user. It converts data into information and allows users to use
the computer in different ways. Computer programs are written by human beings.
The person who writes a program also decides on its functionality and behaviour. Software
also governs how the hardware is utilized; for example, how information is retrieved
from a storage device. The interaction between the input and output devices is controlled
by software which is called the Basic Input Output System (BIOS) software. Software
as a whole can be divided into a number of categories based on the types of work done
by programs. The two primary software categories are system software, and application
software.

New Gateway to Computer Science Book -9


29
Data and Information
Data are the facts or details from which information is derived. Data are raw, unorganized
facts that need to be processed. When data are processed, organized, structured or
presented in a given context so as to make them useful, it is called information. Some
differences between data and information are presented in the given table.

Data Information
Data are used as input for the computer Information is the output of data.
system.
Data are unprocessed facts figures. Information is processed data.
Data don’t depend on Information. Information depends on data.
Data are not specific. Information is specific.
Data don’t carry a meaning. Information must carry a logical meaning.
Data are the raw material. Information is the product.

Understanding Users
People who are the computer operators are also known as users. A user is a person
who uses a computer or computing devices. The most majority of computer users are
application oriented. They have traing and experence with some computer basis sofware.
They understand the general concept of computer such as files and folder management,
storing, saving and editing the documents and so on. The person who uses the software
or hardware after it has been fully developed, marketed and installed are called the End
user. The term 'user' and 'end user' is the same thing. End users are seprate group from the
installer or administrators of the product. End users are usually support staff, management
professionals, data processing staff and end-user support personnel. We can say that end
users are not trained programming professionals.

Let’s Review
 Input unit provides or fetches information and instructions to the computer.
 An output unit consists of hardware that transfers information from the computer’s
CPU to the computer user.
 Storage units provide permanent storage of information and programs for
retrieval to the computer.
 Computer programs are written by human beings.
 The interaction between the input and output devices is controlled by software
called the Basic Input Output System (BIOS) Software.
 Data are the facts or details from which information is derived.
 Information is processed data.

New Gateway to Computer Science Book -9


30
Expand your knowledge
 In 1936, the Russians made a computer that ran on water.
 ENIAC was the first electronic computer, which weighed around 27 tons and has
taken up about 1800 square feet of space.
 The first microprocessor 4004 which literally set the path for the modern
computing era was developed by Intel.
 The world’s first commercial water-cooled PC was Apple’s Power Mac G5.
 Intel 4004 was the first commercially available microprocessor with a maximum
clock rate of 740 kHz.

Assignment
1. Select the correct answer from the given options.
a. Which of the following is related to computer hardware?
i. Windows OS ii. Output devices iii. Software programs iv. Device driver
b. Which of the following is memory unit?
i. RAM ii. Motherboard iii. Power supply iv. Input devices
c. Which of the following is input unit?
i. OCR ii. MICR iii. OMR iv. All of them
d. Which of the following section is used to perform arithmetic and logical
calculations?
i. CU ii. MU iii. ALU iv. None of them
e. Which of the following is a permanent storage unit?
i. RAM ii. Hard drive iii. Input units iv. Output unit
2. Fill in the blanks with suitable words.
a. A ……………….. allows users to input, manipulate and store data.
b. CPU is also known as the ………………. of the any computer system.
c. ……… unit maintains the sequence of operations being performed by the CPU.
d. An ……………… unit consists of hardware that transfers information from the
computer’s CPU to the computer user.
e. ……………… are the facts or details from which information is derived.
f. ………………… is processed data.
3. State whether the given statements are true or false.
a. Computer software refers to the physical units or machine of functional units,
which makes up the computer configuration.

New Gateway to Computer Science Book -9


31
b. The logical operation can be addition, subtraction, multiplication and division.
c. The main memory is also responsible for holding instructions between CPU and
the I/O devices.
d. Output unit provides or fetches information and instructions to the computer.
e. Computer programs are written by human beings.
f. The interaction between the input and output devices is controlled by software
called BIOS Software.
4. Write appropriate technical terms for the followings:
a. It consists of the components that can be physically handled.
b. It consists of the input, output and auxiliary storage units.
c. It is the part of the CPU that performs arithmetic operations on the data.
d. It fetches an instruction from the storage area, decodes the instruction and
transmits the corresponding signals to the ALU and the storage registers.
e. It is a temporary storage location that holds the data only for a short period
of time.
f. The computer unit that consists of hardware that transfers information from the
computer’s CPU to the computer user.
g. It is a set of instructions that tells the computer what to do and when to do it.
h. It is a raw, unorganized facts that need to be processed.
5. Write the full form of the followings.
ALU, IMU, RAM , OCR, MICR, OMR, DVST, VDU, LCD, LED, BIOS
6. Match the following.
MICR Section of CPU
BIOS RAM
ALU Input Unit
LED Related to software
7. Answer the following questions.
a. Define computer system with its few components.
b. Define computer hardware with some examples.
c. What are the sections of CPU that are used in processing operations?
d. Define ALU and control unit.
e. What do you mean by 'input' and 'output' unit?
f. What is the function of storage unit?
g. Write any four differences between data and information.
Project Work
• Prepare a report about computer system and explain its units.

New Gateway to Computer Science Book -9


32
Lesson
Introduction to Computer Hardware
4

Inside the Lesson

 Introduction to computer hardware


 Understanding about motherboard with its components
 Understanding about microprocessor with its function
 Understanding about memory
 Primary memory
 Cache memory
 Secondary memory
 Types of secondary memory
 Magnetic storage devices and their types
 Optical storage devices and their types
 Units of memory measurement
 Input devices and their types
 Output devices and their types

Computer hardware is the collection of physical components that make a


computer system. A computer has mainly two types of hardware they are internal hardware
and external hardware. Computer hardware is the component of a computer, such as the
monitor, mouse, keyboard, computer data storage, hard disk drive (HDD), graphic cards,
sound cards, memory, motherboard, and so on. All of them are physical objects that are
tangible. Here we are going to discuss various types of internal and external hardware.

Understanding Motherboard

The motherboard is an internal computer hardware. It is a body of the computer, through


which all other components interface. The motherboard is essential to the computer as
it provides the computer with main computing capability. It is the printed circuit board
making up a complex electronic system. It provides electrical connections through
which other components of the system communicate. The mother board includes
many components such as CPU, RAM, firmware, and internal and external buses.The

New Gateway to Computer Science Book -9


33
motherboard connects other components through the
use of traces, or electrical pathways such as video cards,
sound cards,disk controller, etc. Personal computers
normally have one CPU on the motherboard. Let’s discuss
some of the components of the motherboard.
CPU Socket
CPU socket helps to install the processor into the motherboard. That means the CPU
connects the socket for connecting motherboard. On the bottom of the motherboard, the
socket carries hundreds of metalconnectors for the metal pins or balls. It helps to supply
power to the processor.
Input and Output Ports
Input and output ports are placed at the back side of computer chassis. In particular, the
I/O ports are built to connect the monitor, speakers, a microphone, an ethernet networking
cable and multiple USB devices.
Expansion Card Slots
When you need to add new components to the motherboard or if you want to update any
parts of the motherboard, a motherboard’s expansion card can be used. An expansion card
slots helps to add external devices to display.
RAM (Memory) Slots
To install the RAM a motherboard has more than one slots and it is positioned near
the CPU socket. In general, RAM is the most needed part of the motherboard. It is the
temporary memory of the computer, but it helps to run the applications and opening
the files. Particularly, if the processors have a large amount of RAM, it can operate the
computer more smoothly and it helps to increase the performance of the computer.
Power Connectors
A Motherboard needs power to keep running and it gets the power from SMPS (Switch
Mode Power Supply). There are various types of connectors which we are going to discuss
below.
AT Connector: It is one of the connectors which are found on the oldest motherboard and
it has 2 numbers of 6 pin male connectors to make the supplying process.
ATX Connector: These types of the connector are found on the latest form of the
motherboard. It consists of 20 or 24 pin female connectors and it is considered as the
latest power connector.
SATA Connector: It stands for Serial Advanced Technology Attachment. It is the latest
connector with 7-pin interface. It is used to connect the SATA hard disks or optical drives.
It is faster and better than the IDE connector.

New Gateway to Computer Science Book -9


34
IDE Connector: It stands for Let’s Review
Integrated Drive Electronics.  Computer hardware is the collection
It is used to connect of physical components that makes a
the disk drives including FDD computer system.
(Floppy Disk Drives) and HDD
 A motherboard provides the electrical
(Hard Disk Drives). It has 40-
connections through which the other
pin male connector that is used
components of the system communicate.
to connect HDD and 34-pin male
connector that is used to connect the  CPU socket helps to install the processor
FDD. into the Motherboard.
 RAM is the temporary memory of the
Cabinet Connections: It is the place
computer, but it helps to run the application
where the motherboard is installed.
and open the files.
It contains many buttons to connect
the cabinet with the motherboard.  A Motherboard needs power to keep
Mostly used cabinet connectors are running and it gets the power from the
Power Switch, Reset Switch, Front SMPS.
USB, Front Audio, Power indicator
(LED) and HDD LED.

Understanding Microprocessor

Microprocessor is an internal computer hardware which is a controlling section of


a computer. It is made-up on a small chip capable of performing ALU operations and
communicating with the other devices connected to it. It is also called the CPU which is
the brain of the computer system. The first microprocessor was the Intel 4004, introduced
in 1971. It was not very powerful; it was primarily used to perform simple mathematical
operations in a calculator. Microprocessor consists of an ALU, register array, and a
control unit. Nowadays, modern microprocessors can perform extremely sophisticated
operations in areas such as meteorology, aviation, nuclear physics and engineering, and
take up much less space with much better performance than the previous one.
Functional Sections of Microprocessor
 ALU: The ALU section calculates the ability of the microprocessor to perform
either arithmetical or logical operations.
 Registers: This section is a temporary storage area that holds data, keep tracks
of instruction, and holds the location and results of these operations.
 Control Section: This section regulates the operation of the entire computer system,
by using its instruction decoder to read patterns of data in a designated register and
translate the patterns into activities, such as addition or comparison. It also uses

New Gateway to Computer Science Book -9


35
its interrupt input to indicate the order Let’s Review
in which individual operations use the  The first microprocessor was the Intel
CPU and regulate the amount of CPU 4004, introduced in 1971 AD.
time allotted to each operation.  Microprocessor consists of an ALU,
register array, and a control unit.
 Internal Bus: Inernal bus is data
connection between two or more than  ALU, registers, internal bus and control
two devices connected to the computer. sections are the functional sections of
It operates only within the internal microprocessor.
circuitry of the CPU, communicating
among the internal caches of memory that are the parts of the CPU chip's design.

Functions of the Microprocessor


 It controls the use of the main storage in storing data and instructions.
 Control the sequence of operations.
 Give commands to all the parts of the computer system.
 Carry out the processing activities.

Understanding Memory

Memory is one or more sets of chips that store data and program instructions, either
temporarily or permanently. Memory is a critical processing component in any computer
system. Personal computer uses several types of memory, but they use two most
important memory they are RAM and ROM which are included in primary memory.
These two types of memory work in very different ways and perform distinct function.
Primary memory is only not sufficient
in computer system but also we must Let’s Review
have secondary memory for storage. Characteristics of Main Memory
Here, we are going to discuss the types  These are semiconductor memories.
computer memory.  It is known as the main memory.
Primary Memory  Usually volatile memory.
 Data are lost in case power is switched
Primary memories are called the off.
main memory that is used to store
 It is the working memory of the
data and instructions currently
computer.
required for processing. These
memories are manufactured by  They are faster than secondary
using integrated electronic circuits memories.
or semiconductor device. It has  A computer cannot run without the
limited capacity and data are lost primary memory.

New Gateway to Computer Science Book -9


36
when power is switched off. A memory is just like a human brain. It is used to
store data and instructions. Computer memory is the storage space in the computer, where
data are to be processed and instructions required for processing are stored. Some types
of computer memory are explained below.

RAM (Random Access Memory)


RAM is the most common type of temporary memory which is
made up of a set of chips mounted on a small circuit board. The
information stored in this memory is lost as the power supply to
the computer is turned off. That’s why it is also called volatile
memory. RAM needs a constant supply of power to hold its data.
It stores the data and instruction given by the user and also the results
produced by the computer temporarily. RAM has a tremendous
impact on the speed and power of a computer. Generally, the more RAM a computer
has, the more it can do and the faster it can perform certain tasks. The most common
measurement unit for describing a computer’s memory is the byte. Some common types of
RAM are Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random
Access Memory (SDRAM), Static RAM, Video RAM, Flash RAM, etc.

ROM (Read Only Memory)


ROM is built-in permanent primary memory that stores
data, even when the computer is switched off. ROM is called
non-volatile memory because it never loses its contents. ROM
holds instructions that the computer needs to operate. Whenever
the computers power is turned on, it checks ROM for directions that helps it to start up
for information about its hardware devices. There are various types of ROMs such as
Programmable Read Only Memory (PROM), Erasable Programmable Read Only Memory
(EPROM), Electrically Erasable Programmable Read Only Memory (EEPROM).

Cache Memory
It is a small, fast and expensive semiconductor memory that stores the copies of data that
needs to be accessed frequently from the main memory. It acts as a buffer between the
CPU and the main memory. It is used to hold those parts of data and program which are
most frequently used by the CPU. The cache memory is always placed between CPU and
the main memory of the computer system. The transfer of data between the processor and
the cache memory is bidirectional. The availability of data in the cache is known as cache
hit. The capability of a cache memory is measured on the basis of cache hit.

New Gateway to Computer Science Book -9


37
The advantages of cache memory are as follows:
 Cache memory is faster than main memory.
 It consumes less access time as compared to main memory.
 It stores the program that can be executed within a short period of time.
 It stores data for temporary use.

Secondary Memory
This type of memory is also known as external memory or non-volatile memory. It is
slower than the main memory. This memory is permanent in nature. It is used for storing
data and information permanently. It is used to store different programs and the information
permanently. It holds the information till we erase it.CPU directly does not access these
memories; instead they are accessed via input-output routines. The contents of secondary
memories are first transferred to the main memory, and then the CPU can access it. Disk,
CD-ROM, DVD, etc. are the popular Let’s Review
secondary memories. The following are
the characteristics of secondary memory.  Primary memories are called the
main memory that are used to store data
 These are magnetic and optical
and instructions currently required for
memories.
processing.
 It is known as the backup memory.
 RAM is a volatile memory of the
 It is a non-volatile memory. computer system.
 Data is permanently stored even if  ROM is called non-volatile memory
power is switched off. because it never loses its contents.
 It is used for storage of data in a  The contents of secondary memories
computer. are first transferred to the main
 These are slower than primary memory, and then the CPU can access
memories. it.
 Cache memory acts as a buffer between
Types of Secondary Memory the CPU and the main memory.
Magnetic Storage Device
Magnetic storage can be defined as the storage system that stores the data on a magnetised
medium with the help of magnetised particles. This type of memory is also known as
external memory. It is used for storing data and information permanently. There are many
types of computer storage, but the most common is the magnetic storage device. Magnetic
tapes, magnetic disks, hard disk, floppy disks, etc. are the examples of magnetic storage
system. The magnetic storage systems are non-volatile. Let’s discuss some magnetic
storage devices.

New Gateway to Computer Science Book -9


38
Magnetic Tape
Magnetic tape is one of the oldest technologies for electronic data storage. These are
plastic tapes with magnetic coating. They are used for storing the data, such as text, audio
or video. Magnetic tapes are similar to normal recording tapes. It is a linear recording
system that is not good for random access. A magnetic tape usually consists of a tape of ½
or ¼ inch wide, 600 to 3000 feet long and has wound on a spool in the form of a cartridge
or a reel. In magnetic tapes, the data are stored in the form of records. Let’s discuss some
advantages and disadvantages of using magnetic tape.

Advantages
 It has low cost.
 It has large storage capacity.
 It is easily transportable.
 It is very easy to handle and store.
Disadvantages
 It has low data transmission speed due to sequential access.
 It is not suitable for random access.
 It requires protected environment for storage.
 It is very difficult for updating, editing and deleting data.

Hard Disk
Hard disk is the main storage device of the computer which is fixed inside the CPU box.
Its storage capacity is very high that varies from 10 GB to 3 TB or even more than that.
As it is fixed inside the CPU box, it is not easy to move the hard disk from one computer
to another. A hard disk contains a number of metallic disks which are called platters.
Information is recorded on the surface of the platters in a series of concentric circles.These
circles are called Tracks. The hard disk platters spin at a high rate of speed, typically 5400
to 7200 revolutions per minute (RPM). The following are the basic components of hard
disk.
 Disk platters
 Read/ Write head
 Head actuator mechanism
 Logic board
 Cable and connectors
 Jumper/switches
 Spindle motor

New Gateway to Computer Science Book -9


39
Flash Memory
Flash memory is an electronic memory device popularly known as pen drive in which
data can be stored permanently and erased when it is not necessary. It is a portable storage
device that can be easily connected and removed from the CPU to store data in it. Its
capacity can vary from GB to TB.

Optical Storage Devices


The optical storage systems use the laser light as the optical medium to retrieve as well as
record data. They have more higher area density and longer data life than magnetic storage.
They are also standardized and relatively inexpensive. Like other storage devices, the
optical storage are non-volatile in nature. The optical storage systems are more reliable as
compared to magnetic storage system because they are less prone to mechanical damage.

Types of Optical Disks


Compact Disk (CD): It is a thin plastic disc coated with metal. Computer can read and
write data stored on it.This is an optical storage device with a storage capacity of up to
700 MB and it can store varieties of data like pictures, sounds, movies, texts, etc.
CD-ROM: CD-ROM refers to Compact Disc-Read Only Memory. Data or information
is recorded at the time of manufacturing and it can only be read. A CD-ROM cannot be
used to record fresh data by the computer.
CD-R: CD-R is the short form of Compact Disc-Recordable. Data can be written on it
once and can be read whenever required.The data written once cannot be erased.
CD-RW: CD-RW stands for Compact Disc Re-writable. CD-RW can be used to write
information over and over again and again. Previous information can be erased and new
information can be written on it using a CD writer. CDs are slow in comparison to hard
discs to read or write the information on them.They are portable storage devices.
DVD: DVD stands for Digital Versatile Disc. It is an optical storage device which reads
data faster than a CD. A single layer, single sided DVD can store data up to 4.7 GB, around
6 times more than that of CD and a double layer DVD can store data up to 17.08 GB,
around 25 times more than that of CD. DVDs look just like CDs but they can hold more
data,such as full length movie.
Blu-ray Disc: This is a newly invented optical data storage device whose storage
capacity can be form 25 GB up to 200 GB. It is mainly used to store high quality sound
and movie data.They are the scratch resistant discs, so storing data on them is much safer
than a CD OR DVD.

New Gateway to Computer Science Book -9


40
Let’s Review
 Magnetic storage can be defined as the storage system that stores the data
on a magnetised medium with the help of magnetised particles.
 In magnetic tapes, the data are stored in the form of records.
 Hard disk is the main storage device of the computer which is fixed inside the CPU
box.
 Flash memory is a portable storage device that can be easily connected and
removed from the CPU to store the data.
 The optical storage systems use the laser light as the optical medium to retrieve as
well as record data.
 CD, CD-ROM, CD-R, CD-RW, DVD, etc. are the types of optical storage media.

Units of Memory Management

Data in the computer’s memory are represented by two digits 0 and 1.These two digits are
called Binary Digits or Bits. A bit is the smallest unit of computer’s memory. To represent
each character in memory, a set of 8 binary digits is used. This set of 8 bit is called a Byte.
So, one Byte is used to represent one character of data.

To represent a large amount of data in memory, higher data storage units are used
like KB (Kilobyte), MB(megabyte), GB(Gigabyte), TB(Terabyte), PB(Petabyte), etc.
Let’s discuss the memory units in detail.

Bit (Binary Digit): A binary digit is logical 0 and 1 representing a passive or an active
state of a component in an electric circuit.

Nibble: A group of 4 bits is called nibble.

Byte: A group of 8 bits is called byte. A byte is the smallest unit, which can represent a
data item or a character.

Word: A computer word, like a byte, is a group of fixed number of bits processed as a unit,
which varies from computer to computer but is fixed for each computer. The length of a
computer word is called word-size or word length. It may be as small as 8 bits or may be
as long as 96 bits. A computer stores the information in the form of computer words.

Below are the lists of all the standard units of measurement used for data storage, from
the smallest to the largest.

New Gateway to Computer Science Book -9


41
bit (b) 0 or 1 1/8 of a byte
byte (B) 8 bits 1 byte
kilobyte (KB) 1024 bytes 1,000 bytes
megabyte (MB) 1024 KB 1,000,000 bytes
gigabyte (GB) 1024 MB 1,000,000,000 bytes
terabyte (TB) 1024 GB 1,000,000,000,000 bytes
petabyte (PB) 1024 TB 1,000,000,000,000,000 bytes
exabyte (EB) 1024 PB 1,000,000,000,000,000,000 bytes
zettabyte (ZB) 1024 EB 1,000,000,000,000,000,000,000 bytes
yottabyte (YB) 1024 ZB 1,000,000,000,000,000,000,000,000 bytes
brontobyte(BB) 1024 YB 1,000,000,000,000,000,000,000,000, 000 bytes

Input Devices

All computer peripheral devices which are used to input data and instructions to the
computer are called input devices. They are electromechanical devices that are used
to provide data to a computer for further processing. Input devices accept data and
instructions from the user and convert instructions or data in to a form which can be
understood by the computer. The basic task of an input device is to take the input from the
user and translate it into the machine readable from and then present it to the processing
unit of the computer for execution. A good input device should provide accurate, timely
and useful data to the main memory of the computer for processing.

Types of Input Devices


Keyboard
Keyboard is the most popular input device for direct entry of data
and instructions into computer. The standard QWERTYkeyboard
is used for computer. The computer keyboard is like the electronic
typewriter keyboard. But it has additional keys. The keyboard is
linked to the CPU and it is also linked to the computer screen
so that the data entered into the memory can be seen by the user
as he types in the data. Keyboards are of two sizes 84 keys or 101/102 keys, but now
keyboards with 104 keys or 108 keys are also available. The Computer keyboard has the
following types of keys .
Typing Keys: These keys include digit keys (0-9) and letter keys (A-Z). Which generally
give same layout as that of typewriters.

New Gateway to Computer Science Book -9


42
Numeric Keypad: It is located in the right side of the keyboard. This looks like a
calculator’s keypad with its 10 digits and some mathematical operators.
Function Keys: There are twelve function keys from F1 to F12 that are present on the
keyboard which are arranged in a row at the top of the keyboard. Each function key has
unique meaning and is used for some specific purpose.
Control Keys: These keys provide cursor and screen control. It includes four directional
arrow keys. Control keys also include Home, End, Insert, Delete, Page Up, Page Down,
Control(Ctrl), Alternate(Alt), Escape (Esc), etc.
Special Purpose Keys: The special purpose keys helps to perform certain kind of
operations, like exiting a program or deleting some characters in a document. Keyboard
has also some special purpose keys like Escape, Insert, Pause, Enter, Shift, Caps Lock,
Num Lock, Space bar, Tab, and Print Screen.

Mouse
A mouse is a small hand-held ‘point and click’ device that basically
controls the two-dimensional movement of the cursor on the
displayed screen. It is connected to the CPU through a cable. It
was developed by Douglas Engelbart in 1963 AD. It is generally
used with personal computer. It rolls on a small ball and has two or
three buttons on the top. There are mainly two types of mouse they
are mechanical mouse, and optical mouse.
Mechanical mouse: A mechanical mouse consists of three buttons: left button, right button
and scroll button. Inside the plastic coating of the mouse, there is a ball, which is rolled
over a flat surface corresponding to which the cursor moves on the display screen.
Optical mouse : An optical mouse is a pointing input device in which the reflected light
determines the movement of the cursor on the displayed screen. The upper portion of the
optical mouse is similar to that of the mechanical mouse. The lower portion of the optical
mouse consists of a ball having Light Emitting Diodes (LEDs), an optical sensor and a
Digital Signal Processor (DSP).
Light Pen
It is an electro-optical pointing device that is used for selecting objects
on the display screen with the help of light sensitive pen. Light pen
consists of a stylus connected by a cable to the computer terminal. When
the stylus is brought into contact with the screen, a dot appears there on
the screen. By moving the stylus lines and curves can be drawn on the
screen. A light pen is similar to a mouse. With a this, you can move the pointer and select
objects on the display screen by directly pointing to the objects.

New Gateway to Computer Science Book -9


43
Trackball
It is a pointing device that basically consists of a socket containing the
ball, which can be rolled manually to move the cursor on the screen. It was
originally built into the keyboard. The cursor is used to make selection from
a menu displayed on the computer screen.The trackball is stationary so it
does not require much space to use it. You can place a trackball on any type
of surface. It can be used as a game controller in games like Centipede, Golden Tee and
Marble Madness.
Joystick
Joystick is a pointing device that usually consists of one or more buttons and
a stick which controls the movement of the cursor. The first joystick was
invented in the U.S. by C. B. Mirick and patented in 1926. It is a small vertical
stick attached to a trackball for easier mechanical movements. It is used mainly in game
programs.Today, most computer joysticks connect to the computer using a USB port.

Scanners
Scanner is an input device that optically “reads” an image and
converts it into a digital signal. These are direct-entry input devices.
As the data entry is automatic, the scanners ensure more accurate
data entry. These scanners include optical scanners and magnetic
ink character readers. The optical scanners use light for sensing
input and they include OCR, OMR, Barcode reader, etc.

Touch pad
A touchpad is also called trackpad. It is a flat control surface used
to move the cursor and perform other functions on a computer.
Touchpads are commonly found on laptops and replace the
functionality of a mouse. A touchpad is designed to be controlled
with your finger. Similar to a mouse, touchpads can detect
acceleration as well as linear motion. This allows you to have refined control with slow
movements and quickly move the cursor across the screen using a fast motion.

Optical Mark Reader


Optical Mark Reader (OMR) reads the presence or absence of a
mark on a paper optically. Light is directed on to the paper and the
reflected light is analysed for the detection of a mark. If a mark is

New Gateway to Computer Science Book -9


44
there on the surface of the paper, that area sends back lesser light to the OMR. It is used
to read multiple choice answers in a test and the data are transferred to a computer for
processing.

Optical Character Reader


Optical Character Reader (OCR) detects shape, and can identify
characters. It can examine each character as if it were made up of
a collection of minute spots. Once the whole character has been
scanned, the pattern detected is matched against a set of patterns
stored in the computer. The pattern that matches or nearly matches is taken to be the
character read. Patterns that cannot be identified are rejected. It is used in mail sorting and
credit card billing.

Bar Code Reader


Barcode is a set of small bars of varying thickness and spacing printed
on the packages of products, on the back cover pages of books, tags
etc. The barcode reader uses an optical scanner to read product code
and converts it into electrical pulses. The device is connected to a
computer and the information read is passed to the computer in digital
form for automatic bill generation and updating of files. It is also
called a direct data entry device.

Digital Camera
A digital camera is a handheld electronic device that is used to capture
the image of an object electronically. The digital camera consists of a
built in computer, which helps in recording the images electronically.
Whenever a user initiates the process of capturing an image by pressing
the button available on the camera, the image light enters the camera through the lens.

Microphone
It is an input device that basically converts the sound waves into
electrical signals with the help of sensors. The sound wave pattern
is converted into electrical pattern, which is either in the form of voltage or current. The
microphones are also called transducers as they transform one from of signal into another.

Digitizer Tablet
A digitizer tablet is a peripheral device that allows users to draw on
a computer screen. Tablets are typically used by artists working with

New Gateway to Computer Science Book -9


45
graphics software such as Adobe Photoshop or Illustrator. Tablets allow for much more
precise control than a mouse or trackball. A digitizer tablet is also known as a graphics
tablet.
Touch Screen
A touch screen is an input device of an information processing system.
A user can give input or control the information processing system
through simple or multi-touch. Some touch screens use ordinary or
specially coated gloves to work while others may only work using a
special stylus or pen. It is very popular on laptops and other handled devices. We can use
finger to point the command displayed on the screen.
QR Code Scanner
The QR code stands for Quick Response Code. This system was
invented in 1994 AD by the Japanese company Denso Wave. It was
used to track the vehicles during manufacturing. It was designed to
allow high-speed component scanning. A QR code consists of black
squares arranged in a square grid on a white background, which can be
read by an imaging device such as a camera.

Let’s Review
 A bit is the smallest unit of computer’s memory.
 Input devices accept data and instructions from the user and convert information
or data in to a form which can be understood by the computer.
 A mechanical mouse consists of three buttons: left button, right button and scroll
button.
 Keyboard is the most popular input device for direct entry of data and instructions
into the computer.
 Light pen consists of a stylus connected by a cable to the computer terminal.
 The first joystick was invented in the U.S. by C. B. Mirick and patented in 1926.
 Scanner is an input device that optically “reads” an image and converts it into a
digital signal.
 OMR reads the presence or absence of a mark on a paper optically.
 The barcode reader uses an optical scanner to read product code and converts it into
electrical pulses.
 A digitizer tablet is a peripheral device that allows users to draw on a computer
screen.
 A touch screen is an input device of an information processing system.
 A QR code consists of black squares arranged in a square grid on a white
background.

New Gateway to Computer Science Book -9


46
Output Devices

Output devices are used to display the result for the user. They receive the processed data
from the CPU and present it to the user in desired format. Output devices are pieces of
computer hardware used to communicate the results of data processing performed by a
computer. Output hardware is responsible to convert the machine readable information
into human readable format that may be in the form of text, audio, graphics or video.
Types of Output Devices
There are two types of outputs which are explained below.
Softcopy Output
Soft copy is an electronic display of digital information. The soft copy devices allow the
viewing of information that can be rearranged, modified or corrected as the requirement
of the user. Some types of softcopy output devices are explained below.
Monitors / Display Units
These are the most commonly used softcopy output devices. They display character and
graphics on the screen. Different types of display monitors use different technology for
displaying the data. Let’s discuss different types of monitors.

Cathode Ray Tube (CRT)


Common monitors that use large vacuum tube called Cathode Ray
Tube (CRT) are CRT monitors. They look like a common television
screen. A CRT is the old type of monitor and big in size but it is
cheaper in price. It has high contrast ratio colour depth because of
which it displays the actual colour. CRT monitors are bulky and occupy a lot of space on
the desk. It also consumes a lot of power and produces a large amount of heat.

Liquid Crystal Display (LCD)


LCD monitors use liquid crystals technology to display the output.
The liquid crystals are actually the molecules of the liquid filled
in the LCD. This technology has replaced the traditional Cathode
Ray Tube (CRT) monitors. It is also used in the screens for mobile
devices, such as laptops, tablets, and smartphones. An LCD monitor is small in size and
light in weight so it occupies less space on the desk. The power consumption by an
LCD monitor is very less as liquid molecules need less power to bend light. It has a fix
resolution due to which the images on LCD monitors become blurred when the resolution
is changed.

New Gateway to Computer Science Book -9


47
Light-Emitting Diode (LED)
An LED is an electronic device that emits light when an electrical current is
passed through it. Early LEDs produced only red light, but modern LEDs
can produce several different colours, including red, green, and blue (RGB)
light. Recent advances in LED technology have made it possible for LEDs
to produce white light as well. LEDs are commonly used for indicator lights
(such as power on/off lights) on electronic devices. Traditional flat screen LCD displays
have been started to be replaced by LED displays, which use LEDs for the backlight.
LED TVs and computer monitors are typically brighter and thinner than their LCD.

Let’s Review
 Output devices are computer hardwares used to communicate the results of
data processing performed by a computer.
 The soft copy devices allow the viewing of information that can be rearranged,
modified or corrected as per the requirement of the user.
 An LCD monitor is small in size and light in weight so it occupies less space on the
desk.
 A CRT monitor has high contrast ratio colour depth because of which it displays the
actual colour.
 An LED is an electronic device that emits light when an electrical current is
passed through it.

Hardcopy Output
A hard copy is a printed copy of information from a computer. The output that we get
from a printer or a plotter on a paper is also known as hardcopy output. Hardcopy output
are permanent outputs which we cannot edit, modify and change easily. We can use
hardcopy output for a long time as well. Let’s discuss some types of hardcopy output.

Printer
A printer is an external output device that takes data from a computer
and generates output in the form of graphics and text on the paper.
There are two types of printers which we are going to discuss below.

Impact Printers
Impact printers are those printers in which mechanical contact
between print head and paper exists. It usually forms the print image
by pressing an inked ribbon against the paper using a hammer or pins.

New Gateway to Computer Science Book -9


48
The following are some popular of impact printers.

Dot-Matrix Printers
The dot-matrix printer uses print heads containing 9 to 24 pins.
These pins produce patterns of dots on the paper to form individual
characters. The 24 pin dot-matrix printer produces more dots that
a 9 pin dot-matrix printer, which results in much better quality and
clearer characters. The pins strike the ribbon individually as the print mechanism moves
across the entire print line in both directions. Dot-matrix printers are inexpensive and
typically print at the speed of 100-600 characters per second.

Daisy-wheel Printer
A daisy wheel printer is an impact printer that produces printout of
good quality character. It contains a metal or a plastic disk on which
the character reside on the outer edge of the petals. These printers are
capable of printing text only and not graphics. They are noisy as well
as very slow and can print approximately 10 to 75 characters per second.

Chain Printer
A chain printer uses a chain of print characters wrapped around two pulleys. Like the
drum printer, there is one hammer for each print position. The hammer then strikes the
page, pressing the paper against a ribbon and the character located at the desired print
position. The chain keeps rotating until all the required print positions on the line have
filled. Speeds of chain printers range from 400 to 2500 characters per minute.

Drum Printer
A drum printer consists of a solid, cylindrical drum that has
raised characters in bands on its surface. The number of print
positions across the drum equals the number available on the
page. This number typically ranges from 80-132 print positions.
Typical speeds of drum printers are in the range of 300 to 2000 lines per minute.

Non-Impact Printers
Non-impact printers are the printers in which mechanical contact between the print head
and paper does not exist. These printers spray ink on the paper with the help of nozzle.
Non-impact printers do not produce much noise than the impact printers. These printers
are faster than the impact printers. Some of the popular non-impact printers are explained
below.

New Gateway to Computer Science Book -9


49
Ink-jet Printers
Ink-jet printers work in the same way as dot-matrix printers do to
form images or characters with little dots. However, the dots are
formed by tiny droplets of ink. Ink-jet printers form characters
on paper by spraying ink from tiny nozzles through an electrical
field that arranges the charged ink particles into characters at the
rate of approximately 250 characters per second. Various colours of ink can also be used
in these printers. These printers are cheaper and portable as compared to non-impact
printers.

Laser Printer
Laser printers are the popular non-impact printers that produce
images with the help of laser beam. It works like a photocopy
machine. Laser printers produce images on paper by directing a
laser beam at a mirror which bounces the beam onto a drum. The
drum has a special coating on it to which toner (an ink powder)
sticks. Using patterns of small dots, a laser beam conveys information from the computer
to a positively charged drum to become neutralized. Laser printers have a high speed and
resolution. They produce high quality printing without producing any noise.

Plotter
Plotter is a device used to print high quality images
and graphics. It uses one or more pens to produce a high quality
drawing. Plotters were the first type of printers that could
print with colour and render graphics and full-size engineering
drawings. Plotters are much more expensive than printers. They
are most frequently used for CAE (Computer Aided Engineering) applications, such as
CAD(Computer Aided Design) and CAM (Computer Aided Manufacturing). Instead
of toner, plotters use a pen, pencil, marker, or another writing tool to draw multiple,
continuous lines onto paper rather than a series of dots like a traditional printer.

Speaker
Speakers are popular output devices used with computer systems.
They receive audio input from the computer’s sound card and
produce audio output in the form of sound waves. Most computer
speakers are active speakers, they have an internal amplifier which
allows to increase the volume, or amplitude, of the sound. Speakers usually come in a
pair, which allows them to produce stereo sound from two separate audio channels.

New Gateway to Computer Science Book -9


50
Let’s Review
 The output that we get from a printer or a plotter on a paper is also known as
hardcopy output.
 Impact printers are those printers in which mechanical contact between print head
and paper exists.
 A daisy wheel printer is an impact printer that produces printout of good quality
character.
 A drum printer consists of a solid, cylindrical drum that has raised characters in
bands on its surface.
 Non-impact printers are the printers in which mechanical contact between the
print head and paper does not exist.
 Laser printers produce images on paper by directing a laser beam at a mirror which
bounces the beam onto a drum.
 Plotter is a device used to print high quality images and graphics.
 Computer speakers receive an audio input from the computer’s sound card and
produce audio output in the form of sound waves.

Expand your knowledge


 The mouse was invented by Douglas Engelbart in 1964 AD.
 During the mid and late 1700s and early 1800s, several typing and writing
devices were created around the world.
 The first practical typewriter and the word "Type-Writer" was first developed
in 1868 by Christopher Sholes and is considered to be the first typewriter.
 The first digital computer known as the ENIAC that was completed in 1946
used a teletype machine to input data into the computer.
 In 1984, Apple Computers released the Macintosh personal computer. It was
the first computer that came with 128KB of memory.
 In 1975, personal consumer computer Altair released, it uses Intel's 8-bit
8080 processor and includes 1 KB of memory.

Assignment
1. Select the correct answer from the given options.
a. Which of the following is a computer hardware?
i. Keyboard ii. Monitor iii. Mouse iv. All of the above
b. Which of the following helps to install the processor into the motherboard?
i. CPU socket ii. RAM iii. AT connector iv. Expansion cards

New Gateway to Computer Science Book -9


51
c. Which of the following is the latest connectors with 7 pin interface?
i. AT connector ii. ATX connector iii. SATA connector iv. None of them
d. From where does the motherboard get the power connection?
i. Expansion slot ii. Power connectors iii. RAM slot iv. CPU socket
e. For what can we use IDE connector?
i. FDD & HDD ii. Mouse & Keyboard iii. RAM & ROM iv. CPU socket
f. Which of the following is a primary memory?
i. RAM ii. Hard Disk iii. ROM iv. Magnetic tapa
g. Which of the following is called a flash memory?
i. Pen drive ii. Compact disk iii. Hard disk iv. Motherboard
h. Which of the following represents the binary digits?
i. 0 &2 ii. 0 & 1 iii. Only 0 iv. Only 1
i. Which of the following is the largest memory measurement unit?
i. Bits ii. Bytes iii. Kilobytes iv. Nibble
j. Which of the following is a hardcopy output device?
i. Monitor ii. CPU iii. Printer iv. Scanner
2. Fill in the blanks with suitable words.
a. …………………. is the collection of physical components that constitutes a
computer system.
b. A …………………. provides the electrical connections by which the other
components of the system communicate.
c. CPU socket helps to install the processor into the ………………….
d. RAM is the …………………… memory of the computer.

e. A Motherboard needs the power to keep running and it gets the power
from………………...
f. …………………….. is the collection of physical components that constitutes a
computer system.
g. A …………….. provides the electrical connections by which the other components
of the system communicate.

New Gateway to Computer Science Book -9


52
h. The first microprocessor was the ………………….., introduced in 1971 AD.
i. Primary memories are called …………………….
j. The contents of secondary memories are first transferred to the ……………………,
and then the CPU can access it.
3. State whether the given statements are true or false.
a. AT connector is one of the connectors which has 2 numbers of 6 pin male
connectors.
b. The first microprocessor was introduced in 1620 AD.
c. CPU socket helps to install the processor into the Motherboard.
d. A Motherboard needs the power to keep running and it gets the power from RAM.
e. Microprocessor consists of an ALU, register array, and a control unit.
f. ALU, registers, internal bus and control sections are the functional sections of
microprocessor.
g. RAM is a non-volatile memory of the computer system.
h. Cache memory acts as a buffer between the CPU and the main memory.
i. ROM is called volatile memory because it never loses its contents.
j. Speaker is one of the popular input devices of computer system.
4. Write appropriate technical terms for the followings.
a. A connector used to connect the disk driver including floppy disk drive and hard
disk drive. ‘
b. The section of CPU which is used to calculate the ability of the microprocessor to
perform either arithmetic or logical operations.
c. It is one or more sets of chips that store data or program instructions, either
permanently or temporarily.
d. It is a small, fast and expensive semiconductor memory that stores the copies of
data that needs to be accessed frequently from the main memory.
e. These are plastic tapes with magnetic coating that are used for storing the data,
such as text, audio or video.
f. It is an optical storage device which reads data faster than a CD.
g. A group of 8 bits.
h. A pointing device that usually consists of one or more buttons and a stick which
controls the movement of the cursor on the screen by pointing in all directions.

New Gateway to Computer Science Book -9


53
i. Barcode is a set of small bars of varying thickness and spacing printed on the
packages of products, on the back cover pages of books, tags, etc.
j. A monitor technology that uses liquid crystals technology to display the output.
k. The printer that uses print heads containing 9 to 24 pins.
l. A printer consists of a solid, cylindrical drum that has raised characters in bands
on its surface.
m. A device used to print high quality images and graphics which uses one or more
pens to produce a high quality drawing.
5. Write the full form of the followings.
HDD, FDD, RAM, ROM, SMPS, IDE, LED, DRAM, SDRAM, PROM,
EPROM, EEPROM, CD-ROM, RPM, DVD, OMR, OCR, QR-Code
6. Match the following.
RAM Input device
Hard disk Place on CPU socket
Plotter Called flash drive
Pen drive Hardcopy output
Microprocessor Storage device
Touchpad Permanent memory
7. Answer the following questions.
a. What is computer hardware? Write its types.
b. What is motherboard? What does it provide?
c. Name any six components of motherboard.
d. What is the use of expansion card slot?
e. What is microprocessor? Write down the functional sections of microprocessor
and also wite its functions.
f. What is secondary memory?
g. What is primary memory? Maintain its types.
h. What is cache memory? Write its advantages.
i. Write down the characteristics of secondary memory.
j. What is magnetic storage device? Define magnetic tape.

New Gateway to Computer Science Book -9


54
k. What are the advantages and disadvantages of using magnetic tape?
l. What is hard disk? List out its basic components.
m. What is optical disk? Write and define its types.
n. List out the memory measurement units with their bytes.
o. Define DVD and blue-ray Disk.
p. What is keyboard? Explain the types of various keys.
q. What are the differences between mouse and light pen?
r. Define joystick, scanner and touch pad.
s. What is OCR and Bar Code? Define touch screen technology and QR code scanner.
u. Define output devices with their types.
v. Explain in short about soft copy output and hardcopy output with examples.
w. What is LED and LCD technology in the sense of monitor?
x. What is impact and non-impact printer? Write with examples.
y. Explain any two output devices in short.
z. What is chain printer and drum printer? Write its range of speed per minute.
Project Work
• Prepare a project report about the types of input and output computer hardware.
• Visit IT solution office like computer sales and maintenance centre, mobile sales and
maintenance centre and collect the latest devices that are available there.

New Gateway to Computer Science Book -9


55
Lesson
Introduction to Computer Software
5

Inside the Lesson

 Introduction to computer software


 Types of computer software
 System software
 Operating system, its functions and types
 Utility programs
 Device drivers
 Application software and its types
 Introduction to GUI environment
 Understanding windows desktop
 Mouse pointer and its activities
 File and folder management
 Working with windows explorer
 Language processor
 Introduction to open source software with its advantages
 Introduction to desktop and web apps

A computer system consists of hardware, the electronic devices that are capable of
computing and manipulating information, and software that carries out predefined tasks
to complete a given task. All computer systems consist of two major components that
are hardware and software. Hardware is the physical component and software is a set of
computer programs which enable hardware to function. We can say that software gives life
to the hardware and therefore, the software is popularly referred to as the soul of the computer
system while the hardware like the heart. We can define, software as the collections
of program and other associated documents that helps to control, manage and integrate
the components of computer system to accomplish a specific task. Computer system is
nothing without the software.

New Gateway to Computer Science Book -9


56
Types of Computer Software

The computer software mainly performs two varieties of tasks. The first task is to control
and coordinate the hardware components and manage their performance and the second
one is to enable the users to accomplish their required task. Different types of computer
softwares are discussed below.

System Software
System softwares are those programs that manage the operating system with the
coordination of computer hardware and their resources. Systems software is a set of
instructions that serves mainly as an intermediary between computer hardware and
application programs. Systems software provides important self regulatory functions for
computer systems, such as loading operating system, managing hardware resources and
providing commonly used sets of instructions for all applications to use. System software
includes:
 Operating system
 Utility programs
 Device drivers
Operating System
Operating sytem is a computer system software that acts as an intermediate between the
user and computer hardware. It controls and co-ordinates the overall operations of the
computer. This is the first software that we see when we turn on the PC. It manages the
computer's memory and co-ordinates with computer software and hardware. What we
can say is that, without an OS computer is just useless. The OS usually comes pre-loaded
on any computer when we purchase it. Most of the people uses the OS that comes with it
but they can change or upgrade as their requirements. Modern OS uses a graphical user
interface system so that it is very easy to use and operate. The OS provides services such
as process management, file management, etc.
Functions of an Operating System
Process Management: Process management means managing the programs that are
running on the processor at a given time. The operating system loads a program into
main memory and executes it. Some operating systems offer more sophisticated forms of
process management, such as multitasking, multithreading, and multiprocessing.
File Management: A file system is normally organized into directories for easy
navigation and usage. These directories may contain files and other directories. It keeps
track of information, location, uses, status, etc. It also allocates and de-allocates the
resources.

New Gateway to Computer Science Book -9


57
Memory Management: Memory management refers to management of primary
memory or main memory. Main memory provides a fast storage that can be accessed
directly by the CPU. If a program needs to be executed, it must be in the main memory.
Interface Between the User and the Hardware: An OS provides an interface between
user and machine. The interface can be Graphical User Interface (GUI) and Command
Line Interface (CLI). In graphical user interface user can click on screen elements to
interact with the OS. Like this, in command line interface user can type commands at the
command line interface to tell the OS to accomplish the task.
Coordinate Hardware Components: An OS enables the coordination of hardware
components. Each hardware device understands a different language, but the operating
system can interact to them through the specific translational software called device
drivers. Every hardware component has different drivers for operating systems. These
drivers make the communication successful between the other software and the hardware.

Let’s Review
 Software is the collection of programs and other associated documents that helps
to control, manage and integrate the components of computer system to
accomplish a specific task.
 Systems software is a set of instructions that serves mainly as an intermediary
between computer hardware and application programs.
 Operating system provides services that include process management, virtual
memory, file management, security and the user interface.
 A file system is normally organized into directories for easy navigation and
usage.
 An OS provides an interface between user and machine.
 Memory management refers to management of primary memory or main memory.

Types of Operating System


As previously discussed, operating systems are necessary for computer hardware to
function. Operating systems can be categorized based on the number of users that they
support. The types of operating systems are explained below.
Real Time operating System
A real-time operating system is a very fast and small operating system. It is defined as a
data processing system in which the time interval is required to process and respond. A
real-time operating system must have well-defined, fixed time constraints, otherwise the
system will fail. For example, scientific experiments, industrial control systems, weapon
systems, robots, air traffic control systems, etc. Real time operating systems are very fast
and quick respondent systems. These systems are used in an environment where a large
number of events must be accepted and processed in a short time.

New Gateway to Computer Science Book -9


58
Single User Single Tasking Operating System
An operating system that allows a single user to perform just one task at a time is called
single user single tasking operating system. In this operating system, only one user can
work at a time. An example of a single-user, single-task operating system is the operating
system used by handheld computers such as Personal Digital Assistants (PDA).
Single-User, Multi-Tasking Operating System
A single-user,multi-tasking operating system is one that allows a single user to perform
two or more functions at a time. It takes special operating system to keep two or more
tasks at once. The most commonly used personal computers usually run such OS are
Microsoft Windows and Macintosh Operating system. The multi-tasking features of these
OS have greatly increased the productivity of people in a large variety of jobs because
they can accomplish more in a shorter period of time. This is the type of operating system
which is popularaly used on the desktop and laptop computers today. For example, it is
possible for a Windows user to work with word processor while downloading a file from
the internet, printing the text, listening to music or sending and receiving an e-mail at the
same time.
Multi-User, Multitasking Operating System
Multiuser/Multitasking operating system is a powerful operating system that supports
more than one user at a time and can perform more than one task at a time. UNIX is an
example of a multiuser multitasking operating system. In this operating system, all or
most of the computing occurs at the server. The operating system must make sure that the
requirements of the various users are balanced, and that each of the programs they are
using has sufficient and separate resources. In this OS, if one user is affected remainig
other users stay active.
Utility Programs
Utility programs refer to small programs, which provide additional capabilities to the
computer system. These programs are not provided by the main operating system.
They only provide the additional features to the computer system. Utilities can also be
applications such as screensavers, font and icon tools, desktop enhancements, etc. Some
of the functions of utility program are listed below.
 Repairing damaged files
 Detecting and removing computer viruses
 Reorganising files
 Compressing files
 Translating instructions to display
Some of the major categories of utility software are listed below.
Disk Defragmenter: Defragmentation is the process of consolidating fragmented files on
the user’s hard drive.

New Gateway to Computer Science Book -9


59
Antivirus: Antivirus software is a type of program designed and developed to protect
computers from malware like viruses, computer worms, spyware, etc. The function of
antivirus program is to detect and remove viruses from the computer system.
Disk Cleanup: Disk Cleanup is a computer maintenance utility tool that is included
in the Microsoft Windows operating system and it is designed to free up space on the hard
drive.
File Manager: File manager is a computer program that provides a user interface to
manage the files and folders of a computer system.
Backup Uutility: Data backup software is an application used to create a duplicate copy
of data to safeguard files and recovery them in case they are lost, corrupted or infected by
malware.
Disk Compression: A type of data compression that works by storing compressed
versions of files on the hard disk. A disk compression utility stays between the operating
system and the disk drive.

Device Drivers
A device driver is a software program that enables a specific hardware device to work
with an operating system. The device driver acts as a translator between the I/O devices. A
device driver may be required for internal components, such as video cards , optical media
drives as well as external peripherals, such as printers , monitors, etc.Most of the modern
hardware components are “plug and play,”. It means the devices will work without driver
installation. However, if a hardware device is not recognized by the operating system
itself we need to install the correct drivers so that the device functions properly.

Let’s Review
 A real-time operating system must have well-defined, fixed time constraints,
otherwise the system will fail to work.
 An operating system that allows a single user to perform just one task at a time
is called single user single tasking operating system.
 A single-user, multi-tasking operating system is one that allows a single user to
perform two or more functions at a time.
 UNIX is an example of a multiuser multitasking operating system.
 Multitasking operating system is a powerful operating system that supports
more than one user at a time.
 Utility programs refer to the small programs, which provide additional capabilities
to the computer system.
 A device driver is a software program that enables a specific hardware device
to work with a computer’s operating system.

New Gateway to Computer Science Book -9


60
Application Software
Software which is developed to help the user to perform specific tasks is called application
software. Application software consists of instructions that direct a computer system to
perform specific information processing activities for users. A large number of different
application software programs available have different uses in the computer. Application
software uses the capacity of a computer directly for specific tasks and is used to manipulate
text, graphics and numbers.Various examples of application softwares are listed below.
 Word processing software
 Database programs
 Entertainment software
 Business software
 Educational software
 Computer-aided design(CAD) software
 Spreadsheet software, etc.

Types of Application Software


Packaged Software: Packaged Software is readymade, error free, advance and standard
software for general work. All word processing, database management, graphics, animation
and web-designing softwares are packaged softwares. This software is equipped with
all essential tools and technology to enhance the user's productivity. Software programs
included in packaged software are available to purchase individually. However, purchasing
the packaged software is cheaper than purchasing each software program separately.
Tailored Software: Tailored software is small software, developed by using high level
language for specific small process. These types of softwares are developed for certain
purpose.This software is also called customized software. Software for payroll for
specific organization, software for specific bank, software for railway reservation, hotel
reservation, etc. are the examples of tailored software. This software is developed for
solving specific problems of specific users or organizations

Introduction to GUI Environments

Most of the modern operating systems are Graphical User Interface (GUI) based. GUI is
a type of user interface that enables the users to interact with the operating system
by means of point-and-click operations. A GUI uses windows, icons, and menus to
carry out commands, such as opening, deleting, and moving files. Many GUI operating
systems are navigated through the use of a mouse; the keyboard can also be utilized
by using keyboard shortcuts or arrow keys. The GUI was first developed by Alan Kay,
Douglas Engelhard, and a group of other researchers in 1981 AD.

New Gateway to Computer Science Book -9


61
Let’s Review
 Software which is developed to help the user to perform specific tasks is called
application software.
 Application software uses the capacity of a computer directly for specific tasks
and is used to manipulate text, graphics and numbers.
 Packaged software is readymade, error free, advance and standard software for
general works.
 Tailored software is small software, developed by using high level language
for specific small process.
 A GUI uses windows, icons, and menus to carry out commands, such as opening,
deleting, and moving files.

Understanding Windows Desktop

A windows desktop is the first display screen which appears when you load an operating
system. It has various icons like This PC, Recycle bin, Network, Control Panel, Internet
explorer, etc. The details of some default components of windows desktop are explained
below.
Recycle Bin: It temporarily stores deleted files until they are removed from the Recycle
Bin permanently.
Taskbar: It contains the minimized applications items like, documents, or other windows
which can be used to quickly switch from one program to another.
Notification Area: It is an area within the taskbar. It is used to indicate the time, as well as
display icons which may be used to quickly start programs, adjust settings, or determine
the status of a current task.
This PC: When we open this icon, it displays the components of the computer. It displays
disk drive, local hard drive, local CD, DVD, pen drive as well as network drives and
printers.
Network: When we open this icon, it displays all the resources available on the
network. It displays applications, data files, and printers. It also displays the computers in
your work group.
Internet Explorer: It is a default web browser application which is used to search and
browse internet content, web sites, etc.
User: When we open this icon it displays the files and objects which have been stored
within. My Documents is the default user storage folder for many software applications.

New Gateway to Computer Science Book -9


62
What is a windows dialogue box?

A dialog box is a user interface element that is used to communicate and interact between
a user and a software program. It is a movable window on the computer screen which
is seen when a user selects a menu option. There are two types of windows dialogue
box they are application window dialogue box and document windows dialogue box.
The application window dialogue box provides a framework for the whole application.
This can be opened, closed, resized, and moved around the desktop. All application
windows dialogue box are normally contained in the application windows. It also
contains the application menu bar and status bar. The document windows dialogue box
appears inside the application windows. A document window dialogue box is a section
of the screen used to display the contents of a document file on a GUI operating system.
Various components of dialogue box are title bar, status area, icon area, panel area, button
area, tab area, toolbar, menu area, etc.

Mouse Pointer and its Activities

The mouse is the primary input device which is used to interact with objects in windows.
A modern mouse typically has a primary button (left button), a secondary button (right
button), and a mouse wheel between the two. By positioning the pointer and clicking the
primary and secondary buttons on the mouse, users can select objects and perform actions
on them. The given table shows various mouse pointers with their functions.

Shape Name Use


Normal select Used for most objects.

Link select Used for text and graphics links because of their weak af-
fordance.
Text select Used for text to indicate a location between characters.

Precision select Used for graphic and other two-dimensional interaction.

Busy pointer Used to wait for a window to become responsive.

Working in back- Used to point, click, press, or select while a task com-
ground pointer pletes in the background.

New Gateway to Computer Science Book -9


63
Common Pointer Shapes
The following tables describe the common pointer shapes, along with their interactions.

Action Interaction
Pointing Place the pointer to a specific object without clicking any mouse buttons.
Place the pointer to a specific object without clicking any mouse buttons
Hovering
and without moving for at least a second.
Place the pointer to a specific, non-selectable object and press and release a
Clicking
mouse button without moving.
Place the pointer to a specific, selectable object and press and release a
Selecting
mouse button.
Place the pointer to a specific object and press a mouse button without re-
Pressing
leasing.
Wheeling Move mouse wheel.

File and Folder Management

File management is organizing and keeping track of files and folders. Windows
allows you to organize folders and files in a file hierarchy, like the way you store
paper documents in a record file. Just as a filing cabinet contains several folders,
each containing a set of related documents and folders together. A file hierarchy
allows you to place files in folders, then place folders in other folders, so that
your files are organized and easier to find. Windows provides you with a main file
management window called Windows Explorer. Windows Explorer provides access
to files, folders, drives, and disks on your local, Home group and network computers.

Working with Windows Explorer


 Click the windows explorer button on the taskbar
The Windows Explorer window opens, displaying the contents of the libraries folder.
Windws has four default libraries they are Documents, Music, Pictures, and Videos.
 Point to libraries, click the expand indicator next to libraries if necessary to expand
the list, then click documents in the navigation pane under libraries.
The contents of the Documents library folder open in your Windows Explorer
window.
 If you want to save your files to a USB drive, make sure the USB drive where you
store your data files is plugged into your computer, then click computer in the
navigation pane.

New Gateway to Computer Science Book -9


64
The computer window opens, displaying the contents of your computer, including
all disk drives, removable storage devices, and network locations.
 Click the drive where you store your data files.
The bottom pane of the computer window changes to display details about the
selected drive. If you selected a hard drive, the details pane displays additional
information, including free space and total disk size.
 Double-click the drive where you store your data files.
The folders contained on the disk drive open in the computer window. When you
open a disk drive or folder, the address bar adds the new location to the list.
 Double-click the folder, then double-click the sub folder.
The files and folders are represented by icons that indicate the application they were
created with.
 Double-click the folder.
The folder opens and displays the files that have been created.

Let’s Review
 A windows desktop is the first display screen which appears when you load an
operating system.
 Taskbar contains the minimized application items like, documents, or other
windows which can be used to quickly switch from one program to another.
 Internet Explorer is a default web browser application which is used to search
and browse internet content, web sites, etc.
 A dialog box is a user interface element that is used to enable communication and
interaction between a user and a software program.
 The application window dialogue box provides a framework for the whole
application. This can be opened, closed, resized, and moved around the desktop.
 A document window dialogue box is a section of the screen used to display the
contents of a document file on a GUI operating system.
 File management is an organizing and keeping track of files and folders.

Language Processor

A language processor is a type of a computer software program that has the capacity of
translating source code or program code into machine code. Language translator will
take a source program as input and then will convert it into object code so that it can be
understood by the computer. Different types of language processors are explained below.

New Gateway to Computer Science Book -9


65
Compilers
A compiler is a language processor that converts the source program into machine
code. The compiler converts source program in machine code which is called an
object program. Compiler checks and reports syntax errors in the program. A source
program containing an error cannot be compiled. A program written in high-level
language is called source program. The program in machine language is called
object program. The programs are written mostly in high level languages like Java, C++,
and Python. They are called source code. These source codes cannot be executed directly
by the computer and must be converted into machine language to be executed.
Interpreters
The translation of single statement of source program into machine code is done
by language processor and executes it immediately before moving on to the next
line which is called an interpreter. If there is an error in the statement, the interpreter
terminates its translating process at that statement and displays an error message.
The interpreter moves on to the next line for execution only after the removal
of the error. An Interpreter directly executes instructions written in a programming or
scripting language without converting them to an object code or machine code.
Assemblers
The assembler is used to translate the program written in assembly language into machine
code. The source program is an input of assembler that contains assembly language
instructions. The output generated by assembler is the object code or machine code
understood by the computer.

Difference between Compiler and Interpreter


Compiler Interpreter
A compiler is a program which converts Interpreter takes a source program and
the entire source code of a programming runs it line by line, translating each line
language into executable machine code. as it comes to it.
Compiler takes large amount of time to Interpreter takes less amount of time to
analyse the entire source code but the analyse the source code but the overall
overall execution time of the program is execution time of the program is slower.
comparatively faster.
Compiler generates the error message Debugging is easier as it continues
only after scanning the whole program, so translating the program until the error is
debugging is difficult as the error can be found.
present anywhere in the program.
Generates intermediate object code. No intermediate object code is generated.
Examples: C, C++, Java Examples: Python, Perl

New Gateway to Computer Science Book -9


66
Introduction to Open Sources Software
Open source software refers to any program whose source code is made available for
use or modification as per user’s choice. Open source software is usually developed as
a public collaboration and made freely available. Source code is the part of software
that most computer users don’t see. It is the code that computer programmers can
manipulate to change how a piece of software, a “program” or “application” works.
Programmers who have access to a computer program’s source code can improve that
program by adding features to it or fixing parts that don’t always work correctly.The open
source software must meet the following criteria for the user accessible.
 The program must be freely distributed.
 Source code must be included in the program.
 Anyone must be able to modify the source code.
 Modified versions of the source code may be redistributed.
Advantages of Using Open Source Software
Open source licensing doesn’t involve copyright restrictions. The main advantages of
software with a publicly available source code are:
 Flexibility: The software can be customized to meet specific needs.
 Stability: You can use this product for long-term projects because it won’t disappear
from the market or become out-dated.
 Security and reliability: Many people with different skill levels may work
on the same software, which may lead to code inconsistency.
 Better support: You have more ways of getting technical advice and support: from
a vendor, a consultancy company specializing in this product, or from other users
that are ready to share their experience and knowledge across forums or maiing lists.
Let’s Review
 A language processor has the capacity of translating source code or program code
into machine code.
 A compiler is a language processor that converts the source program into machine
code.
 A program written in high-level language is called source program.
 The translation of single statement of source program into machine code is done
by language processor.
 The assembler is used to translate the program written in assembly language into
machine code.
 Open source software refers to any program whose source code is made
available for use or modification as per user’s choice.
 Flexibility, stability, security and reliability are the advantages of using open
source software.

New Gateway to Computer Science Book -9


67
An Introduction to Desktop and Web Apps

Desktop application is a machine dependent program that runs on a personal computer


device such as a desktop, laptop and personal workstations. This application needs to
install separately on each and every computer. It has fewer security risks than the web
application security risk. In this application data are stored in a particular storage location
of computer system.

Web application is a machine independent which is complex and a bit more different
than desktop application. In a web application, the application is loaded on the server
and lots of computers are connected with the server whose location is unknown.
In this application, user can use different applications without installing anything on the
personal computer. In this application data are remotely stored on the main server and
application can be accessed from any personal computers using any web browser.

There are various categories of apps available for the various users according to their
requirement. Some of the popular categories of apps are Gaming apps, Business apps,
Education apps, Life style apps, Utility apps, Entertainment apps, Travel apps, etc. Let's
discuss some types of apps below.

Mobile Apps
Mobile applications are also known as mobile apps. They are software programs
developed for mobile devices such as smart phones and tablets. Some of the devices come
preloaded with some mobile apps of their manufacturers or the mobile service providers
with which they are associated. Many more apps are available through device-specific
app stores. Apps are generally small, individual software units with limited function.
The use of apps software was popularized by Apple Inc. and its App Store, which offers
thousands of applications for the iPhone, iPad and iPod Touch. A mobile application also
may be known as an app, web app, online app, iPhone app or smart phone app. Some
types of mobile apps are listed below.

Native Apps
Native apps are developed for a single mobile operating system therefore they are
“native” for a particular platform or device. App built for systems like iOS, Android,
Windows phone, Symbian, Blackberry cannot be used on a platform other than their own.
In other words, you won’t be able to use Android app on iPhone.

New Gateway to Computer Science Book -9


68
Hybrid Apps
Hybrid apps are built using multi-platform web technologies such as HTML5, CSS
and Javascript. Hybrid multi-platform apps are fast and are easy to develop. Hybrid
applications lack performance, speed and overall optimization in comparison to native
apps. There are also some certain design issues due to app inability to look in exactly
same way on two or more platforms.
Web Apps
Web apps are software applications that behave similar to native applications. Web apps
use a browser to run and are usually written in HTML5, Java Script or CSS. These apps
redirect a user to URL and offer “install” option by simply creating a bookmark to their
page. Web applications require minimum of device memory. As all personal databases
are saved on a server, users can get access from any device whenever there is internet
connection.

Let’s Review
 Desktop application is a machine dependent program that runs on a personal
computer device such as a desktop, laptop and personal workstations.
 Web application is a independent machine which is more complex and a bit
different than desktop application.
 There are various categories of apps available for various users according to their
requirement. Some of the popular categories of apps are Gaming apps, Business
apps, Education apps, Lifestyle apps, Utility apps, Entertainment apps, Travel
apps, etc.
 Mobile applications are also known as mobile apps.
 They are built using multi-platform web technologies such as HTML5, CSS and
Javascript.

Expand your knowledge


 Android Inc was founded in Palo Alto, california in october 2003 AD. by
Andy Rubin, Rich Miner, Nick Sears and Chris White.
 In 1979 AD, the version of word processors called wordstar was developed.
 Early operating system and software were written in assembly language.
 C++ was the first used in 1980 AD. for system programming.
 Ubuntu is a fast, easy to use and free operating system that can be used on
desktop, laptop and notebook computers.

New Gateway to Computer Science Book -9


69
Assignment
1. Select the correct answer from the given options.
a. Which of the following is a related to computer software?
i. Device Driver ii. Motherboard iii. CPU iv. Hard Disk
b. Which of the following is a system software?
i. Windows ii. Office iii. Database iv. Graphics
c. Which of the following is an operating system?
i. Android ii. iOS iii. Windows iv. All of them
d. Which of the following function refers to the management of memory?
i. Interface ii. Memory management iii File management iv. All of them
e. Which of the following provides an interface between an user and a machine?
i. Office package ii. Graphics package iii. Operating system iv. All of them
f. Which of the following is an utility program?
i. Antivirus ii. File manager iii. Backup utility iv. All of them
g. Which of the following icon stores the deleted items?
i. My network ii. My computer iii. Recycle bin iv. My document
h. Which of the following is an example of compiler?
i. C ++ ii. Python iii. Perl iv. None of them
2. Fill in the blanks with suitable words.
a. ……………………….. is the collections of program and other associated
documents that helps to accomplish a specific task.
b. …………………. provides services that include process management, virtual
memory, file management, and the user interface.
c. An operating system that allows a single user to perform just one task at a time is
called ………………………… operating system.
d. ……………………. is an example of a multitasking operating system.
e. ……………………………. uses the capacity of a computer directly for specific
tasks and is used to manipulate text, graphics and numbers.
f. …………………… software is small software, developed by using high level
language for specific small process.
g. A ……………………. uses windows, icons, and menus to carry out commands,
such as opening, deleting, and moving files.
h. ………………… contains the minimized application items like, documents, or
other windows which can be used to quickly switch from one program to another.
i. A ………………… is a user interface element that is used to enable communication
and interaction between a user and a software program.
j. A document ………box is a section of the screen used to display the contents of
a document file on a graphical user interface (GUI) operating system.

New Gateway to Computer Science Book -9


70
3. State whether the given statements are true or false
a. Systems software is a set of instructions that serves mainly as an intermediary
between computer hardware and application programs.
b. Process management, file management, memory management, etc. are the
functions of an operating system.
c. A device driver provides an interface between a user and a machine.
d. A single-user, multi-tasking operating system is one that allows a single user to
perform two or more functions at a time.
e. Single tasking operating system is a powerful operating system that supports
more than one user at a time.
f. Software which is developed to help the user to perform specific tasks is called
application software.
g. OS is readymade, error free, advance and standard software for general works.
h. Open source refers to any program whose source code is made available for use
or modification as per users the requirement.
i. A windows desktop is the first display screen which appears when you loaded an
operating system.
j. Recycle bin is used to organizing and keeping track of files and folders.
4. Write appropriate technical terms for the followings.
a. The software that are used to manage the OS with the co-ordination of computer
hardware system and their resources.
b. A computer system that helps to control and coordinate overall activities of the
computer system.
c. An operating system that allows a single user to perform just one task at a time.
d. The small programs, which provide additional capabilities to the computer system.
e. Antivirus software is a type of program designed and developed to protect
computers from malware.
f. A software program that enables a specific hardware device to work with a
computer's operating system.
g. It is a default web browser application which is used to search for and browse
internet content, web sites, etc.
h. The programs are written mostly in high level languages like Java, C++, and
Python etc.
i. A machine dependent program that runs on a personal computer device such as a
desktop, laptop and personal workstations.
j. These applications are also known as mobile apps that are the software programs
developed for mobile devices such as smartphones and tablets.

New Gateway to Computer Science Book -9


71
5. Write the full form of the followings.
GUI , CLI, OS, PDA
6. Match the following.
Windows OS Language translator
Compiler Operating System
Antivirus Desktop icon
Recycle bin Application program
MS-Word Utility software
7. Answer the following questions.
a. What is a computer software? Write its tasks.
b. Define system software with its types.
c. What is an operating system? Name any three popular operating systems.
d. What are the major functions of an operating system?
e. What are the types of operating system? Define each in one sentence.
f. What are utility programs? Write its functions.
g. Name any two utility programs and define them.
h. What is a device driver? For what it is required?
i. Define application software with examples.
j. What are the types of application softwares? Define them in short.
k. Name the items available in windows desktop and explain the functions of any
three icons.
l. What is a windows dialogue box? What are the types of the windows dialogue
box?
m. Name any three mouse pointers and write their activities.
n. What do you mean by file and folder management? Why is it important in computer
system.
o. What is a language processor? Write down the types of the language processor.
p. Write down the differences between a compiler and an interpreter.
q. What is an open source software? What are the advantages of using an open source
software.
r. Define desktop application and web application.
s. Define mobile apps and hybrid apps.
Project Work
Take a short interview with your parents and relatives and prepare a field report about
what type of mobile phone or laptops or other devices they are using, what types of OS
the devices install. Also make a list of apps that they have used in their smart phones.

New Gateway to Computer Science Book -9


72
Working with Graphics

Unit

This unit covers the following topics:

Lesson 6: Introduction to Computer Graphics

New Gateway to Computer Science Book -9


73
Lesson
Introduction to Computer Graphics
6

Inside the Lesson

 Introduction to the graphics


 Uses of graphics software
 Different types of graphics format
 Working with photoshop CS6
 Starting photoshop
 Understanding photoshop tools
 Creating , opeaning and saving image
 understanding graphics format
 Working with image size and resolution
 Working with photoshop tools
 Changing the size of image
 Cropping the image
 Working with text tool

The computer is an information processing machine. It is a tool for storing and


manipulating data. There are many ways to communicate the processed information to
the user. The computer graphics is one of the most effective and commonly used ways
to communicate the processed information to the user. It displays the information in the
form of graphics objects such as pictures, charts, graphs and diagrams instead of simple
text. Thus, we can say that computer graphics makes data possible to express in pictorial
form. The picture or graphic object may be an engineering drawing, business graph,
architectural structures, a single frame from an animated movie, or a machine parts. The
term “computer graphics” refers to anything involved in the creation or manipulation of
images on computer, including animated images.
Computer graphics is an art of drawing pictures on computer screens with the help of
various computer graphics programs. It involves computations, creation, and manipulation
of data. In other words, we can say that computer graphics is a rendering tool for the
generation and manipulation of images.

New Gateway to Computer Science Book -9


74
Uses of Graphics Software
Let’s Review
Graphic designing software is used by Some abbreviations:
graphic designers to create images in
JPEG (or JPG) - Joint Photographic
different ways to edit images, to create
video, audio, etc.Graphic software helps Experts Group
users to give visual effects in all form. PNG - Portable Network Graphics
There are two types of graphic designing GIF - Graphics Interchange Format
softwares. One is pixel and another is vector TIFF - Tagged Image File
based graphic software. There are different
PSD - Photoshop Document
types of graphics softwares used by graphics
designer on the basis of requirements. Some PDF - Portable Document Format
of the graphics software are listed below. EPS - Encapsulated Postscript
 Diagram designing software AID - Adobe Illustrator Document
 Photoshop INDD - Adobe Indesign Document
 Web designing software RAW - Raw Image Formats
 Image viewer and management software
 InDesign

Different Graphics Format

There are various types of graphics file formats. Each type stores graphics data in a
different way. Raster, vector and metafile formats are most commonly used file formats.
Let’s discus some major file formats.

Raster Graphics (Bitmap Graphics) Format


Bitmap graphics are also called raster files; that contain an exact pixel-by-pixel map of
an image. Bitmap formats are used to store bitmap data. Files of this type are particularly
well-suited for the storage of real-world images such as photographs and video images.
A rendering application can subsequently reconstruct this image on the display surface of
an output device. Microsoft BMP, PCX, TIFF, and TGA are examples of commonly used
bitmap formats.

Vector Graphics Format


Vector graphics file formats are particularly useful for storing line-based elements, such
as lines and polygons, or those that can be decomposed into simple geometric objects,
such as text. Vector files contain mathematical descriptions of image elements, rather than

New Gateway to Computer Science Book -9


75
pixel values. A rendering application uses these mathematical descriptions of graphical
shapes to construct a final image. In general, vector files are structurally simpler than
most bitmap files and are typically organized as data streams.

Metafile Graphics Format


Metafiles can contain both bitmap and vector data in a single file. The simplest metafiles
resemble vector format files that may be used to define vector data elements, but they may
also store a bitmap representation of an image. Metafiles are frequently used to transport
bitmap or vector data between hardware platforms, or to move image data between
software platforms. WPG, Macintosh PICT, and CGM are examples of commonly used
metafile formats.

Let’s Review
 The computer graphics is one of the most effective and commonly used ways to
communicate the processed information to the user.
 Computer graphics is an art of drawing pictures on computer screens with the
help of various computer graphics programs.
 Graphic designing software are used by graphic designers to create images in
different ways, to edit images, to create video, audio, images, etc.
 There are various different types of graphics file formats. Each type stores
graphics data in a different way.
 Bitmap graphics are also called raster files.
 Vector graphics file formats are particularly useful for storing line-based
elements, such as lines and polygons.
 Metafiles can contain both bitmap and vector data in a single file.

Working with Photoshop CC

Adobe Photoshop is an image editing software which allows users to create


and edit raster images in multiple layers. It has a various editing tools.
It was created by Thomas and John Knoll in 1988 AD. The default file extension for
a work in progress is called a PSD (Photoshop Document). A PSD file has a
maximum of 30,000 pixels for width and height and a file length limit of 2
gigabytes. Another type of Photoshop file is Photoshop Big (.PSB ), it is a large document
format and extends the PSD’s maximum height and width limit to 300,000 pixels and

New Gateway to Computer Science Book -9


76
also extends the length limit to around 4 Exabyte. The first version of Photoshop 1.0 was
released on February 19, 1990 AD. Here we are going to discuss about one of the best
versions of Photoshop CC.

Starting Photoshop in Windows 8


 Press the windows key and type Adobe Photoshop CC in search box and press
enter key to open the Photoshop CC.

 The Photoshop windows will display as below.

New Gateway to Computer Science Book -9


77
Tools of Photoshop
Photoshop has various tools for the picture creating and
editing. The tool always appears at the left most side of the
window. Let’s identify the tools of Photoshop.
1: Rectangular marquee tool: Make the image square or
rectangular
2: Move tool: Move the picture or image.
3: Lasso tool: Free selection with the help of mouse
4: Quick selection tool: Quick selection from the brush tool
5: Crop tool: Crop the image in required size.
6: Eye dropper tool: Select the colour from the image.
7: Spot healing brush tool: Remove the spot from the image.
8: Brush tool: Paint the image.
9: Clone stamp tool: Make clone and duplicate in the
selected area.
10: History brush tool: Apply synapse paint.
11: Eraser tool: Remove any part of the image.
12: Gradient tool: Fill gradient from one colour to another colour.
13: Blur tool: Make image dim by deducting the pixel contrast.
14: Dodge tool: Bring lightness on the image.
15: Pen tool: Edit point location and draw any type of shape.
16: Type / Text tool: Type the text, symbols or characters.
17: Path selection tool: Select an export of any part of image to other application.
18: Rectangle tool: Draw rectangle shape.
19: Hand tool: Move the image to the desired area.
20: Zoom tool:View the image in larger or smaller size.
21: Toggle tool: Set the opposite colour.
22: Foreground colour tool: To apply the foreground colour
23: Background colour tool: To apply the background colour

New Gateway to Computer Science Book -9


78
Creating a New Image
 Click on File menu and select New… from the
options.
 In the New dialogue box, Type a Name of the
image.
 Change the document size (width, Height,
Resolution, Colour Mode, etc.) if required as
shown in the given windows.

 Finally, click on OK to create a new working screen.


Opening a N0ew Image
 Click on File menu and select Open…
from the options.
 The open dialogue box will appear.
 Select the location from Look in: where
you have saved your images.

 Choose the required image and click on Open button to display the image.

New Gateway to Computer Science Book -9


79
Saving a Iew Image
 Click on File menu and select Save from the options.
 A save as dialogue box will appear as below.

 Select the location where you want to store your picture from Save in: options.
 Type required file name in File name box and select the required file Format
that you want.
 Finally click on Save button to save your image.

Understanding Files (graphics) Formats


While Photoshop can be used to create files for all sorts of media, the three most common
uses for image files are web, print, and video production. Following is a list of the most
common formats and how they are used.

New Gateway to Computer Science Book -9


80
Web Production Formats
JPEG This is a common format for digital camera photographs and the
(Joint Photographic primary format for full-colour images shared on the web. JPEG
Experts Group) images use lossy compression, which degrades the quality of
images and discards colour and pixel data.
GIF (Graphic GIF files are used to display limited colour graphics on the Web.
Interchange It is a compressed format that reduces the file size of images, but
Format) it only supports a limited number of colours.
PNG PNG (Portable Network Graphics) is a newer image format that
(Portable provides a combination of many features of both JPEG and GIF.
Network The PNG format allows for use of millions of colorus as well as
Graphics) providing the ability to have transparent backgrounds.

Print Production Formats


PSD The Photoshop Format (PSD) is the default file format. Files saved
(Photoshop as PSD can be used in other Adobe applications, such as Adobe
document) Illustrator, Adobe InDesign, Adobe Premiere, and others.
TIFF or TIF TIFF is a common bitmap image format. Most image-editing software
(Tagged Image and page-layout applications support TIFF images up to 2GB in file
File Format) size. TIFF supports most colour modes and can save images with
alpha channels.
EPS EPS files may contain both vector and bitmap data. Because it is
(Encapsulated a common file format used in print production. Some software
PostScript) applications cannot preview the high-resolution information
contained within an EPS file, so Photoshop allows you to save a
special preview file for use with these programs, using either the EPS
TIFF or EPS PICT option.

Photoshop Photoshop PDF files are extremely versatile, as they may contain
PDF bitmap and vector data. Images saved in the Photoshop PDF format
can maintain the editing capabilities of most Photoshop features,
such as vector objects, text, and layers, and most colour spaces are
supported. These files can be opened by users with the free Adobe
Reader software.

New Gateway to Computer Science Book -9


81
Understanding Image Size and Resolution of Graphics

Pixel: A pixel is the smallest unit of a digital image or graphic that can be
displayed and represented on a digital display device. A pixel is also known as a picture
element. It is the basic logical unit in digital graphics. Pixels are combined to form a
complete image, video, text or any visible thing on a computer display. It is represented
by a dot or square on a computer monitor display screen. Depending on the graphics card
and display monitor, the quantity, size and colour combination of pixels vary and are
measured in terms of display resolution.
Resolution: Resolution is the sharpness and clarity of an image or picture. It is used to
measure the quality of monitors, printers, digital images and various other hardware and
software technologies. The resolution of monitor is measured by the number of pixels.
Printers also have a measure of resolution called DPI (dots per inch).

Different resolutions for common widescreen monitors

Monitor size Resolution


19-inch 1680 x 1050
21-inch 1920 x 1080
23-inch 1920 x 1080 to 2560 x 1440
27-inch 2560 x 1440 to 3840 x 2160

Different resolutions for common ultra wide resolutions monitors

Monitor size Resolution


25-inch 2560 x 1080
29-inch 2560 x 1080
34-inch 2560 x 1080 to 3440 x 1440,
Resampling: Resampling is the process of changing the amount of image data as you
change either the pixel dimensions or the resolution of an image. When you decrease
the number of pixels, information is deleted from the image. When you resample up or
increase the number of pixels, new pixels are added.
Resizing: When you resize an image and do not resample it, you change the image’s size
without changing the amount of data in that image. Resizing without resampling changes
the image’s physical size without changing the pixel dimensions in the image. No data is
added to or removed from the image.

New Gateway to Computer Science Book -9


82
File size: The file size of an image is the digital size of the image file, measured in
kilobytes (K), megabytes (MB), or gigabytes (GB). File size is proportional to the pixel
dimensions of the image. Images with more pixels may produce more detail at a given
printed size, but they require more disk space to store and may be slower to edit and print.

Let’s Review
 Adobe Photoshop is an image editing software which allows the users to create
and edit raster images in multiple layers.
 Photoshop has various tools for creating and editing picture.
 JPEG is a common format for digital camera photographs and the primary format
for full-colour images shared on the web.
 GIF files are used to display limited colour graphics on the Web.
 The PNG format allows for use of millions of colorus as well as provides the
ability to have transparent backgrounds.
 The Photoshop format (PSD) is the default file format.
 TIFF supports most colour modes and can save images with alpha channels.
 Photoshop PDF files can be opened by users with the free Adobe Reader software.
 A pixel is the smallest unit of a digital image or graphic that can be displayed and
represented on a digital display device.
 A pixel is also known as a picture element.
 Resolution is the sharpness and clarity of an image or picture.
 Resampling is the process of changing the amount of image data as you change
either the pixel dimensions or the resolution of an image.

Pixel Dimensions and Printed Image Resolution

Pixel dimensions measure the total number


of pixels along an image’s width and height.
Resolution is the fineness of detail in a
bitmap image and is measured in pixels per
inch (ppi). The more pixels per inch, the
greater the resolution. Generally, an image
with a higher resolution produces a better
printed image quality.
Unless an image is resampled the amount of
image data remains constant as you change
either the print dimensions or resolution. Same image at 72 ppi and 300 ppi;
For example, if you change the resolution of inset zoom 200%

New Gateway to Computer Science Book -9


83
an image, its width and height change accordingly to maintain the same amount of image
data.
In Photoshop, you can see the relationship between image size and resolution with the
help of the given steps.
 In the Image Size dialog box choose Image and move on Image Size options.
 Deselect Resample Image (because you don’t want to change the amount of image
data in your photo).
 Change width, height, or resolution as required.
 As you change one value, the other two values change accordingly with the Resample
Image option selected, you can change the resolution, width, and height of the image
as required.

In the above dialouge box, A. Original dimensions and resolution B. Decreasing the
resolution without changing pixel dimensions (no resampling) C. Decreasing the
resolution at same document size decreases pixel dimensions (resampling).

New Gateway to Computer Science Book -9


84
Understanding Photoshop Tools

When we start Photoshop, we can see the tools panel. The tools panel appears at the left of
the screen. Some tools in the tools panel have options that appear in the context-sensitive
options bar. You can expand some tools to show hidden tools. A small triangle at the lower
right of the tool icon signals the presence of hidden tools.

Move and selection tools


Move Tool * ( V )
The Move Tool is used to move layers, selections and guides within a Photoshop
document. Enable "Auto-Select" to automatically select the layer or group you
click on.
Artboard Tool ( V )
The Artboard Tool allows you to easily design multiple web or UX (User
Experience) layouts for different devices or screen sizes.
Rectangular Marquee Tool * ( M )
The Rectangular Marquee Tool draws rectangular selection outlines. Press and
hold Shift as you drag to draw a square selection.
Elliptical Marquee Tool ( M )
The Elliptical Marquee Tool draws elliptical selection outlines. Press and hold
Shift to draw a selection in a perfect circle.
Single Row Marquee Tool
The Single Row Marquee Tool in Photoshop selects a single row of pixels in the
image from left to right.
Single Column Marquee Tool
Single Column Marquee Tool is used to select a single column of pixels from
top to bottom.
Lasso Tool * ( L )
With the Lasso Tool, you can draw a freeform selection outline around an object.

New Gateway to Computer Science Book -9


85
Polygonal Lasso Tool ( L )
You can click around an object with the Polygonal Lasso Tool to surround it
with a polygonal, straight-edged selection outline.
Magnetic Lasso Tool ( L )
The Magnetic Lasso Tool snaps the selection outline to the edges of the object
as you move your mouse cursor around it.
Quick Selection Tool * ( W )
The Quick Selection Tool lets you easily select an object simply by painting
over it with a brush.
Magic Wand Tool ( W )
The Magic Wand Tool selects areas of similar color with a single click. The
"Tolerance" value in the Options Bar sets the range of colors that will be selected.

Crop And Slice Tools


Crop Tool * ( C )
You can use the Crop Tool in Photoshop to crop an image and remove unwanted
areas.
Perspective Crop Tool ( C )
You can use the Perspective Crop Tool to crop an image and fix common
distortion or perspective problems.
Slice Tool ( C )
The Slice Tool divides an image or layout into smaller sections which can be
exported and optimized separately.
Slice Select Tool ( C )
The Slice Select Tool is used to select individual slices created with the Slice
Tool.

Measurement Tools
Eyedropper Tool * ( I )
The Eyedropper Tool samples colours in an image. Increase "Sample Size" in
the Options Bar for a better representation of the sampled area's colour.

New Gateway to Computer Science Book -9


86
3D Material Eyedropper Tool ( I )
You can use the 3D Material Eyedropper Tool to sample material from a 3D
model in Photoshop.
Colour Sampler Tool ( I )
The Color Sampler Tool displays colour values for the selected area in an image.
Ruler Tool ( I )
The Ruler Tool measures distances, locations and angles of the image.
Note Tool ( I )
The Note Tool allows you to attach text-based notes to your Photoshop document,
either for yourself or for others working on the same project.
Count Tool ( I )
You can use the Count Tool to manually count the number of objects in an
image, or to have Photoshop automatically count multiple selected areas in the
image.

Retouching And Painting Tools


Spot Healing Brush Tool * ( J )
The Spot Healing Brush Tool in Photoshop quickly removes blemishes and
other minor problem areas in an image. Use a brush size slightly larger than the
blemish for the best result.
Healing Brush Tool ( J )
The Healing Brush Tool lets you repair larger problem areas in an image by
painting over them.
Patch Tool ( J )
With the Patch Tool, you can draw a freeform selection outline around a
problem area. Then repair it by dragging the selection outline over an area of
good texture.
Content-Aware Move Tool ( J )
You can use the Content-Aware Move Tool to select and move the part of an
image to a different area.

New Gateway to Computer Science Book -9


87
Red Eye Tool ( J )
The Red Eye Tool removes common red eye problems in a photo resulting from
camera flash.
Brush Tool * ( B )
The Brush Tool is Photoshop's primary painting tool. You can use it to paint
brush strokes on a layer or on a layer mask.
Pencil Tool ( B )
The Pencil Tool is another tool of Photoshop's painting. But while the Brush
Tool can paint soft-edge brush strokes, the Pencil Tool always paints with hard
edges.
Colour Replacement Tool ( B )
You can use the Colour Replacement Tool in Photoshop to easily replace the
colour of an object with a different colour.
Mixer Brush Tool ( B )
The Mixer Brush Tool can simulate elements of real painting such as mixing
and combining colours, and paint wetness.
Clone Stamp Tool * ( S )
The Clone Stamp Tool is the most basic tool of Photoshop. It samples pixels
from one area of the image and paints them over pixels in another area.
Pattern Stamp Tool ( S )
You can use the Pattern Stamp Tool to paint a pattern over the image.
History Brush Tool * ( Y )
The History Brush Tool paints a snapshot from an earlier step into the current
version of the image.
Art History Brush Tool ( Y )
The Art History Brush Tool also paints a snapshot from an earlier history state
into the image, but does so using stylized brush strokes.
Eraser Tool * ( E )
The Eraser Tool permanently erases pixels on a layer. It can also be used to
paint in a previous history state.

New Gateway to Computer Science Book -9


88
Background Eraser Tool ( E )
The Background Eraser Tool erases areas of similar colour in an image by
painting over them.
Magic Eraser Tool ( E )
The Magic Eraser Tool is similar to the Magic Wand Tool. It selects areas of
similar colour with a single click. But the Magic Eraser Tool then permanently
deletes those areas.
Gradient Tool * ( G )
Gradient Tool is used to draw gradual blends between multiple colours. The
Gradient Editor lets you create and customize your own gradients.
Paint Bucket Tool ( G )
The Paint Bucket Tool fills an area of similar colour with your Foreground
colour or a pattern.
3D Material Drop Tool ( G )
This tool is used in 3D modelling, the 3D Material Drop Tool lets you sample a
material from one area and then drop it into another area of your model, mesh
or 3D layer.
Blur Tool *
The Blur Tool blurs and softens areas you paint over with the tool.
Sharpen Tool
The Sharpen Tool sharpens areas you paint over.
Smudge Tool
The Smudge Tool smudges and smears the area you paint over. It can also be
used to create a finger painting effect.
Dodge Tool * ( O )
You can use Dodge Tool to Paint over an areas in the image and lighten it.
Burn Tool ( O )
The Burn Tool will darken the areas you paint over.

New Gateway to Computer Science Book -9


89
Sponge Tool ( O )

Paint over areas with the Sponge Tool to increase or decrease colour saturation.

Drawing And Type Tools


Pen Tool * ( P )
The Pen Tool allows you to draw extremely precise paths, vector shapes or
selections.
Freeform Pen Tool ( P )
The Freeform Pen Tool allows you to draw freehand paths or shapes. Anchor
points are automatically added to the path as you draw.
Add Anchor Point Tool
You can use the Add Anchor Point Tool to add additional anchor points along
a path.
Horizontal Type Tool * ( T )
It is a Type Tool in Photoshop, you can use the Horizontal Type Tool to add
standard type to your document.
Vertical Type Tool ( T )
The Vertical Type Tool adds the text vertically from top to bottom.
Vertical Type Mask Tool ( T )
Rather than adding editable text to your document, the Vertical Type Mask Tool
creates a selection outline in the shape of vertical type.
Horizontal Type Mask Tool ( T )
Like the Vertical Mask Type Tool, the Horizontal Type Mask Tool creates a
selection outline in the shape of type. However, the type is added horizontally
rather than vertically.
Path Selection Tool * ( A )
You can use the Path Selection Tool to select and move to an entire path at once.
Direct Selection Tool ( A )
You can use the Direct Selection Tool to select and move to an individual path
segment, anchor point or direction handle.

New Gateway to Computer Science Book -9


90
Rectangle Tool * ( U )
The Rectangle Tool draws rectangular vector shapes, paths or pixel shapes.
Press and hold Shift as you drag to force the shape into a perfect square.
Rounded Rectangle Tool ( U )
The Rounded Rectangle Tool is similar to the standard Rectangle Tool but
draws the shapes with rounded corners. Press and hold Shift to draw a square
with rounded corners.
Ellipse Tool ( U )
The Ellipse Tool draws elliptical vector shapes, paths or pixel shapes. Press and
hold Shift as you drag to draw a perfect circle.
Polygon Tool ( U )
The Polygon Tool draws polygonal, straight-edged vector shapes, paths or pixel
shapes. Use the "Sides" option in the Options Bar to set the number of sides.
Line Tool ( U )
The Line Tool draws straight lines, either as shapes or paths. The "Weight"
option in the Options Bar controls the width of the line.
Custom Shape Tool ( U )
Custom Shape Tool helps to select and draw custom shapes.

Navigation Tools
Hand Tool * ( H )
The Hand Tool helps to click and drag an image around on the screen to
view different areas when zoomed in.
Rotate View Tool ( R )
You can use the Rotate View Tool in Photoshop to rotate the canvas, so you can
view and edit the image from different angles.
Zoom Tool * ( Z )
You can click on the image with the Zoom Tool to zoom in on a specific area.
Press and hold Alt and click the Zoom Tool to zoom out.

New Gateway to Computer Science Book -9


91
Let’s Review
 Pixel dimensions measure the total number of pixels along an image’s width and
height.
 The Move Tool is used to move layers, selections and guides within a Photoshop
document.
 The Single Row Marquee Tool in Photoshop selects a single row of pixels in the
image from left to right.
 The Slice Tool divides an image or layout into smaller sections which can be
exported and optimized separately.
 The Colour Sampler Tool displays colour values for the selected area in an image.
 The Note Tool allows you to attach text-based notes to your Photoshop document.
 The Red Eye Tool removes common red eye problems in a photo resulting from
camera flash.
 The Background Eraser Tool erases areas of similar colour in an image by painting
over them.
 The Smudge Tool in Photoshop smudges and smears the areas you paint over.
 The Freeform Pen Tool allows you to draw freehand paths or shapes.
 The Polygon Tool draws polygonal, straight-edged vector shapes, paths or pixel
shapes.

Working with Photoshop Tools

Lasso tool
This tool is used for free selection on the image as required.
 Open the required image.
 Click on the lasso tool from the tool box.
 Click on the picture and drag the mouse to select the
required area.
Eraser Tool
Eraser tool is used to remove certain area or part of the
image.
 Open the required image.
 Click on the eraser tool from the tool box.
 Click and drag the mouse to erase the required portion of
the image.

New Gateway to Computer Science Book -9


92
Gradient Tool
This tool is used to fill colours horizontally. We can use this tool to create banners.
 Open the required image.
 Select the part of the image.
 Click on the gradient tool from the tool box.
 Drag the mouse across the image.
 Move towards left or right or as your desired location to
apply it.

Blur Tool
You can also blur portions of your image to emphasize and focus
on a particular element. It is used to reduce the extra pixel contrast and make the image
dim.
 Open the required image.
 Click on the blur tool from the tool box.
 Choose the required brush from the present picker.
 Drag the mouse pointer over the part of the picture and
release the mouse.

Zoom Tool
This tool is used to enlarge the size of the image. This tool is
like a magnifying glass.
 Open the required image.
 Click on the zoom tool from the tool box.
 Press CTRL + (+) for zoom in [Larger View] and CTRL + (-) for zoom out
[smaller view] of the image.

New Gateway to Computer Science Book -9


93
Hand Tool
This tool is used to move the image horizontally or vertically on
the screen.
 Open the required image.
 Click on the hand tool from the tool box.
 Click on image then drag it as required.
 Drag the mouse pointer over the part of the picture and
release the mouse.
Clone Stamp Tool
Clone stamp tool allows you to copy one area of image onto another area of image.
 Open an image.
 Click on clone tool from the tool box.
 Keep on pressing ALT key and click on the area of the
image.
 Click on the new area of the image to apply the effect.
Dodge Tool
This tool is used to apply more lightness on the image. We can use the given steps to apply
this.
 Open the image in which you want to apply the
effects.
 Click on the Dodge tool from the tool box.
 Click on image then drag it as required
Spot Healing Brush Tool
The spot healing brush is the default healing tool in
Photoshop. It can be used to clone areas from an image and blend the pixels from the
sampled area seamlessly with the target area.

 Select the Spot Healing Brush tool from the toolbox.


 Choose a brush size from the option bar.
 Choose blending mode from the mode menu.
 Choose Replace to preserve noise, film grain and texture at the edges of the
brush stroke.
 Click on the area where you want to fix, or click and drag over a larger area.

New Gateway to Computer Science Book -9


94
Magic Wand Tool
This tool is used to select a larger area of image having similar colour, pixel and groups
together.
 Open the required image.

 Select the Magic Wand tool . (If the tool isn’t visible,
access it by holding down the Quick Selection tool .)
 Click on the area of an image to select.

Changing the Size of an Image


We can reduce the size of an image in Photoshop. To change
the image size in Adobe Photoshop let’s follow the given steps.
 Click on Image Size option from the Image menu.
 Activate the check-box Constrain Proportions to keep the
ratio of the image dimensions.
 Make sure that the check-box Resample Image is activated.
 Select the method of interpolation: Nearest Neighbour,
Bilinear or Bicubic.
 In the Pixel Dimensions group select the unit measure and
enter new values for the parameters Width and Height as
given below.

 Finally click on OK button to apply the image size.

New Gateway to Computer Science Book -9


95
Changing Image Resolution
 Click on image menu and choose
Image Size.(Resolution in this dialogue
box means the number of image pixels
that will be assigned to each inch when the
image is printed.)
 Leave width and height set to inches for
printing.
 Deselect Resample to preserve the original
number of image pixels.
 In the Resolution field, set the number of pixels per inch to 300 for printing.
This changes the number of inches in the width and height fields.
 Click OK.

Changing Canvas Size


 Click on Image menu and select Canvas Size
option.
 To add a canvas, enter the amount of width and
height to add. Measure width and height in pixels
for online use or in inches for print.
 Select Relative, and then select an anchor point
in the canvas diagram. The arrows point to the
sides where the canvas will be added.
 Finally click OK to apply.

Cropping the Image


 Open an image in which you want to apply the effects.
 Select the Crop tool in the Tools panel. A crop border
appears.
 Drag any edge or corner to adjust the size and shape of
the crop border.
 Drag inside the crop border to place the image inside
the crop border.
 Drag outside a corner of the crop border to rotate or straighten.
 Click the check mark in the options bar or press Enter to complete the crop.

New Gateway to Computer Science Book -9


96
Working with Text Tool
The type tool allows you to add text to your file. You can use text on a variety of projects,
such as adding it to your images to create a poster, card, or invitation. You can also
customize the text as required.

Using Type Tool


 Select the Type tool from the Tools panel. You can also press the
letter T key on your keyboard to access the Type tool at any time.
 In the Control panel near the top of the screen, choose the desired
font and text size.

 Click the Text Colour picker, then choose the desired colour from the dialog box.

 Click and drag anywhere in the document window to create a text box.

New Gateway to Computer Science Book -9


97
 A new text layer will be added to your document. You can start typing to add
text to the layer.

If you want to add a lot of texts to your document, you can work with multiple text layers
which will give you more control over the appearance of your text.

Let’s Review
 Cropping the picture is a way of removing portions of a photo or image to create
focus or strengthen the composition.
 Lasso tool is used for free selection on the image as required.
 Eraser tool is used to remove certain areas or parts of the image.
 Gradient tool is used to fill colours horizontally. We can use this tool to create
banners.
 You can also blur portions of your image to emphasize and focus on a particular
element.
 Zoom tool is used to enlarge the size of the image.
 Hand tool is used to move the image horizontally or vertically on the screen.
 We can use text tool to type the text, symbols, characters and sentence on selected
area.
 Clone stamp tool allows you to copy one area of image onto another area of
image.
 Dodge tool is used to apply more lightness on the image.
 The spot healing brush tool can be used to clone areas from an image and
blend the pixels from the sampled area seamlessly with the target area.
 Magic Wand tool is used to select a larger area of image having similar colour,
pixel and groups together.
 The type tool allows you to add text to your image.

New Gateway to Computer Science Book -9


98
Expand your knowledge
 In 1950 AD Ben Laposky created the first graphic images, an oscilloscope,
generated by the electronic analog machine.
 The Whirlwind computer at the Massachusetts Institute of Technology (MIT)
has the first computer with a video display or real time data.
 The first light pen was created around 1955 AD. as a part of Whirlwind project
at MIT.
 The first vedio game, space war, ran using an oscilloscope as a display.
 The A pple II was the graphics personal computer.

Assignment
1. Select the correct answer from the given options.
a. Which of the following is the example of bitmap image format?
i. BMP ii. PCX iii. TIFF iv. All of them
b. Which file can contain both bitmap and vector data in a single file?
i. Metafile ii. Raster iii. Vector iv. None of them
c. What is the default file extension of Photoshop document?
i. .PDS ii. .PSD iii. .PMD iv. .PMK
d. Which Photoshop tool brings lightness on the image?
i. Pen tool ii. Eraser tool iii. Dodge tool iv. Toggle tool
e. Which of the following is the smallest unit of a digital graphics that can be
displayed and represented on a digital display device?
i. Pixel ii. Resolution iii. DPI iv. None of them
f. What is the resolution of 19 inch common widescreen monitor?
i. 920 X 1080 ii. 1680 X 1050 iii. 2560 X 1440 iv. 1920 X 1080
g. Which of the tools is used to crop an image and remove unwanted areas?
i. Slice tool ii. Polygonal tool iii. Magic wand tool iv. Crop tool
h. Which tool is used to click and drag an image around on the screen to view
different areas when zoomed in?
i. Zoom tool ii. Hand tool iii. Line tool iv. Rotate view tool
i. Which tool is used to remove unwanted areas of an image?
i. Crop tool ii. Clone stamp tool iii. Eraser tool iv. Blur tool
j. Which of the following is used to insert text in the image?
i. Clone stamp tool ii. Magic wand tool iii. Line tool iv. Type tool

New Gateway to Computer Science Book -9


99
2. Fill in the blanks with suitable words.
a. ………………….. is an art of drawing pictures on computer screens with the help
of various computer graphics programs.
b. Bitmap graphics are also called …………..files; essentially contain an exact
pixel-by-pixel map of an image.
c. …………………. is a common format for digital camera photographs and the
primary format for full-colour images shared on the web.
d. …………….. files are used to display limited (indexed) colour graphics on the
Web.
e. …………… supports most colour modes and can save images with alpha channels.
f. Photoshop PDF files can even be opened by users with the free ……………….
software.
g. A pixel is also known as a ……………...
h. …………….. is the sharpness and clarity of an image or picture.
i. The …………….tool removes common red eye problems in a photo resulting
from camera flash.
j. The ……………..divides an image or layout into smaller sections (slices) which
can be exported and optimized separately.
3. State whether the given statements are true or false.
a. Vector graphics files format are particularly useful for storing line-based elements.
b. Metafiles can contain both bitmap and vector data in a single file.
c. The BMP format allows for use of millions of colorus as well as providing the
ability to have transparent backgrounds.
d. The Photoshop format (PSD) is the default file format.
e. A pixel is the smallest unit of a digital image or graphic that can be displayed and
represented on a digital display device.
f. The Move Tool is used to move layers, selections and guides within a Photoshop
document.
g. The Smudge Tool in Photoshop smudges and smears the areas you paint over.
h. Type tool is used to apply more lightness on the image.
i. Eraser tool is used to remove certain areas or parts of the image.
j. Select tool is used to enlarge the size of the image.
4. Write appropriate technical terms for the followings.
a. It is one of the most effective and commonly used ways to communicate the
processed information to the user.
b. It measures the total number of pixels along an image’s width and height.
c. This tool in Photoshop selects a single row of pixels in the image from left to
right.
d. The tool displays the colour values for the selected (sampled) area in an image.

New Gateway to Computer Science Book -9


100
e. The tool that is used to fill colours horizontally.
f. The tool which is used for free selection on the image as required.
g. The tool that allows you to copy one area of image onto another area of an image.
h. The tool which is used to select a larger area of image having similar colour, pixel
and groups together.
i. The tool that can be used to clone areas from an image and blend the pixels from
the sampled area seamlessly with the target area.
j. The tool that allows you to attach text-based notes to your Photoshop document.
5. Write the full form of the followings.
JPEG, PNG, GIF, TIFF, PSD, PDF, EPS, INDD, RAW,
6. Answer the following questions.
a. What is graphics software? Name some popular graphics softwares.
b. What are the various uses of graphics software?
c. What are the types of graphics format? Define them in short.
d. List out any ten tools that are used in Photoshop.
e. Write down the steps to create a new image canvas.
f. Explain any two popular graphics formats.
g. What is pixel and resolution?
h. Define resampling and resizing.
i. Name any five tools belonging to the move and selection tools.
j. Name any five tools belonging to the drawing and type tools.
k. Write down the uses of the given tools.
1.Gradient tool 2. Blur tool 3. Red eye tool 4. Clone stamp tool
5. Dodge tool 6. Magic eraser tool 7. Line tool 8. Rotate view tool
9. Zoom tool 10. Slice select tool 11. Artboard tool 12. Hand tool
Practical Work
Open Photoshop program and do the given activities.
Task 1: Insert an image, change its size and resolution and save it under your name.
Task 2: Insert an image of an animal and crop the body parts and display only the head
parts.
Task 3: Insert an image and use blur tool on the image and save it.
Task 4: Insert an image and use an eraser tool to erase its some parts.
Task 5: Create a new canvas with a gradient tool.
Task 6: Insert your school picture in Photoshop program, use the type tool and insert
your school name and location. Save the image under your school name.
Task 7: Insert an image and use hand tool, zoom tool, brush tool, pencil tool, clone
stamp tool, burn tool, sharpen tool and rectangle tool then observe the effect
of each of them.

New Gateway to Computer Science Book -9


101
Internet and Web
Technology
Unit

This unit covers the following topics:

Lesson 7 :An introduction to Internet Technology

Lesson 8: Working with HTML

Lesson 9: Working with CSS

New Gateway to Computer Science Book -9


102
Lesson An Introduction to Internet
7 Technology

Inside the Lesson

 Introduction to web browser, search engine, web server, web site, web page,
uploading and downloading, URL, DNS, home page,
 Components of WWW
 Internet of things
 Cloud computing

The Internet is a network of networks that allows computers on different kind


networks to interact with each other. The internet technology refers to the devices,
software, hardware and transmission protocols used to connect computers
together in order to receive or send data from one computer to another within a
small network. Internet can be defined as an information super highway, from
where we can access the information over the web. It is a world-wide global
system of interconnected computer networks. Internet uses the standard Internet Protocol
that is called Transmission Control Protocol (TCP/IP).
The networking of computer has its origin at the US Department of Defence
Advanced Research Projects Agency (DARPA). During 1970’s DARPA developed the
ARPANET as a Wide Area Network. In 1980’s many Internet applications like electronic
mail, newsgroup, file transfer facility and remote login were developed.

Components of WWW

World Wide Web is a large scale, online store of information. It is a system of creating,
organizing, and linking documents. The information stored on it as the collection of
documents that are interconneced with each other through the web links. The interconnected
documents may be located on one or more than one computer or worldwide.The WWW
uses the following components.

New Gateway to Computer Science Book -9


103
Web Browser
Browser is a software program that helps to present and
explore content on the World Wide Web. The process of
using browser to view information on the internet is known
as browsing or surfing. Web browser is also called an
Internet browser. It is also referred to as the user interface
of the web. With the help of browser we can visit websites
and do activities within them like login, view link from one
site to another, visit one page from another, print, send and receive email, among many
other activities. The most popular web browser software is Internet Explorer, Google’s
Chrome, Mozilla Firefox, Apple’s Safari, and Opera. There are two types of browser they
are graphical browser and text-based browser.
Graphical Browser: These types of browsers provide a graphical user interface where
the user can jump from one web page to another web page by clicking on the hyperlink on
a web page. Internet explorer, Chrome, Opera, Firefox, etc. are the examples of graphical
browsers.
Text Browser: These types of browsers are used on computers that do not support
graphics. The Lynx is the best example of text browser.

Search Engine
Search engines are used to search information and multiple resources on the
internet with the help of web browsers. Search engine is a service of internet
that allows the users to search the information and resources via the World Wide Web
(WWW). A user needs to enter the keywords or key phrases into a search engine and
receives a list of Web content results in the form of websites, images, videos or other data.
There are many different search engines available on the Internet, each with their own
abilities and features. The most popular and well-known search engine is Google. Other
popular search engines are AOL, Ask.com, Bing, and Yahoo.

Web Server
The main job of a web server is to display the website
content. Web server is a program that uses hypertext
transfer protocol to serve the files that form Web pages to
the users. Web server is a computer that runs websites. Web
server is a computer program that distributes web pages.
The basic objective of the web server is to store, process
and deliver web pages to the users. This intercommunication is
done using Hypertext Transfer Protocol (HTTP). These web pages are mostly static

New Gateway to Computer Science Book -9


104
content that includes HTML documents, images, style sheets, etc. Web server also
supports SMTP (Simple Mail transfer Protocol) and FTP (File Transfer Protocol) protocol
for emailing, file transfer and storage.

Let’s Review
 The Internet is a network of networks that allows computers on different kind
networks to interact with each other.
 The information stored on www is the collection of documents that are
interconnected with each other through the web links.
 The process of using browser to view information on the internet is known as
browsing or surfing.
 The default web browser may be different according the operating system that is
used.
 Search engine is a service of internet that allows the users to search the information
and resources through the World Wide Web (WWW).
 Web server is a computer that runs websites. Web server is a computer program
that distributes web pages.

Web Site
A Web site is a collection of World Wide Web (WWW)
files such as text, graphics, images, audio and videos.
The first website was built at CERN by Tim Berners-
Lee and launched on August 6, 1991.Web sites are
the virtual location on WWW, which has several
webpages and data files accessible through a browser.
Each website has its own unique web address which
can be viewed through an internet connection. To view a website, we must have web
browsers like Internet Explorer. You can open a website by entering the URL in the
address bar. For example, typing “https://www.shubharambhapublication.com” opens the
home page of Shubharambha Publication. If you don’t know the URL of the website you
want to visit, you can use a search engine to find the website on the Internet.
Web Page
A web page is a document commonly written in HTML (Hypertext Mark-up
Language) that is accessible through the Internet or other networks using an
Internet browser. A web page is accessed by entering a URL address and may contain text,
graphics, and hyperlinks to other web pages and files. The information page that you read
is an example of a web page.

New Gateway to Computer Science Book -9


105
Uploading and Downloading
Uploading is the process of sending web pages, images and files onto a web server.To
make a file visible to everyone on the internet, we have to upload it. Downloading is
the process of getting web pages, images and files from a web server.When users are
copying file to their computer, they are downloading it. Uploading something means to
send data from an individual user’s computer to another computer, network or website.
Downloading something means to transfer data from a website or network and saving it
on computers or mobile devices.

Uniform Resource Locator (URL)


Uniform Resource Locator is a special form of individual address of a certain resource on
the Internet. It can refer to the website, some particular document, or an image. The Internet
user just needs to insert this code into the location bar to find the website, document,
folder, or image. A URL is also a specific type of Uniform Resource Identifier (URI). Let’s
discuss the sections of URL for example http://www.shubharambhapublication.com.
 http:// :“http” means HyperText Transfer Protocol. It allows the browser to identify
what protocol it is going to utilize to retrieve data described in the domain.
 After the http is the colon (:) and 2 forward slashes (//) that segregate the
protocol from the remaining sections of the URL.
 www: www means World Wide Web. It is used to identify the content. This
section of the URL is optional.
 shubharambhapublication.com: It is the domain name for the website. The
latter part (.com) of the domain is called the domain suffix. It is used to classify
the category or location of the website. If the domain suffix “.com” that is commercial
website and if the domain is“.org” that is organizational website.

New Gateway to Computer Science Book -9


106
Home Page
A home page is the initial or main web page of a website or a browser. The initial page
of a website is sometimes called main page. A website may have multiple home pages,
although most of them have only one.
Domain Name Server (DNS)
DNS is an Internet service that translates domain names into IP addresses because domain
names are alphabetic and they are easier to remember. A DNS server is a type of name
server that manages, maintains and processes internet domain names and their associated
records. In other words, a DNS server is the primarycomponent that implements the
DNS protocol and provisions domain name resolution services to web hosts and clients on
an IP-based network. A DNS server stores a database of different domain names, network
names, Internet hosts, DNS records and other related data. The most basic function of a
DNS server is to translate a domain name into its respective IP address.
IoT (Internet of Things)
The internet of things, or IoT, is a system of interrelated computing devices, mechanical
and digital machines that are provided with unique identifiers and it has the ability to
transfer data over a network. The term Internet of Things generally refers to scenarios
where network connectivity and computing capability extends to generate, exchange and
consume data with minimal human intervention.
Cloud Computing
Cloud computing is the delivery of different services through the Internet. These
resources include tools and applications like data storage, servers, databases, networking,
and software. Using cloud computing, users are able to access software and applications
from anywhere. The computer programs are being hosted by an outside party and reside
in the cloud. This means that users do not have to worry about things such as storage
and power. Cloud computing can be both public and private. Public cloud services
provide their services over the Internet for a fee. Private cloud services only provide
services to a certain number of people. These services are a system of networks that
supply hosted services. There is also a hybrid option, which combines elements of both
the public and private services. Cloud computing is still a new service but is being used
by a number of different organizations. Cloud computing services provide users with a
series of functions including:
 Email
 Storage, backup, and data retrieval
 Creating and testing apps
 Analysing data
 Audio and video streaming
 Delivering software on demand

New Gateway to Computer Science Book -9


107
Cloud Storage
Cloud storage is a way to save data securely online, so it can be accessed anytime from
any location and easily shared with those who are providing permission. Cloud storage
also offers a way to back up data to facilitate recovery.

Let’s Review
 A web site is a collection of World Wide Web (WWW) files such as text, graphics,
images, audio and videos.
 Web page is accessed by entering a URL address and may contain text, graphics,
and hyperlinks to other web pages and files.
 A URL is also a specific type of Uniform Resource Identifier (URI).
 Uploading is the process of sending web pages, images and files onto a web
server.
 Downloading is the process of getting web pages, images and files from a web
server.
 A home page is the initial or main web page of a website or a browser.
 DNS is an Internet service that translates domain names into IP addresses
because domain names are alphabetic and they are easier to remember.
 Cloud computing is the delivery of different services through the Internet.

Expand your knowledge


 Mark Elliot Zuckerberg is a CEO of facebook company. He was born on May
14, 1984 AD.
 YouTube was created by three PayPal enployees Chad Hurley, Steve Chen and
Jawed Karim as a video-sharing website.
 The "www.youtube.com" was activated on Monday, Feb.14, 2005 AD.
 The first YouTube video, " Me at the zoo", was uploaded on April 23, 2005 AD.
 Viber, a instant messaging software was developed in December 2, 2010 AD.
 The Google company was officially lunched in 1988 AD. by Larry Page and
Sergey Brin.

New Gateway to Computer Science Book -9


108
Assignment
1. Select the correct answer from the given options.
a. Which of the following is a web browser?
i. Opera ii. Firefox iii. Chrome iv. All of the above
b. Which of the following is a search engine?
i. Google ii. Internet explorer iii. Opera iv. None of them
c. A software program that helps to present and explore content on the World Wide
Web.
i. Browser ii. Web site iii. Search engine iv. Home page
d. Which of the following is a service of internet that allows the users to search the
information and resources.
i. Search engine ii. Browser iii. E-Mail iv. Social media
e. Which of the following is the most basic function of a DNS server?
i. To translate a domain name into its respective IP address.
ii. To connect the internet
iii. To browse the web sites
iv. None of the above
2. Fill in the blanks with suitable words.
a. The Internet is a ………………… that allows computers on different kind
networks to interact with each other.
b. The process of using browser to view information on the internet is known as
browsing or ………….
c. ……………….. is a computer that runs websites. Web server is a computer
program that distributes web pages.
d. A Web site is the ollection of …………………… files such as text, graphics,
images, audio and videos.
e. A ………………… is also a specific type of Uniform Resource Identifier (URI).
f. ………… is the process of getting web pages, images and files from a web server.
g. DNS is an Internet service that translates domain names into …………………...
h. Cloud computing is the delivery of different services through the …………………

New Gateway to Computer Science Book -9


109
3. State whether the given statements are true or false.
a. The information stored on www is the collection of documents that are
interconnected with each other through the web links.
b. The default web browser may be different according the operating system that is
used.
c. Web browser is a service of internet that allows the users to search the information
and resources via the World Wide Web (WWW).
d. Web page is accessed by entering a URL address and may contain text, graphics,
and hyperlinks to other web pages and files.
e. Downloading is the process of sending web pages, images and files onto a web
server.
f. A file page is the initial or main web page of a website or a browser.
4. Write appropriate technical terms for the followings.
a. A software program that helps to present and explore content on the World Wide
Web.
b. It is a large scale, online store of information.
c. The browsers that provide a graphical user interface where the user can jump
from one web page to another web page by clicking on the hyperlink on a web
page.
d. A service of internet that allows the users to search the information and resources
via the World Wide Web (WWW).
e. The virtual location on WWW, which has several webpages and data files
accessible through a browser.
5. Write the full form of the followings.
TCP / IP , DNS , DARPA, ARPANET, FTP , HTTP, WWW, HTML, URL
6. Match the following.
Google.com Main page
Home page Web browser
Opera Collection of web pages
WWW Search engine

New Gateway to Computer Science Book -9


110
7. Answer the following questions.
a. What is internet? Write its uses.
b. List out the components of www.
c. What is a web browser? Write with examples.
d. Write down the types of web browser and define graphical browser.
e. What is a search engine? What is the use of search engine? Write with examples.
f. What is the use of web server? Define web site.
g. What do you mean by uploading and downloading?
h. Define URL and Home page.
i. Explain the domain name server.
j. What is cloud computing? Define cloud storage.
k. What are the services provided by the cloud computing?
Project Work
Search the given terms through Google search engine and prepare a shot note .
Uploading and Downloading, Cloud Storage, Mobile Computing

New Gateway to Computer Science Book -9


111
Lesson

8 Working with HTML

Inside the Lesson

 Introduction to HTML and its features


 Understanding tag and elements of HTML
 Creating and saving HTML document
 Structure of HTML
 Working with HTML tags

HTML stands for Hypertext Transfer protocol. Hypertext is text which contains links
to other text. It was first developed by Tim Berners-Lee in 1990 AD. It is used to create
electronic documents that are displayed on the World Wide Web. Every web page you
see on the Internet is written using one version of HTML code or another. HTML code
ensures the proper formatting of text and images so that internet browser displays them
as they are intended to look. Without HTML, a browser would not know how to display
text as elements, load images or other elements.

Features of HTML
 HTML is a document layout and hyperlink specification language.
 HTML tells the browser how to display the contents of a hypertext document.
 HTML is a language that supports multimedia and new page layout features even it
has its some limitations.
 HTML provides a small mark-up tag that helps to work with various font formatting
activities.
 HTML is a page-layout and hyperlink specification language.

HTML Tag

A tag is a coded HTML command that indicates how the part of web pages should
be displayed. HTML tags are the hidden keywords within a web page which
define how the web browser displays the content. Most of the HTML tags have

New Gateway to Computer Science Book -9


112
two parts, an opening and a closing part. For example, <html> is the opening tag
and </html> is the closing tag. The closing tag has the same text as the
opening tag, but has an additional forward-slash ( / ) character. Each HTML
file must have the essential tags for it to be valid, so that the web browsers can
understand it and display it correctly. The rest of the HTML file can contain as little or as
many tags as you want to display your content.

Elements of HTML

An HTML element is an individual component of the HTML document. It


represents semantics, or meaning. For example, the title element represents the title of the
document. Most HTML elements are written with a start tag and an end tag. The start tag
is called opening tag and the end tag is called closing tag.

HTML Tag Attributes

HTML tag attributes allow you to customise a tag, and are defined within the opening tag,
for example: <img src=”image1.jpg”> or <p align=”center”> ... </p>
Attributes are often assigned a value using the equals sign, such as border=”0” or
width= ”50%”, but there are some that only need to be declared in the tag like this:
<hr noshade>. Most attributes are optional for most tags, and are only used when
you want to change something about the default way a tag is displayed by the browser.
However, some tags such as the <img> tag has required attributes such as src and alt
which are needed in order for the browser to display the web page properly.

Creating and Saving the HTML File


 Open the computer system and open notepad text editor.
 Type some HTML tag as below.
<!DOCTYPE html>
<html>
<head>
<title> Sample HTML document </title>
</head>
<body>
<p> we are learning HTML! <p>
</body>
</html>

New Gateway to Computer Science Book -9


113
 Now save the file on your desktop or desired location with the extension as
"learing.html".
 Now you can open the file in a browser.
 Navigate to your file then double click on it.
 Browser will open your document.

Let’s Review
 HTML is used to create electronic documents that are displayed on the World
Wide Web.
 HTML tells the browser how to display the contents of a hypertext document.
 A tag is a coded HTML command that indicates how part of web pages should be
displayed.
 Each HTML file must have the essential tags for it to be valid, so that web
browsers can understand it and display it correctly.
 An HTML element is an individual component of the HTML document.
 HTML tag attributes allows you to customise a tag, and are defined within the
opening tag.

Structure of HTML

A basic HTML page is a document that typically has the file extension .html, though
HTML frequently appears
in the content of other file <!DOCTYPE html>
types as well. All HTML <html>
documents follow the same <head>
basic structure so that the <title>Page Title</title>
browser that renders the file </head>
knows what to do. The <body>
basic structure of an HTML <h1>Homepage Headline</h1>
document consists of 5 <p>This is a paragraph.</p>
elements: </body>
1. <!DOCTYPE>
2. <html>
3. <head>
4. <title>
5. <body>

New Gateway to Computer Science Book -9


114
<!DOCTYPE>: The first line of code, <!DOCTYPE html>, is called a doctype
declaration and tells the browser which version of HTML the page is written in. There are
a number of different doctype declarations that correspond to various versions of HTML.
<HTML>: The <html> element wraps around all of the other code and content in
our document. This element, known as the HTML root element, always contains one
<head> element and one <body> element.
<HEAD>: HEAD element is a container that can include a number of HTML elements
that are not visible parts of the page rendered by the browser.
<TITLE>:The <title> element is the only element that is required to be contained
within the <head> tags. The content within this element is displayed as the page title in
the tab of the browser and is also what search engines use to identify the title of a page.
<BODY>: There can only be one <body> element in an HTML document because this
element is the container that holds the content of the document.

Understanding Different HTML Tags

A tag is a command in a web page that tells the browser to do something. Tags are enclosed
in less than (<) and greater than (>) signs.
<HTML>: It is a container element that identifies the document as an HTML document.
It is also called root element.To create the html element, we can use an opening <html>
tag followed by a closing </html> tag. Everything else in the web page goes between
these starting and ending tags.The general structure is given below.
<HTML>
--------------
Document area
---------------
----------------
</HTML>
<HEAD> : The head element contains information about the web page. There are many
elements that you can put inside the head element, such as title , link, meta, script, etc. The
general structure is given below.
<head>
<title> Learning Computer is Fun. </title>
</head>

New Gateway to Computer Science Book -9


115
<TITLE>: The title element contains the title of the page. The title is displayed in the
browser’s title bar as well as in bookmarks, search engine results, and many other places.
The title should describe the page’s content briefly and accurately. The general structure
is given below.
<title> Learning Computer is Fun. </title>
<body> The body element appears after the head element in the page. It should contain
all the content of your web page such as text, images, and so on. All web pages have one
single body element. The general structure is given below.
<body>
(page content goes here....)
</body>

Sample l
<!DOCTYPE html>
<html>
<head>
<title> We are working with HTML. </title>
</head>
<body>
The content of the document goes here!
</body>
</html>

Document Formatting in HTML

Font Element
<font> : The <font> tag is used to change the format of the text on the web page. The
most important attributes are as follows:
 face: This indicates the type of font. The default font is Times New Roman. There are
other so many fonts like Verdana, Helvetica, Preeti, Arial, etc.
 size: This indicates the size of the text. The default text size in HTML document
is 3. It is used to set the absolute or relative value ranging from 1 to 7.
 color: This indicates the color of the text. Either the color name or the
six-characer color code (RGB value) may be used to specify color.
Syntax: <font size =“value” color = “color name” face
=“font name”> ……………</font>

New Gateway to Computer Science Book -9


116
Sample 2
<!DOCTYPE html>
<html>
<head>
<title> Title of the document</title>
</head>
<body>
<p>
<font size= ”2” color= ”#1c87c9”>Blue text</font></><p>
<font size=”3” color=”red”>Red text, font size increased.
</font></p>
<p> <font face=”arial” color=”#8ebf42”> Green text, typeface
changed.
</font></p>
</body></html>

Font style elements


<b> : The <b> tag will bold the text inside the tag.
Syntax: <b> ……………</b>
<i>: The <i> tag will italicize the text inside the tag.
Syntax: <i> ……………</i>
<u>: The <u> tag will underline the text inside the tag.
Syntax: <u> ……………</u>
<sup> : The <sup> tag converts the text into superscript.
Syntax: <sup> ……………</sup>
<sub>: The <sub> tag converts the text into subscript.
Syntax: <sub> ……………</sub>
<big>:The <big> tag is used to display the text in a larger font as compared to rest
of the text.
Syntax: <big> ……………</big>
<small>: The <small> tag is used to display the text in a smaller font as compared
to the rest of the text.
Syntax: <small> ……………</small>
<br>: The <br> tag indicates a line break. This tag is most often used by itself,
without a corresponding closing tag.
Syntax: <br>

New Gateway to Computer Science Book -9


117
<p>: The <p> tag indicates a new paragraph. It is same as the <br> tag. This tag is
most often used by itself, without a corresponding closing tag.
Syntax: <p>

Sample 3
<!DOCTYPE html>
<html>
<head>
<title> working with font formatting element </title>
</head>
<body>
We are discussing html font formatting elements. <br><p>
<b> Making the text bold. </b><br>
<i> Making the text italic. </i><br>
<u> Inserting underline to the text </u><br><p>
I know the algebra formula a<sup>2</sup> + 2ab +
b<sup>2</sup><br>
I can use science formula like H<sub>2</sub> SO <sub> 4
</sub><br>
<P>
<big> This text is large </big><br>
<small> This text is small </small><br>
</body>
</html>

Let’s Review
 The basic structure of an HTML document consists of 5 elements. They are
<!DOCTYPE>, <html>, <head>, <title> and <body>.
 The first line of code, <!DOCTYPE html>, is called a doctype declaration
and tells the browser which version of HTML the page is written in.
 A tag is a command in a web page that tells the browser to do something.
 To create the html element, we can use an opening <html> tag followed by
a closing </html> tag.
 The body element appears after the head element in the page.
 The <font> tag is used to change the format of the text on the web page.
 The most important font attributes are font face, size and color.

New Gateway to Computer Science Book -9


118
Header Tags
HTML has six levels of heading tags. The header tags are written with in <hn> …</hn>,
where n is the level of the heading and can take the values from 1 to 6. We can write it
as <h1> which is the largest heading size, and <h6> which is the smallest heading size.
Syntax: <hn align = “align ion”> ……………</hn>
In the above syntax “align position” specifies the alignment of the heading to the left,
right or center.

Sample 4
<!DOCTYPE html>
<html>
<head>
<title> working with heading element </title>
</head>
<body>
<h1 align=”center”>This is h1 (largest) heading text.</
h1>
<h2 align=”left”>This is h2 text.</h2>
<h3 align=”right”>This is h3 text.</h3>
<h4> This is h4 text.</h4>
<h5> This is h5 text.</h5>
<h6> This is h6 text.</h6>
</Body> </HTML>

Paragraph Alignment Tags


The paragraph alignment uses <p> ……………</p> to indicate the paragraph. <P>
indicates the start of a new paragraph. It has the align attribute where align indicates the
alignment of the paragraph. We can apply three types of alignments such as left, center
and right.
Syntax: <P align = “align position”> ……………</P>
We can use it as given below.
<P ALIGN=LEFT>This is aligned left. This is the default.</P>
<P ALIGN=CENTER>This is aligned center.</P>

<P ALIGN=RIGHT>This is aligned right.</P>

New Gateway to Computer Science Book -9


119
Sample 5
<!DOCTYPE html>
<html>
<head>
<title> working with heading element </title>
</head>
<body>
<P ALIGN=LEFT>This is aligned left. This is the default.
</P>
<P ALIGN=CENTER>This is aligned center. </P>
<P ALIGN=RIGHT>This is aligned right. </P>
</Body> </HTML>

Working with Body Background Colour


The <body bgcolor> attribute assigns a background color for an HTML document.
To add a background color to a webpage you can use the <body bgcolor="######">
attribute where "######" specifies a color for the HTML document to display.
All major browsers support the <body bgcolor> attributes.
Syntax: <body bgcolor="color name" or "color RGB value">
Example: <body bgcolor="#af0000"> , where "#af0000" is the value for the red
colour. Instead of this we can also write as <body bgcolor="red">. Here, the
color value can be either a color name (like, red, blue, green) or a hexa value like,
#af0000.

Sample 6
<!DOCTYPE html>
<html>
<head>
<title> Background colour sample page</title>
</head>
<body bgcolor=”#af0000”>
<h1> This webpage has red colored background.</h1>
</body> </html>

New Gateway to Computer Science Book -9


120
Working Horizontal Line
The <hr> tag in HTML stands for horizontal line and is used to insert a horizontal line or a
thematic break in an HTML page to separate document sections. The <hr> tag is an empty
tag and it does not require an end tag. It is also used to separate content in an HTML page.
The table given below describes the <hr> tag attributes:

Attribute Value Description


• left
Align • centre Used to specify the alignment of the horizontal rule.
• right
noshade noshade Used to specify the bar without shading effect.

size pixels Used to specify the height of the horizontal rule.

width pixels Used to specify the width of the horizontal rule.

Syntax: <HR align = “align position” noshade color = “color name” size =
“pixel” width = “pixel”>

Example: HR align = “Center” noshade color = “red” size = “5” width = “25%”>

Sample 7
<!DOCTYPE html>
<html>
<head>
<title> HTML hr tag</title>
</head>
<body>
<p>There is a horizontal rule below this
paragraph.</p>
<hr>
<p>This is a horizontal rule above this
paragraph.</p>
</body>
</html>

New Gateway to Computer Science Book -9


121
Sample 8
<!DOCTYPE html>
<html>
<head>
<title> HR tag with attributes</title>
</head>
<body>
<p> Normal horizontal line.</p>
<hr>
<p> Horizontal line with height of 30 pixels</p>
<hr size=”30”>
<p> Horizontal line with height of 30 pixels and
noshade.</p>
<hr size=”30”noshade>
</body>
</html>

Working with Marquee

Marquee is a scrolling text displayed either horizontally across or vertically down on the
webpage depending on its settings. This can be done with the help of <marquee>………</
marquee> tag. It is one of the important tags introduced in HTML to support such
scrollable texts and images within a web page. The different attributes of <marquee> tag
are listed below.
Syntax: <MARQUEE behavior = "behavior name" direction = "direction way" bgcolor
="color name or value" scrolldelay = "scrolling time"> ……………………</marquee>
Example: <MARQUEE behavior = "slide" direction = "left" bgcolor ="red" scrolldelay
= "5"> ……………………</marquee>

Attribute Description
It provides the width or breadth of a marquee. For example
width
width="10" or width="20%".
It provides the height or length of a marquee. For example height="20"
height
or height="30%".

New Gateway to Computer Science Book -9


122
This specifies the direction in which marquee should scroll. This can
direction
be a value like up, down, left or right.
It provides a feature whose value will be used for delaying among
scrolldelay
each jump.
scrollamount It provides a value for speeding the marquee feature.
It provides the scrolling type in a marquee. That scrolling can be
behavior
like: sliding, scrolling or alternate.
loop This specifies how many times to loop.
It provides a background color where the value will be either the
bgcolor
name of the color or the value.
It provides a vertical space and its value can be like: vspace="20" or
vspace
vspace="30%"
It provides a horizontal space and its value can be like: vspace="20"
hspace
or vspace="30%"

Let’s Review
 HTML has six levels of heading tags. The header tags are written within <hn>
…….. </hn>.
 The paragraph alignment uses <p align> ……………</p> to indicate the
paragraph alignment.
 The <hr> tag in HTML stands for horizontal line and is used to insert a
horizontal line or a thematic break in an HTML page to divide or separate
document sections.
 Marquee is a scrolling piece of text displayed either horizontally across or
vertically down on the webpage depending on its settings.

Sample 9
<!DOCTYPE html>
<html>
<head>
<title> Learning marquee Tag</title>
</head>
<body>
<marquee> Sample of marquee text.</marquee>
</body>
</html>

New Gateway to Computer Science Book -9


123
Sample 10
<!DOCTYPE html>
<html>
<head>
<title> Learning marquee Tag</title>
</head>
<body>
<marquee width=”40%”>This example will take 40% width
</marquee>
</body> </html>

Sample 11
<!DOCTYPE html>
<html>
<head>
<title> Marquee Tag</title>
</head>
<body>
<marquee direction=”right”> This text will scroll from
left to right</marquee>
</body> </html>

Sample 12
<!DOCTYPE html>
<html>
<head>
<title> HTML marquee Tag</title>
</head>
<body>
<marquee direction=”up”>This text will scroll from bottom
to up </marquee>
</body> </html>

New Gateway to Computer Science Book -9


124
Sample 13
<!DOCTYPE html>
<html>
<head>
<title> HTML marquee Tag </title>
</head>
<body>
<marquee> This text will scroll from right to left
</marquee>
<marquee direction=”up”> This text will scroll from
bottom to top</marquee>
<marquee direction=”down”width=”250”height=”200”behavior=
”alternate” style=”border:solid”>
<marquee behavior=”alternate”>
This text will bounce
</marquee>
</marquee>
</body> </html>

List Element

HTML has several ways for specifying lists of information. List elements are used to
present a list of information in a well-formed and semantic way. There are three different
types of lists in HTML and each one has a specific purpose and meaning.
 Unordered List: It is used to group a set of related items without any particular
order. An unordered list is created by using the <ul> tag, and each list item starts
with the <li> tag.
 Ordered List: It is used to group a set of related items, in a specific order. <ol> tag
can be used for ordered list. This will use different schemes of numbers to list the
items.
 Definition List : The definition list created using <dl> tag. The <dl> tag is used
in conjunction with <dt> which defines the item in the list, and <dd> which
describes the item in the list. Definition list displays elements in definition form
like in dictionary. The <dl>, <dt> and <dd> tags are used to define description
list.

New Gateway to Computer Science Book -9


125
 <dl> tag defines the description list.
 <dt> tag defines data term.
 <dd> tag defines data definition (description).
Note: Inside a list item you can put text, line breaks, images, links, etc. You can also place
an entire list inside a list item to create a nested list.

Unordered List:
Syntax: <ul type="disc|circle|square">

Attribute Values

Value Description
disc default filled circle
circle an unfilled circle
square a filled square

Sample 14
<!DOCTYPE html>
<html>
<head>
<title> HTML unordered list </title>
</head>
<body>
<ul type=”circle”>
<li> Dhading Bensi, Headquater of Dhading</li>
<li> Bidhur, Headquater of Nuwakoat</li>
<li> Bensisahar, Headquater of Lamjung</li>
<li> Hetauda, Headquater of Makawanpur</li>
</ul>
</BODY>
</HTML>

New Gateway to Computer Science Book -9


126
Ordered List:
Syntax: <ol type="1|a|A|i|I">

Value Description
1 Default decimal numbers like 1, 2, 3, 4 .......
a Alphabetically ordered list, lowercase like a, b, c, d ........
A Alphabetically ordered list, uppercase like A, B, C, D .....
i Roman numbers, lowercase like i, ii, iii, iv ..............
I Roman numbers, uppercase like I, II, III, IV .............

Sample 15
<!DOCTYPE html>
<html>
<head>
<title> HTML ordered list </title>
</head>
<body>
<ol type=”a”>
<li> Dhading Bensi, Headquater of Dhading</li>
<li> Bidhur, Headquater of Nuwakoat</li>
<li> Bensisahar, Headquater of Lamjung</li>
<li> Hetauda, Headquater of Makawanpur</li>
</Ol>
</BODY>
</HTML>

New Gateway to Computer Science Book -9


127
Definition List:

Sample 16
<!DOCTYPE html>
<html>
<head>
<title> HTML Definition list </title>
</head>
<body> <dl>
<dt> Dhading Bensi</dt>
<dd> The headquater of Dhading District</dd>
<dt> Bensisahar</dt>
<dd> The headquater of Lamjung District</dd>
<dt> Rampur, Palpa</dt>
<dd> The historical place of Palpa District</dd>
<dt> Illam</dt>
<dd> The place popular for tea garden</dd>
</dl> </body></HTML>

Sample 17
<!DOCTYPE html>
<html>
<body>
<ol>
<li> Computer Science </li>
<li> Environment Science </li>
<li> Optional Mathematics </li>
</ol>
<ol start=”10”>
<li> Computer Science </li>
<li> Environment Science</li>
<li> Optional Mathematics </li>
</ol>
</body> </html>

New Gateway to Computer Science Book -9


128
Sample 18
<!DOCTYPE html>
<html>
<body>
<dl>
<dt> HTML</dt>
<dd> It stands for Hyper Text Mark-up Language</dd>
<dt> WAN</dt>
<dd> It stands for Wide Area Network</dd>
<dt> MAN</dt>
<dd> It stands for Metro Area Network</dd>
<dt> SIM</dt>
<dd> It stands for Subscriber Identification Module
</dd>
</dl>
</body>
</html>

Hyperlink and Anchors

A hyperlink is an element in an HTML document that links to either another portion


of the document or to another document. On webpages, hyperlinks are usually colored
purple or blue and are sometimes underlined.We can also define hyperlinks as they are
special elements linked to another location, either in the same page, the same website or
an entirely different domain.

In HTML a hyperlink is created with the tag <a>, specifying the destination on the href
attribute. Therefore the text or elements before the closing tag </a> will be linked.

Anchor text is a type of hyperlink represented by plain text. Anchor text is very important
in search engine optimization. It is used to define the beginning and end of a hypertext
link. There are three anchor attributes you need to know to create functional hyperlinks.
These attributes are href, target, and download.

Syntax: <a href=”url name”>link text</a>

New Gateway to Computer Science Book -9


129
Sample 19
<!DOCTYPE html>
<html>
<body>
<h1>
Working with links
</h1>
<p>
<a href=”https://www.shubharambhapublication.com/html/”>
Visit our official website
</a>
</p>
</body>
</html>

In the above tag the href attribute specifies the destination address (https://www.
shubharambhapublication.com/html/) of the link. The link text is the visible part
(Visit our official website). Clicking on the link text will send you to the specified address

Let’s Review
 List elements are used to present a list of information in a well-formed and semantic
way.
 There are three different types of lists in HTML they are Unordered list,
Ordered list and Definition list
 The definition list is created using <dl> tag.
 A hyperlink is an element in an HTML document that links to either another
portion of the document or to another document.
 We can also define hyperlinks as they are special elements linked to another
location, either in the same page, the same website or an entirely different domain.
 In HTML a hyperlink is created with the tag <a>, specifying the destination on
the href attribute.
 Anchor text is a type of hyperlink represented by plain text.
 Anchor text is used to define the beginning and end of a hypertext link.

New Gateway to Computer Science Book -9


130
Creating Links.

Sample 20
Create a sample link with in various pages as given below.
Task 1: Design Home page as below and Task 2: Design Notice page as below
save it under file name home and save it under file name notice.
Home Page Notice Page
Welcome to our home page Welcome to our notice page
Click here for notice Back to home page
Click here for result Click here for result
Click here for admission Click here for admission
Task 3: Design result page as below and Task 4: Design admission page as below
save it under file name result. and save it under file name admission.
Result Page Admission Page
Welcome to our result page Welcome to our admission page
Back to home page Back to home page
Click here for notice Click here for notice
Click here for admission Click here for result

HTML code for home page HTML code for notice page
<!DOCTYPE html> <!DOCTYPE html>
<html> <body> <html> <body>
<Font color = “red”><b><h1> <Font color = “red”><b><h1>
<P align=center> Home Page <P align=center> Notice Page
</p></font></b></h1><br> </p></font></b></h1><br>
<h2> Welcome to our home
<h2> Welcome to our Notice
page </h2><br>
page </h2><br>
<A href = “notice.html”>
Click here for notice <A href = “home.html”> Back
to home page </a><br>
</a><br>
<A href = “result.html”>
<A href = “result.html”>
Click here for result Click here for result
</a><br> </a><br>
<A href = “admission.html”> <A href = “admission.html”>
Click here for admission Click here for admission
</a><br> </body> </html> </a><br> </body> </html>

New Gateway to Computer Science Book -9


131
HTML code for result page HTML code for admission page
<!DOCTYPE html> <!DOCTYPE html>
<html> <body> <html> <body>
<Font color = “red”><b><h1> <Font color = “red”><b><h1>
<P align=center> Result <P align=center> Admission
Page </p></font></b></h1> Page </p></font></b></h1>
<br> <br>
<h2> Welcome to our Result <h2> Welcome to our
page </h2><br> Admission page </h2><br>
<A href = “home.html”> Back <A href = “home.html”> Back
to home page </a><br> to home page </a><br>
<A href = “notice.html”> <A href = “notice.html”>
Click here for notice </a> Click here for notice </a>
<br> <br>
<A href = “admission.html”> <A href = “result.html”>
Click here for admission </ Click here for result</a>
a><br> <br> </body> </html>
</body> </html>

Working with Images in HTML


Images can be easily inserted at any section in an HTML page. We can insert image in the
web page by using <img> tag. The <img> tag is an empty tag, which means it can contain
only a list of attributes and it has no closing tag. We should use the <img> tag inside
<body>…</body> tag. Following is the simple syntax to use this tag.
Syntax: <img src = “Image URL” ... attributes-list/> In this syntax the src attribute is
used to add the image source.
Attributes
Attribute Description
align It specifies the alignment of an image according to surrounding
elements.
alt It specifies an alternate text for an image.
border It specifies the width of the border around an image.
height It specifies the height of an image.
src It specifies the URL of an image.
vspace It specifies the whitespace on top and bottom of an image.
width It specifies the width of an image.

New Gateway to Computer Science Book -9


132
Sample 21
<!DOCTYPE html>
<html>
<head>
<title> Inserting image Tag</title>
</head>
<body>
<img src=”tiger.png” alt=”Name of wild animal”
width=”200” height=”180”>
</body>
</html>

Working with Table

An HTML table consists of a collection of rows and columns. The intersection of a row
and a column is called a cell. A single row contains one cell for each column. The <table>
element in HTML is used for displaying tabular data. It allows arranging data like text,
images, links, other tables, etc. into rows and columns of cells.The HTML tables are
created using the <table> tag in which the <tr> tag is used to create table rows and <td>
tag is used to create data cells. The elements under <td> are regular and left aligned by
default.
Table Attributes
Attribute Description
align It specifies the alignment of a table according to surrounding text.
bgcolor It specifies the background color for a table.
border It specifies whether or not the table is being used for layout purposes.
cellpadding It specifies the space between the cell wall and the cell content.
cellspacing It specifies the space between cells.
frame It specifies which parts of the outside borders should be visible.
rules It specifies which parts of the inside borders should be visible.
summary It specifies a summary of the content of a table.
width It specifies the width of a table.
Height It specifies the height of a table.

New Gateway to Computer Science Book -9


133
Sample 22
<!DOCTYPE html>
<html> <head>
<title> Working with HTML Tables</title>
</head> <body>
<table border = “2”>
<tr>
<td> Student ID</td>
<td> Student Name </td>
</tr> <tr>
<td> 0441</td>
<td> Divyanshi Adhikari</td>
</tr> </table> </body> </HTML>

In the above code, the border is an attribute of <table> tag and it is used to put a border
across all the cells. If you do not need a border, you can use border = “0”.
Table Heading
Table heading can be defined using <th> tag. This tag will be put to replace <td> tag,
which is used to represent actual data cell. The headings, which are defined in <th> tag
are centered and bold by default.

Sample 23
<!DOCTYPE html>
<html> <head>
<title> Table Header in HTML </title></head>
<body>
<table border = “1”>
<tr>
<th> Name</th>
<th> Salary</th>
</tr> <tr>
<td> Ram Malakar</td>
<td>20,000</td>
</tr> <tr>
<td> Kripa Duwadi</td>
<td>35,000</td>
</tr> </table> </body> </html>

New Gateway to Computer Science Book -9


134
Cellpadding and Cellspacing

Cellpadding and cellspacing helps to adjust the white space in your table cells. The
cellspacing attribute defines space between table cells, while cellpadding represents the
distance between cell borders and the content within a cell.

Sample 24
<html>
<head>
<title> HTML Table </title>
</head>
<body>
<table border = “1” cellpadding = “5” cellspacing = “5”>
<tr>
<th> Name</th>
<th> Salary</th>
</tr>
<tr>
<td> Ram Malakar</td>
<td> 20,000</td>
</tr>
<tr>
<td> Kripa Dubadi</td>
<td> 30,000</td>
</tr>
</table>
</body>
</html>

New Gateway to Computer Science Book -9


135
Colspan and Rowspan

You can use colspan attribute to merge two or more columns into a single column.
In a similar way, you can use rowspan if you want to merge two or more rows.

Sample 25
<!DOCTYPE html>
<html>
<head>
<title> HTML Table Colspan/Rowspan</title>
</head>
<body>
<table border = “1”>
<tr>
<th> Address</th>
<th> Name</th>
<th> Age</th>
</tr>
<tr>
<td rowspan = “2”> Dhading Bensi</td>
<td> Prayusha Nepal </td>
<td> 10 Years </td>
</tr>
<tr>
<td> Prem Nath Adhikari</td>
<td> 84 Years </td>
</tr>
<tr>
<td colspan = “3”>Birtamoad Jhapa</td>
</tr>
</table>
</body>
</html>

New Gateway to Computer Science Book -9


136
Table Backgrounds
You can set table background using one of the following ways:
 bgcolor: You can set background color for whole table or just for one cell.
 Background: You can set background image for whole table or just for one
cell. You can also set border color also using border color attribute.

Sample 26
<!DOCTYPE html>
<html> <head>
<title> HTML Table Colspan/Rowspan</title>
</head>
<body>
<table border = “1” bordercolor = “RED” bgcolor =
“Pink”><tr>
<th> Address</th>
<th> Name</th>
<th> Age</th>
</tr> <tr>
<td rowspan = “2”> Dhading Bensi</td>
<td> Prayusha Nepal </td>
<td> 10 Years </td>
</tr>
<tr>
<td> Prem Nath Adhikari</td>
<td> 84 Years </td>
</tr> <tr>
<td colspan = “3”>Birtamoad Jhapa</td>
</tr>
</table>
</body>
</html>

New Gateway to Computer Science Book -9


137
Table Height and Width

You can set a table width and height using width and height attributes. You can
specify table width or height in terms of pixels or in terms of percentage.

Sample 27
<!DOCTYPE html>
<html> <head>
<title> Table Width and Height</title>
</head>
<body>
<table border = “2” width = “550” height = “200”>
<tr>
<td> Name of District</td>
<td> Capital City </td>
</tr>
<tr>
<td> Gorkha</td>
<td> Gorkha Bazaar</td>
</tr>
</table> </body> </html>
Let’s Review
 The <img> tag is an empty tag, which means it can contain only a list of attributes
and it has no closing tag.
 We should use the <img> tag inside <body>…</body> tag.
 The src attribute is used to add the image source
 An HTML table consists of a collection of rows and columns.
 The intersection of a row and a column is called a "cell".
 The <table> element in HTML is used for displaying tabular data.
 Table heading can be defined using <th> tag.
 Cellpadding and cellspacing help to adjust the white space in your table cells.
 We can use colspan attribute to merge two or more columns into a single column.
 We use rowspan if we want to merge two or more rows.
 We can set a table width and height using width and height attributes.

New Gateway to Computer Science Book -9


138
Working with Forms

The <form> element defines a form and attributes that determine the behavior of the form.
Each time you want to create an HTML form, you must start it by using this element,
putting all the contents inside.
There are various form elements available like text fields, text area fields,
drop-down menus, radio buttons, checkboxes, etc.The HTML <form> tag is used to create
form. The syntax is given below.
Syntax <form action = “Script URL” method = “GET|POST”> form elements like input,
textarea etc. </form>
Forms Elements
Text Input Controls: There are three types of text inputs used on forms. Let’s discuss
them below with some sample example.
Single Line Text Input Controls: It is used for items that require only one line of user
input, such as search boxes or names. Here is a basic example of a single-line text input
used to take first name and last name.

Sample 28
<!DOCTYPE html>
<html>
<head>
<title> Text Input Control</title>
</head>
<body>
<form>
First name: <input type=”text”name=”first_name”/>
<br>
Last name: <input type=”text”name=”last_name”/>
</form>
</body>
</html>

Password Input Controls: It is also a single-line text inputs but it masks the character as
soon as a user enters it.

New Gateway to Computer Science Book -9


139
Sample 29
<!DOCTYPE html>
<html>
<head>
<title> Password Input Control</title>
</head>
<body>
<form>
User ID : <input type=”text”name=”user_id”/>
<br>
Password: <input type=”password”name=”password”/>
</form>
</body>
</html>

Multi Line Text Input Controls : It is used when the user is required to give
details that may be longer than a single sentence.

Sample 30
<!DOCTYPE html>
<html>
<head>
<title> Multiple-Line Input Control</title>
</head>
<body>
<form>
Description :<br/>
<textarea rows=”5”cols=”50”name=”description”>
Enter description here...
</textarea>
</form>
</body>
</html>

New Gateway to Computer Science Book -9


140
Checkbox Control
Checkboxes are used when more than one option is required to be selected. They are also
created using HTML <input> tag but type attribute is set to checkbox.

Sample 31
<!DOCTYPE html>
<html>
<head>
<title> Checkbox Control</title>
</head>
<body>
<form>
<input type=”checkbox”name=”maths”value=”on”> Maths
<input type=”checkbox”name=”physics”value=”on”> Physics
</form> </body>
</html>

Radio Button Control

Radio buttons are used when out of many options, just one option is required to be selected.
They are also created using HTML <input> tag but the type attribute is set to radio.

Sample 32
<!DOCTYPE html>
<html>
<head>
<title> Radio Button Control</title>
</head>
<body>
<form>
<input type=”radio”name=”subject”value=”maths”> Maths
<input type=”radio”name=”subject”value=”physics”> Physics
</form> </body>
</html>

New Gateway to Computer Science Book -9


141
Select Box Control

A select box is also called a drop down box which provides option to list down various
options in the form of drop down list, from where a user can select one or more options.

Sample 33
‑<!DOCTYPE html>
<html>
<head>
<title> Select Box Control</title>
</head>
<body>
<form>
<select name = “dropdown”>
<option value = “SEE subject list of Nepal” selected>
SEE subject list of Nepal</option>
<option value = “Comp. English”>Comp. English</option>
<option value = “Comp. Nepali”>Comp. Nepali</option>
<option value = “Comp. Social Studies”>Comp. Social
Studies</option>
<option value = “Comp. Mathematics”>Comp.
Mathematics</option>
<option value = “Comp. Science”>Comp.Science</
option>
<option value = “Optional Computer Science”>
Optional Computer Science</option>
<option value = “Optional Mathematics”>Optional
Mathematics</option>
<option value = “Optional Population”>Optional
Population</option>
<option value = “Optional Science”>Optional Science
</option>
<option value = “Optional Environment Science”>
Optional Environment Science</option>
</select> </form>
</body> </html>

New Gateway to Computer Science Book -9


142
Sample 34
<!DOCTYPE html>
<html>
<head>
<title> Select Box Control</title>
</head>
<body>
<form>
<select name = “dropdown”>
<option value = “SEE subject list of Nepal” selected>
SEE subject list of Nepal</option>
<option value = “Comp. English”>Comp. English</option>
<option value = “Comp. Nepali”>Comp. Nepali</option>
<option value = “Comp. Social Studies”>Comp. Social
Studies</option>
<option value = “Comp. Mathematics”>Comp.
Mathematics</option>
<option value = “Comp. Science”>Comp.Science</
option>
<option value = “Optional Computer Science”>
Optional Computer Science</option>
<option value = “Optional Mathematics”>Optional
Mathematics</option>
<option value = “Optional Population”>Optional
Population</option>
<option value = “Optional Science”>Optional Science
</option>
<option value = “Optional Environment Science”>
Optional Environment Science</option>
</select>
</form>
</body>
</html>

New Gateway to Computer Science Book -9


143
File Upload Box

If you want to allow a user to upload a file to your web site, you will need to use
a file upload box. It is also known as a file select box. This is created using the
<input> element but the type attribute is set to file.

Sample 35
<!DOCTYPE html>
<html> <head>
<title> File Upload Box</title>
</head>
<body>
<form>
<input type=”file”name=”fileupload”accept=”image/*”/>
</form> </body>
</html>

Button Controls

There are various ways in HTML to create clickable buttons. You can also create a
clickable button using <input> tag by setting its type attribute to button.

Sample 36
<!DOCTYPE html>
<html> <head>
<title> File Upload Box</title>
</head>
<body>
<form>
<input type=”submit”name=”submit”value=”Submit”/>
<input type=”reset”name=”reset”value=”Reset”/>
<input type=”button”name=”ok”value=”OK”/>
</form> </body>
</html>

New Gateway to Computer Science Book -9


144
Let’s Review
 The <form> element defines a form and attributes that determine the behavior of
the form.
 There are various form elements available like text fields, text area fields,
drop-down menus, radio buttons, checkboxes, etc.
 There are three types of text inputs used in forms they are single-line text
input controls, password input controls and multi-line text input controls
 Checkboxes are used when more than one option is required to be selected.
 Radio buttons are used when out of many options, just one option is required
to be selected.
 A select box is also called a drop down box which provides option to list down
various options in the form of drop down list, from where a user can select one or
more options.
 If you want to allow a user to upload a file to your web site, you will need
to use a file upload box which is also known as a file select box.

Expand your knowledge


 HTML 1.0 was released in 1993 AD.
 HTML 4.0 which is widely used and was a successful version of HTML before
HTML 5.0.
 Tim Berners Lee was the inventor of the web.
 Tim Berners Lee developed first web broswer in 1990 AD.
 Opera is a freewere web browser released on April 10, 1995 AD.

Assignment
1. Select the correct answer from the given options.
a. Which of the tags is used to start html tagging?
i. <BODY> ii. <HEAD> iii. <HTML> iv. <!DOCTYPE>
b. Which of the following is used in enclosed HTML tags?
i. < and > ii. ^ and ^ iii. % and % iv. None of them

New Gateway to Computer Science Book -9


145
c. Which of the following element contains the information about the web page?
i. <BODY> ii. <HEAD> iii. <HTML> iv. <!DOCTYPE>
d. Which of the following tag is suitable to make the text superscript?
i. <SUB> ii. <SUP> iii. <SPU> iv. <SPT>
e. How many levels of heading tags are there in HTML?
i. Five ii. Seven iii. Four iv. Six
f. Which of the following hexa colour values is correct for red colour?
i. “#af0000” ii. “#af1100” iii. “#af1110” iv. “#afg100”
g. Which of the following is the element of list element?
i. Unordered List ii. Ordered List iii. Definition list iv. All of them
h. Which tag is used for hyperlink?
i. <IMG SRC> ii. <A HREF> iii. <MARGIN> iv. <MARQUEE>
2. Fill in the blanks with suitable words.
a. HTML stands for …………………. which contains links to other text.
b. A basic HTML page is a document that typically has the file extension ……………
c. The …………….. tag is used to change the format of the text on the web page.
d. The <p> tag indicates a ……………………..
e. The ……………. tag is an empty tag and it does not require an end tag.
f. ……………. elements are used to present a list of information in a well-formed and
semantic way.
g. On webpages, …..........…are usually coloured purple or blue and are sometimes
underlined.
h. ………………. text is a type of hyperlink represented by plain text.
i. Cellpadding and …………… helps to adjust the white space in your table cells.
j. ……………. are used when out of many options, just one option is required to be
selected.
3. State whether the given statements are true or false:
a. HTML was first developed by Tim Berners-Lee in 1920 AD.
b. HTML elements are written with a start tag which is also called an opening tag.
c. A tag is a command in a web page that tells the browser to do something. Tags are
inclosed in less than (<) and greater than (>) signs.
d. The <BODY> element contains information about the web page.
e. HTML has ten levels of heading tags.
f. The <hr> tag in HTML stands for horizontal line and is used to insert a horizontal
line or a thematic break in an HTML page.

New Gateway to Computer Science Book -9


146

g. Marquee is a scrolling piece of text displayed either horizontally across or
vertically down on the webpage depending on its settings.
h. A hyperlink is an element in an HTML document that links to either another
portion of the document or to another document.
i. In HTML a hyperlink is created with the tag <IMG SRC>.
j. We can insert an image in the web page by using <img> tag. The <img> tag is an
empty tag.
4. Write appropriate technical terms for the followings.
a. It is a coded HTML command that indicates how parts of web pages should be
displayed.
b. The element is the only element that is required to be contained within the <head>
tags.
c. The tag that is used to change the format of the text on the web page.
d. This attribute is used to assign a background colour for an HTML document.
e. A scrolling piece of text displayed either horizontally across or vertically down on
the webpage.
f. These elements are used to present a list of information in a well-formed and
semantic way.
g. This tag is used to insert image in HTML.
h. The <table> element in HTML is used for displaying tabular data.
5. Match the following.
<HR> Movable text
<IMG SRC> Inserting table
< A HREF> Horizontal line
<TABLE> Inserting image
<MARQUEE> Hyperlink tag
6. Write down the function of following HTML tags.
a. <SUB> b. <U> c. <IMG SRC> d. <MARQUEE> e. <HR>
f. <FONT SIZE> g. <FORM> h. <A HREF> i. <TABLE> j. <TD>
7. Write down the HTML tag for the following tasks.
a. To make the text bold, Italic and insert underline.
b. To insert the image and change its size.
c. To change the font size using heading tag.
d. To change the font colour red, and face “Preeti”.

New Gateway to Computer Science Book -9


147
e. To change the paragraph.
f. To make a table with 3 rows and 3 columns.
g. To make the text movable from up to down and scroll.
h. To create a radio button and check box.
8. Answer the following questions.
a. What is HTML? Write down the features of HTML.
b. What is HTML tag?
c. What is the use of tag attribute?
d. Write down the structure of HTML.
e. Explain the HTML document elements.
f. What is a font element? Write its attributes.
g. What is a header tag? Write down the syntax for the header tag.
h. Which tag is used to insert horizontal line in HTML tag.
i. Define marquee with its attributes.
j. What is a hyperlink and an anchor text?
k. What are the various font elements? Explain in short.
Practical Work
Do the given task and show it to your teacher.
Task 1: Insert any three images in your page with their name.
Task 2: Type any three line texts. Make first line bold, second line italic and third line
underline.
Task 3: Type a text and apply it heading 1 and change colour as red with colour
value.
Task 4: Design a table as below.
Name Address Subject
Ramesh Maharjan Bhaktapur Computer
Shilpa Adhikari Chitwan OPT. Maths
Sunil Surkheti Palpa Geography
Madan Tharu Dang Population
Task 5: Create any four pages and create a link within the pages.
Task 6: Change the background colour of the page as green.
Task 7: Create password input control, check box control and radio button control
in your page.
Task 8: Create a file upload box in HTML.

New Gateway to Computer Science Book -9


148
Lesson

9 Working With CSS

Inside the Lesson

 Introduction to CSS
 Understanding CSS syntax
 CSS measuring unit
 Working with CSS colour
 Working with CSS background
 CSS font style
 CSS text and image
 CSS links and tables
 CSS border and margin
 CSS scrollbars

CSS stands for Cascading Style Sheets. It is a language that describes the style of an
HTML document like how HTML elements are to be displayed on screen. It can control
the layout of multiple web pages all at once. The external stylesheets are stored in CSS
files.

CSS Syntax

CSS is a set of rules that can be used to define what each of those elements will look. The
rules specify the display properties. A CSS comprises of style rules that are interpreted
by the browser and then applied to the corresponding elements in your document. CSS
rules can control many properties, called declarations, of an element. CSS declarations
are always contained in curly braces ({}) and each declaration will end in a semi-colon(;).
Each element is chosen in CSS by the ‘selector’ and defined in the ‘declaration’ by a
‘property’ and a ‘value.’
A CSS rule set contains a selector and a declaration block as given below. Let’s discuss
it in detail.

New Gateway to Computer Science Book -9


149
Selector Declaration Blog

h1 { colour:red; font-size ; 20 px;}

Property value
Selector
Selector indicates the HTML element you want to style. It could be any tag like <h1>,
<title> etc.CSS selectors are used to select the content you want to style. Selectors are the
part of CSS rule set. CSS selectors select HTML elements according to its id, class, type,
attribute, etc. There are several different types of selectors in CSS which are listed below.
 CSS element selector
 CSS Id selector
 CSS class selector
 CSS universal selector
 CSS group selector
Declaration Block: The declaration block can contain one or more declarations separated
by a semicolon. In the above example, there are two declarations and they are color: red
and font-size:20 px. Each declaration contains a property name and value, separated by
a colon.
Property: a Property is a type of attribute of HTML element. It could be color, border,
etc.
Value: Values are assigned to CSS properties. In the above example, value “red” is
assigned to color property.

CSS Measuring Units

CSS has several different units for expressing a length. Many CSS properties take “length”
values, such as width, margin, padding, font-size, etc. Length is a number followed by
a length unit, such as 10px, 2em, etc. You need these values while specifying various
measurements in your style rules. A whitespace cannot appear between the number and
the unit. However, if the value is 0, the unit can be omitted. For some CSS properties,
negative lengths are allowed. There are two types of length units. They are absolute and
relative length unit.

New Gateway to Computer Science Book -9


150
Absolute length : The absolute length units are fixed and a length expressed in any of
these will appear as exactly as that size. Absolute length units are not recommended for
use on screen. However, they can be used if the output medium is known, such as for print
layout. Some absolute length units are cm, mm, in (inches), px, pt, pc, etc. Let’s observe
the given table with CSS absolute length units.

Length Units Description


cm defines length in centimeters.
mm length unit in millimeters.
in inches (1in = 96px = 2.54cm).
px* pixels (1px = 1/96th of 1in).
pt points (1pt = 1/72 of 1in).
pc picas (1pc = 12 pt).

Relative length: Relative length units specify a length relative to another length property.
Relative length units scale better between different rendering mediums. Some relative
length units are em, ex, ch, rem, vw, vh, etc. Let’s observe the given table with CSS
relative length units.

Unit Description

% It defines a measurement as a percentage relative to another value.


A relative measurement for the height of a font in em spaces. Because an em
em unit is equivalent to the size of a given font, if you assign a font to 12pt, each
"em" unit would be 12pt; thus, 2em would be 24pt.
This value defines a measurement relative to a font's x-height. The
ex
x-height is determined by the height of the font's lowercase letter x.
px Defines a measurement in screen pixels.

vmax Relative to 1% of viewport's largest dimension

ch Relative to width of the "0" (zero)

vw Relative to 1% of the width of the viewport

New Gateway to Computer Science Book -9


151
Let’s Review
 CSS stands for Cascading Style Sheets which is a language that describes the
style of an HTML document like how HTML elements are to be displayed on
screen.
 CSS can be used to define what each of those elements will look like by defining
a Rule.
 CSS rules can control many properties, called declarations, of an element.
 Many CSS properties take "length" values, such as width, margin, padding,
font-size, etc.
 The absolute length units are fixed and a length expressed in any of these will
appear as exactly as that size.
 Relative length units specify a length relative to another length property. Relative
length units scale better between different rendering mediums.

CSS Colors

CSS uses color values to specify a color. Typically, they are used to set a color either for
the foreground of an element or for the background of the element. They can also be used
to affect the color of borders and other decorative effects.
You can specify your color values in various formats. Following table lists all the possible
formats.

Format Syntax Example


Hex Code #RRGGBB p{color:#FF0000;}
Short Hex Code #RGB p{color:#6A7;}
RGB % rgb(rrr%,ggg%,bbb%) p{color:rgb(50%,50%,50%);}
RGB Absolute rgb(rrr,ggg,bbb) p{color:rgb(0,0,255);}
keyword aqua, black, etc. p{color:teal;}

CSS Colors - Hex Codes


A hexadecimal is a 6 digit representation of a color. The first two digits
(RR) represent a red value, the next two are a green value (GG), and the last are the blue
value (BB). A hexadecimal value can be taken from any graphics software like Adobe
Photoshop or advanced paint brush.

New Gateway to Computer Science Book -9


152
CSS Colors - RGB Values
This color value is specified using the rgb ( ) property. This property takes three
values, one each for red, green, and blue. The value can be an integer between
0 to 255 or a percentage.
CSS- Background
The background properties used to define the background effects for elements. Some of
the CSS background properties are given below.
Background-color :This property is used to set the background color of an element.
Sample 1
<!DOCTYPE html>
<html> <head>
</head>
<body>
<p style=”background-color:red;”>
This text has a red background color.
</p> </body> </html>

Background-image: This property is used to set the background image of an element.

Sample 2
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image:url(“/publication matter/images/
computer.jpg”);
background-color:#ccddcc;
}
</style>
</head>
<body>
<h1> Learning CSS is FUN !</h1>
</body> <html>

New Gateway to Computer Science Book -9


153
Background Image Position: This property is used to set the background image
position of an element.

Sample 3
<!DOCTYPE html>
<html> <head>
<style>
body{
background-image:url("/publication matter/images/
computer.jpg");
background-position:100px;
}
</style>
</head>
<body>
<p> LEARNING CSS IN HTML is always fun</p>
</body> </html>

Background-Repeat: This property is used to control the repetition of an image in the


background.

Sample 4
<!DOCTYPE html>
<html> <head>
<style>
body{
background-image:url(“/publication matter/images/
computer.jpg”);
background-repeat: repeat;
}
</style>
</head>
<body>
<p> Learning HTML</p>
</body> </html>

New Gateway to Computer Science Book -9


154
Background-Attachment: Background attachment determines whether a background
image is fixed or scrolled with the rest of the page or not.

Sample 5
<!DOCTYPE html>
<html>
<head>
<style>
body{
background-image:url(“/publication matter/images/
computer.jpg”);
background-repeat:no-repeat;
background-attachment:fixed;
}
</style>
</head>
<body>
<p>The background-image is fixed. Try to scroll down the
page.</p>
</body> </html>

CSS- Font
The font property is a shorthand property for font-style, font-variant, font-weight, font-
size, font-family, etc.

Property/Value Description
font-style It specifies the font style. Default value is "normal".
font-variant It specifies the font variant. Default value is "normal".
font-weight It specifies the font weight. Default value is "normal".
font-size/line- It specifies the font size and the line-height. Default value is
height "normal".
font-family It specifies the font family. Default value depends on the browser.
It uses the font that are used by captioned controls (like buttons,
caption
drop-downs, etc.).
icon It uses the font that are used by icon labels.
status-bar It uses the fonts that are used by the status bar.
status-bar It uses the fonts that are used by the status bar.

New Gateway to Computer Science Book -9


155
Font Style

Sample 6
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “font-family:tiplo;”>
We are in grade nine , We are learning about CSS <br>
Learning CSS is fun.
</p>
</body>
</html>

Font Variant

Sample 7
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”font-variant:small-caps;”>
Learning HTM and CSS.
</p>
</body>
</html>

Font Weight: The font-weight property provides the functionality to specify how bold a
font is. Normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900, etc. are
the possible values for font weight.

New Gateway to Computer Science Book -9


156
Sample 8
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<pstyle=”font-weight:bold;”>
This font is bold.
</p>
<pstyle=”font-weight:bolder;”>
This font is bolder.
</p>
<pstyle=”font-weight:500;”>
This font is 500 weight.
</p> </body> </html>

Font Size: The font-size property is used to control the size of fonts. Possible values
could be xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger, size
in pixels or in %.

Sample 9
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”font-size:20px;”>
This font size is 20 pixels
</p>
<p style=”font-size:small;”>
This font size is small
</p>
<p style=”font-size:large;”>
This font size is large
</p> </body> </html>

New Gateway to Computer Science Book -9


157
Font Size Adjust: The font size adjust property enables you to adjust the
x-height to make fonts more legible. Possible value could be any number.

Sample 10
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”font-size-adjust:0.61;”>
This text is using a font-size-adjust value.
</p>
</body>
</html>

Short Hand Property: You can use the font property to set all the font properties at once.

Sample 11
<!DOCTYPE html>
<html
<head>
</head>
<body>
<p style=”font:italic small-caps bold 15pxgeorgia;”>
Applying all the properties on the text at once.
</p>
</body>
</html>

New Gateway to Computer Science Book -9


158
CSS – TEXT

You can set the following text properties of an element.


Text Color

Sample 12
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”color:red;”>
Text appear in red colour.
</p>
</body>
</html>

Text Direction

Sample 13
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”direction:rtl;”>
This text will be rendered from right to left
</p>
</body>
</html>

New Gateway to Computer Science Book -9


159
Space between Characters
Sample 14
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”letter-spacing:5px;”>
Text is having space between the letters.
</p>
</body> </html>

Space between Words


Sample 15
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “word-spacing:5px;”>
This text is having space between words.
</p>
</body> </html>

Text Shadow
Sample 16
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = "text-shadow:4px 4px 8px red;">
If your browser supports the CSS text-shadow
property,this text will have a red shadow.
</p> </body> </html>

New Gateway to Computer Science Book -9


160
Text Indent
Sample 17
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “text-indent:5cm;”>
The font-weight property provides the functionality to
specify how bold a font is. Possible values could be
normal, bold, bolder, lighter, 100, 200, 300, 400,
500, 600, 700, 800, 900.
</p>
</body>
</html>

Text Alignment

Sample 18
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “text-indent:5cm;”>
The font-weight property provides the functionality to
specify how bold a font is. Possible values could be
normal, bold, bolder, lighter, 100, 200, 300, 400,
500, 600, 700, 800, 900.
</p>
</body>
</html>

New Gateway to Computer Science Book -9


161
Text Cases
Sample 19
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = "text-transform:capitalize;">
This will be capitalized
</p>
<p style = "text-transform:uppercase;">
This will be in uppercase
</p>
<p style = "text-transform:lowercase;">
This will be in lowercase
</p>
</body>
</html>

White Space between Text

Sample 20
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “white-space:pre;”>
CSS uses color values to specify a color.
Typically, these are used to set a color
either for the foreground of an element or for
the background of the element. They can also
be used to affect the color of borders and other
decorative effects.
</p>
</body>
</html> 

New Gateway to Computer Science Book -9


162
Let’s Review
 CSS uses color values to specify a color. Typically, they are used to set
a color either for the foreground of an element or for the background of the
element.
 CSSbackground properties are used to define the background effects for elements.
 CSS background properties are Background-color, Background-image, Background
Image Position, Background-repeat and Background-attachment.
 CSS- Font property is a shorthand property for font-style, font-variant,
font-weight, font-size, font-family, etc.
 The font-weight property provides the functionality to specify how bold a font is.
 The font-size property is used to control the size of fonts.
 Font size adjust property enables you to adjust the x-height to make fonts more
legible.

CSS – Images

Images play an important role in any webpage. It plays a good role to control
image display. You can set the following image properties using CSS.
 Border: This property is used to set the width of an image border.
 Height: This property is used to set the height of an image.
 Width: This property is used to set the width of an image.
 Moz-opacity: This property is used to set the opacity of an image.
Border Property
It is an image which is used to set the width of an image border. This property can
have a value in length or in percentage.

Sample 21
<!DOCTYPE html>
<html> <head>
</head>
<body>
<img style = “border:0px;” src = “logo.png” />
<br/>
<img style = “border:3px dashed red;” src = logo.png” />
</body> </html>

New Gateway to Computer Science Book -9


163
Height Property
The height property of an image is used to set the height of an image. This property
can have a value in length or in percentage.

Sample 22
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img style = “border:1px solid red; height:100px;” src =
“logo.png” />
<br/>
<img style = “border:1px solid red; height:50%;” src =
“logo.png” />
</body>
</html>

Width Property
The width property of an image is used to set the width of an image. This property
can have a value in length or in percentage.
Sample 23
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img style = “border:1px solid red; width:150px;” src =
“/css/images/logo.png” />
<br>
<img style = “border:1px solid red; width:100%;” src = “/
css/images/logo.png” />
</body>
</html>

New Gateway to Computer Science Book -9


164
Moz-opacity Property
The -moz-opacity property of an image is used to set the opacity of an image. This
property is used to create a transparent image.
Sample 24
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img style = “border:1px solid red; -moz-opacity:0.4;
filter:alpha(opacity=40);” src = “logo.png” />
</body> </html>

CSS – Links

Website contains a hyperlink inside a web page or any other website. The <link> tag
defines a link between a document and an external or even internal resource.The <link>
tag is used to link to external style sheets.All the link properties are kept in the header part
of the HTML document.There are four link states which are listed below.
 a:link:This link is a normal and unvisited link
 a:visited: This links where the user has visited
 a:hover:The link on which the user shows the pointer over it
 a:active: The link that is clicked by the user.
Setting Color for the Links
Sample 25
<!DOCTYPE html>
<html>
<head>
<style type = “text/css”>
a:link {color:#000000}
</style>
</head>
<body>
<a href = “”>Click here for Link</a>
</body> </html>

New Gateway to Computer Science Book -9


165
Setting Color for Visited Links

Sample 26
<!DOCTYPE html>
<html>
<head>
<style type = “text/css”>
a:visited {color: #006600}
</style>
</head>
<body>
<ahref = “”>Click here for Link</a>
</body> </html>

Change the Color of the Links when Mouse is Over

Sample 27
<!DOCTYPE html>
<html> <head>
<style type = “text/css”>
a:hover {color: #FFCC00}
</style> </head>
<body>
<a href = “”> Click here for Link</a>
</body> </html>

CSS –Table
Let’s discuss various table properties that we can use in CSS.
Border-collapse: It specifies whether the browser should control the appearance of the
adjacent borders that touch each other or whether each cell should maintain its style.
Border-spacing: It specifies the width that should appear between table cells.
Caption-side: The captions are presented in the <caption> element. By default, these are
rendered above the table in the document.
Empty-cells: It specifies whether the border should be shown if a cell is empty or not.
Table-layout: It allows browsers to speed up layout of a table.

New Gateway to Computer Science Book -9


166
Sample 28
<!DOCTYPE html>
<html>
<head>
<style type = “text/css”>
table.one {border-collapse:collapse;}
table.two {border-collapse:separate;}
td.a {
border-style:dotted;
border-width:3px;
border-color:#000000;
padding: 10px;
}
td.b {
border-style:solid;
border-width:3px;
border-color:#333333;
padding:10px;
}
</style>
</head>
<body>
<table class = “one”>
<caption> Collapse Border Example</caption>
<tr><td class = “a”> Cell A Collapse Example</td></tr>
<tr><td class = “b”> Cell B Collapse Example</td></tr>
</table>
<br />
<table class = “two”>
<caption> Separate Border Example</caption>
<tr><td class = “a”> Cell A Separate Example</td></tr>
<tr><td class = “b”> Cell B Separate Example</td></tr>
</table>
</body>
</html>

New Gateway to Computer Science Book -9


167
CSS - Borders

The border properties allow you to specify how the border of the box representing an
element should look. There are three properties of a border.
Border-Color: It specifies the color of a border.The border color property allows you to
change the color of the border surrounding an element.

Sample 29
<!DOCTYPE html>
<html> <head>
<styletype=”text/css”>
p.example1 {
border:1px solid;
border-bottom-color:#009900;/* Green */
border-top-color:#FF0000;/* Red */
border-left-color:#330000;/* Black */
border-right-color:#0000CC;/* Blue */
}
p.example2 {
border:1px solid;
border-color:#009900;/* Green */
}
</style>
</head>
<body>
<pclass=”example1”>
This example is showing all borders in different colors.
</p>
<pclass=”example2”>
This example is showing all borders in green color only.
</p> </body> </html>

Border-Style: It specifies whether a border should be solid, dashed line, double line,
or one of the other possible values. The border-style property allows you to select one of
the styles of border like none, solid, dotted, etc.

New Gateway to Computer Science Book -9


168
Sample 30
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “border-width:4px; border-style:none;”>
This is a border with none width.
</p>
<p style = “border-width:4px; border-style:solid;”>
This is a solid border.
</p>
<p style = “border-width:4px; border-style:dashed;”>
This is a dashed border.
</p>
<p style = “border-width:4px;
border-top-style:solid;
border-bottom-style:dashed;
border-left-style:groove;
border-right-style:double;”>
This is a border with four different styles.
</p>
</body>
</html>

Border-Width: It specifies the width of a border. The border-width property is


used to set the width of an element border. The value of this property could be
either a length in px, pt or cm or it should be set to thin, medium or thick.

New Gateway to Computer Science Book -9


169
Sample 31
<!DOCTYPE html>
<html> <head>
</head>
<body>
<p style = “border-width:4px; border-style:solid;”>
This is a solid border whose width is 4px.
</p>
<p style = “border-width:thin; border-style:solid;”>
This is a solid border whose width is thin.
</p>
<p style = “border-bottom-width:4px;border-top-
width:10px;
border-left-width: 2px;border-right-width:15px;border-
style:solid;”>
This is a border with four different width.
</p>
</body> </html>

Let’s Review
 We can set the border, height, width, moz-opacity properties using CSS.
 Border Property is an image used to set the width of an image border.
 The width property of an image is used to set the width of an image
 The height property of an image is used to set the height of an image.
 The -moz-opacity property of an image is used to set the opacity of an image.
 The <link> tag defines a link between a document and an external or even internal
resource.
 The <link> tag is used to link to external style sheets.
 Border-spacing specifies the width that should appear between table cells.
 Empty cells specifies whether the border should be shown if a cell is empty or not.

CSS - Margins
The margin property defines the space around an HTML element. We have the following
properties to set an element margin.
Margin: It specifies a shorthand property for setting the margin properties in one
declaration.

New Gateway to Computer Science Book -9


170
Sample 32
<!DOCTYPE html>
<html> <head>
</head>
<body>
<p style = “margin:10px 2%; border:1px solid black;”>
Top and bottom margin will be 10px, left and right margin
will be 2% of the total width of the document.
</p>
<p style = “margin: 10px 2% -10px auto; border:1px solid
black;”>
Top margin will be 10px, right margin will be 2% of the
total width of the document, bottom margin will be -10px,
left margin will be set by the browser
</p> </body></html>

Margin-Bottom: It specifies the bottom margin of an element. The margin-bottom


property allows you set bottom margin of an element. It can have a value in length, % or
auto.

Sample 33
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<pstyle=”margin-bottom:15px; border:1px solid black;”>
This is a paragraph with a specified bottom margin
</p>
<pstyle=”margin-bottom:5%; border:1px solid black;”>
This is another paragraph with a specified bottom
margin in percent
</p> </body> </html>

New Gateway to Computer Science Book -9


171
Margin-Top: It specifies the top margin of an element.The margin-top property allows
you set top margin of an element. It can have a value in length, % or auto.

Sample 34
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<pstyle=”margin-top:15px; border:1px solid black;”>
This is a paragraph with a specified top margin
</p>
<pstyle=”margin-top:5%; border:1px solid black;”>
This is another paragraph with a specified top
margin in percent
</p>
</body>
</html>

Margin-Left: It specifies the left margin of an element. The margin-left property allows
you to set left margin of an element. It can have a value in length, % or auto.

Sample 35
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “margin-left: 15px; border:1px solid black;”>
This is a paragraph with a specified left margin
</p>
<p style = “margin-left: 5%; border:1px solid black;”>
This is another paragraph with a specified top
margin in percent
</p>
</body>
</html>

New Gateway to Computer Science Book -9


172
Margin-Right: It specifies the right margin of an element. The margin-right
property allows you set right margin of an element. It can have a value in length, % or
auto.
Sample 36
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “margin-right: 15px; border:1px solid black;”>
This is a paragraph with a specified right margin.
</p>
<p style = “margin-right: 5%; border:1px solid black;”>
This is another paragraph with a specified right
margin in percent.
</p>
</body>
</html>

CSS - Scrollbars

There may be chances when an element’s content might be larger than the amount of
space allocated to it. CSS provides a property which is called overflow that tells the
browser what to do if the box’s contents are larger than the box itself. Let’s discuss the
scrollbars values and its description.

Value Description
visible It allows the content to overflow the borders of its containing element.
hidden The content of the nested element is simply cut off at the border of the
containing element and no scrollbars is visible.
scroll The size of the containing element does not change, but the scrollbars are
added to allow the user to scroll to see the content.
auto The purposes of auto is the same as scroll, but the scrollbar will be shown
only if the content overflows.

New Gateway to Computer Science Book -9


173
Sample 37
<!DOCTYPE html>
<html>
<head>
<style type = “text/css”>
.scroll {
display:block;
border: 1px solid red;
padding:5px;
margin-top:5px;
width:300px;
height:50px;
overflow:scroll;
}
</style>
</head>
<body>
<p>Example of scroll value:</p>
<div class = “scroll”>
There may be a case when an element’s content might
be larger than the amount of space allocated to it.
CSS provides a property called overflow which tells
the browser what to do if the box’s contents is
larger than the box itself.
Let’s discuss the scrollbars values and its
description.
</div>
<br />
</body>
</html>

New Gateway to Computer Science Book -9


174
Let’s Review
 CSS – Borders properties allow you to specify how the border of the box
representing an element should look.
 There are three properties of a border they are Border-color, Border-style
and Border-width.
 Border-width specifies the width of a border. The border-width property is
used to set the width of an element border.
 The margin property defines the space around an HTML element.
 CSS provides a property which is called overflow that tells the browser
what to do if the box's contents are larger than the box itself.

Expand your knowledge


 In 1971 AD. the first microprocessor Intel 4004 was invented.
 Intel Celeron was introduced in April 1998 AD.
 Pentium were introduced on March 2, 1993 AD.
 Xeon Processor is a 400 MHz Pentium processor from the Intel for use in
workstation and enterprise servers.
 In August 2006, Xeon Dual-core processor was introduced.
 The first practical form of RAM was the Williams Tube starting in 1947 AD.

Assignment
1. Select the correct answer from the given options.
a. Which of the following indicates the HTML element you want to style.
i.Selector ii. Declaration iii. Property iv. Value
b. A type of attribute of HTML element which could be colour, border, etc.
i. Value ii. Property iii. Declaration iv. All of the above
c. Which of the following unit defines a measurement as a percentage relative to
another value?
i. Ex ii. % iii. ch iv. Em

New Gateway to Computer Science Book -9


175
d. In hex code #RRGGBB what is the first two RR represent?
i. Red colour ii. Green colour iii. Blue colour iv. None of them
e. Which of the following specifies the font weight with default normal value?
i. Font style ii. font colour iii. font weight iv. All of them.
f. Which of the following CSS-Image property is used to set the height of an image?
i. Border ii. Height iii. Moz opacity iv. Width
2. Fill in the blanks with suitable words.
a. CSS stands for …………………………
b. ………………… can be used to define what each of those elements will look like
by defining a Rule.
c. The ……………………….. are fixed and a length expressed in any of these will
appear as exactly as that size.
d. CSS ………………. used to define the background effects for elements.
e. CSS- ………………… is a shorthand property for font-style, font-variant, font-
weight, font-size/line-height, font-family, etc.
f. The ………………… of an image is used to set the width of an image.
g. The …………….. tag defines a link between a document and an external or even
internal resource.
h. CSS …………. allow you to specify how the border of the box representing an
element should look.
3. State whether the given statements are true or false.
a. CSS rules can control many properties, called declarations, of an element.
b. Many CSS properties take "length" values, such as width, margin, padding, font-
size, etc.
c. Relative length units specify a length relative to another length property. Relative
length units scale better between different rendering mediums.
d. CSS does not uses color values to specify a color.
e.
CSS background properties are Background-color, Background-image,
Background Image Position, Background-repeat and Background-attachment.
f. The font-size property is used to control the size of image.
g. Border property is an image which is used to set the width of a table border.

New Gateway to Computer Science Book -9


176
h. The height property of an image is used to set the height of an image.
i. The -moz-opacity property of an image is used to set the size of an image.
j. There are three properties of a border. They are Border-color, Border-style and
Border-width.
4. Write down the function of following CSS commands.
a. <p style> b. <img style> c. a: link d. <style type>
5. Answer the following questions.
a. What is CSS? What can it control?
b. What are the different types of selector sin CSS?
c. What does a declaration box contain?
d. What are the CSS measuring units? What are absolute length and relative length?
e. What is the use of CSS-Background properties?
f. What are the various CSS font properties?
g. Write down the different image properties used in CSS.
h. What is the use of CSS link? Write down the four link properties.
i. List out the table properties of CSS.
j. Explain the CSS-scrollbars with their properties description.

New Gateway to Computer Science Book -9


177
Computer Programming
Unit

This unit covers the following topics:

Lesson 10: General Concept of Programming


Lesson 11: Programming Techiniques
Lesson 12: Programming in QBASIC
Lesson 13: QBASIC Statements
Lesson 14: Program Flow and Control Structures
Lesson 15: Library Functions in QBASIC
Lesson 16: Arrays in QBASIC
Lesson 16: Arrays in QBASIC

New Gateway to Computer Science Book -9


178
Lesson

10 General Concept of Programming

Inside the Lesson

 Introduction to programming
 Programmer and programming language
 Types of programming language
 Low level programming language
 High level language
 Middle level programming language
 Fourth generation language
 Fifth generation language
 Translator program and its types
 Program development cycle

Computer is an electronic device that accepts data, processess them and generates the
required output. It can perform both simple and complex tasks with high accuracy.
However, a computer cannot perform task itself. It needs instructions to perform the task.
A set of instructions that instruct the computer the way the task is to be performed is
called a program. Computer program is a set of instructions written for performing a
specific task.
Computer programs are collections of instructions that tell a computer how to interact
with the user, interact with the computer hardware and process data.

Programmer and Programming

A programmer needs to write programs for the computers or even for the machines.
We can define a programmer as a person who designs the algorithms and writes the
necessary codes to create a computer program. A programmer must have the knowledge
of programing language to develop a program. Computer programmers write and test
the code that allows computer applications and programs to function. Programming
language is the tool or means used by the programmer. Programming is the way of giving
instructions about what they should do next. These instructions are known as code, and
computer programmers write code to solve problems or perform a task.

New Gateway to Computer Science Book -9


179
Programming language

To communicate with a person, we need a language. Like the same if you want to
communicate with the computer, you need a programming language. Without any
programming language, you cannot communicate with the computer.Thus, programming
language is the medium of communication between a person and a computer system. It is
a set of instructions written in a specific code to instruct the computer to do some specific
tasks.
Computer programming is the process of developing and implementing various sets of
instructions to enable a computer to do a certain task. These instructions are considered
computer programs and help the computer to operate smoothly. A programming language
is a set of commands, instructions, and other syntax used to create a software program.

Let’s Review
 A set of instructions that instruct the computer that the way the task is to be
performed is called a program.
 Computer programs are collections of instructions that tell a computer how
to interact with the user, interact with the computer hardware and process data.
 A programmer must have the knowledge of programing language to develop
a program.
 Without any programming language you cannot communicate with the computer.
 A programming language is a set of commands, instructions, and other syntax use
to create a software program.

Types of Programming Languages


There are various types of computer programming languages. Let’s discuss some of them
in detail.

Low Level Programming Languages


Low Level programming language programs are faster than high level programming
language. Low level languages are machine dependent programming languages such as
binary and assembly language. Machine code does not need any interpreter or compiler
to convert language in any form because the computer understands these signals directly.
The codes written in such kind of languages are difficult to write, read, edit and understand.
The programs are not portable to any other computer system.The popular examples of
low level languages are explained below.

New Gateway to Computer Science Book -9


180
Assembly Language
Assembly languages are low level languages. Only few programmers write programs in
low level assembly language. It is still used for developing code for special hardware,
such as device drivers. It contains few recognisable human words but lots of mnemonic
code.
Advantages of Assembly Language
 It can make use of special hardware or special machine-dependent instructions.
 The translated program requires less memory.
 The code can be executed faster.
 It has total control over the code.
 It can work directly on memory locations.
Disadvantages of Assembly Language
 It is a machine independent language.
 Coding in this language is much time consuming.
 It is very difficult to understand.

Machine Language
Machine Language is the only language that is directly understood by the
computer. It does not need any translator program. We also call it machine code and it is
written as strings of 1's (one) and 0’s (zero). When this sequence of codes is fed to the
computer, it recognizes the codes and converts them into electrical signals needed to run
it. It is not an easy language to learn because it is difficult to understand. It is efficient
for the computer but very inefficient for programmers. It is considered to be the first
generation language. It is also difficult to debug the program written in this language.
Let's discuss a few advantages and disadvantages of machine language.

Advantages of Machine Language


 It makes fast and efficient use of the computer.
 It doen not require translator to translate the code.
 It is directly understood by the computer.

Disadvantages of Machine Language


 It is very difficult to program in machine language.
 The programmer has to know details of hardware to write the program.
 The programmer has to remember a lot of codes to write a program.
 It is difficult to debug the program.

New Gateway to Computer Science Book -9


181
High Level Programming Languages
High level programming languages are the machine independent programming
languages, which are easy to write, read, edit and understand.The languages like Ada,
FORTRAN, Pascal, BASIC, COBOL, C++, C, C#,Java, .Net, etc. are the popular high
level languages. High level programming languages have some special keywords and
functions. By using them we can easily build a program for the computer. Computer
does not understand program written in such languages directly. We must have some
programming translators to convert a high level program into machine code.
Features of High Level Programming Languages
 The programs written in high level programming languages are independent.
 The programs written in high level language can be run on any other system.
 The programs are easy to learn, use and understand.
 The programs written in high level programming languages are easy to code,
read and edit.
 We can edit programs written by other programmers easily.
 High level language programs are slower than low level language programs.
Middle Level Programming Languages
The programming languages that have features of low level and high level programming
languages are called middle level language. We can say that the programming languages
which have the features of low level as well as high level programming languages known
as "Middle Level" programming language.C programming language is the best example
of middle level programming languages as it has both features of low level and high level
programming languages. These languages do not provide all the built-in functions found
in high level languages, but provide all building blocks that we need to produce the result.
Java, C++, C, FORTH, Macro-assemble, etc. are the popular middle level languages.
Fourth Generation Language (4GL)
Fourth generation languages are more closer to human language than other high-level
languages and are easily accessible. These are the computer languages that consist of
statements similar to human language. Fourth generation languages are commonly used
in database programming and scripts such as Perl, PHP, Python, Ruby, and SQL. 4GLs are
more programmer-friendly and enhance programming efficiency with usage of English-
like words and phrases.

New Gateway to Computer Science Book -9


182
Advantages of Fourth Generation Languages
 It allows the efficient use of data by implementing various databases.
 They require less time, cost and effort to develop different types of software
applications.
 The programs developed in these languages are highly portable as compared to the
programs developed in the languages of other generation.

Fifth Generation Language (5GL)


A fifth-generation programming language is a programming language based on problem
solving. The major fields in which the fifth generation programming languages are
employed are Artificial Intelligence (AI) and Artificial Neural Network (ANN). AI is a
branch of the computer science in which the computer system is programmed to have
human intelligence characteristics. It helps to make computer system so intelligent that it
can take decisions on its own while solving various complicated problems. On the other
hand, ANN refers to a network that is used to imitate the working of human brain. It is
widely used in voice recognition system, image recognition system and industrial robotics.
Prolog, OPS5, and Mercury are the popular examples of fifth-generation languages. This
generation language uses a visual or graphical development interface to create source
language that is usually compiled with a 3GL or 4GL language compiler.

Advantages of fifth generation languages


 These languages can be used to query the database in a fast and efficient manner.
 In this generation of language, the user can communicate with the computer system
in a simple and an easy manner.
 Programmers can use English language while interacting with the computer system.

Let’s Review
 Low level languages are machine dependent programming languages.
 Machine code does not need any interpreter or compiler to convert languages.
 Assembly languages are low level languages.
 High level programming languages are the machine independent programming
languages, which are easy to write, read, edit and understand.
 The programming languages that have features of low level and high level
programming languages are called middle level language.
 Fourth generation languages are commonly used in database programming
and scripts such as Perl, PHP, Python, Ruby, and SQL.
 AI is a branch of the computer science in which the computer system is
programmed to have human intelligence characteristics.
 Fifth generation language uses a visual or graphical development interface to
create source language that is usually compiled with a 3GL or 4GL language
compiler.

New Gateway to Computer Science Book -9


183
Translator Programs

A translator takes a program written in source language as input and converts it into
a program in target language as output. It also detects and reports the error during the
translation process. A translator is a programming language that converts a computer
program from one language to another. It takes a program written in source code and
converts it into machine code. There are several types of translator programs, each are
able to perform different tasks.
Translator translates high-level language program into a machine language that the central
processing unit (CPU) can understand. It also detects errors in the program.

Compiler
A compiler is used to convert high-level programming language to low-level programming
language. It converts the whole program at a time and reports errors detected after the
conversion. A compiler is processor-dependent and platform-dependent. But it has been
addressed by a special compiler, a cross-compiler and a source-to-source compiler. Let’s
discuss some advantages and disadvantages of the compiler:

All
Object Code
High Level Complier
(Execulable)
Source Code

Error Report

Advantages
 The whole program is validated so there are no system errors.
 The executable file is enhanced by the compiler, so it runs faster.
 Users do not have to run the program on the same machine it was created.

Disadvantages
 It is slow to execute as you have to complete the whole program.
 It is not easy to debug as errors are shown at the end of the execution.
 It works on specific machine language and architecture.

Interpreter
An interpreter is used to convert high-level programming language to low-level
programming language. It converts the program one at a time and reports errors detected

New Gateway to Computer Science Book -9


184
at once, while doing the conversion. It is more easier to detect errors than in a compiler.
An interpreter is more faster than a compiler as it immediately executes the code upon
reading the code.
It is often used as a debugging tool for software development as it can execute a single
line of code at a time. An interpreter is also more portable than a compiler.

1 line of
High Level Out
source Code Interpreter (Temporary)

Error Stop:
Error Report

Advantages
 Program can be run before it is completed so you get partial results immediately.
 You can work on small parts of the program and link them later into a whole
program.

Disadvantages
 Program is not enhanced and may encounter data errors.
 It may be slow because of the interpretation in every execution.

Assembler
An assembler is a translator used to translate assembly language to machine language. It
is like a compiler for the assembly language but interactive like an interpreter. Assembly
language is difficult to understand as it is a low-level programming language. An
assembler translates an assembly language to an even lower-level language, which is the
machine code. The machine code can be directly understood by the CPU.

Advantages
 The symbolic programming is easier to understand.
 It is easier to fix the errors.
 Efficiency in execution of program just like in a machine level language.

Disadvantages
 It is machine dependent so it cannot be used in other architecture.
 A small change in design can invalidate the whole program.
 It is difficult to maintain.

New Gateway to Computer Science Book -9


185
Let’s compare compiler, interpreter and assembler.
Compiler Interpreter Assembler
It translates high-level It temporarily executes It translates low-level
language into machine high-level language, one assembly code into
code. statement at a time. machine code.
An executable file of No executable file of An executable file of
machine code is produced. machine code is produced machine code is produced.

Error report is produced at Error message is produced One low-level language


once when entire program immediately. statement is usually
is compiled. translated into one machine
code instruction.

Let’s Review
 A translator is a programming language that converts a computer program from
one language to another.
 A translator translates high-level language program into a machine language
program.
 A compiler is a program that translates source code into object code.
 An interpreter is used to convert high-level programming language to low-level
programming language.
 An assembler is a translator used to translate assembly language to machine
language.
 An assembly language is difficult to understand as it is a low-level programming
language.

Program Development Cycle

The process of developing software, according to the desired needs of a user,


by following a basic set of interrelated procedures is known as program
development life cycle. It is a step by step process where each stage is a building block
of an effective and efficient program. When we want to develop a program using any
programming language, we follow a sequence of steps. These steps are called phases in
program development. The program development life cycle is a set of steps or phases that
are used to develop a program in any programming language. The following are the steps
in the program development life cycle.

New Gateway to Computer Science Book -9


186
Analyzing the Problem
The computer user must point out the problem, and then decide how to resolve it. In this
phase, we have to define the problem statement and we need to decide the boundaries of
the problem. In this phase we need to understand what is our requirement, what should
be the output of the problem solution. These are defined in this first phase of the program
development life cycle. Let’s summarises these steps.
 Understand the problems
 Have multiple solutions
 Select a solution
Designing the Program
Program design starts by focusing on the main goal that the program is trying to achieve.
This approach of program design is called top-bottom program design or modular
programming. The first step involves identifying main routine, which is the one of the
major activities of program. From that point, programmers try to divide various
components of the main routine into smaller parts called modules. For each
module, programmer draws a conceptual plan using an appropriate program design tool
to visualize how the module will do its assigned job. While designing the program, it
requires three steps.
 Algorithm: It is written, with step by step explanation of the solution.
 Flowchart: It is a pictorial description of an algorithm. The solution is represented
diagrammatically, for easy understanding and clarity.
 Pseudo code: It is written for the selected solutions. It uses the structured
programming constructs. The pseudo code becomes an input to the next phase.
Coding and Documentation of the Program
This phase uses a programming language to write or implement actual programming
instructions for the steps defined in the previous phase. In this phase, we construct an
actual program. That means we write the program to solve the problem using programming
languages. Coding the program means translating an algorithm into specific programming
language. The technique of programming using only well-defined control structures is
known as structured programming. The programmer must follow the language rules.
Violation of any rule causes error. These errors must be eliminated before going to the
next step.
Testing & Debugging
During this phase, we check whether the code written in previous step is solving the
specified problem or not. That means, we test the program whether it is solving the
problem for various input data values or not. We also test that whether itis providing the
desired output or not.

New Gateway to Computer Science Book -9


187
Documenting the Program
After testing, the software project is almost complete. The structure charts, pseudocodes,
flowcharts and decision tables developed during the designphase become documentation
for others who are associated with the software project. This phase ends by writing a
manual that provides an overview of the program’s functionality. It also provides
depth explanations of major program features, reference documentation of all program
commands and description of the error messages generated by the program.
Maintenance
During this phase, the program is actively used by the users. If any enhancements are
found in this phase, all the phases are to be repeated again to make the enhancements.
That means, in this phase, the solution is used by the end user. If the user encounters any
problem or wants any enhancement, we need to repeat all the phases from the starting.

Let’s Review
 The process of developing software, according to the desired needs of a user, by
following a basic set of interrelated procedures is known as Program
Development Life Cycle.
 Program Development Life Cycle is a step by step process where each stage is
a building block of an effective and efficient program.
 The computer user must figure out the problem, and then decide how to resolve
it.
 While designing the program, it requires three steps. They are algorithm, flowchart
and pseudo code.
 Coding the program means translating an algorithm into specific programming
language.
 During the maintenance phase, the program is actively used by the users.
 If any enhancements are found in the maintenance phase, all the phases are to be
repeated again to make the enhancements.

New Gateway to Computer Science Book -9


188
Assignment
1. Select the correct answer from the given options.
a. Which of the following language is directly understood by the machine?
i. Machine language ii. High level language
iii. Assembly Language iv. Fourth generation language
b. Which of the following language is difficult to understand by the user?
i. High level language ii. Fourth generation language
iii. Machine language iv. All of them
c. Which of the following is a language translator?
i.Compiler ii. Assembler iii. Interpreter iv. All of them
d. Which of the following language is used to translate assembly language into
machine language?
i. Compiler ii. Interpreter iii. Assembler iv. None of them
e. Which of the following is used to design the program?
i. Algorithm ii. Flowchart iii. Pseudo code iv. All of them
f. Which of the following is the first phase of program development cycle?
i. Testing & debugging ii. Maintenance
iii. Analyzing the problem iv. Coding and documentation
2. Fill in the blanks with suitable words.
a. A set of instructions that instruct the computer that the way the task is to be
performed is called a …………….
b. A …………….. must have the knowledge of programing language to develop a
program.
c. A ………………. is a set of commands, instructions, and other syntax use to
create a software program.
d. Machine code does not need any …………. or ………….. to convert language in
any form.
e. Assembly languages are …………….
f. ……………………….. are the machine independent programming languages,
which are easy to write, read, edit and understand.

New Gateway to Computer Science Book -9


189
g. ……………. uses a visual or graphical development interface to create source
language that is usually compiled with a 3GL or 4GL language compiler.
h. A translator translates ……………… into a machine language program that the
CPU can understand.
i. …………… is a program that translates source code into object code.
j. An assembler is a translator used to translate …………………. to machine
language.
k. The process of developing software, according to the desired needs of a user, by
following a basic set of interrelated procedures is known as ……………………..
3. State whether the given statements are true or false.
a. Computer programs are collections of instructions that tell a computer how to
interact with the user.
b. Without any programming language, you cannot communicate with the computer.
c. High level languages are machine dependent programming languages such as
binary and assembly language.
d. Machine Language does not need any translator program.
e. The programming languages that have the features of low level and high level
programming languages are called assembly language.
f. Fourth generation languages are more closer to human language than other high-
level languages.
g. AI is a branch of the computer science in which the computer system is programmed
to have human intelligence characteristics.
h. A translator is a programming language processor that converts a computer
program from one language to another.
i. A compiler is used to convert high-level programming language to low-level
programming language.
j. An assembly language is difficult to understand as it is a high-level programming
language.
4. Write appropriate technical terms for the followings.
a. The collections of instructions that tell a computer how to interact with the user,
interact with the computer hardware and process data.
b. The process of developing and implementing various sets of instructions to enable
a computer to do a certain task.

New Gateway to Computer Science Book -9


190
c. A set of commands, instructions, and other syntax used to create a software
program.
d. The machine independent programming languages, which are easy to write, read,
edit and understand.
e. It is a branch of the computer science in which the computer system is programmed
to have human intelligence characteristics.
f. A programming language processor that converts a computer program from one
language to another.
g. The process of developing software, according to the desired needs of a user, by
following a basic set of interrelated procedures.
h. During this phase, we check whether the code written in previous step is solving
the specified problem or not.
5. Answer the following questions.
a. What is a programming language? Write its types.
b. What is a low level programming language? Name some low level programming
languages.
c. Define an assembly language with its advantages.
d. What is a machine language? Write its advantages and disadvantages.
e. What is a high level programming language? Write any four features of high level
language.
f. Write down the advantages of fourth and fifth generations languages.
g. What is a translator program? Name the types of translator programs.
h. Define a compiler with its advantages and disadvantages.
i. What are assembler and interpreter?
j. Write any two advantages and disadvantages of an assembler and an interpreter.
k. What is a program development cycle? Write proper phases of program
development cycle.
Project Work
Conduct a presentation about the program development cycle in the class

New Gateway to Computer Science Book -9


191
Lesson

11 Programming Techniques

Inside the Lesson

 Introduction to programming techniques


 Algorithm with its advantages
 Characteristics of an algorithm
 Sample algorithm
 Flowchart with its advantages
 Types of flowcharts
 Symbols used in flowcharts
 Flowchart structure with lots of samples
Programming is telling a computer how it should do its job. A program is a sequence of
instructions that tell a computer how to do a task. When a computer follows the instructions
in a program, we say it executes the program. Programming is writing computer code to
create a program, to solve a problem. Programs are created to implement algorithms.
Algorithms can be represented as pseudo code or a flowchart, and programming is
the translation of these algorithms into a computer program. To tell a computer to do
something, a program must be written to tell it exactly what to do and how to do it. If
an algorithm is designed, the computer program will follow this algorithm, step-by-step,
which will tell the computer exactly what it should do. In this lesson we are going to
discuss about the programming techniques.

Algorithm

An algorithm is a set of instructions, which is also called a procedure or a function that


is used to perform a certain task. An algorithm is defined as a step-by-step procedure or
method for solving a problem by a computer in a finite number of steps. It is a sequence
of instructions that when executed in the specified sequence, gives the desired results.
Steps of an algorithm definition may include branching or repetition depending upon
what problem the algorithm is being developed for. While defining an algorithm steps are
written in human understandable and are language and independent of any programming
language. We can implement it in any programming language of our choice.In order
to qualify to be an algorithm, a sequence of instructions must possses the following
characteristics.

New Gateway to Computer Science Book -9


192
 Each instruction should be clear and definite.
 Each instruction should be executed in a finite number of times.
 No instruction should be repeated infinitely.
 After executing the instructions, the desired results are obtained.
Algorithms can be expressed in many different notations, including natural languages,
pseudocode, flowcharts and programming languages.

Advantages
 It is a step wise step representation of a solution to a given problem, which makes
it easy to understand.
 An algorithm uses a definite procedure.
 It is not dependent on any programming language.
 It is easy to understand for anyone even without the knowledge of programming
languages.
 Every step in an algorithm has its own logical sequence so it is easy to debug.
 The problem is broken down into smaller pieces or steps so that it is easier for
a programmer to convert it into an actual program.

Characteristics of an Algorithm
A good algorithm must have the following characteristics:
 Input: An algorithm must have well defined inputs.
 Output: An algorithm must have well defined outputs, and should match with the
desired output.
 Feasibility: An algorithm must be terminated after a finite number of steps.
 Independent: An algorithm must have step-by-step directions which must be
independent from programming code.
 Unambiguous: An algorithm must be unambiguous and clear. Each of their steps
and input/outputs must be clear.
Algorithm Samples

Sample 1: Write an algorithm to add any two numbers entered by the user.
Step 1: Start
Step 2: Declare the variables num1, num2 and sum.
Step 3: Read the values of num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.

New Gateway to Computer Science Book -9


193
Sum = num1+num2
Step 5: Display sum
Step 6: Stop

Sample 2: Write an algorithm to calculate the interest of amount.


Step 1: Start
Step 2: Read amount,
Step 3: Read years,
Step 4: Read rate,
Step 5: Calculate the interest with formula "Interest=Amount*Years*Rate/100"
Step 6: Print interest
Step 7: Stop

Sample 3: Write an algorithm to multiply the two numbers x and y and


display the result in z.
Step 1: Start
Step 2: Declare three integers x, y & z
Step 3: Define the values of x & y
Step 4: Multiply the values of x & y
Step 5: Store the output of step 4 in z variable.
Step 6: Print z
Step 7: Stop

Sample 4: Write an algorithm to determine whether the given number is even


or odd.
Step 1: Start
Step 2: Read the number N,
Step 3: Set remainder as N module 2,
Step 4: If remainder is equal to 0 then number N is even, else number N is odd,
Step 5: Print the output.
Step 6: Stop

Sample 5: Write an algorithm to find the largest number among three different
numbers.
Step 1: Start
Step 2: Declare variables a,b and c.

New Gateway to Computer Science Book -9


194
Step 3: Read variables a,b and c.
Step 4: If a>b
If a>c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop

Let’s Review
 An algorithm is defined as a step-by-step procedure or method for solving a
problem by a computer in a finite number of steps.
 Algorithms can be expressed in many different notations, including natural
languages, pseudocode, flowcharts and programming languages.
 Every step in an algorithm has its own logical sequence so it is easy to debug.
 An algorithm must be terminated after a finite number of steps.
 An algorithm must have step-by-step directions which is independent of any
programming code.

Flowchart

A flow chart is a graphical representation of a system that details the sequencing


of steps required to create an output. A flow chart is comprised of different
symbols and control lines to connect those symbols. It uses a set of basic
symbols to represent various functions, and shows the sequence and
interconnection of functions with lines and arrows. Each flow chart is concerned
with one particular process or system. It begins with the input of data
into the system and traces all the procedures needed to convert the input
into its final output form. Flow charts are an important tool for the improvement of
processes. By providing a graphical representation, they help project teams to identify
different elements of a process and understand the interrelationships among various steps.

New Gateway to Computer Science Book -9


195
Flowcharts are extremely useful in programming because it simplifies the complicated
algorithm and converts it into the understandable pictorial representation.With the help
of the flowchart, the application designer can easily separate different components of the
process.
Advantages
 The flowchart is a good way of conveying the logic of the system.
 It facilitates the analysis of the problem.
 It provides a proper documentation.
 Easy identification of the errors and bugs.
 It directs the program development.
 Maintenance of the program becomes easy.

Let’s Review
Differences between algorithm and flowchart
 An algorithm involves a combination of sequential steps to interpret the logic of
the solutionwhereas a flowchart is the pictorial illustration of the algorithm.
 A flow chart is more understandable as compared to the algorithm.
 The algorithm is written in a language that can be perceived by humans.
The flowchart is made up using different shapes and symbols.
 There are no stringent rules implemented in the algorithms while the flowchart
is abided by predefined rules.
 Errors are easily detected in the algorithm as compared to the flow charts.
 Flow charts are simple to create but the construction of the algorithm is complex.

Types of Flowcharts
System Flowcharts
System flowcharts display how data flow inside a system and the execution
of decisions to control events. It is the graphical representation of the flow of data in the
system, and represents the work process of the system. Various symbols are used in the
flowchart to designate specific actions. System flowchart is the graphical representation
of the flow of data in the system, and represents the work process of the system.

Program Flowcharts
Program flowchart is a diagram which uses a set of standard graphic symbols to represent
the sequence of coded instructions. It is a great tool to improve the work efficiency. There
are four basic symbols in a program flowchart. They are start, process, decision and end.
Each symbol represents a piece of code written for the program.

New Gateway to Computer Science Book -9


196
The advantages of program flowchart are as follows:
 Program flowchart can help programmers to find the errors in the process before
carrying out the process.
 It works as a blueprint when analyzing the systems and developing programs, which
makes coding more efficient.
 It improves programmers’ efficiency in maintaining the operating program.
 With the help of program flowchart, communicating the logic of a system to all
concerned gets much easier.

Symbols Used in Flowchart


Different symbols are used for different purposes in a flowchart. The table below
describes all the symbols that are used in making flowchart.
Symbol Purpose Description
Used to represent start and end of
Terminal(Stop/Start) Box
flowchart.

Input/Output Box Used for input and output operation.

Used for arithmetic operations and


Processing Box
data manipulations.
Used to represent the operation in
Decision Box which there are two alternatives, true
and false.

On page Connector Used to join different flow line

Used to connect flowchart portion on


Off page Connector
different page.
Used to represent a group of state-
Predefined Process/Func-
ments performing one processing
tion
task.
Used to indicate the flow of logic by
Flow lines
connecting symbols.

New Gateway to Computer Science Book -9


197
Flowchart Structure
Sequence Structure
The sequence control structure is defined as the straight forward execution of one
processing step after another. Sequence structure is a series of actions or steps performed
in sequential order. The sequence of operations carry input, process and output steps.
The flow of logic is from top to bottom in this structure. The general form of a sequence
structure is as given below.

start

get first number

get second number

total= first number+


second number

display "the sum two


number is"; total

end

Selection Structure
Selection structure is used in
flowchart to determine which
False/No True/Yes
particular step or set of steps is to Raining
be executed. This is also called a
‘decision structure’. A selection
statement can be used to choose
a specific path dependent on a Put on Take
condition. suncream umbrella

The selection control structure


can be defined as the presentation
of a condition, and the choice

New Gateway to Computer Science Book -9


198
between two actions depending on whether the condition is true or false. The general
form of the selection structure is given at the right hand side.

Repetition Structure
When a program goes through a loop for certain False
times repeatedly, it is known as repetition. Condition
Repetition is the process of repeating one or more
steps in a process. The branching decision is based
on a condition at the time that the branching test
True
is performed. The condition is normally based on
the value of a single variable known as the control
variable. The steps to be repeated are referred Process
to as the loop body.The step at which the body
starts is known as the loop entrance and the step
at which the test to branch back fails is known as
the loop exit.

Let’s Review
 A flow chart is a graphical representation of a system that details the sequencing
of steps required to create an output.
 Flow chart uses a set of basic symbols to represent various functions, and
shows the sequence and interconnection of functions with lines and arrows.
 Each flow chart is concerned with one particular process or system.
 Flowcharts are extremely useful in programming because it simplifies the
complicated algorithm and converts it into the understandable pictorial
representation.
 With the help of the flowchart, the application designer can easily separate
different components of the process.
 There are two types of flowcharts. They are system flowcharts and program
flowchart.
 System flowchart is the graphical representation of the flow of data in the system,
and represents the work process of the system.

New Gateway to Computer Science Book -9


199
Flowchart Samples

Sample 1: Algorithm and Flowchart to find the sum of two numbers.


Start
Algorithm
Step-1: Start Input value
Step-2: Input first number A of A

Step-3: Input second number B Input value


Step-4: SUM = A + B of B

Step-5: Display SUM


SUM = A+B
Step-6: Stop
Print SUM

Stop

Sample 2 : Algorithm and Flowchart to convert temperature from


Celsius to Fahrenheit.
C : Temperature in Celsius Start

F: Temperature in Fahrenheit
Input value
Algorithm of C
Step-1: Start
Step-2: Input temperature in Celsius C F = (9.0/5.0 × C)+ 32
Step-3: F = (9.0/5.0 × C)+ 32
Step-4: Display temperature in Fahrenheit F Print F
Step-5: Stop
Stop

New Gateway to Computer Science Book -9


200
Sample 3: Algorithm and Flowchart to find the Area and Perimeter of Square.
L: Side Length of Square
Start
Area : Area of Square
Algorithm
Input value
Step-1: Start of L
Step-2: Input Side Length of Square L
Area = L × L
Step-3: Area = L × L
Step-4: PERIMETER = 4 × L PERIMETER
Step-5: Display AREA, PERIMETER
=4×L

Step- 6: Stop Print AREA,


PERIMETER

Stop

Sample 4 : Algorithm and Flowchart to find Area and Perimeter of Rectangle.


L: Side Length of Rectangle
Start
B: Breadth of Rectangle
Area: Area of Rectangle Input value
Perimeter : Perimeter of Rectangle of L, B

Algorithm
Area = L × B
Step-1: Start
Step-2: Input Length and breadth L, B PERIMETER
= 2 × ( L+B:
Step-3: Area = L × B
Print AREA,
Step-4: PERIMETER = 2 × ( L+B)
PERIMETER
Step-5: Display AREA, PERIMETER
Step- 6: Stop Stop

New Gateway to Computer Science Book -9


201
Sample 5 :Algorithm and Flowchart to find the smallest number between two numbers.
Algorithm
Step-1: Start
Step-2: Input two numbers
NUM1, NUM2
Step-3: IF NUM1 < NUM2 THEN
PRINT smallest is NUM1
ELSE
PRINT smallest is NUM2
ENDIF
Step-4: Stop

Start

Input Value
of NUM1

Input Value
of NUM2

No If Yes Print smallest


Print smallest NUM1 < NUM2
is NUM2 is NUM1

Stop

New Gateway to Computer Science Book -9


202
Sample 6 : Algorithm and Flowchart to find the largest of three numbers .
Algorithm
Step-1: Start
Step-2: Read three numbers A, B, C
Step-3: BIG = A
Step-4: IF B > BIG THEN
BIG = B
Start
ENDIF
Step-5: IF C > BIG THEN
Input A, B, C
BIG = C
ENDIF
Step- 6: Write BIG BIG = A
Step- 7: Stop

is Yes
B > BIG BIG = B

No

is Yes
C > BIG BIG = C

No

Write BIG

Stop

New Gateway to Computer Science Book -9


203
Sample 7 : Algorithm and Flowchart to find Even number between 1 to 50.
Algorithm
Step-1: Start
Step-2: I = 1
Step-3: If ( I > 50) THEN
Start
GO TO step 7
Step-4: IF( I mod 2 = 0) THEN
Display I Read N

ENDIF
Step-5: I = I + 1
D=1
Step- 6: GO To Step 3

Step- 7: Stop
If No
Stop
CTRL<N

Yes

If Yes
(N mod D=0) Print D

No

D = D+ 1

Stop

New Gateway to Computer Science Book -9


204
Sample 8 : Algorithm and Flowchart to find print the multiplication table of a number.
Algorithm
Step-1: Start
Step-2: Input value of NUM
Step-3: I = 1
Step-4: IF( I > 10 ) = 0) THEN
GO To Step 9
ENDIF
Step-5: PROD = NUM* I
Step- 6: WRITE I "X" NUM " = " PROD Start
Step- 7: I = I+1
Step- 8: Go to step 4
I=1
Step- 9: Stop

is Yes
I > 50

No

Yes Print
IF(I mod 2 = 0)

No

I=I+1

Stop

New Gateway to Computer Science Book -9


205
Sample 9 : Algorithm and Flowchart to find all the divisor of a number.
Algorithm
Start
Step-1: Start
Step-2: Read number N Input value
of NUM
Step-3: D = 1
Step-4: WHILE (D<N) I=1

DO
IF (N mod D = 0) THEN is 1 > 10

PRINT D No
ENDIF PROD = NUM*1
D = D+1

Step-5: Stop WRITE I "X" NUM


"=" PROD

I=I+1

Stop

Let’s Review
 There are four basic symbols in a program flowchart. They are start, process,
decision and end.
 Program flowchart can help programmers to find the bug in the process
before carrying out the task.
 The sequence control structure is defined as the straight forward execution of one
processing step after another.
 Selection structure is used in flowchart to determine which particular step or set of
steps is to be executed.
 When a program goes through a loop for certain times repeatedly, it is known as
repetition which is the process of repeating one or more steps in a process.
 The step at which the body starts is known as the loop entrance and the step at
which the test to branch back fails is known as the loop exit.

New Gateway to Computer Science Book -9


206
Assignment
1. Fill in the blanks with suitable words.
a. An …………… is defined as a step-by-step procedure or method for solving a
problem by a computer in a finite number of steps.
b. Every step in an ……………. has its own logical sequence so it is easy to debug.
c. An ………….. must have step-by-step directions which is independent of any
programming code.
d. A ……………… is more understandable as compared to the algorithm.
e. There are no stringent rules implemented in the algorithms while the flowchart
is abided by …………. rules.
f. A flow chart is a ……………. representation of a system that details the sequencing
of steps required to create output.
g. Each flow chart is ………………… with one particular process or system.
h. There are two types of flowcharts. They are ………………….. and program
flowchart.
i. There are four basic symbols in a program flowchart they are start, process
, ………. and ……..….
j. ………….. is used in flowchart to determine which particular step or set of steps
is to be executed.
2. State whether the given statements are true or false.
a. Algorithms can be expressed in many different notations, including natural
languages, pseudo code, flowcharts and programming languages.
b. An algorithm involves a combination of sequential steps to interpret the logic of
the solution.
c. The algorithm is written in a language that can be perceived by humans.
d. The algorithm is made up using different shapes and symbols.
e. Errors and bugs are very difficult to detect in the algorithm as compared to the
flow charts.
f. Flow charts are simple to create but the construction of the algorithm is complex.
g. With the help of the flowchart, the application designer can easily separate
different components of the process.

New Gateway to Computer Science Book -9


207
h. Program flowchart is the graphical representation of the flow of data in the
system, and represents the work process of the system.
i. The sequence control structure is defined as the straight forward execution of one
processing step after another.
j. The step at which the body starts is known as the loop entrance and the step at
which the test to branch back fails is known as the loop entrance.
3. Answer the following questions.
a. Define algorithm with its characteristics.
b. Write any four advantages of using an algorithm.
c. Define flowchart with its advantages.
d. What are the types of flowchart? Define each in short.
e. Draw the symbols used in flowchart.
f. What is a sequence structure in a flowchart?
g. Define selection and repetition structure with proper diagram.
4. Write an algorithm for the followings.
a. To add any three numbers entered by the users.
b. To calculate the simple interest.
c. To find the product of any three numbers.
d. To display whether the entered number is divisible by 3 or not.
e. To display the smallest number among three different numbers.
5. Draw a flowchart for the followings.
a. To find the product of any three numbers.
b. To convert the temperature from Celsius into Fahrenheit.
c. To find the area of 4 walls.
d. To find the area and perimeter of a square.
e. To find the even numbers from 1 to 100.
f. To display the multiplication table of any given number.

New Gateway to Computer Science Book -9


208
Lesson

12 Programming in QBASIC

Inside the Lesson

 Introduction to Qbasic
 Features of Qbasic and starting Qbasic
 Qbasic Interface
 Elements of Qbasic Programming
 Qbasic Operators
 Qbasic Expressions

QBasic is a high level programming language developed by Microsoft


Corporation for use in the MS-DOS operating system in 1985. It is the successor of
earlier version of BASIC (Beginners All-purpose Symbolic Instruction Code). It is a
programming language for beginners because of its in-built commands, simple structure
and flexibility. It is also called a modular programming language where program
is divided in different modules or procedures. It uses English like keywords and
mathematical symbols to write a program. QBAISC screen has two types of windows
they are Program Window and Immediate Window. Program window is the upper
window which is titled as ‘Untitled’ where we can write programs. To see the output
of the statements written in this window, we have to press Shift + F5 key. Like this,
immediate window is the lower window which is titled as ‘Immediate’. It is the window to
test commands, expressions, etc. When we press the Enter key, it displays the output on
the screen.

Features of QBASIC

 It is simple, easy to learn and understand.


 It automatically checks syntax.
 It allows you to divide large programs into modules.
 It has a dynamic program debugging feature.
 It supports local and global variables.

New Gateway to Computer Science Book -9


209
Starting QBASIC

 Turn on your PC and load an operating system.


 Locate the QBASIC folder and double click on it.
 Double click on QBASIC.EXE file to open the Qbasic editor screen.
 Now, you can get the welcome screen as below.

 Press Esc key to clear the dialogue box.

 After this, you are ready to work with Qbasic programming.

New Gateway to Computer Science Book -9


210
Let’s Review
 QBasic is a high level programming language developed by Microsoft Corporation.
 BASIC is a programming language for beginners because of its in-built
commands, simple structure and flexibility.
 QBASIC is also called a modular programming language where program is
divided in different modules or procedures.
 QBAISC screen has two types of windows. They are Program Window and
Immediate Window.
 Program window is the upper window which is titled as ‘Untitled’.
 Immediate window is the lower window which is titled as ‘Immediate’.

QBASIC Interface

File Menu
New:This menu clears the current program.
Save: Save the current program in the storage location.
Open: It loads the program from the storage location.
Save as: Save the program file under new name.
Print: Print the selected text or entire program.
Exit:It helps to quit from QBASIC working program.

Edit Menu:The menu provides most of the operations for the Qbasic editor
such as opening a file, saving a file, and so many others. The details are given below.
Cut: It removes the selected text and stores it in the clipboard.
Copy: Copies the text instead of removing it.
Paste: Adds the text in the clipboard to the current position of the cursor.
Clear: Removes the text without storing it to the clipboard.
New Sub: Enables you to create a new subroutine.
New Function: Enables you to create a new function.

View Menu
SUBs: It shows the list of current subroutines and functions.
Split: Displays the contents of the current program in two windows. If the window
is already split, this hides the second window.
Output Screen: Shows the Qbasic output screen.

New Gateway to Computer Science Book -9


211
Search Menu
Find: It allows you to search for a string of text in the program.
Repeat Last Find: Continues the previous search operation.

Change: Replaces each instance of a string with another string.

Run Menu
Start: Executes the current program.
Restart: Starts from the beginning.

Continue: Continues execution at the current position.

Debug Menu
Step: Processes the next command.
Procedure Step: Processes the next command, but does not show QBasic going
inside a subroutine or function.
Trace On: Shows the command that is being executed while the program is
running.
Toggle Breakpoint: Sets or removes a breakpoint.
Clear All Breakpoints: Removes all breakpoints in the program.
Set Next Statement: Allows you to continue execution at the specified line

Elements of Qbasic Programming

QBASIC programming has some elements which are required to work with a program.
The element required to construct a QBASIC program consists of a set of characters,
keywords, constants, variables, operators and expressions. Let’s discuss them in details.

Character Set
The QBASIC Character Set consists of alphabets (both small and capital),
numbers (0 to 9) and special characters (; , = , + , / , ^ , (), % , $ , < , > , #). These
special characters have their own meaning and function. A set of characters
that are allowed to use in QBASIC is known as the QBASIC Character Set.
QBASIC keywords and variables are formed by using the characters defined in
the QBASIC Character Set.

New Gateway to Computer Science Book -9


212
Keyword
Keywords are those words which have special meanings in QBASIC. Keywords are
formed by using characters of QBASIC Characters Set. Keywords are statements,
commands, functions (built in functions) and names of operators. The keywords are also
called reserved words. Some reserved words are CLS, REM, INPUT, LET, PRINT, FOR,
DO, SELECT, MID$, ASC, SQR, LEN, LEFT$, TIME$, INT, etc.

Let’s Review
 The element required to construct a QBASIC program consists of a set of
characters, keywords, constants, variables, operators and expressions.
 The QBASIC Character Set consists of alphabets (both small and capital),
numbers (0 to 9) and special characters (; , = , + , / , ^ , (), % , $ , < , > , #).
 Keywords are those words which have special meanings formed by using
characters of QBASIC characters set.
 The keywords are also called reserved words.
 Some reserved words are CLS, REM, INPUT, LET, PRINT, FOR, DO,
SELECT, MID$, ASC, SQR, LEN, LEFT$, TIME$, INT, etc.

Constants
Constants are defined as the values used in programs that do not change during the
execution of program. The constant data may be a letter, words, numbers, or special
characters. A constant can be stored in a variable when it is required to use in more
than one statement or expression. CONST statement is used to declare the constants
in QBASIC programming. For Eg: CONST pi=3.14. In QBASIC, these constants are
grouped into two main categories. They are sting constant and numeric constant.
String Constant
Sting Constant is a letter, words, numbers, combination of letters with numbers or special
characters enclosed in double quotes. Mathematical operations cannot be performed
on String Constants. “A”, “SHUBHARAMBHA”, “ROLL NO:10”, “ !Welcome to
Kathmandu !”, etc. are some examples of Sting Constants.
Numeric Constant
Numeric Constant refers to a number. A number with or without decimal point is a numeric
constant. Separators are not allowed to use in numeric constant. Numeric data should not
be enclosed in double quotes. Mathematical operations and logical operations can be
performed on the numeric constants. 110, 205.40, 420, 65503, etc. are some examples of
numeric constants. Numeric Constants may be integer, long integer, single precision or
double precision.

New Gateway to Computer Science Book -9


213
 Integer: Integer is whole number between -32768 to 32767.
 Long Integer: Long Integer is a large range of whole number.
 Single Precision: Single Precision is seven digit or less than seven digit positive or
negative number that contain decimal point. Single Precision can be in the
exponential form using E or with a trailing exclamation point. (!). 612, 78.65, 1.2
E-06 and 12345.678! are some examples of single precision constants.
 Double Precision: Double Precision is 17 digit or less than 17 digit positive or
negative numbers that contains decimal point. Double Precision can be in the
exponential form using D or with trailing hash sing (#). 9999.99D-12, 2345.786#
and 3456.7 are some examples of double precision constants.

Understanding literal constants and symbolic constants


A literal constant is just a value. For example, 50 is a literal constant. It does not have a
name; it is just a literal value. You cannot make the value 50 to represent any other value.
The value of 50 is always 50. You cannot assign a new value to 50.
Symbolic Constants assign a name to a constant value. The CONST keyword is followed
by a type, an identifier, the assignment operator (=), and the value to assign to the constant.
This is similar to declaring a variable except that you start with the keyword CONST and
symbolic constants must be initialized.

Let’s Review
 Constants are defined as the values used in programs that do not change during the
execution of program.
 CONST statement is used to declare the constants in QBASIC programming.
 Sting constant is a letter, words, numbers, combination of letters with numbers or
special characters enclosed in double quotes.
 A number with or without decimal point is a numeric constant. Separators are not
allowed to use in numeric constant.
 Mathematical operations and logical operations can be performed on the numeric
constants.
 A literal constant is just a value. It does not have a name; it is just a literal value.
 Symbolic Constants assign a name to a constant value.

Variable
A variable is a quantity whose value changes during the execution of a program.
It is a quantity which can store value in computer memory. A program needs data to

New Gateway to Computer Science Book -9


214
produce information. A program can use data only when data are stored in the computer
memory (RAM). In a computer memory, there may be many data. So, you need to tell the
computer to use only those data which you want to use in a program. This is possible if
you assign a name to the place where you have stored data. Simply, we can say, a variable
is an entity that stores data needed to be used in a program. Each program defines different
number of variables. A value of a variable can be changed during the execution of the
program. In QBASIC, variables care grouped into two main categories. They are numeric
variable and string variable.

Numeric Variable
Numeric variable has a number as its value. Salary!, Age%, Mark, Number1, Number2,
FirstNum, RollNumber, etc., are examples of Numeric variables. A numeric variable can
be Integer, Long integer, Single precision or Double Precision variables.
 An integer variable can store only an integer number. Its type declaration sign is
percentage (%).
 A long integer variable can store a large range of whole number.
 A single precision variable can store a whole number as well as number with
decimal. Its type declaration sign is exclamation sign (!).
 A double precision variable also stores a whole number as well as number with
decimal point. Its type declaration sign is hash (#).
String Variable
A string variable stores sting data. Its type declaration sign is dollar ($).Naam$, Address$,
Bookname$, GameName$, etc., are the examples of sting varibales.
Declaration of Variable
Variables in QBASIC can be declared in two different ways. They are explained below.
Implicit Declaration: Implicit declaration is the default method of declaring
variable in QBASIC. In this declaration, type declaration character is used in an assignment
statement. Using this method, we can declare variable at the time of assigning value to
the variable. We should take care of type declaration symbol during the declaration and
use of variable.
Explicit Declaration: Explicit declaration of variable is done before the use
of variables. In this declaration, a value is not assigned to the variable. DIM
statement is used to declare variables explicitly in QBASIC. Eg: DIM a AS
INTEGER, DIM b AS STRING, etc. It’s not mandatory to use type declaration
symbol while declaring variables explicitly. Also, as all variables are declared at
the top, programmers are less prone to use same variable name for different purposes.

New Gateway to Computer Science Book -9


215
Rules for Naming a Variable
 Variable names can have maximum of 40 characters.
 Variable names can have alphabets, numbers and decimal points.
 A variable name must begin with a letter.
 Variable names cannot be reserved words.
 Variable names may be ended with type declaration characters like $, %, &, !, and #.

Let’s Review
 A variable is a quantity whose value changes during the execution of a program.
 Numeric variable has a number as its value. Salary!, Age%, Mark, Number1,
Number2, FirstNum, RollNumber, etc., are the examples of Numeric Variables.
 A numeric variable can be Integer, Long integer, Single precision or Double
precision variables.
 A double precision variable also stores a whole number as well as number
with decimal point. Its type declaration sign is hash (#).
 A string variable stores sting data. Its type declaration sign is dollar ($).
 Implicit declaration is the default method of declaring variable in QBASIC.
 Explicit declaration of variable is done before the use of variables. In this
declaration, a value is not assigned to the variable.
DIM statement is used to declare variables explicitly in QBASIC.
 Variable names can have maximum 40 characters.

QBASIC Operators

Operators are the symbols that indicate the type of operation that has to be performed on
the data or on the values of variables.There are four types of operators in QBASIC. They
are Arithmetic Operators, Relational Operators, Logical Operators and Sting Operators.

Arithmetic Operators
Arithmetic Operators are used to perform mathematical calculations like addition,
subtraction, division, multiplication and exponential. The following table shows arithmetic
operators used in QBASIC.

New Gateway to Computer Science Book -9


216
Operation Operator Example Output
Addition + Sum = 3 + 4 Sum = 7
Subtraction - Diff = 10-5 Diff = 5
Multiplication * Product = 10*10 Product = 100
Floating Point Division / Div = 5/2 Div = 2.5
Integer Division \ Div = 11\5 Div = 2
Exponential ^ Exp = 2 ^ 5 Exp = 32
Modulus Division Mod Mod = 5 MOD 2 Mod = 1
Relational Operators
Relational operators are used to perform comparisons on two values of same type. A
comparison of sting data with numeric data cannot be done. The comparison of sting data
is done on the basis of ASCII value. The result of comparison is either true or false. The
following table shows the relational operators used in QBASIC

Name of operator Relation Example


= equal to 5 = 5 , A = B , A$=B$
> greater than 10>5, A>B
< less than 5<10, B<A
>= greater than or equal to 10>=5, A>=B
<= less than or equal to 5<=10, B<=A
<> not equal to 6<>5 , A<>D

Logical Operators
Logical Operators combine two or more relational expressions to evaluate a single value
as True or False. The result of evaluation is used to make decisions about the program
flow. The commonly used logical operators in QBASIC are AND, OR and NOT.
AND Operator
AND operator returns ‘True’ when all the results returned from individual relational
expressions are ‘True’ otherwise it returns ‘False’.The Truth Table of AND operator is
given below.

Input A Input B Output A AND B


False False False
False True False
True False False
True True True

New Gateway to Computer Science Book -9


217
OR Operator
OR Operator return ‘True’ if any one of the relational expressions returns ‘True’. If all
the relational expressions returns ‘False’ then only the combined result returned by OR
operator will be ‘False’.The Truth table of OR operator is as given below.

Input A Input B Output A OR B


False False False
False True True
True False True
True True True

NOT Operator
NOT Operator operates on one operand and returns ‘True’ if the logical operation returns
‘False’. The NOT truth table is as given below

Input A Output NOT A


False True
True False

Let’s Review
 Operators are symbols that indicate the type of operation that has to performed
on the data or on the values of variables.
 There are four types of operators in QBASIC. They are arithmetic operators,
relational operators, logical operators and sting operators..
 Arithmetic operators are used to perform mathematical calculations like addition,
subtraction, division, multiplication and exponential.
 Relational operators are used to perform comparisons on two values of same type.
 Logical operators combine two or more relational expressions to evaluate a single
value as True or False.
 AND operator returns ‘True’ when all the results returned from individual
relational expressions are ‘True’ otherwise it returns ‘False’.
 OR operator returns ‘True’ if any one of the relational expressions returns ‘True’.
 NOT operator operates on one operand and returns ‘True’ if the logical operation
returns ‘False’.

String Operators (+)


A string expression consists of string constant, string variables and other string
expressions combined by string operators. There are two classes of string operations.

New Gateway to Computer Science Book -9


218
They are concatenation and string function. The act of combining two strings is called
concatenation. The plus (+) symbol is the concatenation operator for string. For example,
the following program fragment combines the string variables A$ and B$ to produce the
value ShubharambhaPublication.
A$ = “Shubharambha” : B$ = “Publication”
Print A$+B$
Print “Our” + A$+B$
The output is :
Form Print A$+B$: ShubharambhaPublication
Print “Our” + A$+B$: OurShubharambhaPublication
Assignment Operators (=)
The assignment operator evaluates an expression on the right of the expression and
substitutes it to the value or variable on the left of the expression. For Example : x = a +
b, Here the value of a+b is evaluated and substituted to the variable x.

Expressions

An expression is the combination of operators, constants and variables that is evaluated


to get a result. The result of the expression is string data, numeric data or logical value and
can be stored in a variable. Algebraic expression cannot be used directly in programming.
It must be converted into QBASIC expression. Let’s discuss some algebraic and QBASIC
expressions in table below.

Algebraic Expression Qbasic Expression


a2 + 2ab + b2 A^2 + 2*a*b+b^2
x2 + y2
z2 (x^2 + y^2)/z^2

2x + 3y – 4c 2*x + 3*y – 4*c


2�(r+h) 2*3.141*r*(r+h)
ax2 + bx + c a*x^2 +b*x +c
Arithmetic Expression
An arithmetic expression is a syntactically correct combination of numbers, operators,
parenthesis, and variables. Arithmetic expressions are the parts of statements, so they
must follow syntax rules in order to be correct.

New Gateway to Computer Science Book -9


219
Logical (Boolean Expression)
A Boolean expression is a logical statement that is either TRUE or FALSE. Boolean
expressions can compare data of any type as long as both parts of the expression have the
same basic data type. You can test data to see if it is equal to, greater than, or less than
other data. A Boolean expression can consist of Boolean data, such as the following:
 BOOLEAN values (YES and NO, and their synonyms, ON and OFF, and TRUE and
FALSE).
 BOOLEAN variables or formulas.
 Functions that return BOOLEAN results.
 BOOLEAN values calculated by comparison operators.
String Expression
Any text to be written to a file or displayed on the screen is created with a string expression.
String expressions are created from a combination of the following:
 Character strings
 Concatenation operators "$"
 Numeric Expressions
 CHAR( )
A string expression must begin with a concatenation operator ($) or with a string constant
in quotes (i.e., "..."). The concatenation operator combines components together, and
must be between all components of a string expression.

Let’s Review
 A string expression consists of string constant, string variables and other string
expressions combined by string operators.
 The assignment operator evaluates an expression on the right of the expression
and substitutes it to the value or variable on the left of the expression.
 An expression is the combination of operators, constants and variables that is
evaluated to get a result.
 A Boolean expression is a logical statement that is either TRUE or FALSE.
 Boolean expressions can compare data of any type as long as both parts of the
expression have the same basic data type.
 A string expression must begin with a concatenation operator ($) or with a string
constant in quotes (i.e., "...").
 The concatenation operator combines components together, and must be between
all components of a string expression.

New Gateway to Computer Science Book -9


220
Assignment
1. Fill in the blanks with suitable words.
a. QBasic is a ………….programming language developed by Microsoft
Corporation.
b. QBASIC is also called a …………. language where program is divided in
different modules or procedures.
c. Immediate window is the lower window which is titled as ‘……………..’.
d. The QBASIC ………. consists of alphabets (both small and capital), numbers (0
to 9) and special characters (; , = , + , / , ^ , (), % , $ , < , > , #).
e. …………….. are those words which have special meanings that are formed by
using characters of QBASIC Characters Set.
f. A ……………. is a quantity whose value changes during the execution of a
program.
g. A numeric variable can be Integer, Long Integer, Single Precision or ……………
variables.
h. ……………. is the default method of declaring variable in QBASIC.
i. ……………. can have maximum 40 characters.
j. ……………. are used to perform mathematical calculations like addition,
subtraction, division, multiplication and exponential.
k. An ……………… is the combination of operators, constants and variables that is
evaluated to get a result.
l. A ……………….. is a logical statement that is either TRUE or FALSE.
2. State whether the given statements are true or false.
a. QBAISC screen has two types of windows. They are Program Window and System
Window.
b. The keywords are also called library words.
c. Constants are defined as the values used in programs that change during the
execution of program.
d. A number with or without decimal point is a numeric constant.
e. Mathematical operations and logical operations can be performed on the numeric
constants.
f. Symbolic constants assign a name to a string constant.
g. A single precision variable also stores a whole number as well as number with
decimal point. Its type declaration sign is hash (#).

New Gateway to Computer Science Book -9


221
h. Explicit declaration of variable is done before the use of variables.
i. DIM statement is used to declare variables explicitly in QBASIC.
j. There are two types of operators in QBASIC. They are arithmetic operators and
relational operators,
k. Relational operators are used to perform comparisons on two values of same type.
l. Logical operators combine two or more relational expressions to evaluate a single
value as True or False.
m. AND operator return ‘True’ if any one of the relational expressions returns ‘True’.
n. An arithmetic expression is a syntactically correct combination of numbers,
operators, parenthesis, and variables.
o. The concatenation operator combines components together, and must be between
all components of a string expression.
3. Answer the following questions.
a. What is QBASIC programming? Write its features.
b. What are the various options with edit menu of QBASIC screen? List out it in
details.
c. What are the elements of QBASIC programming? Define each in short.
d. What is a variable? Define its types.
e. What are ways of declaring variables? Write in short.
f. Write down the rules for naming a variable.
g. What are the operators? Write its types in detail.
h. Prepare a truth table for AND, OR and NOT operator.
i. What is a string operator? Write with examples.
j. What is an expression? Write about an arithmetic and a Boolean expression.
4. Convert the following algebraic expression into QBASIC expression.

a. a2 + 2ab + b2

b. x + y
2 2

z2
c. 2x + 3y – 4c
d. 2�(r+h)
e. ax2 + bx + c

New Gateway to Computer Science Book -9


222
Lesson

13 QBASIC Statements

Inside the Lesson

 Introduction to Qbasic statement


 Explanation of Qbasic statements
 REM, CLS, LET, INPUT, PRINT, END
 PRINT USING, LINE INPUT, LPRINT
 LPRINT USING, READ….DATA
 RESTORE, LOCATE, SWAP

A statement is a computer instruction written in a source language, which is converted


into one or more machine code instructions by a compiler. The command or the set of
instructions in the QBASIC is called a statement. Statements are first stored in the memory
and executed only when the command is given. Qbasic statements are classified into
two statements. They are executable and non-executable. Executable statement specifies
actions where as non-executable statements specify characteristics, arrangements and
initial values of data.
The commonly used QBASIC statements are: LET, PRINT, INPUT, CLS, END, REM,
etc. Let’s discuss various Qbasic statements.

QBASIC Statements

REM statement: REM is a non-excutable statement that is used to insert explanatory


remarks for the program that we are writing. It can be used at any part of the program. The
general format of REM statement is as given below.

REM <remark> Here, remark may be any statement or phrase to define the program.
CLS Statement: This statement is used to clear the previous output from the display
screen and makes the screen blank. This command is given before the starting of any new
program. The general format of CLS statement is as given below.
<CLS>

New Gateway to Computer Science Book -9


223
LET Statement: This statement is used to assign the value in the variable. It is also called
an assignment statement. This is also an optional statement is Qbasic. The general format
of CLS statement is as given below.
LET <variable> = <expression> Here, variable is the name of a numeric or string variable
which receives the value and expression in a numeric or string expression whose value
will be assigned to a variable.
INPUT Statement: This statement is used to receive input data from the keyboard during
the execution of the program. It will prompt the user to input data and then place the
input data into a variable. INPUT string and the variable must be separated by either a
comma or a semicolon. The semicolon will print a question mark at the end of the text.
The general format of INPUT statement is as given below.
INPUT [“Message”] ; list of Variables Here, message is a string constant enclosed in
double quotes and list of variables contain the numeric or string variable which stores the
data input by the user.
PRINT Statement: This statement is used to display the output on the screen. Question
mark (?) also can be used instead of PRINT statement to display on the screen. The
general format of PRINT statement is as given below.
PRINT[list of expressions][{; | ,}]
END Statement:This statement is used to indicate the end of the QBASIC program to
terminate it.The general format of END statement is as given below.

<END>Practical Assignment
a. REM 'To add the number 30 and 40
CLS
LET a = 30
LET b = 40
sum = a + b
PRINT "The Sum is"; sum
END
b. REM 'To find the sum of any two numbers
CLS
INPUT "Enter the first number"; a
INPUT "Enter the second number"; b
sum = a + b
PRINT "The sum is"; sum
END

New Gateway to Computer Science Book -9


224
PRINT USING Statement: This statement is used to display string or number using a
specified format. The general format of PRINT USING statement is as given below.
PRINT USING string expressions;list of expressions[;] Here, string expressions
is a string literal or variable consisting of special formatting characters. The formatting
characters determine the field and the format of printed strings or numbers and list of
expressions consists of the string or numeric expressions separated by semicolons.

The string formatting characters are given in the table below.

! displays only the first character of string


\n\ prints first n+2 characters from the string
& displays all the string
# digit position is specified
&& prints leading & sign
^^^^ prints the number in exponential format
. decimal point position specification

Let’s Review
 A statement is a computer instruction written in a source language, which is
converted into one or more machine code instructions by a compiler.
 The command or the set of instructions in the QBASIC is called a statement.
 Qbasic statements are classified into two statements.They are executable
and non-executable.
 Executable statement specifies actions whereas non-executable statements
specify characteristics, arrangements and initial values of data.
 REM statement is used to insert explanatory remarks for the program that
we are writing.
 REM is a non-executable statement where single quotation (‘) is used.
 CLS statement is used to clear the previous output from the display screen and
makes the screen blank.
 LET statement is used to assign the value in the variable. It is also called as
an assignment statement.
 INPUT statement is used to receive input data from the keyboard during the
execution of the program.
 PRINT statement is used to display the output on the screen.
 END statement is used to indicate the end of the QBASIC program to terminate it.

New Gateway to Computer Science Book -9


225
Practical Assignment
a. CLS
x$ = "Dinesh"
y$ = "Prasad"
z$ = "Adhikari"
PRINT USING "!"; x$; ".";
PRINT USING “!”; y$; ".";
PRINT USING "&";z$;
END
LINE INPUT Statement : This statement allows to input line of data at a time and assign
in to single variable.The general format of LINE INPUT statement is as given below.
LINE INPUT “prompt”; variable Here, prompt is a string constant that will be displayed
when the statement is executed and variable in the name of a string variable or array
element to which the line will be assigned.

Practical Assignment

a. CLS b. CLS
LINE INPUT "Enter the data"; n$ LINE INPUT "Enter a sentence"; n$
PRINT n$ PRINT n$
END END

LPRINT and LPRINT USING Statement: The LPRINT statement is used to print the
text to a printer and the LPRINT USING statement is used to print formatted output to a
printer. The general format of LPRINT and LPRINT USING statement is as given below.

LPRINT [expression [, \; expression]……] [;]

LPRINT USING “string”: expression [, \;expression]…... [;] Here, expression is a numeric


or string to be printed and string is a string constant or variable that identifies the format
in which expression is to be printed.

READ….DATA Statement: This statement is used to read values from the DATA
statement and assign them to variables. It is used mostly when dealing with large quantities
of data in program.The DATA statement is to store the numeric and string constants that
are accessed by the READ statement. The general format of READ…..DATA statement
is as given below.

New Gateway to Computer Science Book -9


226
READ [Variable1, variable 2, variable 3…..]
------
------
------
DATA [constant1, constant2, constant 3….

Practical Assignment
a. CLS b. CLS
READ a, b, c READ A, B, C, D
PRINT a, b, c Total = A + B +C + D
DATA 100,200,300 Avg = Total / 4
END PRINT "The total value is"; Total
PRINT "The average value is"; Avg
DATA 80,50,40,70
END

RESTORE Statement: The RESTORE statement is used to reset the DATA


pointer to the beginning of the data. Once the data element is read, it cannot be read
again until the program resets it. The RESTORE statement is used to reset the data in the
program. The general format of RESTORE statement is as given below.

RESTORE[line number] Here, If line number is specified, the next READ statement
accesses the first item in the specified DATA statement and If line number is omitted, the
next READ statement accesses the first item in the first DATA statement.

Practical Assignment
a. CLS
READ a, b, c
PRINT a, b, c
RESTORE
READ d, e, f
PRINT d, e, f
DATA 10,20,30
END

New Gateway to Computer Science Book -9


227
LOCATE Statement: This statement is used to move the cursor to the specified position
on the screen.
LOCATE [row][,[col][,[cursor][,[start] [,stop]]]] Here, row is the screen line number, col
is the screen column number,cursor is a boolean value indicating whether the cursor is
visible or not. Start is the cursor start scan line, stop is the cursor stop scan line.

Practical Assignment
a. CLS
LOCATE 5, 30
PRINT "New Gateway to Computer"
END
SWAP Statement :This statement is used to exchange the values of two variables. The
general format of SWAP statement is as given below.
SWAP variable1, variable2

Practical Assignment
a. CLS
INPUT "Enter the first number"; a
INPUT "enter the second number"; b
PRINT "Before using SWAP”; a, b
SWAP a, b
PRINT "After SWAP"; a, b
END
Let’s Review
 PRINT USING statement is used to display string or number using a specified
format.
 LINE INPUT statement allows inputting line of data at a time and assigning
in to single variable.
 READ….DATA statement is used to read values from the DATA statement
and assign them to variables.
 The RESTORE statement is used to reset the DATA pointer to the beginning
of the data.
 LOCATE statement is used to move the cursor to the specified position on the
screen.
 SWAP statement is used to exchange the values of two variables.

New Gateway to Computer Science Book -9


228
Practical Section

Program 1: Write a program to input any three numbers and display its sum
and average.
REM 'to calculate sum and average of three numbers
CLS
INPUT "Enter first number"; A
INPUT "Enter second number"; B
INPUT "Entre third number"; C
SUM = A + B + C
AVG = (A + B + C) / 3
PRINT "The sum is"; SUM
PRINT "The average value is"; AVG
END

Program 2: Write a program to display the area of a rectangle.


REM PROGRAM TO DISPLAY AREA OF RECTANGLE
CLS
INPUT "ENTER LENGTH"; L
INPUT "ENTER BREADTH"; B
A=L*B
PRINT "AREA OF RECTANGLE "; A
END

Program 3: Write a program to display the area of a square.


REM PROGRAM TO DISPLAY AREA OF SQUARE
CLS
INPUT "ENTER LENGTH"; L
A=L^2
PRINT "AREA OF SQUARE"; A
END

Program 4: Write a program to display the perimeter of a rectangle.


REM PROGRAM TO DISPLAY PERIMETER OF RECTANGLE
CLS

New Gateway to Computer Science Book -9


229
INPUT "ENTER LENGTH"; L
INPUT "ENTER BREADTH"; B
P = 2 * (L + B)
PRINT "PERIMETER OF RECTANGLE"; P
END

Program 5: Write a program to display the area and perimeter of a rectangle.


REM 'TO DISPLAY AREA AND PERIMETER OF RECTANGLE
CLS
INPUT "ENTER LENGTH"; L
INPUT "ENTER BREADTH"; B
A= L * B
P = 2 * (L + B)
PRINT "AREA OF RECTANGLE" ; A
PRINT "PERIMETER OF RECTANGLE"; P
END

Program 6: Write a program to display the area and circumference of a circle.


CLS
LET PIE = 3.14
INPUT "Enter radius of circle"; R
A = PIE * R ^ 2
C = 2 * PIE * R
PRINT "The area of the circle is"; A
PRINT "The circumference of the circle is"; C
END

Program 7: Write a program to exchange the value of any two variables.


CLS
INPUT "Enter the first number"; a
INPUT "Enter the second number"; b
PRINT "Before using SWAP"; a, b
SWAP a, b
PRINT "After SWAP"; a, b
END

New Gateway to Computer Science Book -9


230
Assignment
1. Fill in the blanks with suitable words.
a. The command or a set of instructions in the QBASIC is called a …………...
b. ………… specifies actions whereas non-executable statements specify
characteristics, arrangements and initial values of data.
c. ……………. is a non-executable statement where single quotation (‘) is used.
d. …………. statement is used to assign the value in the variable.
e. …………..statement is also called an assignment statement.
f. …………….. statement is used to display the output on the screen.
g. …………….. statement is used to display string or number using a specified
format.
h. ……………. statement is used to read values from the DATA statement and assign
them to variables
i. The RESTORE statement is used to reset the ………….. pointer to the beginning
of the data.
2. State whether the given statements are true or false.
a. A statement is a computer instruction written in a source language, which is
converted into one or more machine code instructions by a compiler.
b. QBASIC statements are classified into two statements and they are executable
and non-executable.
c. CLS statement is used to insert explanatory remarks for the program that we are
writing.
d. REM statement is used to clear the previous output from the display screen and
makes the screen blank.
e. INPUT statement is used to receive input data from the keyboard during the
execution of the program.
f. END statement is used to indicate the end of the QBASIC program to terminate
it.
g. LINE INPUT statement allows inputting line of data at a time and assigning in to
single variable.
h. SWAP statement is used to move the cursor to the specified position on the screen.
i. LOCATE statement is used to exchange the values of two variables.

New Gateway to Computer Science Book -9


231
3. Answer the following questions.
a. What is a QBASIC statement? List out some QBASIC statements.
b. What is the use of CLS and LET statements?
c. Define locate statement with syntax.
d. Write down the function and syntax of the following QBASIC statements.
i. INPUT statement
ii. PRINT statement
iii. PRINT UNING statement
iv. LINE INPUT statement
v. READ…..DATA statement
4. Write a QBASIC program for the followings.
a. To input any three numbers and display its sum.
b. To display the area of a rectangle.
c. To display the area of a circle.
d. To display the area and perimeter of a rectangle.
e. To exchange the value of any two variables.
5. Debug the following programs.
a. CLS
REM To find Sum of two numbers b. CLS
INPUT "Enter the first number"; a REM To find Area of Rectangle
INPUT "Enter the second number"; b INPUT "Enter the length" ; l
SUM = a + c INPUT “Enter the breadth” ; b
PRIT "The sum of two number is"; S AR = l * b
END PRINT "The area of rectangle is AREA
c. CLS END
REM To find area of circle
LET r = 6
LET P = 3.14
AREA = PAI * N ^ 2
PRINT "The area of circle is" ARE
END

New Gateway to Computer Science Book -9


232
d. CLS
INPUT "Enter the name of student" ; n$
INPUT "Enter the marks of English"; e
INPUT "Enter the marks of Nepali" ; n
INPUT "Enter the marks of Computer"; c
TO = e + n - c
PER = e + n + c / 300 * 100
PRINT "Student’s name" ; n
PRINT "Total marks of student" ; TOTAL
PRINT " Percentage of student"; PR
END
6. Write down the output of the following programs.
a. CLS
x = 5
y = 3
LET c = (x2+3x-y)
PRINT " The value of c is " ; c
END
b. CLS
READ A, B, C, D
Total = A + B +C + D
Avg = Total / 4
PRINT "The total value is"; Total
PRINT "The average value is"; Avg
DATA 90,110,50,130
END
c. CLS
x$ = "Ram"
y$ = "Krishna"
z$ = "Malakar"
PRINT USING "!"; x$; ".";
PRINT USING “!”; y$; ".";
PRINT USING "&";z$;
END

New Gateway to Computer Science Book -9


233
7. Study the following programs and answer the given questions.
a. CLS
INPUT "Enter the first number"; a
INPUT "enter the second number"; b
PRINT "Before using SWAP”; a, b
SWAP a, b
PRINT "After SWAP"; a, b
END
i. If the user input the first number as 50 and second number as 70, what will be
the output?
ii. What are the variables use in the above program?
iii. What is the statement use in above program to exchange the value?
b. CLS
INPUT "ENTER LENGTH"; L
INPUT "ENTER BREADTH"; B
P = 2 * (L + B)
PRINT "PERIMETER OF RECTANGLE"; P
END
i. If the user input the length 150 and breadth 60, what will be the output?
ii. What are the operators use in the above program?
iii. List out the variables use in the above program.

New Gateway to Computer Science Book -9


234
Lesson

14 Program Flow and Control Structures

Inside the Lesson

 Introduction to program flow and control structure


 Types of control statements
 Branching statement
 Conditional branching statement
 Unconditional branching statement
 Looping statement
 Practice section

Statements that specify the order in which actions are executed are called control
statements. A program consists of a number of statements which are usually executed
in sequence. Control statements allow you to change the computer's control from
automatically reading the next line of code to reading a different one. The control
statements are used for controlling the execution of the program. In a program, a control
structure determines the order in which statements are executed. Mainly, there are two
types of control statements in QBASIC. They are Branching Statement and Looping
Statement.

Types of Control Statements

Branching statement
Branching statement is a decision making statement. Depending upon the decision,
branching statement can change the order of execution. Branching statements are divided
into two types.

Conditional Branching Statement


This statement allows the selective execution of statements based on a particular condition.
This statement directs the computer to another part of the program based on the results

New Gateway to Computer Science Book -9


235
of a compare. High-level language statements, such as IF….. THEN, IF…..THEN…..
ELSE, IF ... THEN ... ELSE IF, SELECT ... CASE, are the popular conditional branching
statements. We are going to discuss more about it.

IF ... THEN Statement


This statement is a decision making conditional branching statement which
executes a block of statements only if the given expression or condition is true. If
the condition is false, then the IF blocks will be skipped and execution continues
with the rest of the program.
Syntax :IF [conditional expression] THEN [statement block]
Practical Assignment
1. CLS
INPUT "Enter your marks in computer : "; C
IF C>= 40 THEN PRINT "You are passed”
IF C<40 THEN PRINT "You are failed"
END

2.
CLS
INPUT "Enter a number "; N
IF N MOD 2 = 0 THEN PRINT "It is Even Number"
IF N MOD 2 = 1 THEN PRINT "It is Odd Number"
END

3. CLS
INPUT "Enter first number "; A
INPUT "Enter second number "; B
INPUT "Enter third number "; C
IF A>B AND A>C THEN G=A
IF B>A AND B>C THEN G = B
IF C>A AND C>B THEN G= C
PRINT “The greatest number is:”; G
END

New Gateway to Computer Science Book -9


236
IF ... THEN .... ELSE Statement
It is also a control statement which is used to execute the multiple statements depending
on the condition. It is also called two way decision making statement. In this statement if
the condition is true, the statements after THEN will be executed and if the condition is
false, the statements in the ELSE block will be executed.
Syntax :IF [conditional] THEN[statement 1]ELSE[statement 2]
……………….
END IF

Practical Assignment
1. CLS
INPUT "Enter your marks in computer"; C
IF C >= 40 THEN
PRINT "You are passed."
ELSE
PRINT "You are failed ."
END IF
END

2. CLS
INPUT "Enter first number "; A
INPUT "Enter second number "; B
INPUT "Enter third number "; C
IF A> AND A>C THEN
PRINT "The greatest number is"; A
IF B>A AND B>C THEN
PRINT "The greatest number is"; B
ELSE
PRINT "The greatest number is:"; C
END

3. CLS
INPUT "Enter a number "; N

New Gateway to Computer Science Book -9


237
IF N MOD 2 = 0 THEN
PRINT "It is an even Number"
ELSE
PRINT "It is an odd Number"
END IF
END
IF ... THEN ... ELSEIF Statement
This statement is another form of IF….THEN…..ELSE statement. The conditions are
evaluated from top to buttom. The syntax is given below.
Syntax :
IF [condition] THEN
[statement 1]
ELSEIF
[statement 2]
ELSEIF
[statement n]
........................
.......................
ELSE
[statement n]
END IF

Practical Assignment
1.
CLS
INPUT "Enter First Number "; A
INPUT "Enter Second Number "; B
INPUT "Enter Third Number "; C
IF A>B AND A>C THEN
PRINT "The greatest number is "; A
ELSEIF B> A AND B>C THEN
PRINT "The greatest number is "; B
ELSE
PRINT "The greatest number is "; C
END IF
END

New Gateway to Computer Science Book -9


238
2. CLS
INPUT "Enter your percentage "; P
IF P>= 80 THEN
Result$ = "Distinction"
ELSEIF p >= 60 THEN
Result$ = "First Division"
ELSEIF p >= 40 THEN
Result$ = "Second Division"
ELSEIF p >= 35 THEN
Result$ = "Third Division"
ELSE
Result$ = "Sorry! No result found"
END IF
PRINT "Division ::: "; Result$
END

SELECT CASE Statement


This statement is a multi-way branching statement which makes the control jump to one
of the several statements based on the value of an expression.
Syntax : 1. CLS
SELECT CASE INPUT "Enter your percentage "; P
CASE test 1 SELECT CASE P
[statement1] CASE 80 TO 100
CASE test 2 div$ = "Distinction"
[statement 2] CASE 60 TO 80
........................ div$ = "First Division"
....................... CASE 40 TO 60
CASE ELSE div$ = "Second Division"
[statements] CASE 35 TO 40
END SELECT div$ = "Third Division"
CASE ELSE
div$ = "Fail"
END SELECT
PRINT "Division :: "; div$t
New Gateway to Computer Science Book -9
239
Practical Assignment
1. CLS
INPUT "Enter your choice (1 – 3)"; N
SELECT CASE N
CASE 1
PRINT "Baishak"
CASE 2
PRINT "Jestha"
CASE 3
PRINT "Ashad"
CASE ELSE
PRINT "Invalid Value"
END SELECT
END
2. CLS
INPUT "Enter First Number "; A
INPUT "Enter Second Number "; B
PRINT "****** MENU *******"
PRINT "1. Addition"
PRINT "2. Subtraction"
PRINT "3. Multiplication"
PRINT "4. Division"
INPUT "Enter your choice! (1/2/3/4) "; CH
SELECT CASE CH
CASE 1
PRINT "Sum = "; A + B
CASE 2
PRINT "Difference = "; A - B
CASE 3
PRINT "Product = "; A * B
CASE 4
PRINT "Quotient = "; A / B
CASE ELSE
PRINT "InvalidData!”
END SELECT

New Gateway to Computer Science Book -9


240
Let’s Review
 A program consists of a number of statements which are usually executed in
sequence.
 Control statements allow you to change the computer's control from automatically
reading the next line of code to reading a different one.
 Branching statement is a decision making statement.
 Conditional branching statement allows the selective execution of statement
based on a particular condition.
 IF... THEN statement is a decision making conditional branching statement
which executes a block of statements only if the given expression or condition is
true.
 IF...THEN...ELSE statement is also called two way decision making statements.
 The IF….THEN…..ELSE statement is another form of IF….THEN…..ELSE
statement in which the conditions are evaluated from top to buttom.
 SELECT CASE statement is a multi-way branching statement which makes the
control jump to one of the several statements based on the value of an expression.

Unconditional Branching Statement


Unconditional branching statement is used when the programmer forces the execution of
a program to jump to another part of the program. This can be done using the combination
of loops and if statements. You can avoid such unconditional branching and use this
technique only when it is very difficult to use a loop.
GOTO Statement
This statement in QBASIC is used to transfer the program control from one statement to
another. It is an unconditional branching statement.
Syntax : GOTO [line number / line label]

Practical Assignment
1. CLS 2. CLS
AA: n=1
INPUT "Enter the first Number"; A top:
INPUT "Enter the second Number"; B PRINT n;
Sum = A + B n=n+1
PRINT "The sum is"; Sum
IF n <= 20 THEN GOTO top
GOTO AA
END
END

New Gateway to Computer Science Book -9


241
Looping Statement
Looping statement is the statement that executes one or more statements repeatedly in a
several number of times. In QBASIC there are three types of loops they are for, while and
do-while.When you need to execute a block of code several number of times then you
need to use looping. Let’s discuss the major looping statements in QBASIC.
Statement before FOR

FOR

COUNTER_VARIABLE = STARTVALUE

COUNTER_VARIABLE FALSE
<END_VALUE

COUNTER_VARIABLE =
COUNTER_VARIABLE +
Statement of Loop
STEPVALUE

NEXT

Statement after NEXT

FOR……NEXT Statement
It is the fundamental looping statement in QBASIC. It provides a way to repeat a block
of statements over a predetermined number of times. The FOR…..NEXT loop is used
when we are required to perform repetitive tasks, such as to display addition of all values
between 100 to 200, display all prime numbers between 1 to 100, etc.
Syntax
For counter variable = <initial value>To <Ending Value> [step increment / decrement]
[statements]
[Exit For]
[statements]
Next

Let’s observe the given table to understand the parts of the syntax.

New Gateway to Computer Science Book -9


242
Part Description
counter Numeric variable used as a loop counter. The variable can't be an array
element or an element of a user-defined type.
initial Starting value of counter.
ending Final value of counter.
step Amount counter is changed each time through the loop. If not specified,
step defaults to one.
statements One or more statements between FOR and NEXT that are executed at
the specified number of times.

Practical Assignment

1. CLS 2. CLS
FOR I = 1 to 10 FOR I = 1 to 10 STEP 2
PRINT I; PRINT I;
NEXT NEXT
END END
3. CLS 4. CLS
FOR I = 10 to 1 STEP -2 FOR I = 1 to 10
PRINT I; PRINT "Computer";
NEXT NEXT

END END

5. CLS
FOR I = 1 to 3
FOR J = 1 to 3
PRINT "Computer"
NEXT
NEXT

END

New Gateway to Computer Science Book -9


243
WHILE……WEND Statement
Statement before WHILE
The WHILE…WEND loop is the fundamental
loop statement in QBASIC. It provides a way
For
to repeat a block of statements, as long as the
condition is true. It is used to perform a repetitive
task based on a condition. The condition usually
results from a comparison of two values, but it
can be any expression that evaluates to a Boolean CHECK CONDITION
value (TRUE or FALSE).

Syntax TRUE
WHILE (TEST CONDITION) Statement of Loop
(Statements OF Loop)
WEND WEND

Statement after WEND

Let’s observe the given table to understand the part of the syntax.

Part Description
TEST CONDITION It is a numeric or string expression that evaluates whether
the statement is TRUE or FALSE.
Statements OF Loop It is a set of one or more QBASIC statements.
WHILE Statement It always checks the condition before it begins the loop.
LOOP It continues till the condition remains TRUE.

Practical Assignment
1.
REM to print series from 1 to 10 2.
REM to print series from 1 to 20
CLS CLS
C=1 C=1
WHILE C <= 10 WHILE C <= 20
PRINT C PRINT C
C=c+1 C=c+1
WEND WEND
END END

New Gateway to Computer Science Book -9


244
Statement before DO
DO….WHILE LOOP WHILE

A DO….WHILE loop is used when we want


DO WHILE
to repeat a set of statements as the long as
condition is true.The condition usually results
from a comparison of two values, but it can
be any expression that evaluates to a Boolean
FALSE
value (TRUE or FALSE). The condition may be CHECK CONDITION
checked at the beginning of the loop or at the end
of the loop.
Syntax
TRUE
DO WHILE (TEST CONDITION) Statement of Loop
(Statements Of Loop)
LOOP
LOOP
Let’s observe the given table to understand
the part of the syntax. Statement After LOOP

Part Description
It is numeric or string expression that evaluates whether the con-
TEST CONDITION
dition is TRUE or FALSE.
• It is a set of one or more QBASIC statements.
• If the condition is TRUE, all statements in statement in loop
are executed until the loop statement is encountered.
Statement of Loop
• Control then returns to the WHILE statement and Condition is
again checked.
• If the condition is still TRUE, then the process is repeated.
If the Condition is FALSE, then the loop statements are skipped
LOOP
and the statement after LOOP statement is executed.

Practical Assignment
1. REM to print the series from 1 to 10 2 REM to print the series from 1 to 20
CLS CLS
c=1 C=1
DO WHILE c <= 10 DO WHILE C <= 20
PRINT c PRINT C
c=c+1 C=C+1
LOOP LOOP
END END

New Gateway to Computer Science Book -9


245
DO….UNTIL LOOP Statement before DO
UNTIL
A DO….UNTIL loop is used when you want to
repeat a set of statements as long as the condition DO UNTIL
is false. The condition may be checked at the
beginning of the loop or at the end of the loop.
Syntax
DO UNTIL (TEST CONDITION) CHECK CONDITION
FALSE
(Statements of Loops)
REPORT THIS AD
LOOP
TRUE
Statement of Loop

LOOP

Statement After LOOP

Let’s observe the given table to understand the part of the syntax.
Part Description
TEST CONDITION It is a numeric or string expression that evaluates
whether the statement is TRUE or FALSE.
Statement of Loop It is a set of one or more QBASIC Statements.

Practical Assignment
1.
REM a program to print the series from 1 to 10.
CLS
C=1
DO UNTIL C = 11 (this number will not be displayed)
PRINT C
C=C+1
LOOP
END
2.
REM a program to print the series from 1 to 20.
CLS
C=1

New Gateway to Computer Science Book -9


246
DO UNTIL C = 21(this number will not be displayed)
PRINT C
C=C+1
LOOP
END

EXIT Statement:
Statement before
The EXIT Statement is used to terminate
the loop based on certain criteria before DO UNTIL
the expected number of iterations.
DO UNTIL
When the EXIT Statement is executed,
the control jumps to next statement
immediately after the loop. We can use
the EXIT Statement in all types of loops.
FALSE
CHECK CONDITION
Syntax: EXIT DO / FOR

TRUE

EXIT
Statement of Loop
DO

LOOP

Statement After LOOP

Practical Assignment
1. CLS
X=1
DO
prod = x* 5
IF prod >50 THEN EXIT DO
PRINT prod
X=X
LOOP WHILE X<=10
END

New Gateway to Computer Science Book -9


247
Let’s Review
 Unconditional branching is when the programmer forces the execution of a
program to jump to another part of the program.
 The GOTO statement in QBASIC is used to transfer the program control from
one statement to another.
 Looping statement is the statement that executes one or more statements
repeatedly in a several number of times.
 The FOR…..NEXT loop is used when we are required to perform repetitive
tasks.
 A DO….WHILE loop is used when we want to repeat a set of statements as
long as the condition is true.
 A DO….UNTIL loop is used when you want to repeat a set of statements as long
as the condition is false.
 The EXIT Statement is used to terminate the loop based on certain criteria before
the expected number of iterations.

Practical Section

Program 1: Write a Qbasic program to find out the simple Interest and the
Amount.
CLS
Input "Enter the Principal";P
Input "Enter the Rate";R
Input "Enter the Time";T
Let I = P*T*R/100
Let A= P + I
Print "The simple Interest = ";I
Print "The amount=";A
End

Program 2: Write a Qbasic program to find out the area of four walls of a
room.
CLS
Input "Enter the height";H

New Gateway to Computer Science Book -9


248
Input "Enter the length"; L
Input "Enter the Breadth";B
Let A= 2 * H * (L+B)
Print "The area of four walls =";A
End

Program 3: Write a Qbasic program to enter any three numbers and calculate
their sum and average.
CLS
Input "Enter any number" ;A
Input "Enter any number" ;B
Input "Enter any number" ;C
Let Sum = A+B+C
Let Average =Sum/3
Print "The sum=" ;Sum
Print "The Average is" ;Average
End

Program 4: Write a Qbasic program to input student's name,marks obtained


in five different subjects and find the total and average marks.
CLS
Input "Enter the name" ;N$
Input "Enter the marks in English" ;E
Input "Enter the marks in Computer" ;C
Input "Enter the marks in Maths" ;M
Input "Enter the marks in Science" ;S
Input "Enter the marks in Nepali" ;N
Let S=E+C+M+S+N
Let A=S/5
Print "The name of the student is" ;N$
Print "The total marks is" ;S
Print "The Average marks" ;A
End

New Gateway to Computer Science Book -9


249
Program 5: Write a Qbasic program to enter any number and check whether
it is negative or positive number.
CLS
Input "Enter the number"; N
If N>0 Then
Print "The number is positive"
Else
Print "The number is negative"
EndIf
End

Program 6: Write a Qbasic program to enter any number and find out whether
it is even or odd using select case statement.
CLS
Input "Enter any number" ;N
Rem=N mod 2
Select case Rem
Case = 0
Print "The number is Even number"
Case Else
Print "The number is odd number"
End Select
End

Program 7: Write a Qbasic program to check the numbers between 1 and 5.


CLS
Input "Enter the numbers between 1-5";N
Select case N
Case 1
Print "This is number 1";
Case 2
Print "This is number 2";
Case 3
Print "This is number 3"
Case 4

New Gateway to Computer Science Book -9


250
Print "This is number 4"
Case 5
Print "This is number 5"
Case else
Print "Invalid number range ";
End select
End

Program 8: Write a QBASIC program to enter any alphabet and test whether
the alphabet is ‘a’ or not using the select case statement.
CLS
Input "Enter the alphabet";A$
A$=UCase$ (A$)
Select Case A$
Case 'A'
Print "It’s alphabet A"
Case Else
Print "It’s not alphabet A"
End Select
End

Program 9: Write a QBASIC program to enter any alphabet and find out
whether the alphabet is vowel or not.
CLS
Input "Enter Letters"; A$
A$ = UCase $ (A$)
Select case A$
Case "A", "E", "I", "O", "U"
Print "It is vowel"
Case Else
Print "It is not a vowel"
End Select
End

New Gateway to Computer Science Book -9


251
Program 10: Write a QBASIC program to generate the following series using
For….Next…..Loop.
1,3,5,7,9, 11, 13, 15………………...99
CLS
For I = 1 to 99 Step 2
Print I
Next I
End
Program 11: Write a QBASIC program to generate the following series using
For….Next…..Loop.
5,10,15,20,25…100
CLS
For I = 5 to 100 Step 5
Print I
Next I
End
Program 12: Write a QBASIC program to print numbers from 1 to 100 using
WHILE…WEND statement.
CLS
I=1
While I<=100
Print I ;
I=I+1
WEND
END
Program 13: Write a QBASIC program to print series as below using
WHILE…WEND statement.
1,4,9,…upto 10th term.
CLS
I=1
While I < =10
Print I^2;
I=I+1
WEND
END

New Gateway to Computer Science Book -9


252
Program 14: Write a QBASIC program to read any 10 different numbers and
find the greatest number among them.
CLS
READ G
FOR I = 2 to 10
READ N
IF N>G THEN G = N
DATA 19, 2, 56, 11, 76, 10, 22, 12, 55, 1
NEXT I
PRINT "The greatest Number is:"; G
END

Program 15: Write a QBASIC program to find out the factorial of a given
number (n).
CLS
REM' PROGRAM TO FIND THE FACTORIAL OF A GIVEN NUMBER
INPUT "ENTER A NUMBER:"; N
F=1
FOR I = 1 TO N
F=F*I
NEXT I
PRINT "THE FACTORIAL OF THE NUMBER IS", F
END

Program 16: Write a QBASIC program to find check whether the entered
number is palindromic or not.
CLS
INPUT "ENTER ANY NUMBER"; N
A=N
S=0
WHILE N <> 0
A palindromic number is a number that is the same when
R = N MOD 10
written forwards or backwards. The few palindromic
S = S * 10 + R numbers are 0 to 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101,
N = N \ 10 111, 121 and so on
WEND

New Gateway to Computer Science Book -9


253
IF A = S THEN
PRINT A; "This is a palindromic number."
ELSE
PRINT A; "This is not a palindromic number."
END IF
END
Program 17: Write a QBASIC program to check whether the entered number
is prime or composite.
CLS A prime number is a whole number that has
INPUT "Enter any number"; N only two factors which are itself and one. A
A=0 composite number has factors in addition to
FOR I = 1 TO N one and itself.
IF N MOD I = 0 THEN A = A + 1 The numbers 0 and 1 are neither prime nor
composite.
NEXT I
All the even numbers are divisible by two
IF A = 2 THEN
and so all even numbers greater than two are
PRINT "It is prime number"; composite numbers.All the numbers that end in
ELSE five are divisible by five. Therefore all numbers
PRINT "It is composite number"; that end with five and are greater than five are
END IF composite numbers.
END The prime numbers between 2 and 100 are 2, 3,
5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
53,59, 61, 67, 71, 73, 79, 83, 89 and 97.

Program 18: Write a QBASIC program to display the prime numbers from
2 to 100.
Method 1
CLS
FOR I = 1 TO 100
C=0
FOR J= 1 TO i
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF C = 2 THEN PRINT I;
NEXT I
END

New Gateway to Computer Science Book -9


254
Method 2
CLS
FOR I = 2 TO 100
FOR J = 2 TO I - 1
IF I MD J = 0 THEN GOTO DD
NEXT J
PRINT J;
DD:
NEXT i
END

Program 19: Write a QBASIC program to display the Fibonacci sequence up


to 10th terms.
CLS
A=1 The Fibonacci sequence is the series of numbers as below.
B=1 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...................
PRINT A, B, Where, the next number is found by adding up the two
FOR I = 1 TO 10 numbers before it.
C=A+B • The 2 is found by adding the two numbers before it (1+1).
PRINT C, • The 3 is found by adding the two numbers before it (1+2).
A=B • The 5 is found by adding the two numbers before it (2+3)
and so on.
B=C
NEXT I
END

Program 20: Write a QBASIC program to check whether the entered number
is Armstrong or not.
The number which is formed by the sum of
Method 1:Using DO………LOOP cubes of its own digits is Armstrong number.
CLS 153, 370, 371, 407 are the Armstrong
numbers.
INPUT "Enter a number"; N
B=N Let’s take an example of 153.
DO WHILE N<> 0 153 = 13 + 53 + 33
R = N MOD 10 = 1 + 125 + 27
A = A +R ^ 3 = 153

New Gateway to Computer Science Book -9


255
N = N \ 10
LOOP
IF A = B THEN
PRINT "It is an Armstrong number";
ELSE
PRINT "It is not an Armstrong number";
END IF
END

Method 2: Using WHILE………WEND


CLS
INPUT "ENTER ANY NUMBER"; N
A=N
S=0
WHILE N <> 0
R = N MOD 10
S=S+R^3
N = N \ 10
WEND
IF A = S THEN
PRINT A; "It is an ARMSTRONG number."
ELSE
PRINT A; "It is not an ARMSTRONG number."
END IF
END
Program 21: Write a QBASIC program to display the output as below.

1 CLS
222 FOR I = 1 TO 6
LOCATE I, 50 - I
33333 FOR J = 1 TO I * 2 - 1
4444444 PRINT USING "#"; I;
NEXT
555555555 PRINT
666666666666 NEXT
END

New Gateway to Computer Science Book -9


256
Program 22: Write a QBASIC program to display the reverse of a given
number.
CLS
INPUT "Enter the number to reverse"; N
WHILE N <> 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
PRINT "The reverse of the given number is"; S
END

Assignment
1. Fill in the blanks with suitable words.
a. ……….. allow you to change the computer's control from automatically reading the
ext line of code to reading a different one.
b. …………… statement allows the selective execution of statements based on a
particular condition.
c. ………….. statement is also called two way decision making statements.
d. The IF….THEN…..ELSE statement is another form of ………….. statement in
which the conditions are evaluated from top to button.
e. The ………….. statement in QBASIC is used to transfer the program control
from one statement to another.
f. The ……………. loop is used when we are required to perform repetitive tasks.
g. A ………….. loop is used when you want to repeat a set of statements as long as
the condition is false.
2. State whether the given statements are true or false.
a. A program consists of a number of statements which are usually executed in
sequence.
b. Branching statement is not a decision making statement.

New Gateway to Computer Science Book -9


257
c. IF... THEN statement is a decision making conditional branching statement
which executes a block of statements only if the given expression or condition is
true.
d. Conditional branching is when the programmer forces the execution of a program
to jump to another part of the program.
e. Looping statement is the statements that executes one or more statement
repeatedly in a several number of times.
f. The SWAP statement is used to terminate the loop based on certain criteria before
the expected number of iterations.
3. Write down the function and syntax for the following statements.
a. IF…….THEN statement
b. IF…….THEN……ELSE statement
c. SELEST CASE statement
d. GOTO statement
e. FOR….NEXT statement
f. WHILE…….WEND statement
g. DO….WHILE LOOP statement
h. DO………UNITL LOOP statement
i. EXIT statement

4. Debug the following programs.

a. CLS b. CLS
INPUT "Enter your marks in computer"; C$ C=1
C >= 40 THEN DO NEXT C = 21
PRINT "You are passed." PRINT M
ELSE C=C+2
PRINT "You are failed ." LOOP WHILE
IF END
END

New Gateway to Computer Science Book -9


258
c. CLS d. CLS
INPUT "Enter your choice (1 – 3)"; N C=1
SELECT CASE Z WHILE B <= 10
CASE 1 PRINT
PRINT "Baishak" C=b+1
CASE 2
END
PRINT "Jestha"
CASE 5 WEND
PRINT "Ashad"
ELSE CASE
PRINT "Invalid Value"
SELECT END
END
5. Write down the output of the following programs.
a. CLS b. CLS
For I = 1 to 99 Step 2 I=1
Print I While I < =10
Next I Print I^2;
End I=I+1
WEND
END

c. CLS
FOR I = 1 TO 6 f. CLS
LOCATE I, 50 - I A=1
FOR J = 1 TO I * 2 - 1 FOR I = 1 TO 5
PRINT USING "#"; I; FOR J = 1 TO I
NEXT PRINT A;
PRINT A = A+I
NEXT J
NEXT
PRINT
END
NEXT I
END

New Gateway to Computer Science Book -9


259
e. CLS d. CLS
A = 50 A=1
B = 70 B=2
FOR I = A TO B STEP 5 FOR I = 1 TO 15
FOR J = B TO 1 STEP -5 PRINT A; "/"; B
PRINT J; A = A+I
NEXT J B = B+I
PRINT NEXT I
NEXT I END
END
6. Write a QBASIC program for the followings.
a. To enter a number and check whether it is odd or even using select case statement.
b. To find the factorial of a given number.
c. To check whether the entered number is prime or composite.
d. To check whether the given number is divisible by 5 or not.
e. To check whether the given number is palindromic or not.
f. To display the Fibonacci sequence up to 20th term.
g. To check whether the given number is Armstrong or not.
h. To display the reverse of a given number.
i. To print the sum of square of odd numbers upto 200.
j. To input any number and count the total even numbers present in it.
7. Write the program to display given series.
a. 1, 4, 9, 16, 25 b. 5, 10, 15, 20, 25 c. 100, 90, 80, 60, 50
d. 1, 3, 5, 7, 9 , 11, 13, 15 e. 2, 2, 4, 6, 10, 16 f. 10, 20, 30, 40, 50

New Gateway to Computer Science Book -9


260
Lesson

15 Library Functions in QBASIC

Inside the Lesson

 Introduction to library function


 User defined function
 Understanding built in function
 Numeric function
 String function
 Practice session

A function is a built-in formula or a readymade program which helps us to perform a


certain task such as mathematical, statistical, financial, logical calculations, etc. Functions
are readymade programs which take some data, manipulate them and return the value,
which may be string or numeric.There are two types of functions they are user defined
function and built-in function. Let’s discuss them in detail.

User Defined Function

A function which is written and stored by the programmer to perform a specific


task is known as a user defined functions. It is created by the programmer to perform the
operations as required. It can be numeric or string function. To define a function DEF
FN is used and it must be executed before the function. FUNCTION……………END
FUNCTION statement can be used to define the function in Qbasic. The following is the
syntax of a user defined function.

Syntax: DEF FNname(parameter list) = expression

Here, DEF FN defines a single-line function. The name you must use to call your function
is FNname. If you use this, you will be able to calculate everything using one line.

New Gateway to Computer Science Book -9


261
Practical Assignment
CLS
A = 5: B = 10
DEF FNC (x, y) = x ^ 10 / y ^ 5
TOTAL = FNC(A, B)
PRINT TOTAL
END

Built in Function

Buit in function is a pre-defined program which is provided by QBASIC to perform some


task easily. It gives many more built-in functions for manipulating strings and numbers.
Built-in functions are also called Library functions. These functions are required to be
called by the programmer to use them in a program. Some common Built-in functions are
LEN, LEFT$, RIGHT$, MID$, UCASE$, LCASE$, CHR$, etc. There are two types of
built in function.They are numeric functions and string functions. Let’s discuss them in
detail.

Numeric Functions:
Numeric function provides a faster way to evaluate many mathematical functions. Some
of the numerical functions are listed below.
ABS Function : This function is used to obtain an absolute corresponding positive value
of a numerical expression. The syntax of ABS function is given below.

ABS (x), where x is a numeric expression.

Practical Assignment
CLS
N = ABS(5 * (-3))
PRINT "The absolute value is:"; N
END
CINT Function: It is a mathematical function used to convert numeric expression to
an integer by rounding the fractional portion or it returns the integer to the given number.
The syntax of CINT function is given below.
CINT (x), where x is a numeric expression. If it is not in range ( -32768) to (+32767), an
overflow error message will appear.

New Gateway to Computer Science Book -9


262
Practical Assignment
CLS
X = CINT(105.345)
PRINT "The value is"; X
END
COS Function: It is a mathematical function which is used to obtain the cosine of x. It
can be any number or expression. To convert degrees to radians use the formula: radian =
degree*(Pi/180). Where, Pi=3.14. The syntax of COS function is given below.

COS(x) where x is the angle whose cosine is to be calculated.

Practical Assignment
CLS
INPUT "Enter an angle in degree"; A
R = A * 3.14 / 180
P = COS(R)
PRINT "COSINE OF"; A; "Degree"; "is"; P
END
SIN Function: It is also a mathematical function which is used to get the sine of x. To
convert degrees to radians use the formula: radian = degree*(Pi/180). Where, Pi=3.14.
The syntax of SIN function is given below.

SIN(x), where x is an angle expressed in radians.

Practical Assignment
CLS
INPUT "Enter an angle in degree"; A
R = A * 3.14 / 180
P = SIN(R)
PRINT "Sineof"; A; "Degree"; "is"; P
END
TAN Function: It is a mathematical function that returns the tangent of an angle expressed
in radians. To convert degrees to radians use the formula: radian = degree*(Pi/180).
Where, Pi=3.14. The syntax of TAN function is given below.

TAN(x), where x is an angle expressed in radians.

New Gateway to Computer Science Book -9


263
Practical Assignment
CLS
INPUT "Enter an angle in degree"; A
R = A * 3.14 / 180
P = TAN(R)
PRINT "The tangentof"; A; "Degree"; "is"; P
END

Let’s Review
 A function is a built-in formula or a readymade program which helps us to perform
a certain task such as mathematical, statistical, financial, logical calculations, etc.
 A function which is written and stored by the programmer to perform a specific
task is known as a user defined function.
 Built in function is a pre-defined program which is provided by QBASIC to
perform some task easily.
 Numeric function provides a faster way to evaluate many mathematical functions.
 ABS function is used to obtain the absolute corresponding positive value of
a numerical expression.
 CINT is a mathematical function used to convert numeric expression to an integer
by rounding the fractional portion.
 COS is a mathematical function which is used to obtain the cosine of x.
 TAN is a mathematical function that returns the tangent of an angle expressed in
radians.

INT Function: This function is used to obtain the largest integer that is less than or equal
to x. INT rounds negative numbers to the next more negative integer. The syntax of INT
function is given below.

INT(x), where x is any numeric expression.

Practical Assignment
CLS
INPUT "Enter a number"; N
Result = INT(N)
PRINT "The integer value is"; Result
END

New Gateway to Computer Science Book -9


264
SGN function: It is used to obtain the mathematical sign of x. The SGN function has the
following return values.

If the number is, SGN returns


Greater than zero 1
Equal to zero 0
Less than zero -1
The syntax of SGN function is given below.

SGN(x), where x is any numeric expression.

Practical Assignment
CLS
INPUT "Enter a number"; N
Result = SGN(N)
PRINT "The SGN value is"; Result
END
SQR Function: It is used to calculate and return the square root of non-negative number.
If the number is negative, an illegal function will appear. The syntax of SQR function is
given below.

SQR(x), where x is any numeric expression that is greater than or equal to 0.

Practical Assignment
CLS
INPUT "Enter a number"; N
Result = SQR(N)
PRINT "The square root value is"; Result
END
String Functions
QBASIC program has various built in string functions that are mainly used to operate and
manipulate string expressions. Some of the string functions are listed below.
ASC Functions: It is a string processing function which is used to return a numeric
value that is the ASCII code for the first character of the string. The ASCII values of some
commonly used characters are given below.

New Gateway to Computer Science Book -9


265
Characters ASCII Value (Code)
A-Z 65-90
a-z 97-122
0-9 48-57
The syntax of ASC function is given below.

ASC (String expression)

Practical Assignment
CLS
A = ASC("SHUBHARAMBHA")
B = ASC("gatewaycomputer")
C = ASC("4302109")
PRINT A
PRINT B
PRINT C
END
CHR$ Function : This function returns a character that corresponds to specific ASCII
values in between -128 and 127 as arguments. The syntax of CHR$ function is given
below.

CHR$ (ASCII code)

Practical Assignment
CLS
PRINT "The ASCII code of 80 is::"; CHR$(80)
PRINT "The ASCII code of 110 is::"; CHR$(110)
PRINT " The ASCII code of 50 is::"; CHR$(50)
END
LEN Function: It is a string processing function which is used to count and return to the
total number of characters in a string. The syntax of LEN function is given below.

LEN (string -expression)

New Gateway to Computer Science Book -9


266
Practical Assignment
CLS
INPUT "Enter first word"; A$
INPUT "Enter second word"; B$
INPUT "Enter Third Word"; C$
PRINT "The total number of characters in fist word are::"; LEN(A$)
PRINT "The total number of characters in second word are::"; LEN(B$)
PRINT "The total number of characters in third word are::"; LEN(C$)
END
INSTR$ Function: It is a string processing function which is used to search for one
string inside another and return to the position of first character.The syntax of INSTR$
function is given below.
INSTR([n,]x$,y$) where n is an integer expression and x$ and y$ can be any string
variable, expression or constants.

Practical Assignment
CLS
A$ = "SCIENCE"
B$ = "C"
PRINT "In the word SCIENCE, The first letter C occurs at the position:"; INSTR(A$, B$)
PRINT "In the word SCIENCE, The second letter C occurs at the position:"; INSTR(3,
A$, B$)
END
VAL Function: It is a string processing function which converts a string expression
consisting of digits into value. The extracted value is numeric in nature and can be used
for mathematical calculation. If the first character of a string is not numeric, then VAL
will return 0(zero). The syntax of VAL function is given below.
VAL(N$), Where N$ is any string expression.

Practical Assignment
CLS
A$ = "20 Computer Books"
C = VAL(A$)
B$ = "40 Maths Books"

New Gateway to Computer Science Book -9


267
CO = VAL(B$)
Total = C + CO
PRINT "The total books are"; Total
END
LEFT$ Function: This is a string processing function which is used to extract
and return to the numbers of characters from the left of a string. The syntax of LEFT$
function is given below.
LEFT$ (String expression, n) where, string expression is a string constant, variable or
expression and n is an integer expression in the range.

Practical Assignment
CLS
INPUT "Enter a Word"; C$
FOR I = 1 TO LEN(C$)
PRINT LEFT$(C$, I)
NEXT I
END
RIGHT$ Function:This string processing function is used to extract and return to
the numbers of characters from the right of a string. The syntax of RIGHT$ function is
given below.
RIGHT$ (String expression, n) where, string expression is a string constant, variable or
expression and n is an integer expression in the range.

Practical Assignment
CLS
INPUT "Enter a Word"; C$
FOR I = 1 TO LEN(C$)
PRINT RIGHT$(C$, I)
NEXT I
END
MID$ Function:This function is used to replace the part of the string variable with
another. The syntax of MID$ function is given below.
MID$(string expression,start,length) where, string expression is the string from which
the sub starting has to be extracted. Start is the starting position to extract from the string
expression and length is the number of characters to extract.

New Gateway to Computer Science Book -9


268
Practical Assignment
CLS
INPUT "Enter a Word"; c$
PRINT MID$(c$, 2, 6)
PRINT MID$(c$, 3, 4)
END

Let’s Review
 INT function is used to obtain the largest integer that is less than or equal to x.
 SQR function is used to calculate and return to the square root of non-negative
number.
 ASC is a string processing function which is used to return to a numeric value that
is the ASCII code for the first character of the string.
 LEN is a string processing function which is used to count and return to the total
number of characters in a string.
 VAL is a string processing function which converts a string expression consisting
of digits into value.
 LEFT$ is a string processing function which is used to extract and return to the
numbers of characters from the left of a string.
 RIGHT$ is a string processing function which is used to extract and return to the
numbers of characters from the right of a string.
 MID$ function is used to replace the part of the string variable with another.

SPACE$ Function: This function is used to generate a string of spaces of a specified


length. The syntax of SPACE$ function is given below.
SPACE$(n) where, n is an integer expression in the range of 0-32,767.

Practical Assignment
CLS
FOR I = 1 TO 10
N$ = SPACE$(I)
PRINT N$, I;
NEXT I
END

New Gateway to Computer Science Book -9


269
STR$ Function: It is a string processing function that is used to convert a numeric
expression to string and return to the same. The syntax of STR$ function is given below.

STR$(n) where, n is any numeric expression.

Practical Assignment
CLS
INPUT "Enter a decimal number"; N
WHILE N <> 0
R = N MOD 2
S$ = STR$(R) + S$
N=N\2
WEND
PRINT "THE BINARY EQUIVALENT VALUE IS::"; S$
END
STRING$ Function:This function is used to return to a string of a specified length made
up of a repeating character. The syntax of STRING$ function is given below.
STRING$(x,y | z$)Where, x and y are the numeric expression and Z$ is any string
expression.

Practical Assignment
CLS
FOR I = 1 TO 6
PRINT STRING$(I, "*")
NEXT I
END
LCASE$ Function: This is a string processing function which converts the string into
lower case. The syntax of LCASE$ function is given below.
LCASE$(String expression)

Practical Assignment
CLS
INPUT "Enter a word or sentence in UPPER case"; C$
PRINT LCASE$(C$)
END
UCASE$ Function: This is a string processing function which converts the string into
upper case. The syntax of UCASE$ function is given below.
UCASE$(String expression)

New Gateway to Computer Science Book -9


270
Practical Assignment
CLS
INPUT "Enter a word or sentence in LOWER case"; C$
PRINT UCASE$(C$)
END
DATE$ Function: This string function is used to display the system date. The syntax of
DATE$ function is given below.
DATE$
Practical Assignment
CLS
PRINT DATE$
END
TIME$ Function: This string function is used to display the system time. The syntax of
TIME$ function is given below.
TIME$
Practical Assignment
CLS
PRINT TIME$
END
LTRIM$ Function: It is a string processing function which removes the leading blank
space from the string expression. The syntax of LTRIM$ function is given below.
LTRIM$(String expression)
Practical Assignment
CLS
A$= " DINESH ADHIKARI "
PRINT LTRIM$(A$)
END
RTRIM$ Function: It is a string processing function which removes the trailing blank
space of the string expression. The syntax of RTRIM$ function is given below.
RTRIM$(String expression)

New Gateway to Computer Science Book -9


271
Practical Assignment
CLS
A$= " DINESH ADHIKARI "
PRINT RTRIM$(A$)
END
INPUT$ Function: It is a string processing function which waits until the
specified numbers of characters are pressed on keyboard. Users do not have to press
‘ENTER’ key after the last character is typed or pressed.The syntax of INPUT$ function
is given below.
INPUT$ (n, [# ] file number]) Where, n is the number of characters to be read. Filenum
is the number under which the file was opened.

Practical Assignment
CLS
INPUT "Enter your name in 5 digits"; N$
N$=INPUT$(5)
PRINT N$
END

Let’s Review
 SPACE$ function is used to generate a string of spaces of a specified length.
 STR$ is a string processing function that is used to convert a numeric expression
to string and return to the same.
 STRING$ function is used to return to a string of a specified length made up of a
repeating character.
 LCASE$ is a string processing function which converts the string into lower case.
 UCASE$ is a string processing function which converts the string into upper case.
 DATE$ is a string function used to display the system date.
 TIME$ string function is used to display the system time.
 LTRIM$ is a string processing function which removes the leading blank space
from the string expression.
 RTRIM$ is a string processing function which removes the trailing blank space
of the string expression.
 INPUT$ is a string processing function which waits until the specified numbers of
characters are pressed on keyboard.

New Gateway to Computer Science Book -9


272
Practical Section
Program: 1: Write a Qbasic program to check whether the entered letter is
uppercase or lowercase.
CLS
INPUT "Enter a letter";A$
U$=UCASE$(A$)
IF U$=A$ THEN
PRINT "It is capital letter"
ELSE
PRINT "It is small letter"
ENDIF
END
Program: 2: Write a Qbasic program to check a given string is palindrome or
not .
CLS
INPUT "ENTER A STRING"; S$
FOR I = LEN(S$) TO 1 STEP -1
M$ = MID$(S$, I, 1)
REV$ = REV$ + M$
NEXT I
IF S$ = REV$ THEN
PRINT "THE GIVEN STRING IS PALINDROME"
ELSE
PRINT "IT IS NOT PALINDROME"
END IF
Program: 3: Write a Qbasic program to convert decimal to octal.
CLS
INPUT "ENTER A DECIMAL NUMBER"; N
WHILE N <> 0
A = N MOD 8
B$ = STR$(A)
N = FIX(N / 8)
C$ = B$ + C$
WEND
PRINT "THE OCTAL EQUIVALENT IS"; C$
END

New Gateway to Computer Science Book -9


273
Program: 4: Write a Qbasic program to convert Hexadecimal to Decimal.
CLS
INPUT "ENTER HEXADECIMAL VALUE";B$
FOR I=LEN(B$) TO 1 STEP -1
A$=MID$(B$,I,1)
C=VAL(A$)
IF A$="A" THEN C=10
IF A$="B" THEN C=11
IF A$="C" THEN C=12
IF A$="D" THEN C=13
IF A$="E" THEN C=14
IF A$="F" THEN C=15
H=H+C*16^P
P=P+1
NEXT I
PRINT "DECIMAL VALUE IS";H
END
Program: 5: Write a Qbasic program to reverse a given string.
CLS
INPUT "ENTER A STRING"; S$
FOR I = LEN(S$) TO 1 STEP -1
M$ = MID$(S$, I, 1)
REV$ = REV$ + M$
NEXT I
PRINT REV$
END

Program: 6: Write a Qbasic program to display the given pattern.


N CLS
NE A$="NEPAL"
FOR I = 1 TO LEN (A$)
NEP
PRINT LEFT$(A$,I)
NEPA NEXT I
END
NEPAL

New Gateway to Computer Science Book -9


274
Program: 7: Write a Qbasic program to display the given pattern.
NEPAL CLS
NEPA A$ = "NEPAL"
FOR i = LEN(A$) TO 1 STEP -1
NEP
PRINT RIGHT$(A$, i)
NE NEXT i
N END

Program: 8: Write a Qbasic program to display the given pattern.


L CLS
A$ = "NEPAL"
AL
FOR I = 1 TO LEN(A$)
PAL PRINT RIGHT$(A$, I)
EPAL NEXT I
END
NEPAL

Program: 9: Write a Qbasic program to display the given pattern.


CLS NE
a$ = "NEPAL"
x = LEN(a$) EP
FOR i = 1 TO x – 1 PA
PRINT TAB(i); MID$(a$, i, 2)
AL
NEXT i
END
Program: 10: Write a Qbasic program to display the given pattern.
CLS
A
s$ = "PROGRAMMING"
RAM
t=6
GRAMM
FOR i = 1 TO LEN(s$) STEP 2
PRINT TAB(t); MID$(s$, t, i)
OGRAMMI
t=t–1
ROGRAMMIN
NEXT i
PROGRAMMING
END

New Gateway to Computer Science Book -9


275
Program: 11: Write a Qbasic program to display the given pattern (flag
pattern of Nepal).
CLS
*
A$ = “*********”
** A=1
*** B=1
FOR I = 1 TO 5
****
COLOR 4
***** PRINT MID$(A$, A, B)
* B=B+1
NEXT I
**
A=1
*** B=1
**** FOR J = 1 TO 5
COLOR 6
*****
PRINT MID$(A$, A, B)
* B=B+1
* NEXT J
FOR K = 1 TO 5
*
COLOR 5
* PRINT MID$(A$, K, 1)
* NEXT K
END

Program: 12: Write a Qbasic program to calculate the square root of a given
number.
REM Program to calculate the square root of a given number
CLS
INPUT "Enter any number"; n
s = SQR(n)
PRINT "Square root of "; n; " is "; s
END

New Gateway to Computer Science Book -9


276
Assignment
1. Fill in the blanks with suitable words.
a. A function is a built-in formula or a ………… which helps us to perform a certain
task such as mathematical, statistical, financial, logical calculations, etc.
b. ……………….. provides a faster way to evaluate many mathematical functions.
c. …………… is a mathematical function used to convert numeric expression to an
integer by rounding the fractional portion or it returns the integer to the given
number.
d. ………….. is a mathematical function that return to the tangent of an angle
expressed in radians.
e. …………….. function is used to calculate and return to the square root of
non-negative number.
f. …………… is a string processing function which is used to count and return to
the total number of characters in a string.
g. ……………… is a string processing function which is used to extract and return
to the numbers of characters from the left of a string.
h. ………………….. function is used to replace the part of the string variable with
another.
i. ………………. is a string processing function which converts the string into
upper case.
j. …………….. string function is used to display the system time.
2. State whether the given statements are true or false.
a. Built in function is a pre-defined program which is provided by QBASIC to
perform some tasks easily.
b. CNT function is used to obtain an absolute corresponding positive value of a
numerical expression.
c. COS is a mathematical function which is used to obtain the cosine of x.
d. SQRT function is used to obtain the largest integer that is less than or equal to x.
e. ASC is a string processing function which is used to return to a numeric value that
is the ASCII code for the first character of the string.
f. VAL is a string processing function which converts a string expression consisting
of digits into value.
g. RIGHT$ is a string processing function which is used to extract and return to
the numbers of characters from the left of a string.
h. TIME$ function is used to generate a string of spaces of a specified length.

New Gateway to Computer Science Book -9


277
i. STRING$ function is used to return to a string of a specified length made up of a
repeating character.
j. INPUT$ is a numeric function which waits until the specified numbers of
characters are pressed on keyboard.
3. Write down the function and syntax for the following statements.
a. ABS function b. TAN function c. INT function
d. SQR function e. SGN function f. CHR$ function
g. LEN function h. INSRT$ function i.VAL function
j. LEFT$ function k. MID$ function l. SPACE$ function
m. STRING$ function n. UCASE$ function o. LTRIM$ function
4. Debug the following programs.
a. CLS b. CLS
A = "20 Computer Books" INPUT "Enter a decimal number"; N
WHILE X <> 0
C = VAL(A$)
R = N MOD 2
B$ = "40 Maths Books"
S = STR$(R) + S$
C = VAL(B) D=N\2
Total = C + CO END
PRINT "The total books are"; T PRINT "BINARY EQUIVALENT IS::"; S$
END END

c. CLS d. CLS
INPUT "Enter a letter";A$ INPUT "ENTER A DECIMAL NUMBER"; N

U=UCASE(A$) WHILE N <> 0

IF U$=A THEN A = N MOD 8

PRINT "It is capital letter" B$ = STR$(A)


N = FI(C / 8)
ELSE IF
WEND
PRINT "It is small letter"
C$ = A$ + C
IFEND
PRINT "THE OCTAL EQUIVALENT IS"; C$
END
END

New Gateway to Computer Science Book -9


278
5. Write down the output of the following program.
a. CLS
A$="NEPAL"
FOR I = 1 TO LEN (A$) b. CLS
PRINT LEFT$(A$,I) A$ = “*********”
A=1
NEXT I
B=1
END
FOR I = 1 TO 5
c. CLS COLOR 4
a$ = "NEPAL" PRINT MID$(A$, A, B)
x = LEN(a$) B=B+1
FOR i = 1 TO x – 1 NEXT I
PRINT TAB(i); MID$(a$, i, 2) A=1
NEXT i B=1
END FOR J = 1 TO 5
d. CLS COLOR 6
A$ = "NEPAL" PRINT MID$(A$, A, B)
B=B+1
FOR I = 1 TO LEN(A$)
NEXT J
PRINT RIGHT$(A$, I)
FOR K = 1 TO 5
NEXT I
COLOR 5
END PRINT MID$(A$, K, 1)
NEXT K
END
6. Write a QBASIC program to display the following outputs.
G
GA NEPAL COMPUTER G
GAT NEPA OMPUTER OGR
GATE NEP MPUTER POGRA
GATEW NE PUTER PROGRAM
GATEWA N UTER
GATEWAY TER
ER
R

New Gateway to Computer Science Book -9


279
7. Write a QBASIC program for the followings.
a. Write a program to input a number and check whether it is positive, negative or
zero
b. Write a program to check whether the entered letter in uppercase or lowercase.
c. Write a program to check whether the given string is palindrome or not.
d. Write a program to convert the decimal number into octal.
e. Write a program to reverse a given string.
f. Write a program to calculate the square root of a given number.
g. Write a program to count the number of vowels in an input string.
h. Write a program to input a string and count the number of words in it.
i. Write a program to input three strings and find the longest among them.

New Gateway to Computer Science Book -9


280
Lesson

16 Arrays in QBASIC

Inside the Lesson

 Introduction to array
 Advantages of using array
 Declaring and using an array
 Arrays variables
 Arrays elements
 Types of array
 Rules for declaring one dimensional array
 Sorting data in array
 Searching data in array
 Working with single and double dimensional array

An array is a collection of variables of the same data type that are referred to by common
name. When there are large lists of variables and data, it is easier to contain the data in
an array than have large amounts of separate variables to hold the data. Array is a group
of related data items having a common variable name. An array is primarily used when
groups of data items must be stored and manipulated efficiently. An array is given a name
and also a specified number of data items that it will contain; each individual item is
referred to as an element. Each element is given a unique storage location in the array and
a subscript or index value is used to identify the position of a particular element.
An array declared should indicate the three main things.
a. Name of the array.
b. Type of value to be stored in an each element.
c. Number of elements in an array.

Advantages of Using an Array


 It can reduce the number of variable name in a program because single array can
store large number of data.
 It can be used to store the similar type of data rather than using many simple variables.
 It can be used to prepare more efficient programs.

New Gateway to Computer Science Book -9


281
 It is very easy to compare and manipulate data with the help of array variable rather
than simple variables.
 It is very easy to understand and use.

Sample program to store and display data using an array.


CLS
DIM N(10)
FOR i = 1 TO 10
INPUT N(i)
Sum = Sum + N(i)
NEXT i
PRINT "The total sum is the given numbers::"; Sum
END
In the above program, N(i) is an array variable, which stores ten different values using
For…Next loop. The variable sum stores the sum of all input numbers.

Declaring and Using an Array

Arrays need to be declared before using in a program and to declare an array; we must
use a DIM statement. DIM statement plays the role of reserving internal memory space
for an array of any desired size. We have to remember the name of array, number of
elements required and data type required before declaring an array.
Syntax: DIM [SHARED] arrayname (subscript) [AS TYPE] [arrayname (subscript) [AS
TYPE]]
Here, SHARED is a keyword that is used to share the value of the variable with the
procedures. Arrayname is the name of the array variable. Subscript specifies the size of
an array and AS TYPE defines the type of array variable.
Examples
DIM age (20)
DIM name$(20)
In this example age and name$ are the name of array variables and 20 is the size of
variable which provides maximum 21 elements (o to 20) or subscripted variables for an
array.

New Gateway to Computer Science Book -9


282
Array Variables
A variable of array type holds a reference to an object. Declaring a variable of array type
does not create any array object or allocate any space for array components. It creates
only the variable itself, which can contain a reference to an array.

Subscripted Variables or elements of an array Data stored in each element


N(0) 67
N(1) 7
N(2) 44
N(3) 34
…………….. ………….
N(8) 23
N(9) 55
N(10) 90

Array Elements
Once an array is created, we have to put something in it. Each element or index has an
integer value associated with it. Each data item of an array is called array elements. Each
array element is individually referred to by its subscript. The number of elements that an
array can store is calculated using the given formula.
Number of elements = (upper bound – lower bound +1)
Example: Declare a string array variable that can store address of any 10 students.
DIM add$(9)
Or
DIM add(9) AS STRING
Here, add$ is the name of string type array variable and 9 is subscript. Its upper bound
is 9. It can store any 10 string values from 0 to 4. The add$ array can store the ten string
values in the given format.

Add$ Add$ Add$ Add$ Add$ Add$ Add$ Add$ Add$ Add$
(0) (1) (2) (3) (4) (5) (6) (7) (8) (9)
Pokhara Palpa Dhading Butwal Sarlahi Dhanusa Mugu Rolpa Sindhuli Parbat

Here the first element is represented by subscript 0. For example, Add$(0) = Pokhara
and the ninth element is represented by subscript 9 which is Add$(9) = Parbat. The upper

New Gateway to Computer Science Book -9


283
bound of this array is 9 and the lower bound of this array is 0. So this array can store only
(9-0+1=10) elements.
Option base statement: This statement defines the lower bound value for an array. This
statement should appear before the array in a program otherwise Qbasic displays error
message as ‘Duplicate Definition’. The general format of this statement is given below.
OPTION BASE n ,where n is a number whose value can be either 0 or 1.
Types of Array
There are various types of array but on the basis of number of data elements used,
the array can be classified into two types which we are going to discuss below.
 Single or one dimensional array
 Multi or two dimensional array
Single or One Dimensional Array
Single dimensional array represents a series of similar type of data represented by
a variable name with a single subscript. The data may be a series of numbers or
string arranged in a single row or column.
Let’s see the given table.
Elements of an array (N) N(1) N(2) N(3) N(4) N(5)

Values stored by an array 10 20 30 40 50


In the above table, an array variable (N) stores different numbers which contain the
number of variables which are called elements or subscripted variables. Likethis, N1, N2,
N3, N4, N5 are subscripted elements of variables of an array. It stores different values of
similar type.

Rules for declaring one dimensional array


 An array variable must be declared before being used in a program.
 Elements of an array must be of same type.
 An array index always starts from 0. For example, if an array variable is
declared as s[10], then it ranges from 0 to 9.
 Each array element is stored in a separate memory location.
 The name of array should be unique.
 It is not necessary to write a subscript as a constant.
 We can use variable and expression as its subscripts.

New Gateway to Computer Science Book -9


284
Practical Assignment
Program 1: Write a program to find the greatest number among any 10 different
numbers.
OPTION BASE 1
DIM N(10)
FOR I = 1 TO 10
INPUT "Enter a number"; N(I)
NEXT I
G = N(1)
FOR I = 2 TO 10
IF N(I) > G THEN G = N(I)
NEXT I
PRINT "The numbers entered by the users are:"
FOR I = 1 TO 10
PRINT N(I);
NEXT I
PRINT
PRINT "The greatest number is:"; G
END
Program 2: Write a program to find the sum of any 10 numbers.
CLS
DIM NUM(10)
FOR I = 1 TO 10
READ N(I)
S = S + N(I)
NEXT I
DATA 20, 30, 40, 50, 60
DATA 10, 15, 20, 25, 30
PRINT "The sum is"; S
END

New Gateway to Computer Science Book -9


285
Program 3: Write a program to store the marks of 5 subjects in an array.
OPTION BASE 1
CLS
DIM Marks(5)
FOR I = 1 TO 5
READ Marks(I)
PRINT Marks(I)
NEXT I
DATA 90, 85, 75, 65, 60
END
Program 4: Write a program to display the given output in the tabular form as given
below:
5 10 15 20
25 30 35 40
45 50 55 60
65 70 75 80
CLS
DIM N(16)
FOR I = 1 TO 4
FOR J = 1 TO 4
READ N(J)
PRINT N(J),
NEXT
PRINT
NEXT
DATA 5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80
END

New Gateway to Computer Science Book -9


286
Sorting Data in an Array
Sorting is the process of arranging data either in ascending or in descending order. It is
very important in programming. It can be applied both on string data or numeric data.
Let’s practise some programs for sorting data.

Practical Assignment

Program 5: Write a program to sort numbers in ascending order.


CLS
DIM N(15)

PRINT "The numbers entered by the users are::";


FOR I = 1 TO 15
READ N(I)
PRINT N(I);
NEXT I
DATA 15,11,17,19,14,22,45,35,10,9,7,46,32,77,89
FOR I = 1 TO 15
FOR J = 1 TO 15 - I
IF N(J) > N(J + 1) THEN SWAP N(J), N(J + 1)
NEXT J
NEXT I
PRINT
PRINT "The numbers in ascending order are::"
FOR I = 1 TO 15
PRINT N(I);
NEXT I

END

New Gateway to Computer Science Book -9


287
Program 6: Write a program to sort any five strings in ascending order.
CLS
DIM W$(5)
FOR I = 1 TO 5
INPUT "Enter the words"; W$(I)
NEXT I
FOR I = 1 TO 4
FOR J = I + 1 TO 5
IF W$(I) > W$(J) THEN SWAP W$(I), W$(J)
NEXT J
NEXT I
PRINT "The word in ascending order is as given below::"
FOR I = 1 TO 5
PRINT W$(I);
NEXT I

END

Searching Data in an Array


Searching is a process of finding the records required by the user. It is very easy to search
a record in the list of data stored in an array variable. We can search data by comparing
the data with each value stored in the array variable one after another in sequence. Let’s
practise some programs for searching data.

Practical Assignment
Program 7: Write a program to search data within an array.
CLS
DIM N(1 TO 5)
FOR I = 1 TO 5
READ N(I)
NEXT I
DATA 10,11,15,17,20
INPUT "Type the number to search"; N

New Gateway to Computer Science Book -9


288
FOR I = 1 TO 5
IF N = N(I) THEN
PRINT "The number is available on::"; I;
F=1
END IF
NEXT I
IF F = 0 THEN
PRINT "The number is not available"
END IF
END
Program 8: Write a program to search string data within an array. (ERROR)
CLS
DIM N$(5)
FOR I = 0 TO 5
READ N$(I)
NEXT I
DATA RAJU , RAM , KAMAL, DINESH, GOPAL SHYAM
FOR J = 0 TO 5
CH$ = LEFT$(N$(J), I)
IF UCASE$(CH$) = "D" THEN
PRINT N$(J)
END IF
NEXT J
END

Two Dimensional Arrays or the Matrix


The two dimensional array is also called a double dimensional array which is used for
representing the elements of the array in the form of the rows and columns and these
are used for representing the matrix. A Two Dimensional Array uses two subscripts for
declaring the elements of the Array. The double dimensional array is declared as:
DIM ArrayName(row,column) AS typeWhere, row and column specify the number of
rows and columns in the table.
Example
DIM D(3,4)

New Gateway to Computer Science Book -9


289
It defines a two dimensional array named ‘D’ having 3 rows and 4 columns. It has total 12
subscripted variables. The above example DIM D(3,4) displays the table as below.

Column 1 Column 2 Column 3 Column 4


Frist Row D(1,1) D(1,2) D(1,3) D(1,4)
Second Row D(2,1) D(2,2) D(2,3) D(2,4)
Third Row D(3,1) D(3,2) D(3,3) D(3,4)

Practical Assignment
Program 9: Write a program to display the output as below.
1 1
2 2
CLS
DIM vars(2, 2) AS INTEGER
vars(1, 1) = 1
vars(1, 2) = 1
vars(2, 1) = 2
vars(2, 2) = 2
FOR y = 1 to 2
FOR x = 1 to 2
PRINT vars(y,x),
NEXT x
PRINT
NEXT y
END
Program 10: Write a program to store data in the table.
CLS
OPTION BASE 1
DIM N(3, 4)
FOR I = 1 TO 3
FOR J = 1 TO 4

New Gateway to Computer Science Book -9


290
READ N(I, J)
NEXT J
NEXT I
DATA 10,11,12,13,14,15
DATA 16,17,18,19,20,21
REM DISPLAYING DATA IN TABULAR FORMAT
FOR I = 1 TO 3
FOR J = 1 TO 4
PRINT N(I, J),
NEXT J
PRINT
NEXT I
END
Program 11: Write a program to display the tabular form using multi- dimensional
array with their row sum.
CLS
DIM N(3, 3)
FOR I = 1 TO 3
FOR J = 1 TO 3
READ N(I, J)
NEXT J
NEXT I
DATA 2,4,5,3,2,1,7,8,3
FOR I = 1 TO 3
S=0
FOR J = 1 TO 3
PRINT N(I, J);
S = S + N(I, J)
NEXT J
PRINT "="; S
NEXT I
END

New Gateway to Computer Science Book -9


291
Program 12: Write a program to do the addition of a matrix.
CLS
REM Addition of Matrix.
INPUT "ENTER ROW"; R
INPUT "ENTER COLUMN"; C
DIM M1(R, C), M2(R, C)
PRINT "Enter Matrix M1"
FOR I = 1 TO R
FOR J = 1 TO C
INPUT M1(I, J)
NEXT J
NEXT I
PRINT " Enter Matrix M2"
FOR I = 1 TO R
FOR J = 1 TO C
INPUT M2(I, J)
NEXT J
NEXT I
FOR I = 1 TO R
FOR J = 1 TO C
M3(I, J) = M1(I, J) + M2(I, J)
NEXT J
NEXT I
PRINT "Addition of Matrix"
FOR I = 1 TO C
FOR J = 1 TO R
PRINT M3(I, J);
NEXT J
PRINT
NEXT I
END

New Gateway to Computer Science Book -9


292
Practical Section
Program 1: Type the following program in Qbasic and write the output in the given
box.
CLS
DIM X(5)
FOR I = 1 TO 5
X(I) = 2 * I
PRINT I; X(I)
NEXT I
END
Program 2: Write a program that allows the user to enter the various numbers and
display the sum of only an even digit.
CLS
INPUT "Enter the required numbers that you want to enter"; N
DIM NUM(N)
S=0
FOR I = 1 TO N
INPUT "Enter a Number"; NUM(I)
IF NUM(I) MOD 2 = 0 THEN
S = S + NUM(I)
END IF
NEXT I
PRINT "The sum of even numbers is:"; S
END
Program 3: Write a program to enter any ten numbers and display the
numbers in reverse order.
CLS
DIM n(10)
PRINT "Enter any 10 numbers"
FOR i = 1 TO 10
INPUT n(i)
NEXT
PRINT "The reverse order of number is"

New Gateway to Computer Science Book -9


293
FOR J = 10 TO 1 STEP -1
PRINT n(J);
NEXT
END
Program 4: Write a program to enter any five numbers and display the greatest
number among them.
CLS
DIM num(4)
PRINT "Enter any any 5 numbers"
FOR j = 0 TO 4
INPUT num(j)
NEXT j
L = num(0)
FOR j = 0 TO 4
IF L <num(j) THEN
L = num(j)
END IF
NEXT j
PRINT "largest number is="; L
END
Program 5: Write a program to enter any five numbers and display the smallest
number among them.
CLS
DIM num(4)
PRINT "Enter any any 5 numbers"
FOR j = 0 TO 4
INPUT num(j)
NEXT j
S = num(0)
FOR j = 0 TO 4
IF S >num(j) THEN
S = num(j)
END IF
NEXT j
PRINT "The smallest number is="; S
END

New Gateway to Computer Science Book -9


294
Program 6: Write a program to enter name and marks of any 5 students and display
with result either pass or fail.
CLS
DIM N$(5)
DIM M(5)
PRINT "Enter Name and Marks of any 5 students"
FOR I = 1 TO 5
PRINT I
INPUT "Enter Name: "; N$(I)
INPUT "Enter Marks:"; M(I)
NEXT I
PRINT
PRIN
PRINT
PRINT "MARKS OF STUDENTS"
PRINT "NAME", "MARKS", "RESULT"
FOR I = 1 TO 5
IF M(I) >= 40 THEN
R$ = "PASSED"
ELSE
R$ = "FAILED"
END IF
PRINT N$(I), M(I), R$
NEXT I
END
Program 7: Write a program to display the name and roll number of first 7 students.
DIM N$(6), roll(6)
CLS
FOR I = 0 TO 6
READ n$(I), roll(I)
NEXT I
FOR I = 0 TO 6
PRINT N$(I), roll(I)
NEXT I
DATA Dinesh,1, Kamal,2 ,Maya,3,Bhupendra,4,Divyanshi,5,Pranjita,6,Bikey,7
END

New Gateway to Computer Science Book -9


295
Assignment
1. Answer the following questions.
a. What is an array? What are the things that we have to indicate while declaring an
array?
b. What are the advantages of using an array?
c. What are the array variables?
d. What is an array element?
e. What are the types of an array? Define them.
f. What are the rules for declaring one dimensional array?
g. What is searching data in an array?
2. Debug the given programs.
a. DIM N(5, 10)
LET S = 0
FOR I = 0 TO 5
FOR J = 10 TO 1
LET S = S + N(I + 1) (J-1)
NEXT
NEXT
END
3. Write down the output of the given programs.
a. DIM N (5)
FOR I = 1 TO 5
READ N (I)
NEXT I
S = 0
FOR J = 1 TO 5
PRINT N (J)
S = S+N (J)
NEXT J
PRINT "SUM"; S
DATA 5, 10, 15, 20, 25
END

New Gateway to Computer Science Book -9


296
b. DIM N$(4)
FOR A = 1 TO 4
READ N$ (A)
NEXT A
FOR B = 1 TO 4
PRINT LEFT$(N$(B), B)
NEXT B
DATA ARUN, BARUN, KARUN, TARUN
END
5. Write array program for the followings.
a. A program to accept 15 numbers into an integer array and display odd or even
numbers.
b. To input 10 numbers and arrange them in an ascending order.
c. To input 20 numbers and arrange them in a descending order.
d. To display the largest number from the given data set.
45, 42, 56, 51, 48, 55, 96, 78, 22, 35,40,50
e. To display the smallest number from the given data set.
45, 42, 56, 51, 48, 55, 96, 78, 22, 35,40,50
f. Using single dimensional array display the given output.
10 15 20
25 30 35
40 45 50
g. To print the given table format.
1 3 5 7 = 16
9 2 4 3 = 18
8 6 5 4 = 23

h. To input any 15 numbers and display only the number that are divisible by
4.
i. To input the age of any 10 person and display the youngest one.
j. To read and print the 7 numbers in reverse order.

New Gateway to Computer Science Book -9


297
Program Writing Project
Program writing project to prepare sales bill report
CLS
INPUT "How many items to be calculated? ",totalItems%
DIM itemName$(1 TO totalItems%) ' Declare our arrays
DIM itemCost!(1 TO totalItems%)
DIM numItems%(1 TO totalItems%)
DIM totalCost!(1 TO totalItems%)
FOR i% = 1 TO totalItems% 'First loop: get inputs
CLS
PRINT "Item "; i% ' Display the current item number
PRINT
INPUT "Item name -- ", itemName$(i%)
INPUT "Item cost -- ", itemCost!(i%)
INPUT "Quantity --- ", numItems%(i%)
totalCost!(i%) = itemCost!(i%) * numItems%(i%)
NEXT i%
CLS
PRINT "Summary"
PRINT
format$ = "\ \ $$#,###.## #,### $$#,###,###.##"
PRINT "Item name Item Cost Quantity Total Cost "
PRINT "----------------- ---------- -------- --------------"
FOR i% = 1 TO totalItems%
PRINT USING format$; itemName$(i%); itemCost!(i%); numItems%(i%);
totalCost!(i%)
netTotal! = netTotal! + totalCost!(i%)
NEXT i%
PRINT
PRINT "Net Total = "; netTotal!
END

New Gateway to Computer Science Book -9


298
Specification Grid - 2077
Class - 9
Time: 1 Hour 30 Minutes Full Marks: 50
1×2 Type of Q. No. Area No. of Marks
Questions Questions
1 Subjective Group A
& (Computer Fundamentals) – 22 Marks
2 1.a - Introduction to Computer 1×2 2
1.b -Types of computers 1×2 2
1.c - Computer System 1×2 2
1.d - Computer Hardware 1×2 2
1.e - Computer System 1×2 2
1.f - Working with Graphics 1×2 2
Objective 3 -Matching 4×0.5 2
4 - Multiple choice 4×0.5 2
5 - True&False 4×0.5 2
6 -Technical terms 4×0.5 2
7 -Full forms 4×0.5 2
(From the below chapters:
a) Introduction to Computer
b) Types of Computers
c) Computer System
d) Computer Hardware
e) Computer System
f) Working with Graphics )
3. Subjective Group B
(Internet & Web Technology) – 12 Marks
8.(a, b) -Internet Technology 2×2 4
9. a - HTML Tags (functions) 4×0.5 2
9. b - CSS Commands 4×0.5 2
Objective 10. a -Multiple choice/True and False 4×0.5 2
10. b - Technical terms/Matching 4×0.5 2
4. Subjective Group C
(Computer Programming) – 16 Marks
11. -Conceptual questions 2×1 2
(a,b,c) -Function and use of QBASIC 2×1 2
statements/functions
- Algorithm and Flowchart 1×2 2
12 -Debug a program 1×2 2
13 -Output of the given program code 1×2 2
14 - Write QBASIC program 2x3 6
15. a,b)
Total 53 50

New Gateway to Computer Science Book -9


299
Practical Assessment

Time: 1 Hour Full Marks: 25



Unit Group/Area Topics No. of Marks
Questions
2 Working with Graphic Design a graphic/Edit a photo(s). 1×2 5
3 Internet & Web Create a web-page using HTML 1×10 10
Technology and CSS
4 Computer Program- a) Write a sequential program 1×2 2
ming b) Write a program (selection) 1×2 2
c) Write a program (iteration) 1×2 2
d) Write a program (library func- 1×2 2
tion)
e) Write a program (array) 1×2 2
Total 7 25

Project Work
Full Mark: 25

Unit Group / Area Marks


2 Working with Graphics 5
3 Internet and Web Technology 10
4 Computer Programming 10

New Gateway to Computer Science Book -9


300

You might also like