100% found this document useful (2 votes)
3K views

RS3668 - Computer Science Grade 9 PDF

Uploaded by

Shree Shrestha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3K views

RS3668 - Computer Science Grade 9 PDF

Uploaded by

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

Computer Science

Grade 9
 
 
 
 
 
 

 
Government of Nepal 
Ministry of Education, Science and Technology 
Curriculum Development Centre 
Sanothimi, Bhaktapur 
Computer Science
Grade 9

Government of Nepal
Ministry of Education, Science and Technology
Curriculum Development Centre
Sanothimi, Bhaktapur
2076
Publisher:
Government of Nepal
Ministry of Education, Science and Technology
Curriculum Development Centre
Sanothimi, Bhaktapur

© Publisher

Edition:
2076 BS (2020 AD)

Printing:
Janak Shikshya Samagri Kendra Limited
Sanothimi, Bhaktapur
Preface
The curriculum and curricular materials are developed and revised on a regular basis
with the aim of making education objective-oriented, practical, relevant and job oriented.
It is necessary to instill the feelings of nationalism, national integrity and democratic
spirit in students and equip them with morality, discipline and self-reliance, creativity
and thoughtfulness. It is essential to develop in them the linguistic and mathematical
skills, knowledge of science, information and communication technology, environment,
health and population and life skills. It is also necessary to bring in them the feeling of
preserving and promoting arts and aesthetics, humanistic norms, values and ideals. It
has become the need of the present time to make them aware of respect for ethnicity,
gender, disabilities, languages, religions, cultures, regional diversity, human rights and
social values so as to make them capable of playing the role of responsible citizens. This
textbook for grade nine students as an optional Computer Science has been developed
in line with the Secondary Level Optional Computer Science Curriculum, 2074 so as
to strengthen knowledge, Skills and competencies on computer literacy. It is finalized
by incorporating the recommendations and feedback obtained through workshops,
seminars and interaction programmes.

The textbook is written by Mr. Sunil Kumar Gharti, Mr. Sushil Upreti and Mr. Bimal
Thapa. In Bringing out the textbook in this form, the contribution of the Director General
of CDC Dr. Lekha Nath Poudel is highly acknowledged. Similarly, the contribution
of Prof. Dr. Shashidhar Ram Joshi, Dr. Dipendra Gurung, Ms. Pramila Bakhati,
Mr. Nabaraj Paudel, Mr. Jagadish Bhatta, Mr. Dibakar Durdarshi is also remarkable. The
content was edited by Mr. Yubraj Adhikari and Mr. Khil Narayan Shrestha. The language
of this book was edited by Mr. Shankar Adhikari and Mr. Nabin Kumar Khadka. The
layout of this book was designed by Mr. Khados Sunuwar. CDC extends sincere thanks
to all those who have contributed in developing this textbook.

Efforts have been made to make this textbook activity-oriented, interesting and learner
centered Curriculum Development Centre welcomes constructive feedback.

2076 Curriculum Development Centre


Sanothimi, Bhaktapur
Contents
S.N. Page No

Unit 1.1 Computer Fundamentals 1

Unit 1.2 Types of Computer 12

Unit 1.3 Basic Architecture of Computer 22

Unit 1.4 Computer Hardware 29

Unit 1.5 Computer Software 57

Unit 2.1 Computer Graphics 77

Unit 3.1 Internet Technology 99

Unit 3.2 HTML (Hypertext Markup Language) 113

Unit 3.3 Cascading Style Sheets (CSS) 157

Unit 4.1 Computer Programming 174

Unit 4.2 Programming in QBASIC 186


Unit 1.1
Computer Fundamentals

Introduction to Computer
The modern world is called the age of science and technology. We cannot imagine life
without science and technology. The modern world of advanced technology could not
have been established without the development of computer technology. There is rapid
development in computer. Computer is used in many different fields for varieties of tasks.
It is used all over the world, no matter whether a country it is developed, developing
or underdeveloped. Computer is also used in Nepal various fields like: business, bank,
education, entertainment, scientific research, law, airlines, traffic control, etc. So, the
computer is now affecting every sphere of human activities and leading to many changes.
It has brought enormous changes in the world.

Introduction
The word "Computer" is derived from the Latin word "Computare" which means
'to calculate'. Nowadays, computer has become an indispensable part of our life.
Computer is used in various places like: home, school, college, offices etc. Computer
can perform complex mathematical calculations accurately in a short period of time.
The modern computer has lots of capabilities like creating documents, videos, games,
music presentation, etc. It can use AI (Artificial Intelligence) for understanding natural
language, taking self-decision capabilities, analysing graphs and patterns, etc.

Data is raw facts, concepts, or instructions in a formalized manner, which should


be suitable for communication, interpretation, or processing by computer. Data is
represented with the help of characters such as alphabets (A-Z, a-z), digits (0-9) or
special characters (+,-,/,*,<,>,= )

Information is organized or classified data, which has some meaningful results for the
receiver. Information is the processed data or meaningful results on which decisions
and actions are based.

1 Computer Science : Grade 9


A computer is an electronic device that accepts raw data and instructions from users;
processes it according to the given set of instructions, stores and gives meaningful
information.

Computer
Working Principle of a Computer
Computer is an electronic device that converts raw data into meaningful information
carrying out various processes as instructed by the programme. Every computer has
the ability to:

a. Input: Enter raw data into the computer.


b. Process: Process according to the given set of instructions to produce the required
result.
c. Output: Get meaningful information from the computer.
d. Storage: Store data and information for future use.
Characteristics of a Computer
A computer is powerful and useful in all areas. The use of computer is increasing with
time. The main features or characteristics of computer are described below:

i. Automatic
A computer is an automatic device. It can do tasks automatically as instructed by
software. It can automatically control various devices attached with computer system.

2 Computer Science : Grade 9


ii. Speed
A computer performs tasks accurately. The operations on data in computer are performed
through electronic circuit according to given instructions. Computer can perform millions
and billions of operations on data within a second. The speed of computer is measured
in MegaHertz (MHz) or GigaHertz (GHz). The time taken to perform a task is measured
in fraction of second. The smaller units of second are given below:

Power of
Unit of Time Meaning Part of Second
10
Millisecond (ms) One thousandth of second 1/1000 10-3sec.
Microsecond(us) One millionth of second 1/1,000,000 10-6sec.
Nanosecond(ns) One billionth of second 1/1,000,000,000 10-9sec.
Picosecond (ps) One trillionth of second 1/1,000,000,000,000 10-12sec.
Femtosecond (fs) One quadrillionth of second 1/1,000,000,000,000,000 10-15sec.

iii. Accuracy
A computer performs t4asks accurately. If data and instructions given to the computer
are correct then it gives an accurate output. It means output totally depends on the given
instructions and input data. If input data is incorrect then the output will be incorrect
which is called GIGO (Garbage in Garbage out).

iv. Storage
Computer system consists of data storage unit. A computer has main storage and
secondary storage. A large amount of data can be stored in secondary storage like hard
disk, pen drive, CD/DVD, etc. for future use. The main memory (RAM) stores currently
used data. Computer stores data in term of 0 and 1. The different units of storage in
computer are given below:

S.No. Memory Unit Description


1 Bit 1 Bit = 0 or 1
2 Nibble 1 Nibble = 4 Bits
3 Byte 1 Byte = 8 Bits

Computer Science : Grade 9 3


4 Kilobyte (KB) 1 Kilobyte (KB) = 1024 Bytes
5 Megabyte (MB) 1 Megabyte (MB) = 1024 KB
6 Gigabyte (GB) 1 Gigabyte (GB) = 1024 MB
7 Terabyte (TB) 1 Terabyte (TB)= 1024 GB
8 Petabyte (PB) 1 Petabyte (PB) = 1024 TB
9 Exabyte (EB) 1 Exabyte (EB) = 1024 PB
v. Diligence
A computer can continuously work for a long time without losing its speed and accuracy.
So it is called diligent device. It doesn’t get tired or bored or lazy while working.

vi. Versatile
A computer is a versatile device which means it is flexible. It has capability of performing
different types of tasks like drawing paints, playing games, music, calculations, sending
an e-mail, desktop publishing work, etc. in different field efficiently. So it is used in
different fields to perform varieties of tasks.

Application of Computer
A computer is given great importance in every field of work. Nowadays, it is impossible
to find where computer are not used. Computer and its technology are used in education,
agriculture, industries, banking, engineering, scientific research and many more. The
main applications of computer are described below:

i. Education
Nowadays, computer and Internet technology have changed the present education
system. Computer technology can be used for visual illustration like smart classroom
and distance learning education system. Today, school and colleges use computer in
computer lab and multimedia to teach students. A teacher can teach by using computer-
based presentations. Students can study various subject and complete assignment by
using Internet.

4 Computer Science : Grade 9


Computer in Education
ii. Communication
A computer plays a key role in the field of communication. The Internet and computer are
used to send and receive information. A computer uses various communication services
like e-mail, video conferencing, net phone, chatting, Facebook, Twitter, Instagram, etc.

Computer in Communication
iii. Banking Sector
A computer has brought revolution in the banking sector. The different services like
accounting, customer records to update, bank statement etc. are performed by using
computer in banking sector. ATM (Automated Teller Machine) allows 24 hours banking
services to their customers so that they can withdraw money at any time.

Computer Science : Grade 9 5


Computer in Banking Sector

iv. Medicine
A computer is used in scanning and diagnosing of various diseases through CT scan
(Computed Tomography scan), ultrasounds, ECG (Electro Cardio Graph) etc. It is also
used in hospitals to keep records of patients and medicines. Nowadays, computer is
used in surgery too. Doctors use computer and Internet services to provide telemedicine
services to remote areas of our country, Nepal.

Computer in Medicine
v. Entertainment
A computer is used to entertain people. It is used to play games, listen to music, watch
videos, movies and cartoon etc. It is used to watch online movies and play online games
6 Computer Science : Grade 9
by using Internet.

Computer in Entertainment
vi. Scientific Research
A computer is used in all types of scientific research. Scientists collect the latest
information by using internet all over the world. It is used in weather forecasting, space
research, complex research in various scientific fields etc.

Computer in Scientific Research


vii. Agriculture
Computer has not only made changes in modern occupation but also made changes in the
traditional occupation sector like agriculture. Through the social networking site, farmers
can get connect with other experts and exchange their views and other details when they
have internet connected computers. Farmers can get information on different agricultural
issues through internet surfing. Farmers can get connect with foreign customer which
can help to improve their product and increase their production capacity. Farmers can
use the computer to keep financial record, production record, online banking, online
sales, onlne purchased the required resources through the internet. The amount of water
sprinkled in a balanced quantity can also computerized.
Computer Science : Grade 9 7
Computer in Agriculture

Summary
 The word "Computer" is derived from the Latin word "Computare" which means
to calculate.
 A computer is an electronic device that accepts the raw data and instructions from
the user; processes raw data according to the given set of instructions, stores and
gives meaningful information.
 The speed of computer is measured in MegaHertz (MHz) or GigaHertz (GHz).
 A large amount of data is stored in secondary storage like hard disk, pen drive,
CD/DVD, etc. for future use.
 Computer and its technology are used in education, medicine, banking sector,
entertainment, scientific research and agriculture.

Technical Terms
Computer : An electronic device that processes raw data to give information.
Input : Enter raw data and instruction into the computer.
Output : Display meaningful information from the computer.
Process : Computation according to given set of instructions to produce
required result.
8 Computer Science : Grade 9
Storage : Keeping data and information for future use.
GIGO : If inputted data is incorrect then output will be incorrect.
Byte : The combination of eight bits.

Exercises
1. Answer the following questions.
a) Define Computer and list its capabilities.
b) Write the limitations of computer.
c) What is GIGO?
d) Explain working principles of computer with block diagram.
e) List any four features of computer.
f) Why is computer called diligence machine?
g) Describe the use of computer in education field.
h) Mention any four uses of computer.
i) State different units of storage in computer.

2. State 'True' or 'False'.


a) Computer is an electrical machine which can perform a task.
b) Computer processes raw data according to the given set of instructions.
c) The speed of computer is measured in MegaHertz (MHz).
d) A large amount of data is stored in secondary storage.
e) Computer is a versatile device which has the capability of performing
different types of tasks.
f) The combination of 1025 Megabyte is equal to one Gigabyte.

Computer Science : Grade 9 9


3. Match the following.
Group 'A' Group 'B'
i) Microsecond a) Raw facts or figures
ii) Data b) Application of computer
iii) GIGO c) One millionth of second
iv) Education d) Error due to wrong input
f) RAM

4. Choose the best answer from the list.


a. The measurement of second equal to one-millionth of a second is called...
i) millisecond ii) microsecond iii) nanosecond iv) picosecond
b. When the input is wrong, then the output will also be wrong, it is termed
as
i) FIFO ii) LIFO iii) GIGO iv) None of above
c. How many kilobytes make one megabyte?
i) 1030 ii) 1000 iii) 1048 iv) 1024
d. Repeatedly working capability of computer is known as
i) storage ii) speed iii) diligence iv) versatility

5. Fill in the blanks with appropriate words:


a) The word "Computer" is derived from the Latin word………
b) The speed of computer is measured in…………..
c) Nowadays, computer and……… technology has changed the present
education system.
d) ……allows 24 hours banking services to their customers to withdraw money
at any time.

10 Computer Science : Grade 9


6. Write the full form of.
i) GIGO ii) GB iii) TB iv) PB v) EB
vi) KB vii) AI viii) MHz ix) GHz x) ATM
xi) ECG xii) RAM xiii) CT scan

7. Write a short note on the following.


a) Application of computer
b) Use of computer in Scientific Research
c) Computer in banking Sector
d) Storage
e) Speed

Project Work
1. Draw a computer and its parts on a chart paper and display it in your classroom.
2. Divide a class into various groups and conduct a presentation on the following
topics:
a) Features of computer
b) Main application area of computer
3. During the course of a normal day, keep a list of your encounters with computer
of various kinds. Your list should include the and the time of the encounter, the
type of interaction you had with the technology and the result of the interaction.
Share your list with the class.
4. Conduct a speech competition on the topic 'Role of computer in education and
entertainment'.

Computer Science : Grade 9 11


Unit 1.2
Types of Computer

Nowadays, various types of computer are available. These computers are different from
each other on the basis of their purpose, capacity, size, working principle, brand etc.
Computer can be categorized into three types according to the working principle (data
type they operate). They are:

i. Analog computer
ii. Digital computer
iii. Hybrid computer

On the basis of
working principle

Analog Computer Digital Computer Hybrid Computer

On the basis of
On the basis of size
purpose

Special purpose General purpose

Mainframe
Micro computer Mini computer Super computer
computer

Classification of Computer

12 Computer Science : Grade 9


Analog Computer
Analog computers are special-purpose computers which can measure continuously
changing data such as pressure, temperature, voltage, etc. It can perform a single task.
For example, speedometer which displays speed of vehicles, voltmeter, analog watch,
seismograph, etc. The features of analog computer are given below:

 cheaper than other device.


 on continuous data.
 storage capacity is low.
 works in real-time.
 gives output in the form of graph and signals.

Analog computer
Digital Computer
Digital computers are general-purpose computers which solve problems by computing
discrete data. It works on digital values, binary digits (0 or 1). It can perform many tasks
according to user requirements. Computer in school, home and office are examples of
digital computer.

Feature of digital computer


 works on discontinuous.
 highly accurate and reliable.
 used for general purpose.
Computer Science : Grade 9 13
 based on discrete data (digit 0 and 1).

Digital Computer
On the basis of purpose, digital computers are classified into two types.

i. Special Purpose Digital Computer


These types of digital computer are designed to perform a single specific task. The
program is loaded during manufacturing time in this type of digital computer which
cannot be changed by user. Digital thermometer, digital watch, self-driven vehicle,
washing machine, digital television, etc. are the example of special-purpose digital
computers.

ii. General Purpose Digital Computer


These types of digital computer are designed to perform more than one task. The user
can load programs into the computer as per requirement to perform a different task.
Desktop computer, laptop, notebook, etc. are the example of general-purpose digital
computers.

On the basis of size, digital computers are classified into four types. They are

i. Microcomputer
ii. Minicomputer
iii. Mainframe computer and
iv. Supercomputer
i. Microcomputer
Microcomputer is also called PC (Personal Computer) because it is used by a single
person at a time. Microprocessor is used as main processing unit (CPU). IBM-PC was

14 Computer Science : Grade 9


the first microcomputer designed by IBM (International Business Machine) company.
Microcomputers are used in the home, school, college, hospital, offices, etc. for data
processing purpose. These microcomputers are further divided into the following
categories:

 Desktop computer
 Laptop computer
 Palmtop computer
 Notebook computer
 Tablet computer

Notebook Computer
ii. Minicomputer

Minicomputer
Minicomputer is more powerful and expensive than microcomputer but less powerful and
costly than mainframe computer. So, the capabilities of a minicomputer are in between
microcomputer and mainframe computer. Minicomputer is used in scientific research,
banking system, telephone switch, etc. These computers work on multiprocessing
system and about two hundred of PCs can be connected to the network. PDI-1 was
the first minicomputer designed by DEC (Digital Equipment Crop) company in 1960.

Computer Science : Grade 9 15


Time-sharing, batch processing, online processing, etc. are the services provided by
minicomputer. IBM-System/3, Honeywell 200, etc. are some examples of minicomputer.

iii. Mainframe Computer

Mainframe Computer
Mainframe computers are more powerful, have large storage capacity and more
expensive than minicomputer but less powerful and costly than supercomputer. These
computers allows multi-user and have multi-processor and support more than 200 PCs.
These computers are used as a server on WWW (World Wide Web) and also used in
large organizations such as a bank, telecommunication, airlines and universities for large
data processing. IBM is the major manufacturer of mainframe computer. IBM 1401
mainframe computer was brought to Nepal for the first time to process census data in
year. IBM-2 series, system 210 servers, CDC (Control Data Cyber) 6600 etc. are the
popular examples of mainframe computer.

iv. Supercomputer

Sunway Taihulight
Supercomputers are the most powerful, most expensive and have the highest processing
speed most than other computers. It has parallel processing for performing any task.
These computers are mainly used in weather forecasting, nuclear energy research,
national security, space-related research, etc.

16 Computer Science : Grade 9


Nowadays, most powerful supercomputer is Sunway Taihulight from National Super
Computing Centre, Wuxi, China. Supercomputer can perform more than one trillion
calculations per second. Piz Daint, Tianhe-z, Titan, Seq voie, Cori, ETA-10, etc. are the
popular examples of supercomputer.

Hybrid Computer

Hybrid Computer
The computer-designed with combined features of analog computer and the digital
computer is called a hybrid computer. These computers are designed for a special
purpose. They are used in hospital for Ultra Sound, ECG (Electro Cardio Graph), CT
scan (Computed Tomography scan), etc., in aeroplanes for air pressure, temperature,
speed, weight, in scientific lab, in ships, large industries etc.

Feature of hybrid computer


 expensive
 designed for special purpose
 works on both has continuous and discrete value
 more complex and limited storage

Computer Science : Grade 9 17


Summary
 Computers are different from each other on the basis of their purpose, capacity,
size, working principle, brand etc.
 Analog computers are special purpose computer which can measure continuously
changing data such as pressure, temperature, voltage, etc.
 Digital computers are general-purpose computers which solve problems by discrete
data.
 IBM-PC was the first microcomputer designed by IBM (International Business
Machine) company.
 Desktop computer, laptop, notebook, etc. are the examples of general-purpose
digital computers.
 On the basis of size, digital computers are classified into four types: Microcomputer,
Minicomputer, Mainframe computer and Supercomputer
 Supercomputer is the most powerful and expensive and has the highest processing
speed than other computers.
 The computer-designed with combined feature of analog computer and digital
computer is called a hybrid computer.

Technical Terms
Analog computer : Measures continuously changing data such as pressure, temperature.
Digital computer : Solves problems by discrete data.
Minicomputer : More powerful and more expensive than a microcomputer.
Mainframe computer : More powerful and has large storage and more expensive than
minicomputer.
Super computer : The most powerful, the most has expensive and with the highest
processing speed than others.
Hybrid computer : A computer with the combination of features of both analog
computer and digital computer.

18 Computer Science : Grade 9


Exercises
1. Answer the following questions.
a) How are computers classified into different types?
b) What is analog computer? Where is it used?
c) Define digital computer. What are the types of digital computers?
d) Differentiate between general-purpose computers and special purpose
computers.
e) Classify a computer on the basis of size.
f) What is mainframe computer and what are its typical applications?
g) What are supercomputers? Write their application.
h) What is microcomputer? Write its types.
i) Define hybrid computer? How is it used in hospitals.

2. State 'True' or 'False'.


a) Analog computer solves problems by discrete data.
b) Laptop computers are portable computers.
c) Hybrid computer has the features of analog and digital computer.
d) Minicomputer is more powerful and more expensive than mainframe
computer
e) Desktop computer is an example of general-purpose digital computers.

3. Match the following.


Group 'A' Group 'B'
a) i) Analog computer a) about 200 users
ii) Digital computer b) used in hospital
iii) Hybrid computer c) deals with 0 or 1
iv) Minicomputer d) measures continuously changing data
e) about 5000 users
Computer Science : Grade 9 19
Group 'A' Group 'B'
b) i) Mainframe computer a) PC
ii) Super computer b) PDP-1
iii) Microcomputer c) IBM1401
iv) Minicomputer d) Sunway Taihulight
e) IBM 2040

4. Choose the correct answer.


a. The most powerful, expensive and largest processing computer is...
i) Microcomputer ii) Supercomputer
iii) Mainframe computer iv) Minicomputer
b. CT- Scan is an example of ……… computer.
i) Analog ii) Micro iii) Hybrid iv) None of above
c. ….. is the mainframe computer brought to Nepal for the first time to process
census data in 2028 BS.
i) IBM 1400 ii) IBM1401 iii) IBM1402 iv) IBM1403
d. Nowadays, the most powerful supercomputer is Sunway taihulight from
……….
i) India ii) Germany iii) China iv) America
e. Minicomputer is more powerful and expensive than ……….. computer.
i) Micro ii) Super iii) Mainframe iv) None of them

5. Fill in the blanks with appropriate.


i) ……… computers are special-purpose computers which can measure
continuously changing data.
ii) ………….. was the first microcomputer designed by IBM.
iii) ……….. computer is more powerful and expensive than microcomputer
but less powerful and costly than mainframe computer.

20 Computer Science : Grade 9


iv) ……… computers are used as server on WWW.
v) …… computers are general-purpose computers which solve problems by
computing discrete data.
vi) ……….. has parallel processing for performing any task.
vii) ……… computer is used in hospital for UltraSound.

6. Write the full form of the following.


i) IBM ii) CPU iii) PC iv) DEC
v) WWW vi) CDC vii) ECG
7. Write short notes on the following.
a) Mainframe computer
b) Supercomputer
c) Desktop computer
d) Hybrid computer
e) Analog computer

Project Work
1. Draw on a chart paper the types of computer on the basis of working principle
and paste in your classroom.
2. Collect some examples of analog, digital and hybrid computers.
3. Prepare a presentation about the use and purpose of hybrid and supercomputer in
different sectors and present to your class as a group work.
4. Divide a class into various groups and conduct a presentation on the following
topics:
a. Type of computer on the basis of purpose.
b. Type of computer on the basis of size.
c. Type of computer on the basis of work.

Computer Science : Grade 9 21


Unit 1.3
Basic Architecture of Computer

A combination of related units that have common purpose of achieving some objectives
is called a system. For example, there are different units in the hospital system like
doctor, nurse, surgery room, medical, etc.

Likewise, there are different units in computer system that work together to perform
varieties of tasks. So, computer system is a group of hardware and software which
work together to process data according to the instructions given by user to produce
information.

Basic Architecture of Computer


The main components of computer system are defined below:

a. Data: Data is the main part of computer system. It can be processed to get desired
22 Computer Science : Grade 9
output as information.
b. Software: A set of programs are called software which instructs the hardware to
perform a task. For example MS Windows, MS Word, MS Excel, etc.
c. User: The person who operates computer system is called a user.
d. Hardware: The physical parts of a computer which can be touched, seen and felt
are called computer hardware. For example Keyboard, mouse, monitor, etc.
The computer hardware is further divided into four units:

a. Input unit
b. Process unit
c. Output unit and
d. Storage unit
a. Input Unit
This unit enters data into the computer. An input unit consists of input devices like
keyboard, mouse, microphone, joystick, etc. These devices are used to enter data and
instructions or commands into computer system. Input unit acts as a communication
channel between user and computer. The input devices translate the information into a
form understandable by the computer.

Input Device
b. Processing Unit
A processing unit consists of processing devices like CPU (Central Processing Unit).
CPU is the main processing unit of a computer system. It is also known as the brain of
computer system. It receives data from input unit, processes it as instructed by the user
and produces information as output.

Computer Science : Grade 9 23


CPU (Central Processing Unit)
The speed of CPU is measured in hertz. Hertz is also called CPU clock rate or CPU
clock speed. Nowadays, CPU speed is measured in Gigahertz (GHz).

1 GHz = 1000 MHz (MegaHertz).

= 1,000,000 KHz (Kilo Hertz).

= 1,000,000,000 Hz (Hertz).

So, one GigaHertz is equal to one billion hertz. The CPU speed of 2.1 GHz is equal to
2.1 *1,000,000,000 Hertz.

The CPU consists of the three main parts.

i. CU (Control Unit),
ii. ALU (Arithmetic Logic Unit) and
iii. MU (Memory Unit- Register Array)
i. Control Unit
Control Unit is a part of the CPU that controls and coordinates activities of other units
of computer system. It acts as a nervous system of computer. It controls the execution of
instructions given to system. It coordinates the flow of data in or out of ALU, memory
and various input or output devices.

ii. Arithmetic Logic Unit


Arithmetic logic unit is a part of CPU that can perform arithmetic operation like addition,
subtraction, multiplication and division. It also performs logical comparison like equal
to, greater than, less than, etc. to compare between two numbers.

24 Computer Science : Grade 9


iii. MU (Memory Unit- Register Array)
Memory unit is also a part of CPU but not the part of main memory that store currently
executing task. It is located inside the microprocessor and has very limited storage. It
is used to store very active data and instructions temporarily during processing.
c. Output Unit
An output unit consists of output devices like monitor, printer, speaker, etc. These devices
are used to display information after processing raw data from the processing unit.

Output devices
d. Storage Unit
A storage unit consists of primary and secondary storages. The primary storage or main
storage stores raw data and instruction. RAM (Random Access Memory) and ROM
(Read Only Memory) are the examples of storage unit.The functions of the storage
unit are below.

 It stores intermediate results of processing.


 It stores all the data and the instructions required for processing.
 It stores the final results of processing before these results are released to
an output device.
The secondary storage stores processed or unprocessed data or information for future
use. Hard disk, pen drive, CD, DVD, etc. are the examples of the storage unit.

Storage devices

Computer Science : Grade 9 25


Summary
 A combination of related units that have common purpose of achieving some
objectives is called computer system.
 A processing unit consists of Control Unit, Arithmetic logic unit and Memory
unit.
 The speed of CPU is measured in hertz. Hertz is also called CPU clock rate or
CPU clock speed.
 An output unit consists of output devices like monitor, printer, speaker, etc.
 A storage unit consists of primary and secondary storages.

Technical Terms
Computer system : A combination of hardware and software to produce information.
Hardware : The physical parts of computer which can be touched, seen
and felt.
Software : A set of programs which instruct hardware to perform a task.
User : The person who operates a computer system.
Data : Raw facts or figures which do not have a clear meaning.
Input unit : To enter data and instructions or commands into the computer
system.
Processing unit : Processes raw data as instructed by the user and produce output.
Arithmetic unit : Performs arithmetic operation like addition, subtraction, etc.
Logic unit : Performs logical operations like equal to, greater than, less than,
etc.

Exercises
1. Answer the following questions.
a) What is the computer system?
b) Write down the main units of the computer system.

26 Computer Science : Grade 9


c) Draw a block diagram of the computer system.
d) Mention the functions performed by ALU.
e) Define CPU with two major sections of it.
f) Differentiate between input unit and output unit.
2. State 'True' or 'False'.
a) The main units of computer system are input, process, output and storage.
b) The user enters data and instruction by using input device and it is called
input.
c) The processing unit display results from computer.
d) A scanner is the device of the memory unit.
e) The CPU speed of 3.1 GHz is equal to 3.1 x1,000 Hertz.
3. Match the following words.
Group 'A' Group 'B'
i) Input unit a) Process raw data to produce output
ii) Output unit b) store currently executing task
iii) Processing unit c) To enter data and commands
iv) Memory unit d) Produce information
e) Fraction of second
4. Choose the best answer.
a. How many units are there in a computer system?
i) 2 ii) 3 iii) 4 iv) 5
b. Which device does not belong to input unit?
i) Microphone ii) Keyboard
iii) Printer iv) Mouse
c. ……. is also known as the brain of the computer system.
i) Input unit ii) Processing unit
iii) Output unit iv) Memory unit
Computer Science : Grade 9 27
d. The nerve centre of computer is ……….
i) ALU ii) main memory
iii) control unit iv) all of the above
e. Monitor, printer, plotter and speaker are the examples of ……….. device.
i) input ii) output
iii) processing iv) none of them

5. Fill in the blanks with appropriate word.


a) computer system is a combination of……… and software.
b) ………….. unit consists of input devices.
c) ……… is a part of CPU that controls and co-ordinates.
d) …… can perform arithmetic operation as well as logical operation.
e) ……….. is a part of CPU that stores currently executing task.
f) ……… consists of output devices.

6. Write the full form of:


i) CPU ii) ALU iii) Hz iv) MHz v) GHz
vi) MU vii) CU viii)RAM ix)ROM x) KHz

7. Write short notes on:


a. ALU
b. Storage Unit
c. Components of computer system
d. Output unit

Project Work
1. Describe computer system and its main unit by using power point presentation
and demonstrate in your class as a group work.
2. Prepare a presentation about "CPU is also known as the brain of computer system"
and demonstrate in your class.
28 Computer Science : Grade 9
Unit 1.4
Computer Hardware

The physical parts of a computer which can be seen, felt and touched are called computer
hardware. Computer hardware is important component of computer system. The user
can perform a task by using a set of instructions through the computer hardware. So, the
combination of computer hardware and software makes up a full functioning computer
system that performs specific task. Motherboard, microprocessor, RAM, ROM, hard
disk, pen drive, keyboard, scanner, monitor, etc. are the examples of computer hardware.

a. Motherboard
Motherboard is called PCB (Printed Circuit Board) or system board or main circuit
board. All parts of computer system like microprocessor, slots, ports etc. are mounted
on motherboard. So, it is also called backbone of computer system. It also connects
important chips like ROM chip, Network chip, sound card, etc.

Motherboard
Function of motherboard
a. There are different slot which joins modem, TV card, etc. in motherboard.
b. Motherboard helps in data communication among different hardware.
c. BIOS (Basic Input Output System) programs are stored in ROM and ROM is

Computer Science : Grade 9 29


attached to motherboard to boot the system.
b. Microprocessor
Microprocessor is an important part of computer hardware. Computer cannot perform
the task without a microprocessor. So, it is also called the brain of a computer.

Microprocessor gets data and instructions from various hardware and processes it with
the help of software to produce information as an output to the user. It can do arithmetic
calculation and logical comparison between two numbers. Nowadays, a trillion of
instructions can be processed within a second.

Microprocessor
Working of Microprocessor
i. Fetch
The user can give data and instructions which is stored in RAM. Microprocessor receives
data and instruction according to necessity and requirement which is known as fetch.
So, fetch means get instruction from memory.

ii. Decode
The main function of microprocessor is to change fetched instruction into decoded
instruction. The given instruction is separated for arithmetic or logical calculation. So
decode means to decide what the instruction means.

iii. Execute
Microprocessor can perform the main task in this unit. For example, ALU is used for
mathematical calculation. So, execute means to carry out the instruction into action.

iv. Write back

30 Computer Science : Grade 9


Microprocessor processes the instructions and produces result which is transferred to
memory for storage. This is called to write back.

The complete cycle of four units as fetch, decode, execute and write back of
microprocessor for processing the instruction is called the instruction cycle.

c. Memory
The physical part of a computer that store data, information and software temporarily
or permanently is called memory or storage. Storage device or memory device is used
to store data and information. The three types of memory are as follows

i. Primary memory,
ii. Secondary memory and
iii. Cache memory.
Register

High cost Cache memory Low cost


Fast access time High disk storage
Low storage capacity Main memory capacity
Slow access time
Magnetic Disks

Magnetic Tapes
Memory Hierarchy
i. Primary memory
The main memory is called primary memory. Primary memory stores data temporarily
or permanently. It stores information during the processing of raw data. The two types
of primary memory are:

RAM (Random Access Memory)

ROM (Read Only Memory)

Computer Science : Grade 9 31


RAM (Random Access Memory)
RAM is the main memory of computer system. It is volatile or temporary memory.
Volatile memory means that RAM loses its information when the computer is switched
off or faces power failure. So, it needs constant power supply to hold currently running
program. It is also called semiconductor memory. It is read/write memory. There are
two types of RAM. They are SRAM and DRAM.

SRAM: SRAM stands for Static Random Access Memory. It does not need periodic
refreshing to preserve the information. It is faster and expensive than DRAM.

Characteristic of Static RAM


 Long life and no need to refresh
 Faster and used as cache memory
 Large size and expensive
 Expensive and high power consumption
DRAM: DRAM stands for Dynamic Random Access Memory. It needs a periodic
refreshing to preserve the information. It is slower and cheaper than SRAM.

Characteristics of Dynamic RAM


 Short data lifetime and needs to be refreshed continuously
 Slower as compared to SRAM and used as RAM
 Smaller in size and less expensive
 Less power consumption

RAM
ROM (Read Only Memory)
ROM is a non-volatile or permanent memory. Non-volatile means never loses data in
ROM. It stores data permanently even when the computer is switched off or power
failure. It is read-only memory because the programs in ROM are stored at the time of

32 Computer Science : Grade 9


manufacture of the computer. It is fixed on motherboard. The three types of ROM are
PROM, EPROM and EEPROM.

PROM
PROM stands for Programmable Read Only Memory. Once a program has been written
onto the PROM, it remains there forever and can't be updated and deleted.

EPROM
EPROM stands for Erasable Programmable Read Only Memory. It can be erased by
ultraviolet light and reprogramming.

EEPROM
EPROM stands for Electrical Erasable Programmable Read Only Memory. It is called
flash ROM. It can be erased by exposing it to an electrical charge and reprogramming.
It is also called hybrid memory with a combined feature of RAM and ROM.

ROM
Firmware
Firmware is software that's embedded in a piece of hardware. So, the firmware is
software for hardware.

CPU Register
CPU Register is a small storage memory, located inside the microprocessor and has a
high speed data transfer rate. It stores data and instructions used by the microprocessor.

Cache Memory
Cache memory is also like CPU Register, located inside the microprocessor but has
high storage capacity than CPU Register and high-speed data access rate. It also stores
the data and instruction used by the microprocessor. So, it stores very active data and
instructions temporarily during processing. If required data and instruction are not found
in cache memory then the searching is done in primary memory.
Computer Science : Grade 9 33
ii. Secondary Memory
Secondary memory is also called auxiliary memory or backup memory. These memories
are used to store data and instructions permanently for future use. CD/DVD, pen drive,
hard disk, etc. store data and instruction for future. The various types of secondary
memory are Magnetic Tape, Hard disk, SSD (Solid State Drive), Optical Storage Disc,
Pen drive, etc.

a. Magnetic Storage
Computer systems need to store data in digital format. One of the most widely used
types of digital data storage is magnetic storage. This refers to any type of data storage
using a magnetized medium. Several types of magnetized media are used in computer
systems, including magnetic tape, floppy disks, Super disks, hard disks, etc.

Magnetic Tape
Magnetic Tape is a usable secondary storage device to store and retain a large volume
of data. It is made up of a plastic strip of which one surface is coated with magnetic ink.
Analog and digital data are stored in magnetic tape. Normally, minicomputer, mainframe
computer, large scale business organization server, etc. uses magnetic tape for backup
data and information. Magnetic tape driver are used to store and retrieve the data and
information from magnetic tape. The main important function of magnetic tape is to
store data safely for a long period of time.

Magnetic Tape and Tape Drive


Hard Disk
Hard disk is commonly used storage device. It stores large amount of data and
information permanently. It is also called fixed disk. It is made of aluminium materials
34 Computer Science : Grade 9
and the surface is coated with the ferromagnetic element. Circular metal discs also
called platters to rotate while writing or reading the data and information into them. It
stores a large amount of data on hard disk. The speed of the hard disk is measured in
rpm (revolutions per minute). The hard disks with 5400 rpm or 7200 rpm are generally
used in present-day computer system.

Hard disk capacity


Hard disk must be formatted before use. There are thousands of track on the surface of
hard disk. So, each track is divided into various sectors. Each sector stores 512 bytes.
Header is used to read and write on hard disk. The storage capacity of hard disk is
determined from number of disk or platter it contains and their density.

Hard Disk Track and Sector


SSD (Solid State Drive)
Hard disk can be replaced and upgraded by SSD (Solid State Drive) as new technology.
Semiconductor chips are used to store data in SSD. The speed to read and write data is
greater than hard disk. So its price is more expensive than hard disk. Laptop, notebook,
ultra book, etc. uses SSD as storage device. Its storage capacity is about 4 TB but various
companies are trying to develop SSD with high storage capacity. It is more costly than
HDD (Hard Disk Drive).

Computer Science : Grade 9 35


Solid State Drive
Differences between SSD and Hard disk
S.N. Hard disk SSD
1 It is heavier than SSD. It is lighter than hard disk.
Its storage capacity is 500 GB to
2 Its storage capacity is 1 TB to 4 TB.
100 TB.
3 It is cheaper than SSD. It is more expensive than hard disk.
4 It takes 6-7 watt electricity. It takes 2-3 watt electricity.
The file writing speed is 50-120 The file writing speed is 200-550 MB/S
5
MB/S (megabyte per second) (megabyte per second)
6 It is made up of aluminium material. It is made up of semiconductor microchip.

External Hard Drive


The working principle of hard disk is similar to that of internal hard drive but it is not
placed inside CPU casing. It can be externally connected with a USB (Universal Serial
Bus) port. It is portable and easy to carry. It is used to transfer data, information and
software from one computer to another.

External Hard Drive

36 Computer Science : Grade 9


Pen drive
Pen drive is a popular flash storage device. It is also called flash memory. It is connected
through the USB ports. It is a small size and portable device. It can be carried in a pocket
like pen. So it got its name as a pen drive. It is used to transfer data, information and
software from one computer to another. It is made up of semiconductor chip which is
EEPROM technology. The writing speed of pen drive of USB 3.0 is up to 60 MB/S and
data reading speed up to 120 MB/S.

Pen drive
b. Optical Storage Disc
The disc that uses laser light technology to store and retrieve data is called optical storage
disc. The most commonly used optical storage discs are CD, DVD, Blu-ray disk, etc.

CD (Compact Disc)
In 1980, Philips Company of Netherland developed first CD or optical disk which
was 12cm in diameter and had 72 minutes audio/video storage capacity. The laser ray
technology is used to retrieve and store the data. The information on the optical disk is
stored in the form of pits. The pits are tiny reflective bump.

CD has the diameter of 12 cm. It's weight is 18gm and width 1mm (millimetre). The
data can be written on a CD only once. CD is made up of poly carbon and both surfaces
are coated with aluminium. Nowadays, CDs are commonly used in microcomputer. It
can be used to transfer data from one computer to another. The storage capacity of a
CD is 700MB.

The three types of optical storage devices are:


 CD-ROM → Compact Disc – Read Only Memory
 WORM → Write Once Read Many
 CD-RW → Compact Disc – Rewritable

Computer Science : Grade 9 37


a. CD-ROM stores data or programs like video, music, software, etc. for selling
purpose developed by different company. The information stored on it is read-only.
b. WORM is an optical storage media which is purchased as blank media and data
can be written only once but can be read many times.
c. CD-RW (Compact Disc - Rewritable) means read and write in it multiple time.
It is similar to pen drive as information can be read from and written to the disk
many times.

CD (Compact Disk)
DVD (Digital Versatile Disc)
DVD stands for Digital Versatile Disc or Digital Video Disc. Its storage capacity is
higher than CD. It stores multiple layers of data. The various DVD storage capacities are
 Single Side Layer- 4.7 GB
 Single Side Double Layer-8.5 GB
 Double Layer Single Side- 9.4 GB
 Double Layer Double Side-17.08 GB
Philips, Sony, Toshiba/ Panasonic companies developed first DVD in 1995. DVD Drive
is used to read/write the data on DVD.

DVD

38 Computer Science : Grade 9


Differences between CD and DVD
S.N. CD DVD
1 Its storage capacity is 700MB. Its storage capacity is up to 20GB.
2 It is cheaper. It is more expensive.
It is used to store audio and
3 It is used to store video and software.
software.
4 Its types are CD-R, CD-RW, etc. Its types are: DVD-RW, DVD+RW, etc.
It was developed by Philips and It was developed by Philips, Sony, Toshiba,
5
Sony. Panasonic etc.

Blue-ray Disc
It is an optical data storage device. Its storage capacity is up to 200GB. It is mainly used
to store high-quality audio and movie data. It is scratch resistant discs.

Differences between Primary memory and Secondary memory:


S.N. Primary memory Secondary memory
It is also called main memory or It is also called auxiliary memory or
1
internal memory. backup memory.
2 It is volatile and non-volatile memory. It is non-volatile memory.
3 The storage capacity is less. The storage capacity is more.
4 Its types are RAM, ROM, etc. Its types are: Hard disk, CD/DVD, etc.
It is made up of magnetic materials, poly
5 It is made up of semiconductor.
carbon, etc.
The data is directly accessed by the The data cannot be directly accessed by
6
processing unit. the processing unit.

iii. Units of memory measurement


The smallest unit of memory measurement is bit (binary digit- 0 or 1). The data stored
in a computer is a binary digit, byte, kilobyte, megabyte, gigabyte, terabyte, etc.

Bit
Bit stands for Binary digit. The value of the binary digit is 0 or 1.

Computer Science : Grade 9 39


Nibble
Nibble is the combination of 4 bits.

Byte
Byte is the combination of 8 bits.

The units of memory measurements are as follows:

S.N. Memory Unit Description


1 Bit 1 Bit = 0 or 1
2 Nibble 1 Nibble = 4 Bits
3 Byte 1 Byte = 8 Bits
4 Kilobyte (KB) 1 Kilobyte (KB) = 1024 Bytes
5 Megabyte (MB) 1 Megabyte (MB) = 1024 KB
6 Gigabyte (GB) 1 Gigabyte (GB) = 1024 MB
7 Terabyte (TB) 1 Terabyte (TB)= 1024 GB
8 Petabyte (PB) 1 Petabyte (PB) = 1024 TB

d. Input Device
The devices through which raw data and instructions are entered into the computer
system are called input devices. The user gives raw data into the computer for processing
through the input devices. Keyboard, mouse, joystick, microphone, etc. are examples
of an input device.

i. Keyboard
Keyboard is a common input device. The data is entered into the computer by typing
through the keyboard. The most common layout of the keyboard is "QWERTY"
keyboard. The different keys present in the keyboard are:

 Alphabet keys – A-Z


 Numeric Keys – 0-9
 Function Keys – F1, F2 ….. F12
 Special Purpose Keys – Shift, Delete, Alt, Enter, Ctrl

40 Computer Science : Grade 9


 Arrow keys →, ↓, ←, ↑
The keyboard which is connected to a computer without wire is called wireless keyboard.
Multimedia keyboard contains additional multimedia keys. The different types of
keyboard are multimedia keyboard, AT-keyboard, Enhanced Keyboard, XT-keyboard,
etc.

Keyboard
ii. Mouse
The mouse is a pointing input device. It is used to point object, give command, draw
paint, etc. into the computer. The common three buttons of a mouse are:

i. Left Button
ii. Right Button
iii. Scroll Button Mouse
The user uses buttons for clicking, double clicking, right-clicking, dragging, scrolling,
etc. to give command into the computer.

The mouse was developed by Douglas Engelbart in 1964 that was of wood. Apple
Macintosh was the first computer to use mouse. Mechanical mouse, optical mouse and
wireless mouse are different types of mouse.

iii. Joystick
Joystick is an input device which is used to play video games. There
are different types of joystick available for various video games.
It has more buttons that help in playing and controlling objects in
Joystick
games.

iv. Track Ball


Track ball is a pointing input device. It consists of a movable small ball in a socket.

Computer Science : Grade 9 41


The pointer moves on screen when the ball rolls with our fingertips.
Track ball are mostly used on a laptop, palmtop, notebook etc. It is
also called upside-down mouse as it contains ball on the top of the
device. It is fixed and requires less space for operation.

v. Touchpad Track Ball

Touchpad is a touch-sensitive pad that is used as a pointing


device in a laptop computer. It is also known as Glide
pad, Glide point, pressure-sensitive tablet or track pad etc.
Touchpad has two buttons (left and right) like a mouse.
Touch Pad

vi. Scanner
Scanner is an input device which scans drawing or document
and enters into computer in digital format. The photocopy
machine gives the facility of the scanner. Scanner converts Scanner
hardcopy into soft copy.

vii. BCR (Bar Code Reader)


BCR is a hand-held or stationary input device used to capture and read the information
contained in a bar code. A BCR merely captures and translates the barcode into numbers
or letters. The data must be sent to a computer so that a software application can make
sense of the data. Barcode scanners can be connected to a computer through serial ports,
keyboard port, or an interface device called a wedge. A BCR works by directing a beam
of light across the bar code and measuring the amount of light that reflects back. The
scanner converts the light energy, which is then converted into data by the decoder and
forwarded to a computer.

42 Computer Science : Grade 9


Bar Code Reader Bar Code
viii. QR Code Scanner
It stands for Quick Response Code. The advanced form of Bar Code
Reader is QR Code Scanner. A QR code is a pattern of black and white
squares. The QR code of any product gives information about the
website address. A QR code can be read and processed by a smartphone QR Code
or a cell phone with the help of Apps or Applications.

ix. Microphone
Microphone is a sound input device. It helps to input sound or music
into the computer in a digital format. It is used in audio chatting and
video conferencing through Skype, Viber, Facebook, messenger etc.
Microphone

x. Digital Camera
Digital Camera is an input device that takes photographs or
video and enters them into the computer system in digital
format. It stores the file in SD card. The data from the SD
card then get transferred into the computer through a cable.
Mobile phone camera is also an example of digital camera.
Digital Camera
xi. Graphic Digitizer
Graphic Digitizer is an input device. It is a device
used to convert hand sketch image or signature
into digital format to the computer. It is also called
digital tablet. Stylus (electronic pen) helps to draw
an image onto the flat surface and send to the
Graphic Digitizer
Computer Science : Grade 9 43
computer for digital store. Graphic Digitizer is mainly used by designer and engineer.

xii. Touch Screen


Touch Screen is a touch-sensitive display panel covering the screen. It is mostly used
in smartphone. Nowadays, laptop, notebook, palmtop and desktop computer use touch
screen as their display unit. The user touches on the screen with their finger to select
an object on the screen and give command to the computer system.

Touch Screen
e. Output Device
The device which displays meaningful information from the computer is called an
output device. So, an output is the result produced by processing unit. The common
output devices are monitor and printer. Some other output devices are: plotter, speaker,
headphone, etc.

Monitor
Monitor is the most common output device. It is also called VDU (Visual Display
Unit) in computer system. The output displayed on monitor's screen in the form of text,
videos and graphics is called soft copy output. On the basis of colour the monitors are
of two types:

i. Monochrome monitor and


ii. Colour monitor
Monochrome monitor
The monitor which display output in one colour like green, white, black, blue, etc. is
called monochrome monitor.

44 Computer Science : Grade 9


Colour monitor
The monitor which displays output in different colours more than sixteen is called
colour monitor.
The information displayed on the screen is made of combination of small tiny dots. The
small tiny dots are called pixel.
The clear screen consists of three terms as screen resolution, dot pitch and refreshes rate.

i. Screen Resolution
It represents the number of horizontal and vertical pixels. The clear screen is due to the
high resolution of the monitor. The common resolution ranges are 640 ˟ 480, 1024˟768,
1600˟1200 etc.

ii. Dot Pitch


The dot pitch is a measure of how close the pixels or dots are to create an image on the
monitor. So, it is measured in millimetre. The clear screen is due to the low dot pitch
of the monitor.

iii. Refresh Rate


The refresh rate is the rate due to each pixel on screen re-drawn. A low refresh rate
results in a poor image on the screen. It is measured in hertz. So, the clear image is due
to the high refresh rate.

On the basis of technology, monitors are classified into three types as:

i. CRT Monitor
CRT stands for Cathode Ray Tube. It operates in the following ways:
 The electron gun emits a beam of electrons cathode rays.
 The electron beam passes through focusing and deflection systems that direct it
towards specified positions on the phosphor-coated screen.
 When the beam hits the screen, the phosphor emits a small spot of light at each
position contacted by the electron beam.
 It redraws the picture by directing the electron beam back over the same screen
points quickly.
Computer Science : Grade 9 45
CRT Monitor

There are two ways Random scan and Raster scan by which we can display an object
on to the screen.
ii. LCD Monitor
LCD stands for Liquid Crystal Display. It is very light, thin and consumes less power
than CRT monitor. The two-layer in this monitor which consists of liquid crystal form
an image. It is used in laptop, notebook, digital watch, desktop computer, etc. It is
more expensive than CRT monitor and produces a high quality image on the screen.
The fluorescent lamps are used for backlighting in LCD monitor for displaying image
on the screen.

LCD Monitor
iii. LED Monitor
LED stands for Light Emitting Diode. It is very lighter and thinner than LCD and CRT
monitors. It consumes less power than CRT and LCD monitors. Its working power is
higher than others. So its lifetime is more and can be used for long-time-work. The
quality of image on the screen is higher than that of other monitors. The diodes are used
for backlighting in LED monitor for displaying the image on the screen. LCD and LED
monitors are called flat panel displays.

46 Computer Science : Grade 9


LED Monitor
ii. Printer
Printer is a hard copy output device. It prints text & graphics on paper. There are many
different types of printers available in market. Its speed is measured by CPS (Character
per second), LPM (Line per minute) and PPM (Page per minute). The printers are
classified in two types on the basis of printing quality. They are:

 Impact printer
 Non-impact printer
Impact Printer
An impact printer is a type of printer that operates by striking a metal or plastic head
against an ink ribbon. Its structure is like a typewriter. It uses small pin-like objects or
hammers that strike on the inked ribbon and characters are formed on the paper. These
printers are slow and noisy. These printers use black or blue or red colour. The printing
quality of impact printer is lower than non-impact printer.

The three main types of impact printer are following:

i. Dot Matrix Printer


Dot-matrix printer is a type of impact printer. The printer head contains a number of
pins. The printer head strikes on the inked ribbon, the striking forms dotted characters
on the paper. The speed of Dot-matrix printers ranges from 50 to 400 CPS (Character
Per Second).

Computer Science : Grade 9 47


Dot Matrix Printer
ii. Daisy Wheel Printer
Daisy wheel printer is a type of impact printer. It uses hammer-like object to hit on the
ink ribbon and a character is formed on the paper. The hammer contains letter face and
is arranged in wheel like form and motor spins the wheel at a rapid rate. When desired
characters spin to the correct position, a printer hammer strikes on the ribbon and output
is formed on the paper. The speed of the daisy wheel printer ranges from 25 to 55 CPS
(Character Per Second).

Print Head of Daisy


Wheel

iii. Line Printer


Line printer is a type of impact printer. Its printing quality is better than that of Daisy
wheel printer and Dot- matrix printer. It prints text line by line. So, it is called a line
printer. The three types of line printer are:

Drum printer: In this type, there is a cylindrical drum which continuously rotates over
the paper surface and causes characters rise and hits on the ribbon.

Chain Printer: In the chain printer, high-speed print chain is used. This chain contains
different types of characters.
48 Computer Science : Grade 9
Drum Printer
Band Printer: In this line printer, steel print band is used to print one line printout on
paper at a time.

Non-Impact Printer
The non-impact printer does not use the printing head to strike against ribbon and paper.
Instead, small drops of ink are sprayed onto the paper. So non- impact printers are faster
and are of high quality than impact printer. It does not produce sound while printing.
Inkjet printer, laser printer, 3D printer are the popular types of non- impact printer.

i. Ink-jet Printer
Inkjet printer prints text and graphics on paper by spraying small drops of ink into paper.
The speed of inkjet printer is generally 1 to 4 pages per minute. It uses an A4 size paper.
The liquid colour-filled cartridge is used instead of ink ribbon. Colour inkjet printer
uses black colour. Four colour-CMYK (Cyan, Magenta, Yellow, Black) cartridges are
used for colour printout.

Inkjet Printer
ii. Laser Printer
A laser printer is a type of printer which makes use of a laser beam to produce an

Computer Science : Grade 9 49


image on the drum or you can say that it is a printer that makes use of a focused
beam of light to transfer text and images onto paper. It was first developed by Gary
Starkweather at Xerox PARC in 1971. Laser printer makes use of laser technology
for the printing of copies onto the paper. Its printout technology is like a photocopy
machine. It uses colour powdered toner to print text and graphics on paper. Its printing
quality is high.

Laser Printer
iii. 3D – Three Dimensional Printer
Impact printer & non-impact printer prints text on paper but 3D printer prints an object.
For example, any playing toys or any machinery parts are printed through the 3D printer.
3D printing builds parts out of plastic, metal and other materials directly from CAD
(Computer-Aided Design) drawings that have been cross-sectioned into thousands of
layers. This technology helps to build a 3D object by modelling. This technology is
called additive manufacturing.

3D Printer
iii. Graphic Plotter
The graphic plotter is a hard copy output device which is used for good quality print
or drawing like charts, map, engineering design, etc. Figures or maps are printed on

50 Computer Science : Grade 9


graph paper placed on square board. The graphic plotter is used to print large size figure
or map. It gets instruction from computer and draws a clear image by using pen. The
different types of plotters are given below.

Pen plotter: Pen plotter contains one or more pen. It prints colour drawing with shade.

Electrostatic plotter: Electrostatic plotter does not contain any type of pen. It prints
like laser printer.

Dot-matrix plotter: Dot matrix plotter prints drawing like impact printer. Print head
strikes on ink ribbon and prints images on paper.

Graphic Plotter
iv. Speaker
Speaker is a common audio output device. It is used to receive sound or music from
computer system. It is used to covert digital data into audio analog data which user can
understand. The quality of sound output depends on the speaker's quality. For example,
loud speakers, sub woofers, in- wall/ceiling speaker, outdoor speaker, etc. are the
different types of speakers.

Speaker

Computer Science : Grade 9 51


Summary
 The physical parts of computer which can be seen, felt and touched are called
computer hardware.
 The complete cycle of four units as fetch, decode, execute and write back of
microprocessor for processing the instruction is called instruction cycle.
 Motherboard helps in data communication between different hardwarea.
 Microprocessor gets data and instruction from various hardwarea and processes
it with the help of software to produce information as an output to user
 The physical parts of a computer that store data, information and software
temporarily or permanently is called memory or storage.
 Hard disk stores large amount of data and information permanently and made up
of aluminium materials and surface is coated with the ferromagnetic element.
 The most commonly used optical storage discs are: CD ROM, DVD, Blu-Ray
Disk, etc.
 The devices which ae used to enter raw data and instructions into the computer
system are called input devices.
 The devices which display meaningful information from the computer is called
an output device.

Technical Terms
Hardware : the physical parts of a computer which can be touched, seen
and felt.
Fetch : get an instruction from memory.
Decode : decides what the instruction means.
Write back : microprocessor processes the instructions and produces result.
Primary memory : stores data temporarily or permanently.
Cache memory : the high-speed execution memory.
Secondary memory : stores data and instruction permanently for future use.
Magnetic Tape : store and retains a large volumes of data.
52 Computer Science : Grade 9
Input device : the devices which are used to enter raw data and instructions
Output device : the device which displays meaningful information
Screen Resolution : represents the number of horizontal and vertical pixels.
Refresh Rate : rate where each pixel on the screen is re-drawn.
Speaker : a devoce to receive sound or music from computer system.

Exercises
1. Answer the following questions.
a) Define computer hardware with its importance in computer system.
b) What is a microprocessor? How does it work? Explain.
c) What is computer memory? Write its major classification.
d) Why is secondary memory used for future storage? Explain with its types.
e) What is a motherboard? What does it contain?
f) How does a computer mouse work? Who developed it?
2. Differentiate.
a) RAM and ROM
b) Primary and Secondary memory
c) Input and Output devices
d) Magnetic storage disk and Optical storage
e) Hard disk drive and Solid state drive
f) Impact and nonimpact printers

3. State 'True' or 'False'.


a) Motherboard connects all parts of computer.
b) Volatile memory saves information even when the computer is switched
off.
c) Secondary memory stores information permanently.
d) Mouse is a pointing input device.

Computer Science : Grade 9 53


e) Magnetic tapes are made up of plastic.
f) Pen drive is more popular than an optical storage device.
g) Google Company provides cloud storage services through Google Drive.
h) LED is very heavier and thicker than LCD and CRT monitors.
i) Line printer is a type of non-impact printers.
j) Graphic plotter is a hard copy output device which is used to produce a
good quality print.

4. Match the following.


Group 'A' Group 'B'
a) i) Input device a) Memory losses its information when the power
isfailure.
ii) Output device b) a device to store data and information.
iii) Storage device c) a device to enter data and commands.
iv) Volatile memory d) a device to produce information.
e) a device to process data.
Group 'A' Group 'B'
b) i) CRT monitor a) CAD drawings
ii) LCD monitor b) Diode
iii) LED monitor c) Phosphorus
iv) 3D printer d) Florescent Lamp
e) Carbon

5. Choose the correct answer.


a. ………… is also called a brain of computer.
i) Motherboard ii) Microprocessor
iii) RAM iv) Monitor

54 Computer Science : Grade 9


b. Which is not an output device?
i) Printer ii) Speaker iii) Plotter iv) QR Code Scanner
c. ……. can be erased by ultraviolet light and reprogrammed.
i) PROM ii) EPROM iii) EEPROM iv) RAM
d. ………. is a memory inside the microprocessor.
i) RAM ii) Cache iii) ROM iv) Secondary
e. Hard disk can be replaced and upgraded by ………...
i) pen drive ii) magnetic disk iii) SSD iv) magnetic tape
f. The speed of hard disk is measured in …………
i) mgh ii) kHz iii) rpm iv) rcm
g. ………. represents the number of horizontal and vertical pixels.
i) Size of monitor ii) Screen resolution
iii) Dot pitch iv) Refresh rate
h. ………... is an example of impact printer.
i) 3D printer ii) Inkjet printer
iii) Laser printer iv) Line printer

6. Fill in the blanks with appropriate word.


a) Microprocessor gets data and instructions from various ………… and
processes it.
b) ………….. is called PCB (Printed Circuit Board).
c) ……… devices are used to store data and information.
d) …… is volatile or temporary memory.
e) ……….. is a non-volatile or permanent memory.
f) ……… stores data and instruction used by the microprocessor.
g) Secondary memory is also called …………. memory.
h) Hard disk can be replaced and upgraded by ………….
i) The storage of data on online server by using internet is ………

Computer Science : Grade 9 55


7. Write the full form of:
i) CPU ii) RAM iii) ROM iv) PCB v) BIOS
vi) SRAM vii) DRAM viii) PROM ix)EPROM x) EEPROM
xi) CD xii) DVD xiii) SSD xiv) rpm xv) USB
xvi) BCR xvii) QR xviii) VDU xix) CRT xx) LCD
xxi) LED xxii) CPS xxiii) LPM xxiv) PPM xxv) CMYK
xxvi) 3D
8. Write short note.
a) Motherboard
b) 3D printer
c) QR Code
d) SSD
e) LED monitor

Project Work
1. Prepare a presentation about different hardwares found in computer lab and
demonstrate in your class as a group discussion.
2. Draw a chart paper about different types of computer hardware with name and
paste in your classroom.
3. Consult your computer teacher to follow the steps 'how to store information in
cloud storage' and demonstrate in a sheet of chart paper.
4. Visit IT solution offices such as computer maintenance centre and sales, and
collect information on the latest devices.

56 Computer Science : Grade 9


Unit 1.5
Computer Software

The combination of hardware and software to perform a task is called computer system.
The set of instructions or programs written by using a programming language to solve
a problem is called computer software. So, software controls and operates computer
hardware to perform a task. The set of instruction or command is called program. The set
of program to perform a specific task is called software. Generally, computer software
is classified into two types.
a. System software
b. Application software

a. System Software
The software that manages controls and supports computer system is called system
software. So, system software creates link between computer and user. It is a platform
for running application software. It manages files and folders. It can be sub-divided
into the operating system, utility software, device driver software, language processing
software, etc.

i. Operating System
An operating system is the system
software that manages and controls
the overall operation of computer. It
coordinates, controls and manages
computer hardware. The operating
system is installed in C: drive of hard Operating system
disk. It is the first software that is loaded
into computer memory (RAM). The popular operating system are Windows XP, Windows
7, Windows 8, Windows 10, Linux based fedora, UNIX, MS-DOS etc. Android KitKat,
Android Marshmallow, Android Oreo are the popular operating system of Android
smartphone and IOS is the operating system of Apple iPhone.

Computer Science : Grade 9 57


The main functions of the operating system are explained below:

a. Memory Management:
Operating system performs the task of allocation and de-allocation of RAM-memory
space needed to run programs and other resources.

b. Processor Management
Operating system must allocate resources to processes and enable processes to share
and exchange information.

c. Device management
Operating system co-ordinates with all devices like keyboard, printer, monitor, mouse
etc. So, the operating system helps to manage input, process and output devices.

d. File Management
Operating system manages all files in computer. It keeps records of filename, type,
size, location, etc.

e. Security
Operating system provides a security mechanism while using a computer. For example,
password is used in a system to prevent unauthorized access.

The operating system can be classified into two types based on the mode of the user as:

Single User Operating System


It is designed to manage the computer so that one user can effectively do one thing at a
time. The Palm Operating System for palm handheld computers is a good example of
a modern single-user, single-task operating system. This is the most common type of
operating system used on a home computer as well as on computer in offices and other
work environments. Single User Operating system is designed to manage computer
so that only one user can work on it at a time. MS-DOS, Windows 8/10 etc. are the
examples of single-user operating system.

Multi-User Operating System


Multi-user operating system is designed to manage computer so that many users can

58 Computer Science : Grade 9


work on it at a time. Many computers are connected to network through one operating
system. So operating system coordinates and controls all computers connected to
network. Mainframe computer uses multiuser operating system. UNIX, VMS (Vertical
Memory System), Windows Server 2016, MVS (Multiple Virtual Storage), etc. are
examples of multi-user operating system. The operating system can be classified into
two types based on the user interface as:

CUI (Character User Interface)


In this type of operating system, user gives command or character to perform tasks. The
keyboard is used to give command in this operating system. It is less user-friendly in
comparison to other operating system. DOS, UNIX, Novel Netware, etc. are examples
of character user interface-based operating system.

DOS Screen
GUI (Graphical User Interface)
In this type of operating system, the user gives command to perform the tasks by clicking
on icons, buttons and menus using a mouse. It uses keyboard as well as mouse and it
is user-friendly in comparison to CUI operating system. MS Windows 7/8/10, Linux,
etc. are the examples of GUI.
Nowadays, Microsoft Corporation develops GUI based operating system. Windows
operating system users have increased.
Windows is a GUI based operating system that controls all activities of computer system.
In this operating system, the user uses different application program and document
display on window. So it is named as Windows.
Mouse is used to open file, shut down computer and perform different commands in
windows operating system. The user does not need to remember long commands to
perform task. Nowadays, Windows10 is the latest operating system.
Computer Science : Grade 9 59
ii. Language Processor
A computer is an electronic machine. So it understands machine level language (binary
language: 0 or 1). A computer program is a set of instructions to perform tasks.
System software that converts different programming language into machine level
language is called language processor. So language processor converts high-level
language or assembly language into machine level language and vice versa.

The three types of language processor are explained below:

a. Assemblers
An assembler is a type of language processor which converts program code written in
assembly language into machine language. Machine level language uses binary digit,
0 or 1 to write a program which is difficult. So a programmer writes programs using
assembly language. Mnemonic Code is used for writing program in assembly language.

The source program is an input of assembler that contains assembly language


instructions. The output generated by the assembler is the object code or machine code
understandable by the computer.

Source Code
Assembler Object Code
(Assembly Language) (Machine Language)

Assembler
b. Compilers
The high-level programming language is developed for the improvement of assembly
language. A compiler is a type of language processor which converts the program written
in high-level language into machine level language at once. The equivalent machine
code obtained after translation is called object code. So the process of converting source
code into object code is known as compilation. The compiler specifies the errors at the
end of compilation with line numbers when there are any errors in the source code.
The errors must be removed before the compiler can successfully recompile the source
code again. C, C#, C++, Java, PHP, etc. are compiler-based programming languages.

60 Computer Science : Grade 9


Source Code
Compiler Object Code
(High Level Language) (Machine Language)

Compiler

c. Interpreter
Interpreter is a type of language processor which converts the program written in high-
level language into machine level language line by line. If there is any error in the
middle of the program then program is interrupted in between. So, after removing the
error, the program needs to run again from the beginning. LOGO, QBASIC, BASICA,

Perl, Python, etc. are interpreter based language.

iii. Utility Software


Utility software is also called service program. A set of programs that perform task
related to the maintenance of computer software and hardware is called utility software.
The main objective of utility software is the smooth functioning of computer system.

The examples of utility software are:

 Antivirus software (Kaspersky, Norton Antivirus)


 Backup Software (Nova BACKUP Professional, Ashampoo Backup Pro)
 Encryption Tools (Versacrypt, Bitcocker)
 File Compression Tools (Winzip, WinRAR)
 Disk Utilities (Disk Defrag, WinDirstat)
iv. Device Drivers Software
Operating system often provides programs for working with special devices such as
printers. These programs are called drivers because they allow the operating system
and another program to activate and use the hardware device. Most new software you
buy will work with your printer, monitor and other equipment without requiring you to
install any special driver because the device driver for common peripherals are already
included in the operating system.

Computer Science : Grade 9 61


b. Application Software
Application software is designed to fulfil the requirement of user. A set of programs
designed to do specific tasks is called application software. The application software is
used to type e-mail, edit photos, prepare presentation, listen to music, design engineering
work, edit videos, produce bills etc. The popular two types of application software are
given below.

i. Packaged/General Purpose Application Software


The software developed for all general users to perform
their generalized tasks is called general-purpose
application software. It cannot be modified as per
user requirement. It is costlier and easily available in
market. The examples of general-purpose application
software are:

 MS Office Package (MS-Word, MS-Excel, Microsoft office


MS-PowerPoint)
 Adobe Photoshop
 Auto CAD
 SPSS (Statistical Package for the Social Sciences)
 Autodesk Maya.
ii. Customized/Tailored Software
The software which is designed to fulfil the specific requirement of an individual or office
or organization is called customized/tailored software. It can be modified as per user's
requirement. It can be used in school, college, hotel, travel agency, airlines, hospital,
insurance, etc. for performing different tasks like account, administration, store, ticket
booking, etc. There are different softwares in many offices and they are expensive.

Desktop
Once the computer is started, user name and password is typed and a screen opens
up that is called desktop. The background area of the Windows screen is desktop.
Desktop contains icons, taskbar, start button, etc. which is opened by clicking with
62 Computer Science : Grade 9
mouse. Desktop element differs according to versions of Windows like Windows XP
and Windows10. The user can add/remove icons on desktop.

Windows 10 Desktop Windows XP Desktop


Icon
Icons are the small picture buttons that represent file, folder, programs, etc. Mouse is
used to click on icon to perform a task. Icon is the main component of GUI operating
system.

Windows 10 desktop elements


i. This PC
This PC is an important system folder on desktop. This PC is a gateway
to user to see contents of storage device like hard disk, DVD, pen drive,
network computer, etc. by double-clicking on it.

ii. Recycle Bin This PC

Recycle Bin is a system folder which contains deleted file and folders. It
is very useful for recovering the files and folders which are accidentally
deleted. Select the file and press delete button to transfer to recycle bin.
But pressing shift + delete button on selection will permanently delete
selected file from hard disk. The file and folder can be restored from Recycle Bin
recycle bin to their original location if needed for use in future.

Documents
Document is a system folder of desktop. It is created while installing
Windows operating system. The user stores the document in document
folder.
Documents

Computer Science : Grade 9 63


Addition of Windows 10 Desktop icon
The user can add/remove the icons according to their requirement in Windows10. The
following steps show how to add/remove the icon.

Step 1. Right-click on an empty area of desktop and click personalize.


Step 2. Select setting and click on Themes.
Step 3. Click on Desktop Icon setting which is located on left top part of setting window.
Step 4. Now Desktop Icon setting appears.
Step 5. Click on checkbox of different desktop icons as your requirement for adding/
removing icons.

The user gives command by clicking mouse for different purposes. The actions of mouse
and their uses are as follows:

Word Meaning
Point To put mouse pointer on icon or item.
Click Once click left button of mouse and release it.
Right Click Once click right button of mouse and release it.
Double Click Click left mouse button of in quick succession and release it.
Point and click the item or icon by left button and drag into the new
Drag and Drop
location or place and drop it.
Dialog Box
It is also called a communication box. It
appears to perform a task or command
like file save, document print, etc. to
user in Windows operating system. The
dialog box contains option like ok button
or cancel button. Here, press Ok button
if it is satisfied to send the command to
the computer and press cancel button
if unsatisfied. So the user can choose
different option by means of GUI control Font Dialog Box
64 Computer Science : Grade 9
and perform the tasks.

GUI Control of Dialog Box


a. Radio Button
A radio button is the main GUI control used in window dialog box. It
allows a user to select only one option at a time. A round dark bullet
is marked in the selected button. Radio Button

b. CheckBox
A small square box which
allows a user to select the
available option or multiple
selections is called checkbox. Check Box

c. List Box
The series of options displays on the box is called list
box. The option of list box can be viewed by clicking
on item.

d. Text Box List Box


The rectangular box which allows a user to input or
types text on it is called a text box. It contains default text or blank space.

Text Box Command Button


e. Command Button
A small rectangular box that activates an action is called command button. 'Ok' and
'Cancel' the common command buttons.

Management of Files and Folders in Windows


File
A file is a set of related data and information stored on a computer system. File names
are divided into two parts as illustrated in figure below:

Computer Science : Grade 9 65


Extension gives information about the file types. Some popular extensions of files are:
data.txt

Filename Extension
 Media file (Video File) - .mp4, .mpeg, .avi, .flv, .wmv
 Audio file (Audio File) - .mp3, .wav, .aac
 Picture file (Image File) - .jpg, .gif, .png, .ico
 Office Document - .doc, .docx
 E-Book File - .pdf
 Spread sheet file(Excel File) - .xls, .xlsx
Folder
Folder is a container which stores file, program and subfolder. It is also known
as directory in DOS. Subfolder is located inside the folder and store data and
information.

a. This PC opening file and folder This PC

 Double click on This PC icon on desktop.


 There appears This PC window which contains system folder like Desktop, phone,
videos, documents, etc. and drive C:, D:, E:, etc.
 Double click on required file store in any drive.
 To close the open window, click on close (ˣ) button located on top left side of
window.

b. File Explorer
 Click on Search Windows icon and type file
explorer near to start button on desktop.
 Then click on the File Explorer menu.
 There appears File Explorer window and as a
requirement of the user, click on file located on drive
or folder.
File Explorer
66 Computer Science : Grade 9
Creating a new folder
 Double click on This PC.
 Double click on drive or folder where you wish to create a new folder.
 Right-click on an empty area of the of window.
 There appears temporary Floating Menu.
 Select "New" and click "Folder" and type folder name and press "Enter" key on
the keyboard.

Creating new folder

Rename File or Folder


 Right-click on file or folder to be renamed.
 There appears temporary Floating Menu and click on rename option.
 Type new name and then press "Enter" key on the keyboard.

Deleting File or Folder


 Click on file or folder location to delete.
 Press delete key from keyboard. Or right-click on file or folder to delete.
 Then click on delete option.

Note: While deleting the folder, all files and folders inside that folder also get deleted.

Computer Science : Grade 9 67


The deleted files and folders are stored in recycle bin on the desktop which occupies
hard disk of computer system. So, to delete file and folder permanently press shift +
delete key from keyboard.

Copy or move file or folder


The file and folder can be copied and placed on that disk or another disk. This is called
copy. The file and folder can be replaced to a new location and this is called move. The
file and folder can be copied or moved in the following way.

 Right-click on the file or folder to copy or move.


 Then appears Floating menu, click on copy option to copy or click on the cut
option to move it.
 Go to a new location to transfer the file or folder. Right-click on blank area then
click on paste option.

Searching files and folders


We sometimes forget the name and location of files and folders saved on disk. This
problem is solved by search feature or search facility
provided by Windows. The following is the process of
searching file and folder:

 Go to drive or folder to search. Or go to file


explorer.
 There appears rectangular text box left side. Type
full or half name of the file and folder with the use
Searching files and folders
of wild card characters.
 Press Enter on the keyboard.

OSS (Open Source Software)


The programs written in high level
language like C++, C#, Java, Python,
etc. are called source code. Open-
source softwares are freely available OSS

68 Computer Science : Grade 9


software and source code is also free of cost. So, open-source softwares are called free
software.

Ms office package, Adobe Photoshop, Windows 8/10, etc. are called proprietary
softwares which do not provide source code to user after payment.

In open-source software, the user modifies source code according to user requirement.
Open-source software was started by Richard Stallman in 1983. Richard Stallman
announced the GNU Project in 1983. Free Software Foundations was established in 1985.

Some proprietary software and their alternative open source software are listed below:

Type Proprietary software Open Source Software


Operating System Windows 8/10 Linux
Office Package Microsoft Office Libre Office, Apache Office
Photo Editing Software Adobe Photoshop GIMP
Web Browser Microsoft Edge Mozilla Firefox
E-mail Client Microsoft Outlook 2016 Thunderbird
Database Management Oracle, MS-SQL Server MySQL

Freeware
Freeware is a software available free of charge. It is copyrighted by its developer. The
developer retains the rights to control its distribution, modify it and sell it in the future.
Freeware is typically distributed without its source code, thus preventing modification
by its users. So, it may be freely downloaded, installed, used and shared.

Source code can be written in any programming languages. Some of the most popular
programming languages are C, C++, Java, Perl, PHP, etc.

Freeware is usually distributed with a license that permits its redistribution to some
extent. For example, allowing users to give copies to friends. However, there may be
restrictions, such as limitations on its commercial use. Some licenses permit the software
to be freely copied but not sold.

Computer Science : Grade 9 69


Desktop and Web Apps
A computer program that is designed for a specific purpose is called Apps or Applications.
They are installed in smartphone and tablets for different purposes.

Android operating system is used in a Smartphone. Google Company developed the


Android operating system as Marshmallow, Nougat, Oreo, etc. Google Play is the service
provided by Google Company in Android operating system. It gives service of free or
purchase of different applications or apps upon download. The main android apps are
Facebook, snap chat, Instagram, Viber, Google maps, etc.

iPhone of Apple Company provides app store service of downloading various apps.
Microsoft facilitates its users with Microsoft Store to download desktop apps.

Nowadays, web browser-related apps are used in all smartphones and computers. For
example, Google Company developed Google Chrome as a web browser.

Google play

70 Computer Science : Grade 9


Summary
 The set of instructions or programs written by using a programming language to
solve a problem is called computer software.
 The software that manages controls and supports computer system is called system
software.
 Operating system is the system software that manages, controls overall operations
of a computer.
 The background area of the Windows screen is desktop.
 Icons are the small picture buttons that represent file, folder, programs, etc.
 A dialog box appears to perform a task or command like file Save, document
print, etc. to user in Windows operating system.
 A file is a set of related data and information stored on computer system.
 Folder is a container where files and subfolders are stored.
 Language processor converts high-level language or assembly language into
machine level language and vice versa.
 The main objective of utility software is to maintain smooth functioning of a
computer system.
 The application software is used to type an e-mail, edit photo, prepare presentation,
listen to music, engineering design, video, producing bills etc.
 Open-source software is freely available software and source code is also free of
cost.
 The software which is proprietary or open-source software available free of cost
is called freeware.
 A computer program that is designed for a specific purpose is called Apps or
Applications.

Technical Terms
Computer Software : Program which controls and operates computer hardware to
perform a task.
Computer Science : Grade 9 71
Operating system : Co-ordinates, controls and manages computer hardware and
resources.
Desktop : The background area of the Windows screen.
Icon : The small picture buttons that represent files, folders,
programs, etc.
This PC : A gateway to user to see contents of storage device.
Recycle Bin : Contains deleted files and folders.
Language processor : Converts high-level language and assembly language into
machine level language and vice versa.
Compiler : Converts the program written in HLL into MLL whole
programme at once.
Utility software : Maintains computer software and hardware.
Application software : Designed to fulfil the requirement of the user.
OSS : Freely available software and source code.

Exercises
1. Answer the following questions.
a) Define computer software with its importance in computer system.
b) Explain operating system with examples.
c) What is computer memory? Write its major classification.
d) Mention major functions of operating system.
e) How does utility software maintain computer system? Give the name of
some utility software.
f) Briefly explain about application software with its types.
g) Distinguish between system software and application software.
h) Give the special features of packaged software.
i) What is the language processor? Write its types.
j) What is open-source software? Give examples.

72 Computer Science : Grade 9


k) Define proprietary software with examples.
l) List the advantages of open-source software over proprietary software.

2. State 'True' or 'False'.


a) A set of program is called software.
b) Android Marshmallow is application software.
c) Norton Antivirus is utility software.
d) The background area of the Windows screen is desktop.
e) DOS is an example of a character user interface.
f) There are three types of application software.
g) Open-source software is freely available software with source code.
h) Google play store is a service that provides download of different applications
or apps.
i) The source code can be updated in open-source software.
j) GIMP is a web browser.

3. Match the following.


Group 'A' Group 'B'
a) i) CUI a) Marshmallow
ii) GUI b) iOS
iii) Android c) Windows 10
iv) iPhone d) DOS
e) Apple

b) i) Radio Button a) series of option displayed on box


ii) Check Box b) input or typing text
iii) List Box c) select the available option
iv) Text Box d) select only one options at a time
e) select five options at a time

Computer Science : Grade 9 73


c) i) Video file a) .mp3
ii) Audio file b) .pdf
iii) Picture file c) .mp4
iv) E-book d) .gif
e) .mp5

4. Choose the correct answer.


a. Which is not a function of operating system?
i) Memory management ii) Entertainment
iii) File management iv) Security
b. Which is not a desktop icon on Windows 10?
i) This PC ii) Recycle Bin
iii) Picture iv) Document
c. …….. is an act of clicking left button of mouse in quick succession and
releasing it.
i) Click ii) Right Click
iii) Double Click iv) Drag and Drop
d. Which is not a picture file (Image File)?
i) .jpg ii) .gif iii) .png iv) .pdf
e. ………... allows a user to select the available options or multiple selections.
i) Command button ii) Text box
iii) List box iv) Checkbox
f. To delete file permanently use ………+delete key from keyboard.
i) space ii) alt iii) shift iv) ctrl
g. Which is not utility software?
i) Antivirus software ii) Encryption Tools
iii) Office Package iv) Backup Software

74 Computer Science : Grade 9


h. ……… is not proprietary software.
i) MS office package ii) Adobe Photoshop
iii) Windows8/10 iv) MySQL

5. Fill in the blanks with suitable word.


a) The software that manages controls and supports computer system is
…………
b) ………….. controls and operates computer hardware to perform a task.
c) ……….. is the system software that manages and controls the overall
operation of computer.
d) ……… is designed to manage computer so that only one user can work on
it at a time.
e) …… is used to give command in CUI operating system.
f) Nowadays, Microsoft Corporation develops ……. based operating system.
g) The background area of the Windows screen is ………
h) …………. is a system folder which contains deleted file and folders.
i) …………. is also called communication box.
j) ……… contains default text or blank space.
k) Application software is designed to fulfil the requirement of……..
l) The programs written in a high level language is called ………
m) A computer program that is designed for a specific purpose is called ………

6. Write the full form of.


i) CUI ii) GUI iii) OS iv) MSDOS v) OSS
vi) GPL vii) GIMP viii) VMS ix) MVS x) SPSS
xi) MS WORD

Computer Science : Grade 9 75


7. Write short notes on.
a) Multiuser operating system
b) Dialog Box
c) Customized/Tailored software
d) Desktop and Web Apps

Project Work
1. Collect names of softwares used in hospital, hotel, educational sector and other
different sectors in your locality about and discuss in groups main objectives of
the softwares.
2. Draw in chart paper the different types of computer hardware with name and paste
in your classroom.
3. Name one useful open source software that you are familiar with. List its features.
Prepare a presentation and demonstrate in your classroom.
4. Take a short interview with your teachers, friends, parents and relatives and
prepare a field report about what types of computers, laptops or other devices
they are using, what types of operating system the device has. Also, make a list
of apps that they have used in their smartphones.
5. Make a presentation of system, application and utility software used in your
computer lab.

76 Computer Science : Grade 9


Unit 2
Computer Graphics

Introduction
The term "Graphics" is derived from the Greek
word 'graphikos', which means 'something written'.
Graphics can be defined as visual data in the form of
images or designs created to inform or communicate.
Such visual images that are generated by a computer
are called computer graphics.
Computer Graphics is an important area in computer
applications. The term Computer Graphics includes everything that is presented
through images. Graphics provide visual feedback to the user. Hence, it is considered
as an important component of communication.
Computer Graphics includes everything that is presented through images developed
or designed using different graphical software. Graphic design is a means of visual
communication. As you have heard an English proverb "A picture is worth a thousand
words", with a good graphical design, you can express your message more effectively
and beautifully. Our brain processes visual information so much more effectively and
quickly than textual information. Therefore, Graphics is a very important communication
component in present days.
The term “Computer Graphics” was first used by William Fetter, Graphic Designer of
Boeing Company in 1960.
Uses of Computer Graphics
a) Publication of books, magazines, newspapers etc.
b) Cartoon movies and computer games
c) Educational materials
d) Computer simulation, VR-Virtual Reality, scientific modelling, engineering design
etc.

Computer Science : Grade 9 77


Computer-generated images vary from line drawings to the complex 2-D/3-D animated
graphics. Varieties of software programs are developed to draw simple to complex
graphics. Some popular image editing softwares are given below.

 Adobe Photoshop
 GIMP (GNU Image Manipulation Program)
 Google Drawing
 Adobe Illustrator
 CorelDraw
 Paint.net

2.1 Different Graphics Format


Image files are composed of digital data. Graphic
formats are the standard that is used for organizing and
storing digital images. Basically, there are two types of
graphics format.

a) Raster Format
Raster format (also called Bitmap images) are composed of tiny squares called pixels
(px), and each pixel is assigned a specific colour. If a JPG or GIF image is magnified
greatly in a program like Adobe Photoshop, individual pixels can be viewed and changed.
Pixel is the smallest element of a raster image.

A pixel (short for Picture Element) is the smallest addressable element of a picture
represented on a screen. The number of pixels determines the image quality. Common
file extensions of raster formats are JPG, GIF, BMP, TIF, and PNG.

b) Vector Format
Unlike raster format, vector images are not composed of pixels. Digital information is
stored using some mathematical formula in a vector image. The main feature of vector
graphics is that its quality remains the same when you enlarge it to any size. Common
file extensions of vector formats are AI, PDF, SVG, EPS

78 Computer Science : Grade 9


Note:
BMP- Bitmap
TIFF- Tagged Image File Format
AI- Adobe Illustrator
SVG- Scalable Vector Graphic
EPS- Encapsulated Post Script
PDF- Portable Document Format

2.2 Graphics for Web


Graphics are the most important component of website design. It adds visual appeal to
the information on the web page. Graphics are the most effective and interesting way
to communicate or explain ideas visually. Web graphics include illustrated images, info
graphics, charts, graphs, animated graphics, and photographs.

Things to be considered while using web graphics:


 Graphical content should be used with purpose.
 Don't use graphics with large file size. It consumes more bandwidth.
 Always use graphics relevant to the content.
 Crop the unwanted part of the graphics.
 Balance the graphics with background and text colour.

Graphical Software for web

Computer Science : Grade 9 79


 Adobe Photoshop, GIMP for raster graphics. They also provide limited features
of handling vector graphics.
 Adobe Illustrator, CorelDraw for vector graphics.
 Google Photos, Pixlr, Befunky, Fotor, Pic Monkey, Photoshop Express, iPiccy
are some popular online photo editors.
Web Graphics format
The primary web graphics formats are gif, jpg and png. These entire common web
graphics format are called bitmap graphics.

JPG Graphics
 JPG is the most used image file format.
 Digital cameras usually produce images in JPG format
 Suitable for images with a lot of different colours, like photographs
GIF Graphics
 The second most common image format used on the World Wide Web after JPEG.
 Suitable for images that require a few distinct colours, such as line drawings,
logos, b/w images or images with few colours.
PNG Graphics
 Newest file format.
 Better compression and transparency features than GIF.

Not Transparent Image Transparent Image


supported by GIF and PNG

2.3 Image Size and Resolution


80 Computer Science : Grade 9
Image size refers to the length and
width of a digital image. In the given
figure, the dimension of the image is
given as 900x445. It means:

 The image width is 900 pixels.


 The image height is 445 pixels.
Therefore, the total number of pixels
that made the given image is:

900  445 pixels = 400,500 pixels


Image File Metadata
To check the image size:
Step 1: Right Click on the image file from its folder. A pop-up menu will appear.
Step 2: Click on Properties.
What is a megapixel?
Resolution
Technically a megapixel is equal to 1,048,576
Resolution refers to the number of pixels
pixels but the camera manufacturing
in an image. The greater the number of
company round this figure to 1,000,000
pixels, the higher the resolution, provides
(1 million). Therefore, 1 million pixel is
more details and better definition to the
equivalent to 1 megapixel.
image.
If you have 12 megapixel camera, then
The most common units to measure
the photo it takes can have maximum
resolution are PPI (pixels per inch) and
12x1,048,576 (12,582,912) pixels. If
DPI (dots per inch).
the aspect ratio of your camera is 3:2.
PPI – It refers to the number of pixels Approximately, each full size of raw image
per inch that makes an image. It affects taken by 12MP camera is 4344 x 2896
the print size and quality of an image. pixels in dimension. So, by multiplying the
For Example: resolution – 72 pixels/ number of pixels along the width by those
inch of the height (4344 x 2896 = 12,580,224
– rounded to 12 million pixels) we get the
actual number of pixels in the image.

Computer Science : Grade 9 81


1 inch – 72 pixels

1 inch – 72 pixels
Total number of pixels per square inch = 5,184 pixels (72 pixels x 72 pixels)

In the same way, if the resolution is 300 pixels/inch then the number of pixels per square
inch will be 90,000 pixels.

DPI – It only refers to a printer. It indicates the number of physical dots of ink in a
printed document. For example, 1200 dpi printer uses 1200 dots of ink in every inch
to make up the colours.

2.4 Graphics Editing


As you know, graphics is an important component of web design. Therefore, a web
designer should have good knowledge about graphics editing. There are many graphics
editing application software which are available to edit web graphics. Here, some basic
image editing techniques are discussed using the most popular photo-editing tool –
Adobe Photoshop.

Adobe Photoshop
Adobe Photoshop is a professional image editing software that can be used to create a
new image or edit an existing one. Most of the graphic designers, web designers, graphic
artists, photographers and creative professionals use this popular tool.

Adobe Photoshop is a very popular software because of its different image editing and
retouching effects. Adobe Photoshop allows users to manipulate, crop, resize, correct
colour, apply effects, add text and many other editing tasks.

How to start Photoshop


 Open the Run Window.
 Type Photoshop.
82 Computer Science : Grade 9
 Press Enter or click on OK.
[If Adobe Photoshop is
installed in your computer,
Photoshop will start.]

Photoshop Workspace

❶ Photoshop Title Bar


It displays the name of the application and other title contents.

Computer Science : Grade 9 83


❷ Minimize button
Shrinks the application window to a bar on the taskbar; you click its button on
the taskbar to reopen it.
❸ Maximize/Restore button
If the window is maximized (full screen), click will changes it to windowed (not
full screen) and vice versa.
❹ Close (Quit) button
Closes the Adobe Photoshop application.
❺ Menu Bar
Contains different menus. This is the place where you can access most of the
commands and features in Photoshop.
❻ Tools
It contains the various tools available to create and edit images.
❼ Image Window
The image will appear in its own window once you open a file. This is the main
working area.
❽ Palettes
Palettes include colour, layers, character and other necessary palettes, which
provide you a variety of related controls for working with images. If none of the
palettes are visible, go to Windows in the menu bar and choose palettes you need
to work with.
Opening an Image File
Follow the steps to open
a file:
Step 1: Click on
File Menu > Open …
(Keyboard Shortcut: Ctrl
+ O)
An Open dialog box will
appear:

84 Computer Science : Grade 9


Step 2: Select the folder of your image file.
Step 3: Select the required image file.
Step 4: Click the Open button.
Changing the Image Size
Image size refers to the length and width of a
digital image, also called pixel dimensions.
Follow the steps to change the image size:

Step 1: Open the required image file.


Step 2: Click on Image Menu > Image
Size… (Keyboard Shortcut:
Alt+Ctrl+I)
An Image Size dialog box will
appear:
Here, the size of image is 900x900
pixels. Print size is 12.5 by 12.5
inch and the resolution is 72.
Step 3: Type the required Width and
Height in the pixel dimension
section.
Note: In the above dialog box, Constrain
Proportions is checked. It means if you enter
the value of width, the value for height will
be proportionately set.

Step 4: Change the value of width and


height in document size section if
you want to print it.
Note: Think about the resolution of image.
The output will be in low quality if you
increase the size of low-resolution image.

Computer Science : Grade 9 85


Step 5: Click on the OK button to accept the changes.
Note: The smallest addressable element of a Pixel (Picture Element). Resolution
refers to the number of pixels in an image.
Changing the Image Format
Follow the below steps to change the image format:
Step 1: Open the required image file of which you want to change the format.
Step 2: Click on File Menu > Save As…
(Shortcut Key: Shift+Ctrl+S)
A Save As dialog box will appear:
Step 3: Type name in File Name drop-
down list box, if you want to give
another name.
Step 4: Select the desired folder, if you
want to save in another location.
Step 5: Select the file format that you
want to change.
Step 6: Click on Save button.

Creating a new image file


Follow the steps to create a new image
file:

Step 1: Click on File Menu > New…


(Shortcut Key: Ctrl+N)

A New dialog box will appear:

86 Computer Science : Grade 9


Step 2: Type the required value for width, height and resolution of your page.
Step 3: Select Color Mode and Background Contents.
Step 4: Click on OK.
Now, a blank image file will appear on the workspace.

Tools Panel
This palette contains some groups of tools that are used to edit and manipulate images.
Here, text tool and some selection tools of tools panel are discussed:

Note: The character in the bracket in Tools Panel is a shortcut key to activate the required
tool. For example, press V to activate Move tool.

Computer Science : Grade 9 87


Type Tool
The Type tool is used to add text to your image file. You might have to add text
while creating poster, invitation or any other graphical design. You can also apply
different effects to text in Photoshop.

Adding Text
Follow the steps to add text:
Step 1: Create a new file or open an existing image file.
Step 2: Click on Type tool from Tools panel or simply press "T".

Options bar of Type Tool


Step 4:Choose the desired font, text size and colour.

Step 5:Click and drag anywhere in the workspace (new image or existing image)
window to create a text box.

Step 6:A new text layer will be added to your image.

Text Box over the image Text Player

88 Computer Science : Grade 9


Step 7: Type the required text.

Moving Text:
 Select the text layer.
 Select the Move tool or press V.
 Click and drag the text to the required location.
Edit the Text
 Double-click on the layer icon
of the required text.
or,
 Select the type tool and click
on the text. The text will be
highlighted.
 Now, you can modify the text,
text size and colour
Selection Tools
Selection tool is one of the mostly used tools in Photoshop while manipulating or
designing images. Selection tools are used to isolate different part of an image so that
we can work only on that particular area without affecting the rest of the image.

Marquee Tool
Marquee tool is a basic selection tool available in Photoshop. It allows the user to make
a rectangular or elliptical selection of a certain part of an image. It also provides 1-pixel
rows and columns selection.

Computer Science : Grade 9 89


Follow the below steps to select a part of an image using Marquee tool:

Step 1: Open a required image file.

Step 2: Select either Rectangular or Elliptical selection tool.

Step 3: Click and drag over the area of the image you want to select.

Note: Hold down shift button while dragging to constrain the marquee to square or
circle. You can cut, copy or apply some other effects on the selected portion of the image.

Lasso Tool
Lasso Tool allows the user to draw
freehand selections around objects.
Besides the standard Lasso tool,
Photoshop provides two other types
of Lasso tool: Polygonal Lasso Tool
and Magnetic Lasso Tool.

90 Computer Science : Grade 9


Follow the below steps to select a part of an image using Lasso tool:

Step 1: Open a required image


file.

Step 2: Select the Lasso Tool.

Step 3: Click and drag to draw


a freehand selection border over a
desired part of the image.

Step 4: Release the mouse button.

Note: Press Ctrl+D to deselect the


image.

Polygonal Lasso Tool: The Polygonal Lasso tool


allows the user to draw straight-edged segments
of a selection border.

 Open a required image file.


 Select the Polygonal Lasso Tool.
 Click on the required point on the image to
set the starting point.
 Move the cursor to the next point not far
from the starting point and click the left button again. A selection path will be
drawn between these two points.
 Keep putting points in the same way until the
desired area is outlined.
Note:

- To draw a straight line at a multiple of 45°, hold


down Shift as you move to click the next segment.
- To draw a freehand segment, hold down Alt and
drag.

Computer Science : Grade 9 91


- To erase recently drawn straight segments, press the Delete key.
Magnetic Lasso Tool: The Magnetic Lasso tool is generally suitable for quickly selecting
objects that have complex edges set against high-contrast backgrounds.

 Open a required image file.


 Select the Magnetic Lasso Tool.
 Click on the required point on the image to set the starting point.
 Release the mouse button or keep it pressed, and then move the pointer along the
edge you want to trace.
 Continue to trace the edge in the same way until the desired area is outlined.
Note: To deselect the selection - Press Ctrl + D

Magic Wand Tool: Unlike other selection tools, the


Magic Wand tool selects the pixels based on tone
and colour.

 Open a required image file.


 Select the Magic Wand tool in the Tools panel.
 In the Options bar, uncheck Contiguous if you want to select non adjacent areas
of similar color. Check Contiguous if you want to select only adjacent areas of
similar colour.

 Enter the Tolerance value (up to 255). Higher tolerance value, wider range of
color selection.
 Click the color in the image that you want to select.

In the given image of the flag


of Nepal only the blue color is
selected using the Magic Wand
tool.

92 Computer Science : Grade 9


Adding or subtracting selection
These features are used when you have already selected a part of image and want to add
more part of the image to selection or remove some part of the selection.

Method #1:
Using the Options bar of selection tool

To add: Click Add to selection button and click elsewhere in the image

To subtract: Click Subtract from selection button and click inside the selection.

Method #2:
Using Keyboard Keys

To add: Press Shift key and click elsewhere in the image

To subtract: Press Alt key and click inside the selection.

Note: These adding and subtracting features are applicable in Marquee and Lasso tools
also.

Cropping Images
Cropping images is one of the most basic, but important photo editing
features available in Photoshop. Cropping feature allows you to remove
unwanted outer parts of image.
Crop Tool

Computer Science : Grade 9 93


In Photoshop, you can crop your images using either crop tool or selection tool. Follow
the steps to crop an image:

Step 1: Open a required image.


Step 2: Select the Crop tool
from Tools panel or
press C to activate crop
tool.
Step 3: Select the area of the
image that you want to
have.
Step 4: Click on Image Menu > Crop or Press Enter.

Cropping After Cropping

Summary
 Computer Graphics includes everything that is presented through images
developed or designed using different graphical software.
 Some popular image editing software includes Adobe Photoshop, GIMP, Adobe
Illustrator, CorelDraw, Paint.net etc.
 There are two main types of Graphical Format: Raster and Vector
 Raster images are composed of tiny dots called pixels. JPG, GIF, BMP, TIF and
PNG are common raster formats.
 Vector graphics are composed of paths or lines. AI, PDF, SVG and EPS are
common vector formats.
 Image size refers to the length and width of a digital image, also called pixel
dimensions.
94 Computer Science : Grade 9
 Resolution refers to the number of pixels in an image.
 Adobe Photoshop is a professional image editing software that can be used to
create a new image or edit an existing one.
 Different selection tools available in Photoshop are Marquee Tool, Lasso Tool
and Magic Wand Tool.
 Cropping feature allows the user to remove unwanted outer parts of image.

Technical Terms
(a) Graphics : Visual data created to inform or communicate
(b) Computer Graphics : Images developed using graphical software
(c) Graphics Software : Software used to draw or design simple to complex
graphics
(d) Raster Image : Images composed of pixels
(e) Vector Image : Images composed of paths or lines
(f) Pixel : The smallest addressable element of a raster image
(g) Resolution : Dimension of an image measured in dpi or ppi
(h) Text Tool : Allows to add text on an image
(i) Selection Tool : Allows to select a required part of an image
(j) Cropping : Allows to remove unwanted outer part of an image

Exercises
1. Answer the following questions.
a) Define Computer Graphics.
b) What are the application areas of Computer Graphics?
c) Differentiate between Raster Image and Vector Image.
d) Mention the list of different image file formats.
e) Write some features of JPG and GIF images.
f) What is a pixel?

Computer Science : Grade 9 95


Cropping
g) What is the process of calculating image size?
h) Mention the steps of changing image size.
i) Explain the different selection tools available in Adobe Photoshop.
j) How do you crop an image? Explain.

2. Write 'True' or 'False'.


a) Graphics Software is used to edit images.
b) Microsoft Excel is an example of Graphics Software.
c) Vector image is composed of pixels.
d) Low number of pixels in an image means low quality of the image.
e) SVG is a vector image format.
f) We have to insert a small size image on the website.
g) 1 billion Pixel equals to 1 Megapixel.
h) Magic Wand Tool depends on the colour pattern of image.

3. Match the following.


Group “A” Group “B”
a) i) Magnetic Lasso Tool a) Remove unwanted part
ii) Magic Wand Tool b) Type text
iii) Text Tool c) Colour based selection
iv) Crop Tool d) Circular selection
e) Edge based selection
Group “A” Group “B”
b) i) JPG a) Suitable for paper printing
ii) GIF b) Vector Image
iii) TIFF c) Supports Animation
iv) PNG d) Raster Format
e) Suitable for website

96 Computer Science : Grade 9


4. Choose the best answer.
a) Which is NOT a Graphics Software?
i) Adobe Photoshop ii) Autodesk Maya
iii) GIMP iv) Microsoft Word
b) Which is NOT a Graphics Format?
i) PNG ii) PSD iii) BMP iv) PPT
c) ………….. format supports only 256 colours.
i) GIF ii) JPG iii) TIFF iv) PSD
d) Which is NOT a selection tool of Adobe Photoshop?
i) Marquee Tool ii) Lasso Tool
iii) Crop Tool iv) Magic Wand Tool
e) Graphic file composed of pixels.
i) Vector ii) Autodesk iii) Post Script iv) Raster
f) Tools for removing unwanted outer part of an image.
i) Dodge Tool ii) Eyedropper Tool
iii) Crop Tool iv) Brush Tool
g) The shortcut key to open Save As... dialog box.
i) Shift+Altrl+S ii) Shift+Ctrl+S
iii) Alt+Ctrl+S iv) Shift+Ctrl+Alt+S
h) There are ………….. types of Lasso Tool.
i) 2 ii) 3 iii) 4 iv) 5

5. Write the full form of.


a) VR b) GIMP c) JPG d) GIF e) TIFF
f) BMP g) PNG h) PSD i) SVG j) EPS
k) PDF l)Pixel m) ppi n) dpi

Computer Science : Grade 9 97


6. Write short notes on.
a) Web in Graphics
b) Graphics Software
c) Selection Tools of Adobe Photoshop

Activities
1. Prepare a presentation file on “Importance of Computer Graphics and its uses”
and present it to your class as a group work.
2. Collect the names, logo, application areas, file extensions and other related
information of different Graphics Software and draw in a sheet of chart paper.

Practical Work
1. Open any image file in Photoshop and change its width to 600 pixels and height
800 pixels.
2. Create a collage of 7 wonders of the world. Also write their names.
3. Search few jpg files in your computer. Open any one of them and save the same
file in PNG format.
4. Open any graphic file and demonstrate the uses of different selection tools.
5. Open any one JPG file. Remove some unwanted portion using crop tool and save
it in GIF format.
6. Run MS-Paint. Create a graphic file and save in BMP format. Open the same file
in Photoshop and save it in JPG format.

98 Computer Science : Grade 9


Unit 3
Internet Technology

3.1 Introduction
Many of you might have heard of the term ‘Internet’. Nowadays, it is popularly used
to search for information on any subject, to communicate with people, for shopping,
for knowing the latest news, booking tickets, playing game, sending greeting cards and
for a number of other purposes. Let us learn what exactly the internet technology is.

The internet technology refers


to 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
or as part of a small network
within a larger network, such
as the Internet.

The Internet is a network of Internet technology


networks, a global communication system that links together thousands of individual
networks. As a result, virtually any computer on any network can communicate with
any other computer on any other network. These connections allow users to exchange
messages, to communicate in real-time (seeing messages and responses immediately),
to share data and program, and to access limitless stores of information.

Today, the internet connects thousands of networks and hundreds of millions of users
around the world. It is a huge, cooperative community with no central ownership. This
lack of ownership is an important feature of the Internet because it means that no single
person or group controls the network. The Internet is open to anyone who can access
it. If you can use a computer and if the computer is connected to the internet, you are
free not only to use the resources posted by others, but to create resources of your own.

Computer Science : Grade 9 99


You can publish documents on the World Wide Web, exchange e-mail message, and
perform many other tasks.

The seeds of the internet were planted in 1969 when the Advanced Research Projects
Agency (ARPA) of the U.S. Department of Defence began connecting computer
at different universities and defence contractors. The resulting network was called
ARPANET.

3.1.1 World Wide Web (WWW)


The World Wide Web was created in 1989 at the European Particle Physics Laboratory
in Geneva, Switzerland. The World Wide Web is a term used to describe the interlinked
collection of hypertext documents and multimedia content available on the Internet.
You use a web browser to search, find, view and download information on the Internet.
Over the last few years, the web has become one of the most popular Internet services.

Web Server
The Web is a collection of Internet host systems that make these services available on
the Internet using the HTTP (Hypertext Transfer Protocol). Web-based information is
usually delivered in the form of hypertext and hypermedia using HTML.

Many people believe that the Web and the Internet are the same things, but this is not
correct. In fact, they are two different things. The web is a service (a system for accessing
documents) that is supported by the Internet (a gigantic network).

100 Computer Science : Grade 9


3.1.2 Web Server
Web servers are computers on the Internet that host website, serving pages to viewers
upon request. A computer that delivers (serves up) web pages. Every web server has
an IP address and possibly a domain name. If you enter a URL https://moecdc.gov.np/
in your web browser, the browser tries to find the IP address of the domain name from
the DNS server. Once IP address is resolved then request is sent to the webserver that
serves web pages of moecd.gov.np to fetch specific page “index.html”, now server will
send HTML content of that specific page to the client browser. Client browser knows
how to interpret HTML for end-user. Some of the popular web server applications are
Apache web servers, Microsoft IIS (Internet Information Server), NGNIX, Google Web
Server (GWS) etc.

3.1.3 DNS
DNS stands for Domain Name System (or service or server) and is an internet service
used for converting domain name into IP address on the internet or on local networks
using the TCP/IP. DNS automatically converts the website name typed in web browser
address bar into the IP address of web server hosting that site. For example, the domain
name https://www.moecdc.gov.np might translate to 202.45.144.44

Computer Science : Grade 9 101


3.1.4 URLs
The hypertext transfer protocol uses Internet addresses in a special format, called
Uniform Resource Locator, or URL. In a URL, type specifies the type of server in which
the file is located, address is the address of the server (Http, FTP), and the path is the
location within the file structure of the server. The path includes the list of folders where
the desired file is located. URL is the key to navigating the web. When you provide a
URL for the browser, the browser finds the URL’s page (index.html, index.htm, index.
php) and then transfers the page to your PC.

From the above example:

Hypertext Transfer Protocol / Hypertext Transfer Protocol


http:// or https://
Secure
www Subdomain (World Wide Web)
moecdc Domain Name (eg. Google, YouTube, Baidu, gorkhapatraonline)

102 Computer Science : Grade 9


.gov Domain Extension (eg. .gov=Government, .com=Commercial,
.edu=Education,
.mil=Military,
.net=Networ,
.org=Organization)
.np Contry Code (eg.
.np=Nepal,
.us=USA,
.ca=Canada,
.in=India,
.uk= United Kingdom)

3.1.5 Web Browser


A Web browser is a software application such as Mozilla Firefox, Google Chrome,
Microsoft Edge, Brave, Safari, Opera etc. designed to find hypertext documents on the
web and then open the documents on the user’s computer. It is a client application that
enables the client computer to gain access to a Web server or other internet servers, such
as FTP and Gopher. A browser also interprets and displays documents. Mosaic was the
first web browser while Mozilla Firefox and Google Chrome are the most commonly
used browsers nowadays.

Brave Mozilla firefox Google chrome Microsoft edge Safari


Web browsers
3.1.6 Web Site
A website is a collection of related web pages. These pages contain text, graphics,
audio, video and links to other pages which are typically identified with a common
domain name, and published on at least one web server. Examples are moecdc.gov.np,

Computer Science : Grade 9 103


gorkhapatraonline.com, neb.gov.np etc.

3.1.7 Web Pages


Hypertext documents on the Internet are known as web pages. Your web browser
interprets and displays web pages. Web browsers typically can display text, various
graphic and multimedia format files. Web pages are created by using a special language
called Hypertext Markup Language (HTML). You can see the power of the WWW in
pages that contain hypertext and hypermedia. Web pages are used to distribute news,
interactive educational services, product information, catalogues, highway traffic reports,
and live radio, TV and other kinds of information.

3.1.8 Home Page


When we load a web browser the page which loads first is called home page. Similarly,
when we type a domain name in the address bar the default page that loads on the
browser are called the home page of that website. We can change the homepage of the
browser by Tools Options.

3.1.9 Search Engines


Suppose you want to look at Chapter
6 of your book. What would you do?
You would look at the contents page,
search for the chapter and find out
the page number then open that page
number. Similarly, it is not always easy
to find what you want on the web. That
is because there are tens of millions of
unique web sites, which include billions
of unique pages! Search engines are -
well - "engines" or "robots" that crawl the web looking for new web pages when we
typed by typing one or more words. These robots read the web pages and put the text
(or parts of the text) into a large database or index that you may access. The engine
then displays a list of web pages that contain information related to your words called a

104 Computer Science : Grade 9


keyword. None of them covers the whole net, but some of them are quite large. Google,
Bing, Yahoo Search, Ask.com, AOL.com, Baidu are some popular search engines.

For school students, an important search engine is “KidRex”. It provides a list of


websites based on the provided keywords suitable for school students.

3.1.10 Download/Upload
Downloading means your computer is
receiving data from the internet. Downloading
is the transmission of a file from one computer
system to another. From the Internet user's
point-of-view, to download a file is to request
it from another computer (or from a web page
on another computer) and to receive it.

Where Uploading means data is being sent from your computer to the Internet. From an
internet user's point-of-view, uploading is sending a file to a computer that is set up to
receive it. Examples of uploading include sending an email, posting photos on a social
media site and using your webcam.

3.1.11 Netiquette
The word netiquette is a combination of 'net' (from Internet) and 'etiquette'. It means
respecting other users' views and displaying common courtesy while doing online
activities.

Some Essential Netiquette Rules


i. Never Share Personal Information
ii. Think Before You Post
iii. Avoid Passing on Rumours
iv. Don’t Get Involved with Cyber Bullying
v. Don’t use all caps in your mails or online messages because it is considered
shouting.
vi. Double Check Your Privacy Settings
vii. Treat Others with Respect
Computer Science : Grade 9 105
viii. Keep Everyone’s Privacy
ix. Help Others

3.1.12 IoT (Internet of Things)


A few years earlier only computers and servers were able to communicate with each
other by sharing data and information. Due to the advancement in technology, the
computer-like device can be integrated with any electronic devices enabling them to
share and communicate data to intended users and systems. Devices that can sense or
read the values of their surrounding environment are more likely to have application
for sharing/communicating information. Such devices when connected with server to
communicate data from their surrounding are called the Internet of Things. In a simple
way, you have things (devices) that can collect data and are capable to send these data
via Internet to server or any intended users. For example, a car with a GPS sensor (thing)
continuously transmits its location information to any user via internet. A temperature
sensor (thing) that is reading the temperature of a particular location and transmitting
that data via Internet to a Web Server so that anyone from the world can know the
temperature of that location/place. It can even be used in any home appliances like TV,
refrigerator, lights, AC, door, window with special-purpose sensors.

3.1.13 Cloud Computing


Cloud computing means storing and accessing data and programs over the internet “the
cloud” instead of your computer's hard drive. When you store data or run programs
from the hard drive, that's called local storage and computing. Everything you need is

106 Computer Science : Grade 9


physically close to you, which means accessing your data is fast and easy. For it to be
considered "cloud computing" you need to access your data or your programs over
the internet, or at the very least have that data synched with other information over the
web. With an online connection, cloud computing can be done anywhere, anytime.

Companies offering these computing services are called cloud providers and typically
charge for cloud computing services based on usage, similar to how we paid the bill
for water, electricity, telephone at home. Some of the cloud providers are Amazon
AWS, Microsoft Azure, Google Cloud, IBM Cloud, VMware Cloud, Oracle Cloud and
Alibaba Cloud.

You are probably using cloud computing right now, even if you don’t realise it. If you
use an online service to send an email, edit documents, watch movies or TV, listen to
music, play games or store pictures and other files. It is likely that cloud computing is
making it all possible behind the scenes. Cloud computing can be broken up into three
main services: Software-as-a-Service (SaaS), Infrastructure-as-a-Service (IaaS) and
Platform-as-a-Service (PaaS).

Here are a few things you can do with the cloud :


 Create new apps and services store, back up and recover data
 Host websites and blogs
 Stream audio and video
 Deliver software on demand

Computer Science : Grade 9 107


Examples of Services over Cloud
 Microsoft Office 365
 Office Online (Internet versions of Word, Excel, PowerPoint,
and OneNote accessed via your web browser without
installing anything.)
 Google Drive: This is a pure cloud computing service, with all
the storage found online so it can work with the cloud apps:
Google Docs, Google Sheets, and Google Slides. Google
Drive is also available on more than just desktop computers;
you can use it on tablets like the iPad or on smartphones,
and there are separate apps for Docs and Sheets, as well. In
fact, most of Google's services could be considered cloud
computing; Gmail, Google Calendar, Google Maps, and so
on.
 Apple iCloud: Apple's cloud service is primarily used for online storage, backup,
and synchronization of your mail, contacts, calendar, and more.

Technical Terms
world wide web (www) : An internet service developed to incorporate footnotes,
figures, and cross-references into online hypertext
documents.
Web Server : An internet host computer that may store thousands of
web sites.
Internet Protocol Address : A unique four-part numeric address (between 0 and 255)
assigned to each computer on the internet, containing
routing information to identify its location.
Index page : The default page, or main web page of a website.
Hypertext Markup Language (HTML): A page-description language used on the
world wide web that defines the hypertext links between
documents.

108 Computer Science : Grade 9


DNS : A naming system used for computers on the internet.
Transmission Control Protocol/Internet Protocol (TCP/IP): The set of commands and
timing specifications used by the Internet to connect
dissimilar systems and to control the flow of information.
Uniform Resource Locator : An internet address used with HTTP in the format
type://address/path.
Web Browser : A program that enables the user to view web pages,
navigate web sites, and move from one web site to another.
Web Site : A collections of related Web pages.
Web Pages : A document developed using HTML and found on the
world wide web.
Search Engines : A web site that uses powerful data-searching techniques
to help the user locate web sites containing specific types
of content or information.
Download : To receive a file from a remote computer.
Upload : To send a file to a remote computer.
Netiquette : The correct or acceptable way of using the Internet.
Cloud Computing : A type of Internet-based computing.
Office Online : A completely free, web-based version of Microsoft Office.
Google Drive : A file storage and synchronization service developed by
google.
Apple iCloud : A cloud computing solution by Apple Computer Inc. that
provides cloud storage and apps for desktop, and mobile
devices.

Exercises
1. Answer the following questions.
a. Define the term “Internet Technology”.
b. What is the Web Browser? Name any four web browsers.

Computer Science : Grade 9 109


c. What is a search engine? Give any two examples.
d. Define web page and website.
e. What is the purpose of the webserver? Give any two examples of web server
applications.
f. What does www explain?
g. How does a search engine let you search for information on the web?
h. What is netiquette? Write any four netiquette rules.
i. What is cloud computing?
j. Write any four advantages of cloud computing.
k. What is a cloud service? Give any two examples.
l. Give some examples of IoT devices.
m. Write short notes on
i. URLs
ii. DNS
iii. IoT

2. Fill in the blanks.


i) ……………….was the first web browser.
ii) Web browsers typically can display ……., various ………..and ……….
format files.
iii) Web pages are created by using a special language called………………
iv) The web uses a special protocol, called the …………………..
v) …………….are the key to navigating the web.
vi) A…………lets you search for information by typing one or more words.
vii) Combination of 'net' and 'etiquette' is ………………..
viii) Google chrome is an example of a ………………..
ix) A device that is completely cloud-centric is the ……………….

110 Computer Science : Grade 9


3. Give full forms of the following abbreviations.
a. HTML b. TCP/IP c. WWW d. HTTP e. URL
f. IP g. DNS h. ICT i. ARPA

4. Write the technical terms for these.


i. The language used to develop a web page.
ii. The native protocol of the Internet.
iii. The largest computer network.
iv. The software required for browsing and surfing web sites.
v. The first page of a website.
vi. The website used to search for information on the internet.
vii. An address that identifies the location of a web page on the internet.
viii. The process of transferring data/file from the user’s computer to the internet.
ix. A special set of manners to be followed when using the Internet.

5. Match the following.


Group A Group B
i. Web Browser a) WWW.google.com
ii. Search Engine b) URL
iii. World Wide Web c) Domain Name
iv. Web Address d) Tim Berners Lee
e) Mozilla Firefox

Activities
1. Complete the following exercises as directed by your teacher.
a) Prepare a list of search engines using the Internet.
b) Practice using your browser. Launch your browser and practice navigating
the Web. Try using URLs based on the names of people of companies you
want outlearn more about. As you visit different sites, look for hyperlinked
Computer Science : Grade 9 111
text and graphics; click them, and see where they lead.
c) Search, search, search. Pick a topic and search the Web for information
about it. Pick a keyword to use in your search, then visit three search engines
and use each of them to conduct a search using your chosen keyword. Use
Bing, Altavista, and Google for your searches.
d) Prepare an article on “Internet Safety”. Using the Internet, find some
information about the topic and include in your article and also mention
the name of the website you visited.
2. Make a PowerPoint presentation on the topic.
 “How are the Internet and its services helping us to develop a better society?”

Project Idea
 Choose one service that Internet has been providing us or you can imagine
(develop) a new idea which is possible through the Internet. Limit yourself with
only one service/idea and present it in-depth with all the required specificity. Your
presentation may include multimedia files, pictures, cartoons, graphs, bar charts
etc. Your presentation may include information in the following order:
a) Introduction : (Define/introduce that idea/history of idea/summary of things
you are going to present in this presentation)
b) Main Body : (Its use/beneficial aspects or target group/how it works,
argumentation about do’s and don’ts, relate human development in socio-
economic prospects, benefits and limitations with examples)
c) Conclusion: (Conclude your argumentation with logical interpretation and
integrate it with human development.)

112 Computer Science : Grade 9


Unit 3.2
HTML (Hypertext Markup Language)

3.1 Introduction
In the previous lesson, you learnt that the language used to develop web pages is called
Hypertext Markup Language (HTML) where Hypertext is a text which contains links to
other texts. By clicking on a link in a hypertext document, a user can quickly jump to
different content. For example, software that includes dictionaries and encyclopaedias
has long used hypertext in their definitions so that readers can quickly find out more
about specific words or topics. Though hypertext is usually associated with Web pages.

A Markup Language is a computer language that uses tags to define elements within
a document. It is human-readable; markup files contain standard words, rather than
typical programming syntax. While there are several markup languages the two most
popular are HTML and XML (Extensible Markup Language). HTML was invented
by Tim Berners-Lee at CERN, the European Particle Physics Laboratory. The World
Wide Web Consortium (W3C) is the standard organization that controls the evolution of
HTML. The W3C provides a list of recommendations regarding the use of HTML and
other associated technologies and you should try to adhere to these recommendations
when you are writing your own web pages.

3.2 HTML Tag and Attributes


HTML Tags are instructions that are embedded directly into the text of the document.
An HTML tag is a signal to a browser that it should do something other than just throw
text up on the screen. By convention all HTML tags begin with an open left angle
bracket (<) and end with a close right angle bracket (>). HTML tags can be two types:

a. Container Tag: Most tags come in pairs and surround the material they affect.
They work like a light switch: the first tag turns the action on, and the second
turns it off. For example, the <B> tag is a container tag. It is also called paired tag.
In paired tags, the first tag (<B>) is often called the opening tag and the second
tag (</B>) is called the closing tag. The opening tag activates the effect and the
closing tag turns the effect off.
Computer Science : Grade 9 113
b. Empty Tag: An empty tag does not have a companion tag. Tags that are used
by them are called empty tags. It is also called Singular or stand-alone tag. For
instance, the <BR> tag creates a blank line and doesn't have an "off switch".

3.2.1 Attributes
Some elements may include an attribute, which is additional information that is included
inside the start tag. For example, you can specify the FONT (size, color or face) by
including the appropriate attribute with the HTML code.
<Font Size = "+1"> Attention! </Font>

Tag Name Attribute Value Text Closing Tag


One tag can have more than one attributes and values.
<FONT FACE="MS Sans Serif" Color="red" Size= “+1”> Attention! </Font>
HTML is not case sensitive. <font> is equivalent to <FONT> or <FONT>.

3.2.2 Structure of HTML Document


Every HTML document has a rigid structure. The HTML document is mainly divided in
two sections. The entire document is enclosed within <HTML> </HTML> tags. Within
these tags two distinct sections are Document Head section contained in <HEAD> </
HEAD> and Body section contained in <BODY> </BODY>.

<HTML>

<HEAD>

..head section

</HEAD>

<BODY>

..body section

</BODY>

</HTML>

114 Computer Science : Grade 9


<HTML> This tag recognizes the document as an HTML document.

<HEAD> …</HEAD> This tag identifies the beginning and end of the header section.

<TITLE> This tag is used to place the text in the title bar of the browser window.

<BODY> …</BODY> This tag recognizes the beginning and end of the body section.

There are some attributes of the <BODY> tag which are used to specify the background
colour, text color, font size, font weight and so on.

BGCOLOR Changes the default background color to whatever color is


specified with this tag.

BACKGROUND Specifies the name of the image (.gif) file that will be used as
the background of the document.

TEXT Changes the body text color from its default value to the color
specified with this attribute.

3.2.3 Creating HTML Documents in Notepad.


Now let's put this into practice. All you need is to write an HTML file in a text editor.
All major operating systems have at least one text editor: Mac OS has SimpleText,
UNIX/Linux has vim, emacs and Windows has Notepad; Beside this, there are numerous
HTML "Integrated Development Environments" (IDE's) such as PHPEdit, Textpad,
Editplus, Notepad ++ etc. Basic HTML documents that we will be working with have
the extension .html or .htm.

Here are the steps to create and save the HTML document in notepad.
 In MS-Windows, Click the Start Button
Computer Science : Grade 9 115
 Type Notepad in the search text box and hit Enter. (Notepad window will appear)
 Type the HTML code in the Notepad window as shown in the figure below.
 Save the file from File Menu>Save.
 Notepad will display Save as dialog box asking for a file name as shown in the
figure below.

 In the File name text box, type “Firstpage.htm” or “Firstpage.html”. Type the
filename and .html or .htm extension enclosed in the double quotes else the file
might be saved with TXT extension.
 Click on the save button.
To view your Web page double click on your page “Firstpage.htm” and you can see it
in your default browser (like Internet Explorer or Mozilla Firefox). To view the source
code of your page you can just click on View menu and click source. Now you can see
the HTML source code as shown in the figure below.

116 Computer Science : Grade 9


3.2.4 Organizing Text in HTML document
The web browser only identifies the single space between the word or text even if there
are many spaces given between the words. Use &nbsp; a special code to add additional
spaces between the text. One &nbsp; inserts one space; so, use as many &nbsp; codes
as the number of spaces you want between the text.

For line breaks and paragraph breaks <BR> and <P> tags are used. Apart from simple
formatting tags, text-formatting tags are also used. These tags are used for changing
the color, size, alignment, font etc. of the text.

Paragraph Tag <P>: A blank line always separates paragraphs in textual material. The
tag that provides this functionality is <P>. At this tag, the browser moves onto a new
line skipping one line between the previous line and the new line.

ALIGN=LEFT | CENTER | RIGHT attribute can be used to set the alignment of the
paragraph. Left alignment is set by default.
Input:
<P> Please forward any inquires to [email protected]</P>
<P ALIGN=RIGHT> DATE: </P>

Line Break Tag <BR>: When text needs to start from a new line and not continue on
the same line (without skipping a blank line), the <BR> tag should be used. This tag
simply jumps to the start of the next line.
Input:
Government of Nepal, <BR> Ministry of Education, Science & Technology,<BR>
Curriculum Development Centre,<BR> Tel.:(977-1) 6630588, 6634119.

Output:
Government of Nepal,
Ministry of Education, Science & Technology,
Curriculum Development Centre,
Tel.:(977-1) 6630588, 6634119

Computer Science : Grade 9 117


Comment (<!-- ………. -->) Tag
The comment tag is used to insert a comment in the HTML source code which will not
be displayed on the web page itself. We can use a comment to explain tag/code, which
can help us when we edit the source code later. Comments in HTML always begin with
<!- - and end with - ->. The browser ignores any text or tags placed inside a comment.

<!-- comment here-->


Comment tag requires exclamation (!) symbol after opening bracket, but not before
the closing bracket.

Example 1
<HTML>
<HEAD>
<TITLE> An example of comment </TITLE>
</HEAD>
<BODY>
<!—body tag includes all the tags and other text-->
The comment tag used to insert comment in the HTML source code
</BODY>
</HTML>

Formatting Tags
Formatting tags are used to change the appearance of the text in web page. Formatting
tags can be used set the font face, font color, font size, bold, italics styles of the text.

Heading Styles <H1>…<H6>: HTML supports six different levels of headings. The
highest-level header format is <H1> and the lowest level is <H6>. All the styles appear in
BOLDFACE and the size of the heading depends on the level chosen, i.e. <H1> to <H6>

Input: Output:
<h1>This is a heading one.</h1> This is a heading one.
<h2>This is a heading two.</h2> This is a heading two.

118 Computer Science : Grade 9


<h3>This is a heading three.</h3> This is a heading three.
<h4>This is a heading four.</h4> This is a heading four.
<h5>This is a heading five.</h5> This is a heading five.
<h6>This is a heading six.</h6> This is a heading six.
[Note: Here as the number increases next to <H> like (1,2,3…..) the font size actually
decreases.]

Drawing Horizontal Lines <HR>: The tag <HR> draws line and horizontal ruler. This
tag draws a horizontal line across the whole page, wherever specified. The attributes
of the <HR> tag are:

Attributes Description
Aligns the line on the Browser screen, which is by default, aligned to
the center of the screen.

ALIGN ALIGN=LEFT will align the line to the left of the screen
ALIGN=RIGHT will align the line to the right of the screen
ALIGN=CENTER will align the line to the center of the screen
SIZE Change the size of the rule.
Sets the width of the rule. It can be set to a fixed number of pixels, or
WIDTH to a percentage of the available screen width.

Input:
Welcome to Nepal VisitNepal 2020!
<HR ALIGN= “LEFT” WIDTH= “20” SIZE= “4”>
Text Styles
To format your text, you can use the following tags. <B>…</B> tag to display text in
BOLDFACE style, <I>…<I> tag for ITALICS, <U>…</U> tag is uses to UNDERLINE.
The superscript <SUP>…</SUP> and subscript <SUB>…</SUB> tags are used for
placing the text above and below the specified text.
Input:
<b>this text is bold </b>
<i> this text is italicize </i>
Computer Science : Grade 9 119
<u>this text is underlined</u>
A<sup>2</sup>B<sup>2</sup>
H<sub>2</sub>O
Output:
this text is bold
this text is italicize
this text is underlined
A2B2
H2O

Text Effects
Centering (Text, Image etc.)
<CENTER>…..</CENTER> tags is used to center everything found between them
– text, lists, images, rules, tables or any other page element.

Input:
<CENTER> Welcome to Pokhara VisitNepal 2020! <CENTER>
Controlling Font Size and Color:
All text specified within the tags<FONT> and </FONT> will appear in the font, size
and color as specified as attributes of the tag <FONT>. The attributes are:

FACE Sets the font to the specified font name.

SIZE Sets the size of the text.


Size can take values between 1 and 7. The default sized used is 3.
COLOR Sets the color of the text. COLOR can be set to an English language
color name or to a hexadecimal triplet.

Input:
<FONT face= “Comic Sans MS” Size=6 Color=Red> Welcome to Nepal
VisitNepal 2020! </Font>
If you would like to specify a certain text or background color, you can do so by using
color codes.
120 Computer Science : Grade 9
RGB color codes are represented as hexadecimal values. The RGB color codes contain
three sets of numbers representing the amount of Red, Green and Blue contained in a
color. These codes must be used within your HTML to specify your selected colors.

Here are a few of the basic color codes:

Black #000000 Silver #C0C0C0


White #FFFFFF Lime #00FF00
Red #FF0000 Gray #808080
Green #00CC00 Maroon #800000
Blue #0000FF Purple #800080
Yellow #FFFF00 Aqua #00FFFF

Input:
<font color="#FF0000">RED </FONT>
<font color="#00CC00">Green </FONT>
<font color="#0000FF">Blue </FONT>
The MARQUEE Tag
The <MARQUEE> tag is useful for creating scrolling effect.

Attribute Description Values


Behavior Scrolling behavior alternate, slide, scroll
Direction Scrolling direction left, right, up, down
Bgcolor Background color color name or value
scrolldelay Delay in scrolling text A number in milliseconds
Height Height of scroll area A number is pixels
width Width of scroll area A number in pixels

Input
<MARQUEE> COMPUTER SCIENCE !!!</MARQUEE>
<marquee behavior="scroll" direction="down" bgcolor="#CCFF00"

Computer Science : Grade 9 121


scrolldelay="1000"> Running Text! </marquee>
Lists : Types of Lists
Unordered List (Bullets)
An unordered list starts with the tag <UL> and ends with </UL>. Each list of items
starts with the tag <LI>. The attributes that can be specified with <LI> are
TYPE : Specifies the type of bullet.
TYPE=FILLROUND will give a solid round black bullet
TYPE=SQUARE will give a solid square black bullet

Example 2:
Some of these products include:

<UL TYPE =FILLROUND>


<LI> Pen drive </LI>
<LI> Hard Disk </LI>
<LI> Monitors </LI>
</UL>
Output:
Some of these products include:

 Pen drive
 Hard Disks
 Monitors
Ordered Lists (Numbering)
An ordered lists start with the tag <OL> and end with </OL>. Each list items start with
the tag <LI>. The attributes that can be specified with <LI> are:

122 Computer Science : Grade 9


Controls the numbering scheme to be used.
TYPE= “1” will give counting numbers (1,2, ………)
TYPE= “A” will give Uppercase letters (A,B,………)
TYPE
TYPE= “a” will give Lowercase letters (a,b,………..)
TYPE= “I” will give Uppercase Roman Numerals ( I, II, ………)
TYPE= “i” will give Lowercase Roman Numerals ( i, ii, iii, …….)
START Alters the numbering sequence. Can be set to any numeric value.
Changes the numbering sequence in the middle of an ordered list. It is
VALUES
to be specified with the <LI> tag.

Example 3:
Some of these products include:
<OL TYPE = “1” START=3>
<LI> Pen drive
<LI> Hard Disks
<LI> Monitors
</OL>
Output:
Some of these products include:
3. Pen drive
4. Hard Disks
5. Monitors

Definition Lists
Definition list values appear within tags <DL> and </DL>. Definition lists consist of
two parts:

Definition term appears after the tag <DT>


Definition description appears after the tag <DD>

Computer Science : Grade 9 123


Example 4:
<DL>
<DT> Keyboard
<DD> An input device
<DT> Printer
<DD> An output device
</DL>
Output:
Keyboard
An input device
Printer
An output device

3.2.5 Adding Image to HTML Documents


Other than text, HTML allows placing of static and/or animated images in an HTML
page. Mainly two picture file formats are used in HMTL: .gif and .jpg. Images can be
created to suit the requirements of a web and page and saved in these file formats using
tools such as Gif Constructor or Adobe Photoshop.

Once an image is ready and stored in above-mentioned format, it can be inserted into
a web page using <IMG> tag, which takes the name of the image file (filename.gif,
filename.jpg or filename.jpeg) as the value of SRC attribute.

Inserting Images <IMG> Tag


The <IMG> tag takes the following attributes:

Attribute Value
SRC Location and name of the image file
Controls alignment of the text following the image
ALIGN = TOP indicates the text after the image to be written at the
tip, next to the image.

124 Computer Science : Grade 9


ALIGN = MIDDLE indicates the text after the image to be written
at the middle, next to the image.
ALIGN = BOTTOM indicates the text after the image to be written
at the bottom, next to the image.
CONTROLS ALIGNMENT OF THE IMAGE WITH RESPECT TO
THE VDU SCREEN
ALIGN
ALIGN = LEFT indicates the image is aligned to the left with respect
to the screen.
ALIGN = CENTER indicates the image is aligned to the center with
respect to the screen.
ALIGN = RIGHT indicates the image is aligned to the right with
respect to the screen.
BORDER Specifies the size of the border to place around the image.
WIDTH Specifies the width of the image in pixels.
HEIGHT Specifies the height of the image in pixels.
HSPACE Indicates the amount of space to the left and right of the image.
VSPACE Indicates the amount of space to the top and bottom of the image.
Indicates the text to be displayed in case the Browser is unable to
ALT
display the image specified in the SRC attribute

Example 5:
<IMG WIDTH = 447 HEIGHT = 57 BORDER =0 HSPACE = 0 SRC = “IMAGE1.
GIF” ALIGN=CENTER>

Using the BORDER attribute


[Note: Before practising this example create a folder of your name and create another
subfolder called images and copy some images in it. Save the following web page inside
the folder of your name.]

Computer Science : Grade 9 125


Example 6:
<HTML>
<HEAD>
<TITLE> Working with Images </TITLE>
</HEAD>
<BODY BACKGROUND = “images/texture1.gif”>
<B> Controlling Image Borders!</B>
<CENTER>
<I> Image Without a BORDER </I> <BR> <BR>
<IMG SRC=”images/corp.gif”> <BR> <BR>
<I> Images With BORDER = 3</I> <BR> <BR>
<IMG SRC=”images/corp.gif” BORDER = 3 > <BR>
</CENTER>
</BODY>
</HTML>

Using the WIDTH and HEIGHT attribute


Example 7:
<HTML>
<HEAD>
<TITLE> Working with Images <TITLE>
</HEAD>
<BODY BACKGROUND = “images/texture1.gif”>
<B> Controlling Image Sizes!</B>
<CENTER>
<I> Normal Image Size! </I> <BR> <BR>
126 Computer Science : Grade 9
<IMG SRC=”images/computer.gif”> <BR>
<I> Images With Size (Height And Width) Set to 200</I> <BR> <BR>
<IMG WIDTH = 200 HEIGHT = 200 SRC=images/computer.gif”> <BR> <BR>
</CENTER>
</BODY>
</HTML>

Using the ALIGN attribute


Example 8:
<HTM>
<HEAD>
<TITLE> Working with Images </TITLE>
</HEAD>
<BODY BACKGROUND = “images/texture1.gif”>
<B> <I> Image Aligned Left </I> </B>
<IMG SRC= “images/sctonly2.gif” ALING = left> <BR> <BR>
Silicon Chip Technologies, <BR>
<I> We Specialize In Corporate Training, Software Development and Placements.
Our Training Programs and Software Development include Web Based Commercial
Applications and Commercial Application Development using Databases. </I>
<BR> <BR> <BR> <BR>
<B> <I>Image Aligned Right </I> </B>
<IMG SRC = “images/sctonly2.gif” ALIGN = right> <BR> <BR>
Silicon Chip Technologies, <BR> <I> We Specialize In Corporate Training,
Software Development and Placements. Our Training Programs and Software
Development include Web Based Commercial Applications and Commercial
Application Development using Databases.</I>
</BODY>
</HTML>

Computer Science : Grade 9 127


Using the ALT attribute
Example 9:
<HTML>
<HEAD>
<TITLE> Working with Images </TITLE>
</HEAD>
<BODY BACKGROUND = “images/texture1.gif”>
<B> Use of ALT attribute </B> <BR>
<CENTER> <I> Avaliable Image: Javacup.gif </I> <BR> <BR>
<IMG SRC = “images/javacup.gif”> <BR> <BR>
<I> Unavaliable Image: Javac.gif – Without the ALT Attribute </I> <BR> <BR>
<IMG SRC =“images/javac.fig”><BR><BR>
<I> Unavaliable Image: Javac.fig – With the ALT Attribute set or “Java”</I>
<BR> <BR>
<IMG SRC=“images/javac.gif” ALT = “The Java cup”> <BR>
</CENTER>
</BODY>
</HTML>

3.2.6 Creating Links : <A> Anchor Tag


HTML allows linking to another HTML document as well as images. Clicking on a
section of text or an image in one web page will open another web page or moves to a
specific location of the same page or an image. The text or an image that provides such
linkage is called Hypertext, a Hyperlink, or a Hotspot.
The browser distinguishes Hyperlinks from normal text. Hyperlink has the following
features.
 Appears blue in color
 The hyperlink text/images are underlined
 When the mouse cursor is placed over it, the standard arrow-shaped mouse cursor

128 Computer Science : Grade 9


changes to the shape of a pointing hand
Links are created in a web page by using the <A> </A> tag. Anything written between
the <A> </A> tag becomes a hyperlink/hotspot. Clicking on the hyperlink navigates to
a different web page or images.
The document to be navigated needs to be specified. By using the HREF attribute of
the <A> tag the next navigable web page or images can be specified.
<A HREF = “filename.htm”>

Hyperlinks can be of two types:


 Links to an external document
 Links (jumps) to a specific place within the same document

External Document References


Example 10:

<A HREF = “details.htm”> Visit my Home page </A>

INPUT
<HTML>
<HEAD>
<TITTLE> USING LINKS TO CONNECT TO EXTERNAL SITES </TITLE>
<BODY BGCOLOR= “GREEN”>
<H2 ALIGN= “CENTER”>VISIT THE SITES TO KNOW ABOUT NEPAL</H2> <P>
<OL>
<LI> <A HREF= “http:// WWW.welcomenepal.com”> WWW.welcomenepal.com </A>
<LI> <A HREF= “http://WWW.explorenepal.com”> WWW.explorenepal.com </A>
<LI> <A HREF= “http:// WWW.lonelyplanet.com”> WWW.lonelyplanet.com </A>
<LI> <A HREF= “http:// mofa.gov.np”> mofa.gov.np </A>
</OL>
</BODY>
</HTML>

Computer Science : Grade 9 129


Intra-Page links or Bookmarks
Link created in a page can be opened at a different location on the same page. Such
links are called intra page links or bookmarks. It is also possible to jump to a particular
location on another web page using bookmarks.

Using Named Anchors


To use the intra-page links named Anchors are used.
For instance, <A NAME= “top”> </A>
This is a different use of the <A> anchor tag; it is necessary to give a name at the specific
point on the page where the tag occurs. The </A> tag must be included, but no text is
required between <A> and </A>.
<A HERF= “#top”> TOP </A>
The # symbol identifies the word “top” as a named anchor point within the current
document, rather than a separate page. When a reader clicks on “TOP”, the web browser
will display the part of the page starting with the <A NAME= “top”> tag.

Example 11: INPUT


<HTML>
<HEAD> <TITTLE> Visual Basic Information </TITTLE></HEAD>
<BODY>
<A HREF= “#LAST”> GO BOTTM </A> <!-- Linked to the location named as
“LAST”-->
<BR>
<A HREF= “#DATABASE”> DATABASE SECTION </A> <!-- Linked to the
location named as “DATABASE”-->
<BR>
<A HREF= “#TOP”> WEB SECTION </A> <!-- Linked to the location named
as “WEB”-->
<A NAME = “TOP”> </A> <!--A Name “Top” is given to this location -->
<H3> Mastering Visual Basic 6.0</H3>

130 Computer Science : Grade 9


<P>
<H3>Table of Contents</H3>

<OL> <H4>The Fundamental


<OL>
<LI> Getting started with Visual Basic
<LI> Visual Basic Projects
<LI> Visual Basic Language
<LI> Working With Forms
<LI> Basic ActivX Controls
</OL>
</OL>

<A NAME= “DATABASE”> </A> <!--A NAME “DATABASE” is given to this


location-- >
<OL> Database Programming with VB
<OL>
<LI>Database with VB
<LI>The Active Data objects
</OL>
</OL>

<A NAME= “WEB”> </A> <!--A NAME “WEB” is given to this location -- >
<OL> Visual Basic and the web
<OL>
<LI> Introduction to the Web
<LI> Scripting Objects
<LI> VB and the Web
<LI> Active Server Pages (ASP)
</OL>
Computer Science : Grade 9 131
</OL>

<OL> Special Topics


<OL>
<LI> The Multiple Document Interface
<LI> Recursive Programming
<LI> Optimizing VB Applications
</OL>
</OL>

<OL>
<LI> Introduction to the Web
<LI> Scripting Objects
<LI> VB and the Web
<LI> Active Server Pages (ASP)
</OL>
</OL>
</OL>
</OL>

<A NAME= “LAST”> </A> <!--A NAME “LAST” is given to the this location -- >
<A HREF= “#TOP”> GO TOP</A> <!--Linked to the location named as “TOP”-- >
<BR>
<A HREF= “#DATABASE”> DATABASE SECTION </A> <!--Linked to the
location named as “DATABASE”-- >
<BR>
<A HREF= “#TOP”> WEB SECTION </A> <!—Linked to the location named
as “WEB”-- >
<BR>
</HTML>
132 Computer Science : Grade 9
Email Link
Apart from inter-page links and intra-page links, the <A> tag can also be used for
creating e-mail links. Email link creates a new message addressed to a specified recipient
using the web user’s installed mail client. For this purpose, the email address must be
specified after the mailto: statement in <A HREF> tag.

Example 12:
<HTML>
<HEAD>
<TITLE> USING EMAIL LINKS </TITLE>
</HEAD>
<BODY>
Send your email to <A HREF = mailto: [email protected]> Curriculum
Development Center, Sanothimi Bhaktapur </A>
</BODY>

</HTML>

3.2.6 Table
A table is a two-dimensional matrix, consisting of rows and columns. Tables are intended
for displaying data in rows and columns on a web page. All table-related tags are included
between the <TABLE> </TABLE> tag. Each row of a table is described between the
<TR> </TR> tag. Each column of a table is described between the <TD> </TD> tag.

Table rows can be of two types:

Sunday Monday Tuesday Wednesday


5 6 7 8
12 13 14 15

Header rows
A table header row is defined using <TH> </TH> tag. The content of a table header

Computer Science : Grade 9 133


row is automatically centred and appears in boldface.
Data rows (Individual data cells placed in the horizontal plane creates a data row)
There could be a single data cell (i.e. a single column table) or multiple data cells (i.e.
a multi-column table)
Data cells hold data that must be displayed in the table. A data row is defined using
<TR> </TR> tags. Text matter displayed in a data row is left-justified by default. Any
special formatting like boldface or italics is done by including appropriate formatting
tags inside the <TR> </TR> tags. An image can also be displayed in a data cell.

The attributes that can be included in the <TABLE> tag are:


Horizontal alignment is controlled by the ALIGN attribute. It can
ALIGN be set to LEFT, CENTER, or RIGHT.
Controls the vertical alignment of cell contents. It accepts the
VALIGN
values TOP, MIDDLE or BOTTOM.
Sets the WIDTH to a specific number of pixels or to a percentage
WIDTH of the available screen width. If width is not specified, the data
cell is adjusted based on the cell data value.
Controls the border to be placed around the table. The border
BORDER thickness is specified in pixels.
controls the distance between the data in a cell and the boundaries
CELLPADDING of the cell.

CELLSPACING Controls the spacing between adjacent cells.


The COLSPAN attribute inside a <TH> or <TD> tag instructs
the browser to make the cell defined by the tag to take up more
than one column. The COLSPAN attribute can be set equal to
COLSPAN
the number of columns the cell is to occupy. This attribute is
useful when one row of the table needs to be a certain number
of columns wide.
The ROWSPAN attribute works in the same way as the COLSPAN
attribute except that it allows a cell to take up more than one row.
ROWSPAN The attribute can be set by giving a numeric value. For example
ROWSPAN = 3

134 Computer Science : Grade 9


The Caption Tag
Often tables need to be given a heading, which gives the reader a context for the
information in the tables. Table Headings are called Captions. Captions can be provided
to a table by using the <CAPTION> </CAPTION> tags. The paired tag appears within
the <TABLE> </TABLE> tags. The table caption can be made to appear above or below
the table structure with the help of the attribute ALIGN, as explained in thetable below.
ALING It controls placing of the caption with respect to the table.
ALIGN = BOTTOM will place the caption immediately below the table.
ALIGN=TOP will place the caption immediately above the table.

Bypassing a rows <TR> tag the VALIGN and ALIGN attributes, vertical or the horizontal
alignment can be made identical for every cell in a given row.

Bypassing the <TH> and/or <TD> tags, VALIGN or ALIGN attributes, vertical or
horizontal alignments in both header and data cells can be done. Any alignment specified
at the cell level overrides any default alignments and any alignments specified in a
<TR> tag.

Note:
 Alignments specified in <TD> or <TH> apply only to the cell being defined.
 Alignments specified in a <TR> tag apply to all cells in a row, unless overridden
by an alignment specification in a <TD> or <TH> tag.
Using the WIDTH and BORDER attribute
Example 13:
<HTML>
<HEAD>
<TITLE> Table Attributes </TITLE>
</HEAD>
<BODY BGCOLOR=LIGHTGREY>
<B> Specifying the BORDER and WIDTH of the Table! </B>
<BR> <BR> <BR> <BR>

Computer Science : Grade 9 135


<CENTER>
<TABLE BORDER=5 WIDTH=50%>
<CAPTION ALING=bottom>
<B> Personal Information </B>
</CAPTION>
<TR>
<TH> NAME </TH>
<TH> AGE </TH>
</TR>
<TR ALIGN = CENTER>
<TD> Suniska Gharti </TD>
<TD> 16 </TD>
</TR>
<TR ALIGN=CENTER>
<TD> Pooja Mital </TD>
<TD>32 </TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>

Note:
 If the WIDTH attribute is associated with the <TH> tag then the width of an
individual column can be adjusted.

136 Computer Science : Grade 9


Using the CELLPADDING attribute
Example 14:
<HTML>
<HEAD>
<TITLE> Working With Table </TITLE>
</HEAD>
<BODY BGCOLOR = LIGHTGREY>
<B> Specifying CELLPADDING! </B> <BR>
<HR>
<I> Without cell padding</I>
<CENTER>
<TABLE BORDER=1 WIDTH=25% ALIGN=CENTER>
<TR>
<TH> NAME </TH>
<TH> AGE </TH>
</TR>
<TR>
<TD> Nisha </TD>
<TD> 15 </TD>
</TR>
<TR>
<TD> Aarambha </TD>
<TD> 12 </TD>
</TR>
</TABLE>
</CENTER>
<HR>
<I>With cell padding of 10 </I>
<CENTER>

Computer Science : Grade 9 137


<TABLE BORDER=1 WIDTH=25% CELLPADDING=10 ALIGN=CENTER>
<TR>
<TH> NAME </TH>
<TH> AGE </TH>
</TR>
<TR>
<TD> Nisha </TD>
<TD> 15 </TD>
</TR>
<TR>
<TD> Aarambha </TD>
<TD> 12 </TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>

Cell padding

Cell padding

138 Computer Science : Grade 9


Using The CELLSPACING attribute
Example 15:
<HTML>
<HEAD>
<TITLE> Working With Table </TITLE>
</HEAD>
<BODY BGCOLOR = LIGHTGREY>
<B> Controlling the space between Adjacent Cells! </B> <BR> <BR>
<HR>
<I> Without cell spacing</I>
<CENTER>
<TABLE BORDER=1 WIDTH=25% ALIGN=CENTER>
<TR>
<TH> NAME </TH>
<TH> AGE </TH>
</TR>

<TR ALIGN = CENTER>


<TD> Sushila </TD>
<TD> 67 </TD>
</TR>

<TR ALIGN=CENTER>
<TD> Bimala </TD>
<TD> 37 </TD>
</TR>
</TABLE>
</CENTER>
Computer Science : Grade 9 139
<HR>
<I>With cell spacing of 10 </I>
<CENTER>
<TABLE BORDER=1 CELLSPACING =10 WIDTH=25% ALIGN=CENTER>
<TR>
<TH> NAME </TH>
<TH> AGE </TH>
</TR>
<TR ALIGN = CENTER>
<TD> Sushila </TD>
<TD> 67 </TD>
</TR>
<TR ALIGN=CENTER>
<TD> Bimala </TD>

<TD> 37 </TD>

</TR>

</TABLE>

</CENTER>

</BODY>

</HTML>

140 Computer Science : Grade 9


Cell spacing
Using the BGCOLOR attribute
Example 16:
<HTML>
<HEAD>
<TITLE> Working With Table </TITLE>
</HEAD>
<BODY BGCOLOR=LIGHTGREY>
<B> Specifying Color red Table Cells! </B> <BR> <BR> <BR> <BR>
<CENTER>
<TABLE BORDER = 1WIDTH = 50% ALIGN = CENTER>
<TR>
<TH Bgcolor = Gray> NAME </TH>
<TH Bgcolor = Gray> AGE </TH>
</TR>
<TR ALIGN = CENTER>
<TD Bgcolor = black> <FONT Color = white> Aarambha Gharti </FONT>
Computer Science : Grade 9 141
</TD>
<TD Bgcolor = violet> <FONT Colo r= RED> 4 </FONT> </TD>
</TR>
<TR ALIGN = CENTER>
<TD Bgcolor = blue> <FONT Color = white> Suniska Gharti </FONT>
</TD>
<TD Bgcolor = red> <FONT Color = blue> 8 </FONT> </TD>
</TR>
<CAPTION ALIGN=bottom> <B> <BR>
Personal Information </B>
</CAPTION>
</TABLE>
</CENTER>
</BODY>
</HTML>

142 Computer Science : Grade 9


Using the COLSPAN AND ROWSPAN attributes.
Example 17:
<HTML>
<HEAD>
<TITLE> Working With Table </TITLE>
</HEAD>
<BODY BGCOLOR=LIGHTGREY>
<B> Specifying ROWSPAN and COLSPAN Attributes! </B>
<BR> <BR> <BR> <BR>
<CENTER>
<TABLE BORDER=1 WIDTH=50% ALIGN=CENTER>
<TR>
<TH ROWSPAN = 2> NAME
<TH COLSPAN = 3> MARKS
</TR>
<TR>
<TH> UNIX O/S
<TH> ASP.NET
<TH> SQL Server
</TR>
<TR ALIGN=CENTER>
<TD>Deepak
<TD>85
<TD>80
<TD>72
</TR>
<TR ALIGN=CENTER>
<TD> Rashmi
Computer Science : Grade 9 143
<TD> 82
<TD> 78
<TD> 81
</TR>
<CAPTION ALIGN = bottom> <B> <BR> Mark Sheet </B> </CAPTION>
</TABLE>
</CENTER>
</BODY>
</HTML>
Rowspan Colspan

Rowspan and Colspan

3.2.7 Working with Forms in HTML


HTML forms are basic for web Client-Server capabilities. Forms are the client-side GUI
applications. To create a form, use the <FORM> tag. Inside the opening and closing
FORM tags, individual form elements plus any other HTML content are used to create
a layout for the form (paragraphs, headings, tables, and so on). As many forms on a
page can be used but you can’t include a <FORM> tag inside another <FORM> tag.

The opening tag of the FORM tag includes attributes namely name, method and action.

144 Computer Science : Grade 9


Name is used for defining the name of the form. The method attribute can be either GET
or POST, which determines how the form data is being sent to the server. The action
attribute is a pointer to the script that processes the form on the server-side.

Different types of form elements included in the <FORM> are text boxes, radio buttons,
checkboxes, drop-down boxes, multiline, scrollable text areas and password boxes.

Each of the form element will be placed inside a <FORM>… </FORM> tag.

Elements of HTML Form


a. Text Fields
Text fields enable the client to type text into a single-line field. To create a text field, you
can either use TYPE=“TEXT” in the <INPUT> tag or leave off the TYPE specification
altogether. The default TYPE for the <INPUT> tag is “text”.

NAME indicates the name of this field as passes to the script processing the form.

SIZE indicates the length of the text-entry field, in characters; the field is 20 characters
by default.

Example 18:
<form >
User Name : <Input type= "text" Name= "userName" >
<br><br>
Password :&nbsp;&nbsp;&nbsp; <Input type= "password" Name= "passwd" >
</form>

User Name :
Text box
Password :

Note: <input type = “password”> password text fields are identical to ordinary text
fields, except that all the character types are echoed back in the browser as asterisks or
bullets. Here &nbsp is used for one space

Computer Science : Grade 9 145


b. Text Area
Text areas are input fields that contain many lines of text, making them extremely useful
for forms that require extensive input. For example, if you want to create a form that
enables readers to compose electronic mail, you might use a text area for the body of
the message.

To include a text are element in a form, use the <Textarea> … </Textarea>.

<TextArea> includes three attributes:


NAME The name to be sent when the form is submitted
ROWS The height of the text area element, in rows of text
COLS The width of the text area element in columns (characters)

<Textarea Name= “theBody” Rows= “7” Cols = “30”> Enter your message here
</textarea>
Example 19:
<form>
New Message : <br>
<textarea rows= "5" cols= "50" name= "details">
Compose Your Mail Here...
</textarea>
</form>

c. Radio Button
Radio buttons indicate a list of items, of which only one can be chosen. If one radio
button in a list is selected, all the other radio buttons in the same list are deselected.

146 Computer Science : Grade 9


Example 20:
<INPUT TYPE= “RADIO” NAME = “r1” VALUE = “MALE”>Male
<INPUT TYPE= “RADIO” NAME = “r1” VLAUE = “FEMALE”>Female

Radio buttons

d. Checkbox
Checkboxes makes it possible to choose multiple items in a list. Each checkbox can be
either checked or unchecked.

Example 21:
<Input Type= “checkbox” Name= “Red”> Red
<Input Type= “checkbox” Name = “Green”> Green
<Input Type = “checkbox” Name = “Blue”> Blue
e. Select box
Select has the ability to create pull-down menus and scrolling lists. Selection enables to
select one or more items for a menu on a scrolling list. They’re similar in functionality
to radio buttons or checkboxes, but they’re displayed in a different way on-screen. The
<select> tag and individual options within the selection indicated by the <option> tag
are used for creating such elements.

Example 22:
<HTML>
<HEAD>
<TITLE> Working With Select box </TITLE>
</HEAD>
<BODY BGCOLOR="#aabbcc">
<form>
<P> <b> Select a Country:</b>

Computer Science : Grade 9 147


<Select Name= "Scount">
<option value= "Nepal" selected> Nepal </option>
<option value="Afghanistan"> Afghanistan </option>
<option value= "Bangladesh"> Bangladesh </option>
<option value= "Bhutan"> Bhutan </option>
<option value= "India"> India </option>
<option value= "Maldives"> Maldives </option>
<option value= "Pakistan"> Pakistan </option>
<option value= "Srilanka"> Srilanka </option>
</select> </P>
<b> Select a Capital:</b>
<Select Name= "Capital">
<option value= "Kathmandu" selected> Kathmandu </option>
<Option Value= "Kabul"> Kabul
<Option Value= "Dhaka"> Dhaka
<Option Value = "Thimphu"> Thimphu
<Option Value = "NewDelhi"> New Delhi
<Option Value = "Male"> Male
<option Value = "Islamabad"> Islamabad
<option Valu = "Colombo"> Colombo
</Select> </P>
</form>
</HTML>

148 Computer Science : Grade 9


Select box
f. Submit Button
Submit buttons tell the browsers to send the form data to the server. You should include
at least one submit button on every form.
<input type = “Submit” value= “Submit”>

g. Reset Button
The Reset button is used for renewing the elements of the form. It allows the client to
fill new entries by clicking on the reset button.
<input type = “reset” value = “reset”>

Example 24:
<form>
<input type= "submit" name= "submit" value= "Submit">
<input type= "reset" name= "reset" value= "Reset">
</form>

Computer Science : Grade 9 149


HTML Form
Example 25:
<html>
<head>
<title> Form </title>
</head>
<body bgcolor="#aabbcc">
<h1> Please fill up the below form:</h1>
<form >
Enter your Full Name: <input type="text" size="40" maxlength="256" name="user_
name"> <br> <br>
Enter your password: &nbsp;<input type="password" size="40" maxlength="256"
name="user_password"> <br> <br>
Enter your Address: <br> <textarea name="user_comment" rows="5" cols="40">Type
Your Full Address Here</textarea> <br> <br>
Your Favourite Places: <br>
<input type="radio" name="place1" value="kathmandu"> Kathmandu
<input type="radio" name="place2" value="manang"> Manang
<input type="radio" name="place3" value="pokhara"> Pokhara
<input type="radio" name="place4" value="umustang"> Upper Mustang
<input type="radio" name="place5" value="Rara"> Rara Lake
<input type="radio" name="place6" value="Muktinath"> Muktinath
<input type="radio" name="place7" checked value="PoonHill"> Poon Hill
<input type="radio" name="place8" value="CNpark"> Chitwan National Park
<input type="radio" name="place9" value="Jdham"> Janakpur Dham
<br> <br>

150 Computer Science : Grade 9


Your Favourite Food:<br>
<select name="food" size="1">
<option value="rice"> Daal Bhat Tarkari </option>
<option value="Momo" selected> Momo </option>
<option value="Dheedo"> Dheedo </option>
<option value="AlooTama"> Aloo Tama </option>
<option value="Chatamari"> Chatamari </option>
<option value="Naan"> Naan </option>
<option value="Chapatti"> Chapatti </option>
</select> <br> <br>
Language you speak: <br>
<input type= "checkbox" name= "language" checked value= "Nepail">Nepali
<input type= "checkbox" name= "language" value ="Maithili"> Maithili
<input type= "checkbox" name= "language" value="bhojpuri"> Bhojpuri
<input type= "checkbox" name= "language" value="Tharu"> Tharu
<input type= "checkbox" name= "language" value="Newari"> Nepal Bhasa
<input type= "checkbox" name= "language" value="Magar"> Magar
<br> <br>
Your Favourite Animals:<br>
<select name="animals" size="6" multiple>
<option value="buffalo">Buffalo
<option value="cat">Cat
<option value="dog">Dog
<option value="goat">Goat
<option value="horse">Horse

Computer Science : Grade 9 151


<option value="ox">Ox
<option value="pig">Pig
<option value="sheep">Sheep
<option value="Yak">Yak
</select> <br> <br>
<input type="submit" name="Submit">
<input type="reset" name="reset" value="Reset">
</form>
</body>
</html>

152 Computer Science : Grade 9


SAMPLE PROJECT for Online Registration Form:
<html>
<head>
<title> Sample Project </title>
</head>
<body bgcolor="#FFFFFF">
<form action="" method="post" enctype="multipart/form-data"
name="form1" id="form1">
<table width="600" border="1" align="center" cellpadding="4"
cellspacing="1">
<tr>
<td colspan="2"><h1> <font color="#00CC00">Online Registration
Form!</font></h1></td>
</tr>
<tr>
<td colspan="2" bgcolor="#999999"><b>Registration Form</b></td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="fname" id="fname" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname" id="lname" /></td>
</tr>
<tr>
<td>Occupation</td>
Computer Science : Grade 9 153
<td><select name="select" id="select">
<option value="Student">Student</option>
<option value="Web Designer">Web Designer</option>
<option value="Software Developer">Software Developer</option>
<option value="Others">Others</option>
</select> </td>
</tr>
<tr>
<td>Gender </td>
<td><input type="radio" name="gender" id="radio" value="Male" />
Male
<input type="radio" name="gender" id="radio2" value="Female" />
Female</td>
</tr>
<tr>
<td>Education</td>
<td><input name="chk1" type="checkbox" id="chk1" value="High
School" />
High School
<input name="chk2" type="checkbox" id="chk2" value="Graduate" />
Graduate
<input name="chk3" type="checkbox" id="chk3" value="Some
College"/>
Some College</td>
</tr>
<tr>
<td>Upload Your Photo</td>
154 Computer Science : Grade 9
<td><input type="file" name="fileField" id="fileField" /></td>
</tr>
<tr>
<td valign="top">Write about yourself <br/> (not more then 200
words)</td>
<td><textarea name="textarea" id="textarea" cols="50" rows="10"></
textarea></td>
</tr>
<tr>
<td colspan="2" valign="top" bgcolor="#999999"><strong>Login
Information </strong>
</td>
</tr>
<tr>
<td valign="top">Username</td>
<td><input name="username" type="text" id="username"
maxlength="10"/> (Max 10 characters)</td>
</tr>
<tr>
<td valign="top">Password</td>
<td><input name="textfield" type="password" id="textfield"
maxlength="12" /> (Max 12 characters)</td>
</tr>
<tr>
<td valign="top">&nbsp;</td>
<td><input type="submit" name="submit" id="submit" value="Submit"/>
<input type="reset" name="reset" id="reset" value="Reset" /></td>
</tr>
Computer Science : Grade 9 155
<tr>
<td colspan="2" valign="top">&copy; Copyright Vist Nepal 2020</td>
</tr>
</table>
</form>
</body>
</html>
Output:

156 Computer Science : Grade 9


Unit 3.3
Cascading Style Sheets (CSS)

Dynamic Hypertext Markup Language (DHTML)


DHTML is a new and emerging technology that has evolved to meet the increasing
demand for eye-catching web sites. DHTML combines HTML with Cascading Style
Sheets (CSSs) and scripting Languages. HTML specifies a web page’s elements like
table, frame, paragraph, bulleted list, etc. Scripting Language (JavaScript and VBScript)
can be used to manipulate the web page’s elements so that styles assigned to them can
change in response to a user’s input.

3.3 Cascading Style Sheets


We already know that an HTML document can contain text, hyperlinks, images, and
other multimedia content within HTML elements or tags. These contents are essentials
of web pages. In order to style these HTML, we need a separate language called CSS.
For example, you can define colour, font, and size of paragraph tag as follows:

<p style=“color: #ff0000; font-weight: bold”> Some text that is red and bold </p>

CSS in itself has no meaning unless it is associated with HTML elements or tags. CSS
is defined as a rule of styles associated with a certain element or set of elements of a
HTML document.

According to W3C, “CSS is the language for describing the presentation of Web pages,
including colours, layout, and fonts. It also allows adapting the presentation to different
types of devices, such as large screens, small screens, or printers.”

As said in the definition, CSS can be defined in such a way that it can change layout,
colors, fonts or any other styles based on the size of the screen (PC Screen, tablet screen
and mobile screen) or for printers. In a desktop computer, screen size is large whereas
in mobile screen size is small and accordingly HTML content should be presented to
webpage viewers. CSS is used to define this type of presentation. If a viewer is trying
to print a web page, the presentation of the page can be made different using CSS to
make it printer-friendly.

Computer Science : Grade 9 157


The Style Assignment Process is accomplished with the <STYLE>…</STYLE> tags.
The syntax for making the assignment is simple. Between the <STYLE> <STYLE>
HTML tags, specific style attributes are listed. The <STYLE> </STYLE> tags are
written within the <HEAD>…</HEAD> tags.

CSS Syntax:
<STYLE Type = “text/css”>
Tag {attribute:value; attribute:value…}



</STYLE>

Attribute: Font, Color, Background, Text, Boarder, Margin and List

A CSS rule is formed from:


 A set of properties, which have values set to update how the HTML content is
displayed, For example, I want my element's text color as white, and its background
to be grey.
 A selector, which selects the element(s) you want to apply the updated property
values to. For example, I want to apply my CSS rule to all the paragraphs in my
HTML document.
 A set of CSS rules contained within a stylesheet determines how a webpage should
look.
Let's make things clear by a quick example. First of all, let's take a simple HTML
document, containing an <h1> and a <p>

Example 1:
<!DOCTYPE html>
<html>
<head>
<title>My First CSS Try</title>
158 Computer Science : Grade 9
<style>
h1{
color: blue;
background-color: yellow;
border: 1px solid black;
}
p{
color: red;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>This is my first CSS example </p>
</body>
</html>

CSS Properties
At its most basic level, CSS consists of two building blocks:

Properties: Human-readable identifiers that indicate which stylistic features (e.g. font,
width, background color) you want to change.

Values: Each specified property is given a value, which indicates how you want
to change those stylistic features (e.g. what you want to change the font, width or

Computer Science : Grade 9 159


background color to.)

A property paired with value is called a CSS declaration. CSS declarations are put
within CSS Declaration Blocks. And finally, CSS declaration blocks are paired with
selectors to produce CSS Rulesets (or CSS Rules). Each property has a specific list of
valid values defined for it.

Selectors
In CSS, selectors are used to target the HTML elements on our web pages that we want to
style. Selectors are one part of a CSS rule and come just before CSS declaration blocks.

There are many different types of selectors. For our purpose, we will only introduce
simple selectors that directly match one or more elements of a document, based on the
type of element, class, or id.

160 Computer Science : Grade 9


3.3.1 CSS
There are three different ways to apply CSS to an HTML document. Here we'll briefly
review each one.

i. Inline CSS
ii. Internal CSS
iii. External CSS

i. Inline styles
Inline styles are CSS declarations that affect only one element, contained within a style
attribute:

Example 2:
<!DOCTYPE html>
<html>
<head>
<title>My CSS experiment</title>
</head>
<body>
<h1 style="color: blue;background-color: yellow;border: 1px solid black;">
Good Morning Class!
</h1>
<p style="color:red;">This is my first CSS example of Inline styles </p>
</body>
</html>

ii. Internal stylesheet


An internal stylesheet is where you don't have an external CSS file, but instead place
your CSS inside a <style> element, contained inside the HTML <head> …</head> tag.
So the HTML would look like this:
Computer Science : Grade 9 161
Example 3:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My First CSS Try Page </title>
<style>
h1 {
color: blue;
background-color: yellow;
border: 1px solid black;
}
p{
color: red;
}
</style>
</head>
<body>
<h1> Hello World! </h1>
<p>This is my first CSS example of Internal stylesheet.</p>
</body>
</html>

iii. External stylesheet


An external stylesheet is when you have your CSS written in a separate file with a .css
extension, and you reference it from an HTML <LINK> tag. The HTML file looks
something like this:
162 Computer Science : Grade 9
Example 4:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> My experiment with External Stylesheet </title>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1> Visit Nepal 2020! </h1>
<p> The year 2020 has been announced as Tourism Year for Nepal and
to make Visit Nepal 2020 successful, let every Nepali unite and promote
the beauty of Nepal GoVisit Nepal, Travel, hiking trails, tourist, Tourism
Week. </p>
</body>
</html>

And (create a new file) code for mystyle.css file:


h1{
color: blue;
background-color: gold;
border: 1px solid black;
}
p{
font-size:14pt;font-weight:bold;text-align:justify;color:red;
}

Computer Science : Grade 9 163


i. Common CSS properties reference
Property Values Used with Elements
#RRGGBB (Red, Green, Blue any element that contains
color
hex values) text
block elements h1..h6, p,
text-align left | right | center | justify
li, etc.
none | underline | overline | line- mostly with a (anchor)
text-decoration
through | blink | inherit elements
none | capitalize | uppercase | any element that contains
text-transformation
lowercase text
block elements h1..h6, p,
line-height % or px
li, etc.
any element that contains
letter-spacing normal or px value
text
font or font-family [, font or any element that contains
font-family
font-family ...] text
any element that contains
font-size px or em value
text
any element that contains
font-style normal | italic | oblique
text
any element that contains
font-weight normal | bold
text
#RRGGBB (Red, Green, Blue any element with a
background-color
hex values) background
background-image url("[image url]") mostly with body
repeat | repeat-x | repeat-y |
background-repeat mostly with body
no-repeat
left | center | right | top | center |
background-position mostly with body
bottom
list-style-type disc | square | circle ul

164 Computer Science : Grade 9


list-style-type decimal | lower-roman | upper- ol
roman | lower-alpha | upper-alpha

ii. CSS Box Model


There are several properties in CSS that are often grouped together as box properties
which control the way browsers layout the page using the CSS box model.

These properties might not be immediately intuitive but aren't too difficult. Suppose
we have an element on the page (like a <h2> Element Contents </h2>). Here are the
parts of its “box” when drawn:

So, here is CSS code:


h2{
padding: 1em;
border: medium dashed black;
background-color: grey;
}
will make the <h2> have a grey background, with 1 em of space between the
text and the border. The space inside the border (even if it's invisible because you
don't have one) is covered with the background colour and is controlled by the
padding properties.

Computer Science : Grade 9 165


If we want more space separating this element (and its border) from the stuff
around it, we would have to increase the margin values. It's easy to mistake margin
and padding, especially when there is no border or background colour. If you
are trying to change the space around an element (especially when the browser's
default CSS has some space there), try setting both margin and padding to zero
and work from there.

ul{

margin: 0em;

padding: 0em;

iii. CSS measurement units


You probably noticed the measurement 1em above. The em is a unit of (length)
measurement in CSS. Here are some common units that need a little explanation:

em - The current font size: if the current text is 12 point then this will be 12 points.
Another unit, an ex is half the text size.

px - One screen pixel (dot) on the display. (Note: for some very high-resolution devices,
real “pixels” are very small, so this length is adjusted to be close to the size of a pixel
on a traditional display.)

mm - A millimeter. There are also units for centimeter, inch, etc. (Note: this is the
browsers best guess, but might be inaccurate depending on the scaling of the display/
projector/phone/etc. For example if you display your screen on a projector, the
“millimeter” suddenly becomes much larger.)

166 Computer Science : Grade 9


p{
line-height: 1.5em;
}
blockquote{
margin-left: 2em;
border-left: 0.25em solid black;
}
#logoimg{
width: 120px;
height: 160px;
float: left;
margin-left: 1em;
}

Example 5:
Here is an example page that we can style with some of the properties above:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> CSS Properties </title>
<link rel="stylesheet" href="css-prop.css" />
</head>
<body>
<h1> CSS Properties </h1>

Computer Science : Grade 9 167


<h2> Goals </h2>
<p> This is a page that we're using to demonstrate various CSS properties
and techniques. Because of that, it's probably going to be ugly. </p>
<h2> Results </h2>
<p> Yes, it's turning out rather ugly, but it's important to demonstrate some
CSS stuff. Here are some of the new things: </p>
<ul>
<li> more CSS properties </li>
<li> the box model </li>
<li> the units of length used </li>
</ul>
</body>
</html>

and a CSS to go with it:


body{
font-family: "Helvetica", sans-serif;
}
h1{
text-align: center;
font-weight: bold;
background-color: silver;
color: teal;
padding: 0.25em;
}
h2{

168 Computer Science : Grade 9


border: medium dotted teal;
font-weight: normal;
padding: 0.1em;
}
Try experimenting with CSS on this page (or one you have created).

Exercises
1. State whether the following statements are True or False.
a. HTML is a high-level programming language.
b. HTML supports 6 different levels of headings.
c. The first page of the website is known as the homepage.
d. HTML tags are of two types:
 Paired Tags
 Singular Tags
e. SIZE can take values between 1 and 7.
f. .gif files are specified with BGCOLOR attribute.
g. The tag used for inserting spaces in the HTML document is <MARKER>.
h. Ordered lists are used for the bullet.
i. START alters the numbering sequence in the middle of an ordered list.
j. HTML allows only static text to be displayed on the page.
k. “ALIGN=LEFT” indicates the image is aligned to the left with respect to
the screen.
l. SRC takes the name of an image file to be displayed as a parameter.
m. HTML allows linking to other HTML documents as well as images.
n. The vertical or the horizontal alignment for every cell in a given row is

Computer Science : Grade 9 169


controlled by using the VALIGN and ALIGN attributes in the row’s <TR>
tag.
o. A table header row is defined with the <TD> and </TD> tag pair.
p. CELLSPACING controls the distance between the data in a cell and the
boundaries of the cell.
q. ALIGN=TOP will place the caption immediately above the table.
r. Anchors target links to the beginning of the document.
s. A filename always has to be mentioned before the # symbol in the HREF
attribute of a link.

2. Answer the following questions.


a) What is Hypertext Markup Language?
b) Name the commonly used web browsers for viewing the HTML pages.
c) What is an attribute?
d) Differentiate between the paired tag and singular tag with examples.
e) How is the FONT tag used? What are its attributes?
f) Name the tags for breaking paragraph and line.
g) What are the different types of lists used in HTML?
h) What is a hyperlink?
i) What is the use of intra page links? Illustrate with examples.
j) Is it possible to give a background to the web page? If yes, then how?
k) What are the main tags used in <TABLE> tag?
l) What are the different input types?
m) What is CSS?
n) What are the advantages of using CSS?
o) What are the components of a CSS Style?
170 Computer Science : Grade 9
3. Chose the correct answer.
a. What does HTML stand for?
i. Hyperlinks and Text Markup Language
ii. Hypertext Markup Language
iii. Home Tool Markup Language
b. The correct HTML tag for the largest heading is -------
i. <h1> ii. <head> iii. <heading> iv. <h6>
c. What is the correct HTML tag for inserting a line break?
i. <br> ii. <lb> iii. <break>
d. What is the correct HTML for adding a background color?
i. <body bgcolor="yellow"> ii. <background> yellow </background>
iii. <body color="yellow">
e. The correct HTML tag to make a text bold is -------
i. <bb> ii. <bold> iii. <b> iv. <bld>
f. The correct HTML tag to make a text italic is -------
i. <i> ii. <ii> iii. <italics>
g. What is the correct HTML for making a hyperlink?
i. <a url="http://WWW.w3schools.com"> W3Schools.com </a>
ii. <a href="http://WWW.w3schools.com"> W3Schools </a>
iii. <a name="http://WWW.w3schools.com"> W3Schools.com </a>
iv. <a>http://WWW.w3schools.com </a>
h. How can you make an e-mail link?
i. <mail> xxx@yyy </mail> ii. <a href="mailto:xxx@yyy">
iii. <mail href="xxx@yyy"> iv. <a href="xxx@yyy">
i. How can you open a link in a new browser window?
i. <a href="url" target="_blank"> ii. <a href="url" target="new">
iii. <a href="url" new>

Computer Science : Grade 9 171


j. Which is NOT the attribute of <BODY> tag?
a. Background b. Text c. Color d. Link
k. CSS stands for -----------
(i) Creative Style Sheets (ii) Colorful Style Sheets
(iii) Cascading Style Sheets (iv) Computer Style Sheets
l. Which of the following CSS tag is used for creating External style sheet?
(i) <style src="mystyle.css">
(ii) <stylesheet>mystyle.css</stylesheet>
(iii) <link rel= stylesheet href= “stylesheet file name”>

4. Write the purposes and syntaxes of the following HTML tags.


a) <P> b) <SUB> c) <HR> d) <A>
e) <TABLE> f) <IMG> g) <CENTER> h) <STRONG>
i) <IMG> j) <U> k) <UL> l) <B>

Activities
1. Design a web page having the following specifications.
• The italic tag

• The center tag

• The Paragraph tag

• The Break tag

• The font tag and its attributes

2. Design a web page using the image files according to the following
specifications.
• Use a Border for Image

• Resize the Width and Height of the image to 100 pixels each.

172 Computer Science : Grade 9


3. Create a Web page using HTML and CSS giving the following flight
details.
• Airlines Name

• Departure Airport

• Destination

• Arrival and Departure time

• Fare

Use a caption saying “Time Table and Fare List”.


Time
Airlines Departure
Destination Arrival Departure Fare
Name Airport
Singapore Tri. Int. Airport Singapore 14:45 19:15 Rs.60,000
Airlines Changi
Airport
-------- ---------- ----------- ------- --------- ----------
-------- ---------- ----------- ------- --------- ----------

4. Design website for your school having the following pages using HTML,
CSS and Photoshop.
Home News & Events
About Us Calendar
Teacher Parents
Activities
Contact US
Photo Gallery

Computer Science : Grade 9 173


Unit 4.1
Computer Programming

4.1 General Concept


(a) Program and programming
Computer Program
A computer program is a set of instructions given to the computer to perform a particular
task. It is written in a programming language such as QBASIC, C, C++ etc. given by
the users that are translated into machine level language to obtain the desired result.

Computer Programming
Computer programming is the process of designing, writing, testing, debugging, and
maintaining the source code written in a particular computer language.

Programmer
A programmer is a person who is involved in the different processes of computer
programming.

(b) Programming Language


It is a coded or artificial language used to write instructions that a computer can
understand to do what the user wants.

A programming language is therefore a practical way for us (humans) to give instructions


to a computer.

Types of programming language


i) Machine Language
Machine language is the most basic (also called low-level) computer language. It is
directly understood by the computer as it uses binary ('1' and '0') code which a computer
can run (execute) very fast without using any language translator. But it is very difficult
to program using machine language.

174 Computer Science : Grade 9


Advantages of Machine Language
 It is directly understood by computer. So, no translator is required.
 Programs written using machine language runs fast.
Disadvantages of Machine Language
 It is very difficult to write a program in machine language because the programmer
has to know all the details of the hardware.
It is difficult to debug the program.

ii) Assembly Language


Machine language is difficult to write programs as it requires knowing the details of
hardware. Assembly language was developed to make computer programming easier.
It uses letters and numbers (mnemonic codes) for instructions. It is second generation
language.

Fig. Assembly Language

Computer Science : Grade 9 175


Advantages of Assembly Language
 It is easier to program than machine language.
 It is easier to correct errors.
Disadvantages
 It requires translator (assembler) so it is little slow in execution.
It is machine-dependent. It means a program written for one machine might not run in
other machines.

iii) High-Level Language


It is a third-generation programming language
written in simple English with some mathematical
notations such as +,% etc. It requires a language
translator. QBASIC is one of the examples of high-
level language.

Advantage of High-Level Language


 It is easy to learn and use.
 It is machine-independent.
Disadvantages of High-Level Language.
It requires a language translator. So, program execution takes more time.

(c) Language processor


Language processor is a program that performs tasks, such as translating and interpreting,
required for processing a specified programming language.

Assembler
Translates the program written in assembly language into machine language and vice
versa.

Compiler
Translates the whole program into machine language at once.

176 Computer Science : Grade 9


Interpreter
Translates one statement at a time.

Note:- Computer languages themselves are language processor. We don’t require


any other software/application as a language processor. For eg. C is a compiler and
QBASIC is an Interpreter.

Differences between compiler and interpreter


 A compiler converts the high-level instruction into machine language while an
interpreter converts the high-level instruction into an intermediate form.
 Before execution, entire program is executed by the compiler whereas after
translating the first line, an interpreter then executes it and so on.
 List of errors is displayed by the compiler after the compilation process while an
interpreter stops translating after the first error.
 An independent executable file is created by the compiler whereas interpreter is
required by an interpreted program each time.

High Level Language Language Processor Machine Code

(d) Software Development Cycle


Application software development is the process of creating such software which
satisfies the end user’s requirements and needs. The process of developing the application
software is called the Software Development Life Cycle (SDLC).

Computer Science : Grade 9 177


Problem Definition

Maintenance System Analysis

System
Development
System Evaluation System Design
Life Cycle
(SDLC)

Implementation Coding

System Testing

SDLC consists of mainly the following steps


i) Problem Definition
It involves the following tasks
 Defining the current problem
 Specifying the objectives of the program
 Establishing the system boundaries
 Input & output requirements

ii) System Analysis


In this phase, main activities included
 Understanding the problem
 Feasibility analysis or study
 System requirements
178 Computer Science : Grade 9
iii) System Design
This phase consists of designing a solution of the problem identified in the previous
stages using different design tools such as Algorithm, Flowchart, Pseudo Code, Decision
Table, Decision Tree, Data Flow Diagram (DFD), Entity-Relationship (ER) Diagram etc.

iv) System Development (Coding)


At this stage, the final program specification and the file design prepared in the
previous phase is handed over to the programmer. The programmer will then translate
the specification in a programming language. Executable programs are the outputs of
this stage.

v) System Testing
Testing is a process of executing a program with the intent of finding an error and fixing
them. There are two types of errors (bugs) – syntax errors and logical errors.

A syntax error is a violation of the rules of the programming language whereas the logic
error has occurred when the programmer has used an incorrect calculation.

Testing is primarily divided into two types White Box Testing and Black Box Testing.

vi) System Implementation


In this phase, the system or application is installed and used in day to day activities of
the organization.

vii) System Evaluation


The newly implemented system will be evaluated at this stage that helps developers and
users to analyze and highlight the major strong and weak part of the system.

viii) System Maintenance


After the program has been fully tested and has become operational, it typically will
require maintenance to modify or update the system.

Computer Science : Grade 9 179


(e) Algorithm and Flowchart
Algorithm and Flowchart are the system design tools which are used to solve different
problems before coding.

Pseudocode:
Pseudocode is the method in which we begin to write the step necessary to accomplish
the task with short English statements. These codes are not ready to be used because
they are not standardized as an algorithm.

Example:
Pseudocode to calculate the sum of any two numbers

Start Program
Enter two numbers, A, B
Add the numbers together
Print Sum
End Program
Algorithm:
An algorithm is a precise rule (or set of rules) specifying how to solve a specific problem
infinite number of steps. A good algorithm should:

 Be language independent.
 Be simple, complete, unambiguous and step-wise.
 Have no standard format or syntax.
 Be helpful to understand problems.
Example 1:
Algorithm to calculate the sum of any two numbers

Step 1: Start
Step 2: Ask any two numbers and stores into a and b
Step 3: c = a + b
180 Computer Science : Grade 9
Step 4: Display c
Step 4: Stop

Example 2:
Algorithm to find the greater number among any two supplied numbers

Step 1: Start
Step 2: Ask any two numbers and stores into a and b
Step 3: Is a>b?
If yes, display a
If no, display b
Step 4: Check more?
If yes, go to step 2
If no, go to step 4
Step 5: Stop
Flow chart:
A diagram of the sequence of operations in a computer program is called flow chart. It
uses few standard symbols. They are:

S.N. Symbol Name Description


Start/End Symbol
Represents START and END of
1.
the program.
Input/output Symbol
Represents input and output of
2.
data.

Process
Process block. Represents process,
3.
formula or function.

Computer Science : Grade 9 181


Decision
Decision block. Represents any
4.
decision in the program.

Connector
Connector. Used to link to a
5.
segment of the flowchart.

Flow Lines
Flow lines. Used to show the
6.
direction of flow of the program.

Uses/Advantages of Flow chart:


a) An efficient means of communication
b) An analytic tool
c) A concise form of documentation

Example 1:
Flowchart to find the sum of any two supplied numbers

182 Computer Science : Grade 9


Example 2:
Flowchart to find the greater number among any two supplied numbers

Example 3:
Flowchart to display the first 10 natural numbers

Computer Science : Grade 9 183


Summary
 A computer program is a set of instructions given to the computer to perform a
particular task.
 Computer programming is the process of designing, writing, testing, debugging,
and maintaining the source code of computer programs.
 A "programming language" is a coded or artificial language used to write
instructions that a computer can understand to do what the user wants.
 A programmer is a person who is involved in the different processes of computer
programming.
 Language processor is a program that performs tasks, such as translating and
interpreting, required for processing a specified programming language.
 Compiler translates the whole program at once whereas interpreter translates one
statement at a time.
 SDLC consists of different phases: Problem definition, System Analysis, System
Design, Coding, Testing, Implementation, Evaluation and Maintenance.
 An algorithm is a precise rule (or set of rules) specifying how to solve a specific
problem with infinite number of steps.
 A diagram of the sequence of operations in a computer program is called flowchart.
It uses few standard symbols.

Exercises
1. Answer the following questions.
a) Define program and programming.
b) What is a programming language? Explain with its types.
c) What are the language processors?
d) Differentiate between Compiler and Interpreter.
e) What is SDLC? Explain the various phases involved in SDLC.

184 Computer Science : Grade 9


f) What is an algorithm? List the characteristics of algorithm.
g) What is a flowchart? List the common symbols of flowchart with their
function.
h) List the advantages of the flowchart.

2. Write down the algorithms and draw the flowcharts for the following
programs.
a) To calculate the volume of a room
b) To calculate Simple Interest and total amount.
c) To convert the length of your room from cm to meter
d) To check whether the supplied number is odd or even
e) To display the smallest number among any 3 supplied numbers
3. Write down the single word for the following statements.
a) A step of instructions given to the computer to perform a specific task.
b) The process of designing, writing, testing, debugging and maintaining the
source code of computer.
c) Translates the whole program into machine code at once.
d) Computer language is written in simple English with some mathematical
notation.
e) A step-by-step solution to a problem
f) A graphical representation of a solution to a problem.
g) A flowcharting symbol used while taking decisions.

Computer Science : Grade 9 185


Unit 4.2
Programming in QBASIC

4.2 Programming in QBASIC


4.2.1. Introduction
QBASIC (Quick Beginner’s All-purpose Symbolic Instruction Code) is a high-level
programming language developed by Microsoft Corporation in 1985. It is a modular
programming language, where program is divided into different modules or procedure.
QBasic is simple and easy to learn. It uses English like keywords and mathematical
symbols to write a program.

(a) Features of QBasic programming


Some features of QBasic are:

 It is simple and easy to learn.


 It is an interpreter having its own editor.
 It has dynamic program debugging
 It supports the local and global variable.
 It supports modular programming.
 It capitalizes the reserved words automatically.
 The syntaxes of the statements are checked automatically.
(b) QBASIC interface
Starting QBASIC
QBASIC may not be on your computer. At first, you need to have QBASIC in your
computer. It is freely available. You can download it from the Internet as well.

QBASIC
In Windows XP,
 If you are not using QB64, you can download QBASIC from the Internet and
save it in any location inside your computer. For instance, we have saved it in D:
drive with folder name QBASIC.

186 Computer Science : Grade 9


 Go inside the folder D:\
QBASIC and double click on
the file QB.EXE.
 Now, you will see the QBASIC
window where you have to
write QBASIC statements to
make your program.

In Windows 7, 8 or 10
Since the QBASIC is an old
programming language. You cannot
directly open this version of QBASIC like in Windows XP. You need to install an
emulator program like DOSBox.

Use the following steps to run QBASIC using DOSBox.

1. Download DOSBox from https://WWW.dosbox.com/


2. Install DOSBox by simply double-clicking on the installation file.
3. After the installation of DOSBox, its shortcut icon will appear on
the desktop.
4. Open the QBASIC folder and select the file QB.EXE.
5. Drag and drop on the icon of DOSBox on your desktop.

Computer Science : Grade 9 187


6. QBASIC will open inside DOSBox.
Your First Program
Just type the below statements in the above screen.
PRINT “hello world”
END

Running (executing) your program.


Press F5 button of your keyboard. Now, you will see the output screen as below:

This is a sample program to display the words “hello world” on the output screen.

188 Computer Science : Grade 9


Saving your file
 Go to the File menu and click on “Save”.
 Give a suitable file name.
Opening your existing file
 Go to the File menu and click on “Open”.
 Select the required file and click on “Ok”.
Getting Out
If you need to leave QBASIC, you can click on "File" on

QBASIC's menu and then "Exit".

QBASIC Shortcuts
 Press Alt+F, the sub-menus of “File” menu
will be displayed as in the left-side figure.
 You can see several characters in white
colour.
For example:
Press ‘O’ to open an existing file as the
letter ‘O’ is seen in white colour in “Open
Program” sub menu of “File” menu.

Immediate Window
The lower part of the QBASIC editor is called the Immediate window. From this window,
single-line commands and expressions are tested. In Immediate window, as soon as you
press Enter () key, it displays the output on the screen.

Note: To switch between Program window and Immediate window – Press F6 button.

Computer Science : Grade 9 189


Exercises
1. Answer the following questions.
a) Why is QBASIC called high-level programming language?
b) List any four features of QBASIC.
c) Differentiate between Program window and the Immediate window.
d) List the steps of writing and executing a program in QBASIC.

2. List the shortcut keys to do the following tasks.


a) To run the program
b) To switch between the program window and Immediate window
c) To open an existing file
d) To see the help of QBASIC program
e) To exit from QBASIC editor

190 Computer Science : Grade 9


4.2.2 Variables and Constants
(a) Data and Data Type
Data is any value (raw or unprocessed) given to the program for processing.
Basically, QBASIC supports two types of data.
i) String - any alphanumeric values and valid symbols
ii) Numeric - only numbers (0-9)
QBASIC supports further sub-types of numeric data:
Non-floating-point numbers from -32,768 to 32,767
Integer
Examples: -34, 987, 0
Non-floating-point numbers from -2,147,483,648 to 2,147,483,647
Long Integer
Examples: 340035, 7, -24, 0, -127010, 14, 8, -10
Floating-point numbers from -3.37x10^38 to 3.37x10^38 (up to
Single-Precision 7 digits)
Examples: 3.45, 31.4567, -35.23, 0.45, -3.15, 890, -98
Floating-point numbers from -1.67x10^308 to 1.67x10^308 (up
to 15 digits)
Double Precision
Examples:
723661.90226, -128.78, 185321.093423, 2345544, -123456897

Character Set
Characters from the QBASIC character set are combined to form keywords, variables,
operators and labels. They are further combined to form instructions that make up a
program. The QBASIC character set consists of all alphabetic letters (both uppercase
and lowercase), all digits and some special characters having special meaning to the
basic translators.

#, $,!, %,& They are suffixes used at the end of variable names to specify the type
of variable.
+,-,*,/,\ They are mathematical operators.
<,>,= They are relational operators.
(,) They are parenthesis.
: It is used to write multiple statements in a single line.

Computer Science : Grade 9 191


,; They are separators and are used to separate the arguments in input and
output statements.
^ It is exponentiation and is used to raise power to.
? It can be used in place of a PRINT statement.
‘ It is used to mark a line as a comment instead of a REM statement.
. It is a decimal point and is used in numbers.

A character denotes any alphabet, digit or special symbol used to represent information.
The below table shows the valid alphabets, numbers and special symbols supported
by QBASIC.

A,B,C, …., X,Y,Z


Alphabets a,b,c, …., x,y,z
Digits 0,1,2,3,4,5,6,7,8,9
Special Characters , =, +, -, _, *, /, \, ^, %, $, &, !, #, “, ;, ., ‘, ,, ?, <, >

Words
These are mainly the following two types:

Reserved words: Words having a special meaning to QBASIC such as the name of the
statements, library functions etc. are termed as reserved words or keywords.

E.g. Statements PRINT, INPUT, LET, CLS etc are reserved words and should not be
used as the name of the variables or functions.

User-Defined words: These are the words used in statements as variables or user-defined
functions. These variables may have different meanings in different programs.

Example: LET NAME$=”STEVE”

Here, LET is a keyword and is a reserved word while NAME$ is a variable and is a
user-defined word.

(b) Variable
A variable is a small amount of computer memory (RAM) that has been given a name. It
stores the value of a particular data type while the program is being executed. The

192 Computer Science : Grade 9


location of a variable in RAM is called the "address."

Rules for naming variables


i) Each variable name must start with an alphabetic character though it can contain
alphabetic and numeric characters and periods.
ii) The variable name cannot be a BASIC keyword.
iii) Variable names can be up to 40 characters long.
iv) Each variable name is followed by a symbol. The symbol refers to the data type
it might hold.
Few Examples:

Variable Name Valid Invalid Reason


1BC × The first letter is a numeric character
LET × Keyword
Starts with alphabets and $ sign indi-
ABC$  cates the data type string.
BC+ × The invalid symbol is used

(c) Constants
A constant is an entity that doesn’t change, whereas a variable is an entity that may
change.

Example:
a=4
4
a
Since the location whose name is a can hold different values at different times, so a is
known as a variable. As against this, 4 does not change, hence is known as constant.

Types of Constants
Numeric Constant
It has only numbers from 0 to 9. For example: 45,456.35, -44 etc.

Computer Science : Grade 9 193


String Constant
It accepts both numbers and alphabets (alphanumeric values). Examples: “Nepal”,
“45.67”, “A45” etc.

Symbolic Constant
A constant whose value remains the same through the whole program is called a symbolic
constant. In QBASIC, CONST statement is used to declare a symbolic constant.

(d) Variable Declaration


QBASIC supports two types of variable declaration.

i) Implicit Declaration
In this type of declaration, the type of variable is defined as certain special declaration
characters. We use %,&,!,# and $ symbols to declare the variable type implicitly.

Example:
A$=”Nepal”

Here, we use $ symbol after the variable name A, which indicates the type of variable
is string.

INPUT “Type any number “;B%

Here, we use % symbol to declare the variable type integer.

ii) Explicit Declaration


In this type of declaration, we use DIM …AS statement.

DIM variable AS type


It defines the type of variable and we can use the following keywords.

INTEGER, LONG, SINGLE, DOUBLE, and STRING


Example:
DIM A AS STRING, B AS INTEGER
CLS

194 Computer Science : Grade 9


INPUT "Type your name "; A
INPUT "Your roll number "; B
C$ = MID$(A, 1, 1)
PRINT "First character of your name is "; C$
PRINT "Your roll number is "; B
END
Here, in the above program, the declaration characters ($ and %) are not used for the
string-type variable A and integer-type variable B. So, A and B are defined explicitly
using DIM…AS statement and C is defined implicitly.

Data types and variable declaration in QBASIC

Data Type Declaration Byte Length Maximum Minimum


String $ [STRING] 1 byte/char 32,767 chars 0 chars
Integer % [INTEGER] 2 bytes 32,767 -32,768
Long Integer & [LONG] 4 bytes 2,147,483,647 -2,147,483,648
Single
Precision (up ! [SINGLE] 4 bytes ±3.402823 E+38 ±1.401298 E-45
to 7 digits)
Double
±1.7976931
Precision (up # [DOUBLE] 8 bytes ±4.940656 D-324
D+308
to 15 digits)

Computer Science : Grade 9 195


Exercises
1. Answer the following questions:
a) What is QBASIC character set?
b) Differentiate between reserved word and user-defined word.
c) Define constant. List its types.
d) What is a variable? Why is it needed in programming?
e) Mention the rules for naming variables.
f) What are the differences between variable and constant?
g) Define a symbolic constant.
h) List the different types of numeric variables and describe briefly each of
them.
i) What are implicit and explicit declarations of variables? How are they
declared in QBASIC?

2. State whether the following statements are True or False.


a) In QBASIC, any characters can be used for writing programs.
b) The word with special meaning defined already in QBASIC is called user-
defined word.
c) Numeric data should be enclosed in double-quotes.
d) A variable stores data used in a program permanently.
e) A numeric variable can store alphanumeric value.
f) An integer variable can store number with a decimal place.
g) A variable name can be up to 14 characters long.
h) A double-precision variable allocates 8 bytes of memory.
i) The declaration of a variable using special symbols is called an explicit
declaration.
j) Integer variables cannot hold negative values.

196 Computer Science : Grade 9


4.2.3 Operators, expressions and operands
(a) Operators
Operators are the symbols used to represent a particular operation. QBASIC supports
three types of operation: arithmetic, relational and logical operators.

i) Arithmetic Operators
These operators represent arithmetic operations such as addition, subtraction,
multiplication etc.

Operator Operation Example Result


^ (caret) Exponentiation 10^3 1000
/(slash) Division 10/3 3.333333
\(back slash) Integer Division 10\3 3
* (asterisk) Multiplication 10*3 30
+ (plus) Addition 10+3 13
- (minus) Subtraction 10-3 7
MOD Modular Division 10 MOD 3 1

Sequence of operation in BASIC (Hierarchy/Precedence of operation)

The hierarchy of operation in BASIC is commonly called as the PEDMAS rule where;

P Parenthesis ()

E Exponentiation ^

D Division /, \, MOD

M Multiplication *

A Addition +

S Subtraction -

Computer Science : Grade 9 197


 Multiplication and division has the same hierarchy and hence whichever comes
first from left to right has to be dealt first.
 Similarly, addition and subtraction also have the same hierarchy.
 E.g.: In the expression A*B/C; A will be divided by B first after which the
result will be divided by C.
 Similarly, in the expression X-Y+Z, Y will be subtracted by X after which Z will
be added to it.

ii) Relational (Comparison) Operators


Relational operators are used to comparing two values and return either true or false.

Assuming that the values of a and b are 6 and 3 respectively.

Operator Operation Example Result


= Equal to a=b False
< Less than a<b False
> Greater than a>b True
<= Less than or equal to a <= b False
>= Greater than or equal to a >= b True
<> Not equal to a <> b True

iii) Logical Operator


Logical operators are used to combining two or more relational expressions and return
a single value as True or False after evaluating them.

AND Operator
An AND operator returns True (1) at its output only when all of the inputs are high (1).
False (0) is returned when one or more of the inputs are low (0).

OR Operator
An OR operator returns True (1) at its output when one or more of its inputs are high
(1). False (0) is returned only when all of the inputs are low (0).
198 Computer Science : Grade 9
NOT Operator
The NOT operator (Inverter) performs the logic function called inversion or
complementation. If the input signal is low then the high output signal is obtained and
vice versa.

iv) String Operator


+(plus) → Concatenation

Concatenation is the process of joining two string expressions.

A$ = “Visit”
The value of C$ is:
B$= “Nepal”
VisitNepal
C$=A$+B$

(b) Expressions
An expression is a set of variables and constants having a definite value (operands) in
which various mathematical operators are used to show the relationship between the
variables and constants.

Example:

a+b)^2-2*a*b
X$=MID$(A$,N,1)
Types of expression
Algebraic Expression
The expressions that are used in mathematical and other fields are called Algebraic
expression.

Example: S = ut + at2

QBASIC Expression:
The expressions that can be used in QBASIC programs are called QBASIC expressions.

Example: S = u*t + (a*t^2)/2

Computer Science : Grade 9 199


Boolean Expression
Any expression that yields true or false value (0 or 1) is known as a Boolean expression.
The conditions we check in the programs are Boolean expression.

Example: a >= b

Algebraic Expression into QBASIC Expression


QBASIC has the provision to handle any complex arithmetic expression. However,
the system cannot understand terms like X2, A × B, etc. in the present form. Certain
arithmetic operators (or symbols) which are meaningful to the computer are to be used
to evaluate such arithmetic expressions.

Algebraic Expression QBASIC Expression


A+B-C A+B-C
X×Y÷Z X*Y/Z

I=(P*T*R)/100

(a+b)(a-b) (a+b)*(a-b)

(a/b)*x^2

(c) Operands
Operands are the values on which the operator performs its operation.

For example, in the below expression

C = A+B
The symbols ‘=’ and ‘+’ are the operators and the variables ‘C’, ‘A’ and ‘B’ are the
operands.

200 Computer Science : Grade 9


Exercises
1. Answer the following questions.
a) What is the operator? List the different operators that can be used in
QBASIC.
b) What are the arithmetic operators? List their operations.
c) What are the relational operators? List their operations.
d) What are the logical operators? List their operations.
e) Define AND operator. Write down the truth table of AND operator.
f) Define OR operator. Write down the truth table of OR operator.
g) What is an expression? List its types.
2. Write down the QBASIC expression of the following algebraic
expression.

a) A = Πr2h b) c)

d) A = 2h(l+b) e) x3+x2y+xy2+y3 f)

g) h) i) (a+b)2 = a2+2ab+b2

j)

3. State whether the following statements are True or False.


a) Concatenation is the process of combining two strings.
b) The logical operator compares two values.
c) The relational operator combines the results of relational expression and
returns either True or False.
d) An operand is a symbol that represents a particular operation.
e) OR operator returns True if any of the input is True.
f) AND operator returns False if all the inputs are False.

Computer Science : Grade 9 201


4.2.4 Program Statements
QBASIC Statements
The instructions within a program are called statements. Each QBASIC instruction is
like a sentence. As a sentence must have a verb in it, each QBASIC instruction must
have a QBASIC keyword. A QBASIC statement is either executable or non-executable.

Types of Statements
Statements can be categorized into four groups.

→ Declaration Statements
→ Assignment Statements
→ I/O (Input/Output) Statements
→ Control Statements

(a) Declaration Statement


i) REM or ‘ statement [Comments]
Comments may be included in a QBASIC program to describe the purpose or to clarify
some portion of code in the program. In QBASIC, we use REM or ‘ for comments.

Purpose: To write explanatory remarks (comments) to be inserted in a program

Example:
REM to find the sum of two numbers
CLS
INPUT "Type any two numbers: "; a, b
PRINT "Sum = "; a + b
END
ii) END statement
You have already used the END statement to terminate your program.

Purpose: It is a declaration that ends a QBASIC program, procedure or block.

202 Computer Science : Grade 9


Syntax:
END [{DEF | FUNCTION | IF | SELECT | SUB | TYPE}]

Note: END statement is also used to terminate function, IF construct, subprocedure


etc., which will be covered in the next chapter.

iii) CONST statement [Symbolic Constant]


A symbolic constant is a symbol represented by a name such as a variable which stores
one and only one value throughout the whole program.

Symbolic constants may be numbers or strings. A symbolic constant can be declared


using keyboard CONST.

Purpose: A non-executable statement that declares symbolic constants to use in place


of numeric or string values

Syntax:
CONST constant name = expression

- constant name is a name of a variable.


- expression consists of literals, other constants, or any of the arithmetic and logical
operators except exponentiation (^).
Example:
CONST pi=3.14

Here, pi is a symbolic constant and its value remains same as 3.14 throughout the whole
program and cannot be changed.

General Constant Symbolic Constant


A = 45 CONST A = 45
A = A+5 A= A + 5
Possible to change the value of general Not possible to change the value of
constant. symbolic constant.

Computer Science : Grade 9 203


iv) DIM statement
Purpose: DIM specifies a data type for a variable (explicit declaration) or declares an
array.

We have discussed about explicit declaration of variable in previous chapter. Array will
be discussed later on.

Explicit declaration of Variable using DIM statement:

Syntax:
DIM variable [AS type]

- type declares the data type of variable (INTEGER, LONG, SINGLE, DOUBLE,
STRING)
Example:
DIM A AS STRING

Here, 'A' is declared explicitly as string variable.

(b) Assignment Statement


These statements are used to assign a value to a variable.

i) LET statement
Purpose: To assign a value to a variable.

Syntax:

[LET] variable=expression
Example:
LET A = 200
C$ = “SCHOOL”
Here, A is a numeric variable and the value 200 is assigned to A. Similarly, C$ is a string
variable and the value “SCHOOL” is assigned to C$.

Note: In QBASIC, a value can be assigned to a variable without LET statement also.

204 Computer Science : Grade 9


Example:
LET A=200
The above statement is equivalent to
A=200
ii) SWAP statement
Purpose: an assignment statement that exchanges the values of two variables of same
type.

Syntax:
SWAP variable1, variable2

- variable1 and variable2 must be of exactly the same type


Example:
CLS
a = 5: b = 10
SWAP a, b
PRINT "The value of a = "; a
PRINT "The value of b= "; b
END
(c) I/O (Input/Output) statements
The statements that are used to supply the data during the execution of the program
from the keyboard or file are called input statements.

Similarly, the statements that are used to get the result of the processing from the output
device or to the file are called output statements.

i) CLS statement
Purpose: To clear the display screen
Syntax:
CLS
Computer Science : Grade 9 205
Note: It is a good practice to start your every program with CLS statement so that the
previous displayed content will be erased before executing your new program.

ii) INPUT statement


Purpose: To read input from the keyboard during program execution and stores it into
a list of variables.

Syntax:
INPUT[;]["prompt string"{;|,}]variable list

- variable list is one or more variables separated by commas


- promptstring, if used, is displayed on the screen to tell the user of the program
what to enter on the keyboard
- the characters ";" and "," are the separators
Example:
INPUT “Type First Number”;a
Here, a is a numeric variable.
“Type First Number” is a prompt string
Note: You can also ask more than one value from a single INPUT statement.

INPUT “Type any two numbers:”; a, b


Here, comma (,) is used to separate the list of variables.
INPUT a, b
The above statement is also valid without a prompt string.
iii) LINE INPUT statement
Purpose: To input an entire line (up to 255 characters) to a string variable, without the
use of delimiters.

Syntax:
LINE INPUT[;] ["promptstring";] stringvariable

206 Computer Science : Grade 9


Example:
CLS
LINE INPUT "Describe about yourself "; S$
PRINT S$
END

iv) PRINT statement


Purpose: To display the output on the screen.

Syntax:
PRINT [expressionlist][{,|;}]

- If all arguments are omitted, a blank line is printed.


- If expression list is included, the values of the expressions are printed on the
screen.
- The expressions in the list may be numeric or string expressions. (String literals
must be enclosed in quotation marks.)
- The optional characters "," and ";" are the separators.
Example:
N = 50
PRINT “I live in Kathmandu.”
PRINT 5;6
PRINT (3+2 + N) / 3
Note: You must enclose string constant with double quotes (“ ”).

As a shortcut, use a question mark symbol (?) for PRINT. Try it. Press <Enter> to start
typing on a new line. Now

Type this:

? "Programming is fun."
and press <Enter> again.

Computer Science : Grade 9 207


Other Examples:
RINT
A blank line is printed.
PRINT 2*8+5
Here the expression is 2*8+5 and the evaluated value of this expression 21 (2*8+5=21)
is printed.

PRINT “Nepal”
String literals “Nepal” enclosed in quotation marks is printed.

Similarly, the values of variables can be displayed in the following ways.

INPUT “Type your name ”; N$


PRINT “Your name is ”; N$
INPUT “Type your roll number ”;r
PRINT “Your roll number is ”;r
Or you can write this statement.

PRINT “Your name is ”; N$; “ and your roll number is ”;r


Try these statements:
PRINT N$;r
PRINT N$,r
Now find the difference in the output using; and, as a separator.

v) PRINT USING statement


Purpose: To print strings or numbers using a specified format

Syntax:
PRINT USING formatstring; expressionlist[{,|;}]
- formatstring, a string-expression, specifies the format.

208 Computer Science : Grade 9


- expressionlist contains the items to be printed
Characters used to format a Numeric Expression

# Digit position
- Decimal point position
, Placed left of the decimal point, prints a comma every third digit
$$ Prints leading $
+ Position of number's sign
^^^^ Prints number in exponential format
** Fills leading spaces with *
**$ Combines ** and $
Example:
Statement Output
PRINT USING "##.##"; .12 0.12
PRINT USING "###.##"; 117.614 117.61
PRINT USING "##.## "; 10.2; 5.3; 66.789; .234 10.20 5.30 66.78 0.23
PRINT USING "+##.## "; -68.95; 2.4; 55.6; -.9 -68.95 +2.40 +55.60 -0.90
PRINT USING "**#.# "; 415.4; -.5; 76.14 415.4 *-0.5 *76.1
PRINT USING "$$###.##"; 125.18 $125.18
PRINT USING "**$##.##"; 7.69 ***$7.69
PRINT USING "##.##^^^^"; 758.56 7.59E+02
PRINT USING "####,.##"; 1452.9 1.452.90

Characters used to format a String Expression

& Prints entire string


! Prints only the first character of the string
\\ Prints first 'n' characters, where n is the number of blanks between slashes + 2

Computer Science : Grade 9 209


Example:
A$ = "LOVE": B$ = "NEPAL"
PRINT USING "!"; A$; B$ 'First characters of A$ and B$.
PRINT USING "\ \"; A$; B$ 'Two spaces between backslashes, prints 4
'characters each from A$ and B$
PRINT USING "&"; B$ 'all of B$
Output:
LN
LOVENEPAL
NEPAL

vi) LPRINT and LPRINT USING statements


Purpose: I/O statements that print data on the printer LPT1
Syntax 1:
LPRINT [expressionlist][{;|,}]
Syntax 2:
LPRINT USING formatstring; expressionlist[{;|,}]
Example:
LPRINT "LOVE"; TAB(76); "NEPAL"

vii) READ and DATA statement


READ statement – an I/O statement that reads values from a DATA statement and
assigns the values to variables

Syntax:
READ variablelist
- Variablelist is made up of one or more variables, separated by commas, which
are to receive the data. The variables may be string or numeric.
DATA Statement – a non-executable statement that stores the numeric and string
constants used by a program's READ statements

210 Computer Science : Grade 9


Syntax:
DATA constant[,constant]...
- constant is any valid numeric or string constant.
Example 1:
READ a, b, c
PRINT a, b, c
DATA 34,56,78
Example 2:
READ a$, b
PRINT a$, b
DATA "Nepal's View",45
Example 3:
FOR i = 1 TO 5
READ n
s=s+n
NEXT i
PRINT "Sum = "; s
DATA 56,78,65,43,21
END
Note:
→ READ statement cannot be used without DATA statement.
→ DATA statement can be placed anywhere in the program.
→ Data and variable types should be same.
→ In DATA statement, string data is not necessary to be enclosed by double quotes.
→ If number of variable in READ statement is more than number of data in DATA
statement, an error message “Out of DATA” will be displayed.

Computer Science : Grade 9 211


Summary of the chapter
- The instructions within a program are called statements.
- Types of statements: Declaration, Assignment, I/O and Control
- Declaration Statement: REM or ', CONST, DIM
- Assignment Statement: LET, SWAP
- I/O Statement: INPUT, PRINT, INKEY$, READ - DATA

Sample Programs
1. REM ask name, address & class and display them
CLS
INPUT "Type your name "; n$
INPUT "Type your address "; a$
INPUT "Type your phone "; c
PRINT "Your name is "; n$
PRINT "You live in "; a$
PRINT "You study in class "; c
END
2. REM To find the sum of any two integers
REM Implicit declaration
CLS
INPUT "Type first number "; a%
INPUT "Type second number "; b%
c% = a% + b%
PRINT "Sum = "; c%
END

212 Computer Science : Grade 9


3. REM To find the area of a circle
' Symbolic constant
CONST pi = 3.14
INPUT "Radius of a circle "; r
a = pi * r ^ 2
PRINT "Area = "; a
END

4. REM Explicit declaration


DIM a AS INTEGER, b AS INTEGER, c AS LONG
CLS
INPUT "Type first number "; a
INPUT "Type second number "; b
c=a*b
PRINT "Product = "; c
END

5. REM find average using READ ... DATA


CLS
READ a, b, c
avg = (a + b + c) / 3
PRINT "Average = "; avg
DATA 45,67,52
END

Computer Science : Grade 9 213


Exercises
1. Calculate the output from the following QBASIC expression:
a) (3 - 4) + 3 * 2 / 4
b) 3 * 5 / 5 + 2 - (14 * 2)
c) (2 + 4 / 2 * 3) * 2
d) (3 + 4 - 2 * 3 / 2) / 2
e) (4 * (4 / 4 + 4 * 4 + 4 - 4))

2. Write down the syntax and use of the following QBASIC statements.
a) SWAP statement
b) CONST statement
c) PRINT statement
d) INPUT statement
e) READ … DATA statement

3. Debug the following programs.


a) CLS
a$ = Mount Annapurna
b = "45"
c% = 32.45
d# = 456
e% = 40512
PRINT a$, b, c%, d#, e%
END

214 Computer Science : Grade 9


b) CLS
p = Rs. 34045
t = 2 years
r = 6%
I = ptr / 100
PRINT "Simple Interest = "; I
END

c) CLS
READ a$
READ c, r
PRINT "Your name is "; a$
PRINT "Your class is "; c
PRINT "Your roll is "; r
READ s$
PRINT "Your section is "; s$
DATA Ramesh
DATA 4
DATA 10,A,5
END
4. Write down the output of the following.
PRINT USING "##.##"; 1.36
PRINT USING "###.##"; 17.614
PRINT USING "##.## "; 187.2
PRINT USING "+##.## "; -168.9

Computer Science : Grade 9 215


PRINT USING "**#.# "; 45.4
PRINT USING "$$###.##"; 4125.18
PRINT USING "**$##.##"; 7.69
PRINT USING "##.##^^^^"; 758.56
PRINT USING "####,.##"; 1452.9
PRINT USING "!"; "Nepal"
5. Write down the QBASIC code for the following problems.
a) Write a program that asks any two numbers and displays their sum, difference
and product.
b) Write a program that asks any number and calculates its square, cube, square
root and cube root.
c) A salesman has purchased a computer at Rs. 45,000 and he sold it at Rs.
49,850. Write a program to calculate profit percent on sale (use explicit
declaration).
d) Computer book costs Rs. 457. Write a program that asks the number of
books to be purchased and calculates the total amount to be paid (use LET
statement).
e) Write a program that asks radius of a circle and calculates its diameter,
circumference and area (use symbolic constant).
f) Write a program that accepts the room temperature in Fahrenheit degree
and calculates its equivalent in Celsius degree. [Hint: ]
g) Write a program to convert the length from feet into inches.
h) Write a program that asks the length, breadth and height of a room and
calculates the volume of the room.
i) Write a program that reads the below data and calculates their average value.
DATA 45,64,23,12,54

216 Computer Science : Grade 9


4.2.5 Program Flow and Control Structures

A program is a set of statements. When we run the program, its statements are executed
to perform our tasks. Normally, they are executed one after another from top to bottom.
The order of execution of statements of a program is known as the flow of program or
program control.

Control Structure
Control structures are used to alter the way of execution of the program or used to
control the flow of a program. The controls are classified into three types.

→ Sequential Structure
→ Selection Structure
→ Looping Structure

(a) Sequential Structure


In sequential structure, the statements are executed
one after another sequentially from top to bottom
Statement 1
without changing the flow of the program. The
programs which you have written in previous chapters
are based on sequential structure.
Statement 2
(b) Selection Structure
It is also called a branching structure. In this structure,
the control of the program is transferred from one part Statement 3
of the program to another on the basis of a specified
condition or without condition.
Fig. Flowchart of a
Branching or Jumping: The process of departure sequential structured program
of the control of the program conditionally or
unconditionally from its sequential flow depending upon the result of the condition
used is termed as branching or jumping. There are two types of branching statements.

Computer Science : Grade 9 217


→ Unconditional statement
→ Conditional statement
Unconditional Statement
The statement that transfers the control of the program from one step to another without
testing the condition is called an unconditional statement. In QBASIC, GOTO statement
is the unconditional statement.

GOTO statement
Purpose: a control flow statement that branches unconditionally to the specified line

Syntax:
GOTO {linelabel | linenumber}
linelabel or linenumber is the label of the line to execute next. This line must be in the
same procedure or subroutine as the GOTO statement

Example:
CLS
PRINT "Kathmandu"
GOTO abc
PRINT "Birgunj"
abc:
PRINT "Biratnagar"
END
Output:
Kathmandu
Biratnagar
Biratnagar
Here, abc is a linelabel. After displaying “Kathmandu”, the control is transferred to
“abc” and displayed “Biratnagar” bypassing the statement PRINT "Birgunj".

218 Computer Science : Grade 9


Using linenumber
The below program gives the same output using line number.

CLS
PRINT "Kathmandu"
GOTO 10
PRINT "Birgunj"
10 PRINT "Biratnagar"
END

Conditional Statement
a) IF .. THEN … ELSE statement
Purpose: It is a control flow statement that allows conditional execution or branching,
based on the evaluation of an expression that must be either true or false.

True
Condition

Statement 1
False

Statement 1

QBASIC supports variety of IF statement.


i) Single line IF statement
Purpose: It allows conditional execution based on the evaluation of an expression that
must be true.

Computer Science : Grade 9 219


Syntax:
IF boolean expression THEN [statement]
- booleanexpression is an expression that must return non-zero (true) or zero (false)
- statement consists of a task to be executed if the booleanexpression returns true.
Example:
CLS
INPUT “Type your marks ”;m
IF m>=40 THEN PRINT “Pass”
END
Note: In the above program, if the booleanexpression m>=40 returns true, it displays
“Pass”. The program displays nothing if the value is less than 40.

ii) Single line IF … ELSE statement


Purpose: It allows conditional execution based on the evaluation of an expression that
must be either true or false.

Syntax:
IF booleanexpression THEN [statement1] ELSE [statement2]
Example:
CLS
INPUT “Type your marks”;m
IF m>=40 THEN PRINT “Pass” ELSE PRINT “Fail”
END
Note: statement1 will be executed if the booleanexpression returns true, otherwise
statement2 will be executed.

iii) Multiline IF Statement


Purpose: To execute a block of statements based on the evaluation of an expression
that must be true.
220 Computer Science : Grade 9
Syntax:
IF booleanexpression THEN
[statementblock]
END IF
- statementblock consists of any number of statements on one or more lines.
Example:
CLS
INPUT “Type your marks ”;m
IF m>=40 THEN
PRINT “Pass”
PRINT “Congratulations”
END IF
END
Note: END IF terminates the multiline IF statement which is not required in single line
IF statement.

iv) Multiline IF … ELSE statement


Purpose: To execute a block of statements based on the evaluation of an expression
that must be either true or false.

Syntax:
IF booleanexpression THEN
[statementblock-1]
ELSE
[statementblock-2]
END IF

Computer Science : Grade 9 221


Example:
CLS
INPUT “Type your marks ”;m
IF m>=40 THEN
PRINT “Pass”
PRINT “Congratulations”
ELSE
PRINT “Fail”
PRINT “Work hard”
END IF
END

v) IF …. THEN … ELSEIF statement


Purpose: To execute a block of statements based on the evaluation of multiple
expressions that must be either true or false.

Syntax:
IF booleanexpression1 THEN
[statementblock-1]
ELSEIF booleanexpression2 THEN
[statementblock-2]
...
ELSE
[statementblock-n]
END IF

222 Computer Science : Grade 9


Example:
CLS
INPUT "Type your percentage "; p
IF p >= 80 THEN
PRINT "Distinciton"
ELSEIF p >= 60 THEN
PRINT "First Division"
ELSEIF p >= 45 THEN
PRINT "Second Division"
ELSEIF p >= 32 THEN
PRINT "Third Division"
ELSE
PRINT "Fail"
END IF
END

b) SELECT CASE statement


Purpose: To execute one of several statement blocks depending on the value of an
expression

Syntax:
SELECT CASE testexpression
[CASE expressionlist1
[statementblock-1]
[CASE expressionlist2
[statementblock-2]

Computer Science : Grade 9 223


...
[CASE ELSE
[statementblock-n]
END SELECT
- testexpression is any numeric or string expression
- expressionlist contains one or more expressions of the same type as testexpression
- The IS keyword must precede any relational operators in an expression
Example:
CLS
INPUT "Type your roll number ", r
SELECT CASE r
CASE 1 TO 10
room = 5
CASE 11 TO 15
room = 6
CASE 18, 21, 28
room = 7
CASE IS >= 35
room = 8
CASE ELSE
room = 9
END SELECT
PRINT "Your room number is "; room
END

224 Computer Science : Grade 9


(c) Looping Structure
Looping is the process of repeating the execution of a statement or a block of statements
guided by a condition. A loop is terminated when the given condition is satisfied.

Example:
CLS
n=1
top:
PRINT "Nepal"
n=n+1
IF n <= 5 THEN GOTO top
END
Flowchart of the above program is: Memory table of dry run

Start n OP (Output)
1 Nepal
2 Nepal
3 Nepal
n=1
4 Nepal
5 Nepal
6
Print "Nepal"
The output of the above program is
Nepal
Nepal
Yes Nepal
n <= 5?
Nepal
Nepal
No

Stop

Computer Science : Grade 9 225


Here the statement PRINT “Nepal” is executed 5 times till the condition n<=5 is true.

QBASIC standard looping statements.


a) DO … LOOP WHILE statement
Syntax:
DO
[statementblock]
LOOP [WHILE booleanexpression]
- booleanexpression is an expression that will return non-zero (true) or zero (false).
- statementblock is any number of statements on one or more lines which are to be
executed as long as boolean expression is true.
Example:
CLS
n=1
DO
PRINT "Nepal"
n=n+1
LOOP WHILE n <= 5
END
Counters, Intermediate Value, Sentinel Value & Accumulators
Counters are the numeric variables which store the number of times a statements or a
block of statements is executed in a loop. Counters may have increment or decrement
of any numbers.

The mid-values of a counter except initial and final value in a loop are called intermediate
value and the final value of a counter is called sentinel value.

Accumulators are the variables in which the intermediate value of another variable is
added.

226 Computer Science : Grade 9


Example:
A=1
DO
PRINT A;
S=S+A
A = A+1
LOOP WHILE A<=10
PRINT “Sum = “;S
END
In the above program, the variable A is used as a counter which counts the number
of execution of a block of statements in the loop. Here, the intermediate values of the
counter A are 2,3,4,5,6,7,8 & 9. Similarly, the sentinel value of A is 10. The variable S
is used as an accumulator which adds the intermediate values of A.

b) DO WHILE … LOOP statement


Syntax:
DO [WHILE booleanexpression]
[statementblock]
LOOP
Example:
CLS
n=1
DO WHILE n <= 5
PRINT "Nepal"
n=n+1
LOOP
END

Computer Science : Grade 9 227


c) WHILE …WEND statement
Syntax:
WHILE condition
[statements]
WEND
- condition is an expression that will return non-zero (true) or zero (false)
- statements are one or more QBASIC statements to be executed as long as condition
is true
Example:
CLS
n=1
WHILE n <= 5
PRINT "Nepal"
n=n+1
WEND
END
d) DO … LOOP UNTIL statement
Syntax:
DO
[statementblock]
LOOP [UNTIL booleanexpression]
Example:
CLS
n=1
DO

228 Computer Science : Grade 9


PRINT "Nepal"
n=n+1
LOOP UNTIL n>5
END
Note: The loop will be continued until the condition is true. That is, if the given Boolean
expression returns false (0) the loop will be continued. The loop will be terminated if
the condition is true.

The above program displays “Nepal” 5 times. When the value of n reaches 6, the given
conditions return true (1) value and the loop will be terminated.

e) DO UNTIL …. LOOP statement


Syntax:
DO [UNTIL booleanexpression]
[statementblock]
LOOP
Example:
CLS
n=1
DO UNTIL n>5
PRINT "Nepal"
n=n+1
LOOP
END

f) FOR … NEXT statement


Syntax:
FOR counter = start TO end [STEP increment/decrement]

Computer Science : Grade 9 229


[statements]
NEXT counter
- counter is a numeric variable used as the loop counter
- start is the initial value and end is the final value of the counter
- increment is the amount the counter is incremented each time through the loop
Example:
CLS
FOR n=1 TO 5 STEP 1
PRINT “Nepal”
NEXT n
END
Note: The above program displays “Nepal” 5 times.

Here, the counter is n and its initial value is 1 and final value is 5 and after each iteration,
the value of the counter will be incremented by 1.

Similarly, the below program also gives the same output.

CLS
FOR n=10 TO 2 STEP -2
PRINT “Nepal”
NEXT n
END
If the counter has to be incremented by 1, then you don’t need to specify it with STEP
keyword.

For example, the below program displays “Mount Everest” 5 times.

CLS
FOR n=1 TO 5

230 Computer Science : Grade 9


PRINT “Mount Everest”
NEXT n
END

Nested Loop
A loop inside another loop is called a nested loop.

Example of a program using a nested loop.

Program Output
FOR X=1 TO 5 1
FOR Y=1 TO X 12
PRINT Y; 123
NEXT Y 1234
PRINT 12345
NEXT X

Sample Program
i) To check whether the supplied number is prime or not
CLS
INPUT "Type any number "; n
FOR x = 2 TO n - 1
IF n MOD x = 0 THEN c = c + 1
NEXT x
IF c = 0 THEN PRINT "Prime" ELSE PRINT "Composite"
END

Computer Science : Grade 9 231


ii) To display the numeric pattern 2,22,222,222,222
CLS
n=2
FOR i = 1 TO 5
PRINT n;
n = n * 10 + 2
NEXT i
END

iii) To display the smallest among three numbers


CLS
INPUT "Type any three numbers "; a, b, c
IF a > b AND a > c THEN
PRINT a
ELSEIF b > a AND b > c THEN
PRINT b
ELSE
PRINT c
END IF
END

iv) To calculate the sum of individual digits of an integer


CLS
INPUT "Type any integer "; n%
WHILE n% <> 0
r = n% MOD 10

232 Computer Science : Grade 9


s% = s% + r
n% = n% \ 10
WEND
PRINT "Sum of individual digits = "; s%
END

Summary
 Control structures are used to control the flow of program. There are three types
of control structure: Sequential, Selection and Iteration
 In sequential structure, all the statements are executed from top to bottom sequence
without leaving anyone.
 In selection structure (also called branching), the control of the program is
transferred from one part of the program to another on the basis of specified
condition or without condition.
 In looping structure (also called iteration), statements are re-executed for a definite
number of times.

Exercises
1. Answer the following questions.
a) What is control structure?
b) Define branching statement with its types.
c) What is looping? List the standard looping statements of QBASIC.

2. Re-write the programme below using.


a) DO … LOOP WHILE
b) DO UNTIL … LOOP
c) FOR … NEXT

Computer Science : Grade 9 233


i) CLS
n=1
top:
PRINT n;
n=n+1
IF n <= 10 THEN GOTO top
END

ii) CLS
n = 10
top:
PRINT n;
n=n-1
IF n >= 1 THEN GOTO top
END

iii) CLS
c=1
n=5
top:
PRINT n;
n=n*2
c=c+1
IF c <= 10 THEN GOTO top
END
Note: Re-write the programme below using only do…while and DO UNTIL…LOOP
statements

234 Computer Science : Grade 9


iv) CLS
FOR x = 1 TO 5
FOR y = 5 TO 1 STEP -1
PRINT y;
NEXT y
PRINT
NEXT x
END

3. Debug the following programs.


a) REM To find the greater number among two
CLS
INPUT "Any two numbers "; a, b
IF a > b THEN PRINT a ELSE PRINT b
END IF
END

b) REM to check odd or even


CLS
INPUT "Type any number "; a
R=a/2
IF R = 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
END

Computer Science : Grade 9 235


c) REM to display 2,4,6,8,....20
CLS
n=2
DO
PRINT n;
n=n+2
LOOP UNTIL n <= 20
END

d) REM to display 20,18,16,14,....2


CLS
FOR n = 20 TO 2
PRINT n;
n=n+1
NEXT n
END

e) REM to check whether the supplied number is prime or not


CLS
INPUT "Type any number "; n
FOR x = 1 TO n
r= x MOD n
IF r = 0 THEN c = c + 1
NEXT x
IF c = 0 THEN
PRINT "Prime"
ELSE
PRINT "Composite"
END

236 Computer Science : Grade 9


f) REM to display the smallest among three supplied numbers
CLS
INPUT "Type any three numbers "; a, b, c
IF a > b OR a < c THEN
PRINT a
ELSEIF b > a OR b < c THEN
PRINT b
ELSE
PRINT c
END IF
END

g) REM to print given name 20 times


LET c=1
INPUT “Enter Name; N
WHILE c less or equal to 20
PRINT N
c+1=c
END

4. Write down the output of the following programs.


a) S=0
FOR I=1 TO 10
X=I^2
S=S+X
NEXT I
PRINT S
END

Computer Science : Grade 9 237


b) FOR I=1 TO 10
READ N
B=N MOD 5
IF B=0 THEN C=C+1
NEXT I
DATA 7,15,6,10,15,32,8,22,25,5
PRINT C
END

c) CLS
FOR x = 1 TO 3
READ n$, add$, age
PRINT n$, add$, age
NEXT x
DATA "Sushil","Kathmandu",31
DATA "Rajendra",Lalitpur,29
DATA Laxman,Bhaktapur,28
END

d) CLS
n = 15
DO
IF n MOD 3 = 1 THEN PRINT n;
n=n-1
LOOP WHILE n >= 3
END

238 Computer Science : Grade 9


e) CLS
C=1
FOR I = 2 TO 8 STEP 2
PRINT C;
SWAP B, C
C=B+1
NEXT I
END

f) FOR X = 2 TO 15 STEP 2
IF X >= 11 THEN EXIT FOR
PRINT X ^ 2 + 1
NEXT X
PRINT "Done"
END

g) FOR i=2 TO 10 STEP 2


FOR j=i TO 10 STEP 2
PRINT J;
NEXT j
PRINT
NEXT i
END

5. Write down the QBASIC code for the following problems.


a) Write a program that asks the age of a person and tells whether he/she can
vote or not. [Note: A person of 18 years old or above is eligible to vote.]
b) Write a program that asks any number and checks whether it is divisible by
3 or not.

Computer Science : Grade 9 239


c) Write a program that asks any three numbers and displays the greatest
number.
d) Write a program that accepts an alphabet and tells whether it is a vowel or
a consonant.
e) Write a program that asks student’s name and marks in English, Nepali and
Computer Science and calculates the total marks, percentage, result (pass/
fail) and division on the bases given below.
Percentage Division
>=80 Distinction
>=60 and <80 First Division
>=45 and <60 Second Division
>=32 and <45 Third Division
Note: Pass mark for all the subject is 40]
f) Write a program that asks student’s roll numbers and tells him/her room
number where he/she has to sit to give the exam on the following basis.
Roll No. Room No.
1-10 5
11-20 6
22,25,29,31 7
Above 35 8
Others 9
g) Write a program that asks your name and displays it 10 times.
h) Write a program to display the first 100 natural numbers with their sum.
i) Write a program to generate the following series.
i) 1,4,7, …, up to 10th terms
ii) 100,95,90,85,…..,5
iii) 1,2,4,8,16,…., up to 10th terms

240 Computer Science : Grade 9


iv) 999,728,511,342,…, up to 10th terms
v) 1,11,111,1111,1111
vi) 1,2,3,5,8,13,21,…, up to 10th terms
vii) .1,.01,.001,.0001,…, up to 10th terms
j) Write a program that asks any two integers and calculates their HCF and
LCM.
k) Write a program that asks any number and displays its multiple table up to
10.
l) Write a program that asks any number and checks whether it is Armstrong
or not. [A number which is equal to the sum of the cube of its individual
digits is called an Armstrong number. Eg. 371 = 33+73+13]
m) Write a program that checks whether the supplied number is palindrome or
n) Write a program that asks any number and displays its factors.
o) Write a program that asks any number and calculates its factorial. [Hint:
Factorial of 5 = 5×4×3×2×1 i.e. 120]
p) Write a program that asks multi-digit integer and displays the product of
its individual digits.

Computer Science : Grade 9 241


4.2.6 Library Functions
Function
Function is a block of statement executed together to perform specific tasks and usually
returns a value.

Types of Function
Basically, there are two types of function available in QBASIC.

→ Library Function
→ User-Defined Function
Library Function
Also called Built-in function or intrinsic function. It is already available with a
programming language. The programmer does not need to define this function.

a) String manipulation functions


i) LEN function
Purpose: a string processing function that returns the number of characters in a string
or the number of bytes required by a variable

Syntax:
LEN(stringexpression)
or
LEN(variable)
- stringexpression is a string constant or string expression
- variable identifies the object for which you want the number of required bytes
Example:
CLS
a$ = "Nepal"
b% = 456

242 Computer Science : Grade 9


c& = 23
d! = 56.789
e# = 44.55
PRINT LEN(a$) ‘ Displays 5
PRINT LEN(b%)‘ Displays 2
PRINT LEN(c&) ‘ Displays 4
PRINT LEN(d!) ‘ Displays 4
PRINT LEN(e#) ‘ Displays 8
END

ii) LEFT$ function


Purpose: a string processing function that returns a string consisting of the leftmost
n characters of a string

Syntax:
LEFT$(stringexpression,n)
- stringexpression is a string constant, string variable, or string expression
- n, a numeric expression, must have a value between 0 and 32,767. If n is zero,
the null string (a zero-length string) is returned.

iii) RIGHT$ function


Purpose: a string function that returns the rightmost n characters of a string

Syntax:
RIGHT$(stringexpression,n)

iv) MID$ function


Purpose: a string-processing function that returns a substring of a string

Computer Science : Grade 9 243


Syntax:
MID$(stringexpression,start,length)

- stringexpression identifies the string from which the substring is to be extracted


- start, a numeric expression that has an integer value between 1 and 32,767, specifies
the starting character position of the substring
- length can be omitted if you want all the characters to the right of start
Example of using LEFT$, RIGHT$ and MID$ functions:
CLS
S$ = "BIRATNAGAR"
PRINT LEFT$(S$, 5) ‘Displays BIRAT
PRINT RIGHT$(S$, 5) ‘Displays NAGAR
PRINT MID$(S$, 3, 5) ‘Displays RATNA
PRINT MID$(S$, 6) ‘Displays NAGAR
END

v) CHR$ function
Purpose: a string processing function that returns a one-character string whose ASCII
code is the argument

Syntax:
CHR$(code)

- code, a numeric expression that has a value between 0 and 255, is one of the
ASCII character codes

vi) ASC function


Purpose: a string processing function that returns a numeric value that is the ASCII
code for the first character in a string expression

244 Computer Science : Grade 9


Syntax:
ASC (stringexpression)
Characters ASCII Value
A-Z 65-90
a-z 97-122
0-9 48-57
Space 32
Enter 13

Example:
PRINT CHR$(65) ‘ Displays A
PRINT ASC("abc") ‘ Displays 97

vii) VAL function


Purpose: a string-processing function that returns the numeric value of a string of digits

Syntax:
VAL(stringexpression)

viii) STR$ function


Purpose: a string function that returns a string representation of the value of a numeric
expression

Syntax:
STR$(numeric-expression)

Example:
CLS
a=5
b=6
c$ = "7"

Computer Science : Grade 9 245


d$ = "8"
PRINT a + b ‘ Displays 11
PRINT c$ + d$ ‘ Displays 78
PRINT STR$(a) + STR$(b) ‘ Displays 56
PRINT VAL(c$) + VAL(d$) ‘ Displays 15
END

ix) SPACE$ function


Purpose: a string processing function that returns a string of spaces of length n

Syntax:
SPACE$(n)

- n, a numeric expression that has an integer value between 0 and 32,767, is the
number of spaces you want in the string
Example:
CLS
PRINT "Stand-Up"; SPACE$(5); "Online"
END
x) STRING$ function
Purpose: a string processing function that returns a string whose characters all have a
given ASCII code or whose characters are all the first character of a string expression

Syntax:
STRING$(m,n)

STRING$(m,stringexpression)

- m, a numeric expression, is the length of the string to return


- n, a numeric expression that has an integer value between 0 and 255, is the ASCII
character code of the character that fills the string
246 Computer Science : Grade 9
- stringexpression identifies a string whose first character can be used to fill the
string
Example:
CLS
PRINT STRING$(4, 65) ' prints AAAA
PRINT STRING$(2, "Nepal") ' prints NN
END

xi) DATE$
As a statement
Purpose: To set the current system date

Syntax:
DATE$ = stringexpression

- stringexpression must have one of the following forms:


mm-dd-yy, mm-dd-yyyy, mm/dd/yy, or mm/dd/yyyy where mm and dd are the
month and day, and yy or yyyy are the year
Example:
DATE$ = "05-25-1995"
Sets the system date as 25th May 1995
As a function
Purpose: To return a string containing the current system date

Syntax:
DATE$
- a ten-character string is returned, in the form mm-dd-yyyy
mm is the month (01-12),
dd is the day (01-31), and

Computer Science : Grade 9 247


yyyy is the year (1980-2099)
Example:
PRINT DATE$
Displays the current system date

xii) TIME$
As a statement

Purpose: To set the current time

Syntax:
TIME$=stringexpression

- stringexpression must have one of the following forms:


hh, hh:mm, or hh:mm:ss where hh is the hour on a 24-hour clock, mm is the
minutes, and ss is the seconds
Example:
TIME$ = "05:25:55"
Sets the system time as 5 Hour 25 Minutes and 55 Seconds
As a function

Purpose: To return the current system time

Syntax:
TIME$

- an eight-character string is returned, in the form hh:mm:ss


hh is the hour (00-23), mm is the minute (00-59), and ss is the second (00-59)
Example:
PRINT TIME$
Displays the current system time

248 Computer Science : Grade 9


xiii) LTRIM$ function
Purpose: a function that returns a copy of a string with leading spaces removed

Syntax:
LTRIM$(stringexpression)

xiv) RTRIM$ function


Purpose: a string processing function that returns a string with trailing (right-hand)
spaces removed

Syntax:
RTRIM$(stringexpression)
Example:
B$ = “ KATHMANDU”
C$ = “BIRATNAGAR ”
B$=LTRIM$(B$)
C$=RTRIM$(C$)
PRINT LEN(B$);LEN(C$)
END

b) Mathematical Function
i) ABS function
Purpose: a math function that returns the absolute value of a numeric expression

Syntax:
ABS(numeric-expression)

Example:
a = -5
PRINT ABS(a)

Computer Science : Grade 9 249


ii) SGN function
Purpose: a math function that indicates the sign of a numeric expression

Syntax:
SGN(numeric-expression)

- If numeric-expression is positive, the SGN function returns +1.


- If numeric-expression is zero, the SGN function returns 0.
- If numeric-expression is negative, the SGN function returns -1.
Example:
CLS
a=5
b=0
c = -9.8
PRINT SGN(a) ' prints 1
PRINT SGN(b) ' prints 0
PRINT SGN(c) ' prints -1
END
iii) SQR function
Purpose: a math function that returns the square root of numeric expression

Syntax:
SQR(numeric-expression)

- numeric-expression must have a value greater than or equal to zero


Example:
CLS
a=9
b = SQR(a)

250 Computer Science : Grade 9


PRINT "Square root of "; a; " is"; b
END

iv) INT function


Purpose: a math function that returns the largest integer less than or equal to a
numeric-expression

Syntax:
INT(numeric-expression)

v) FIX function
Purpose: a math function that returns the truncated integer part of a numeric expression

Syntax:
FIX(numeric-expression)

vi) CINT function


Purpose: a conversion function that converts a numeric expression to an integer by
rounding the fractional part of the expression

Syntax:
CINT(numeric-expression)

Example:
a=5 a= 5.5 a = -5.5
INT (a) 5 5 -6
FIX (a) 5 5 -5
CINT (a) 5 6 -6

vii) SIN function


Purpose: a math function that returns the sine of an angle given in radians

Computer Science : Grade 9 251


Syntax:
SIN(numeric-expression)

- numeric-expression is the angle, expressed in radians.

viii) COS function


Purpose: a math function that returns the cosine of an angle given in radians

Syntax:

COS(numeric-expression)

ix) TAN function


Purpose: a math function that returns the tangent of an angle expressed in radians

Syntax:
TAN(numeric-expression)

Example:
a = 45
PRINT SIN(a)
PRINT COS(a)
PRINT TAN(a)

c) Other useful functions and statements


i) SPC function
Purpose: an I/O function that skips n spaces in a PRINT statement

Syntax:
SPC(n)

- n, a numeric expression that returns an integer value between 0 and 32,767, is the
number of spaces you want in print line
252 Computer Science : Grade 9
Example:
CLS
PRINT "Kathmandu"; SPC(5); "Nepal"
END
Output:
The SPC function returns 5 spaces which are printed as below.

Kathmandu Nepal

ii) TAB function


Purpose: a device I/O function that moves the print position when used in the PRINT
statement

Syntax:
TAB(column)

- column, a numeric expression that has an integer value between 1 and (column-
width of the display device )
Note: In normal mode, the column-width of the screen is 80.

Example:
CLS
PRINT "Kathmandu"; TAB(5); "Nepal"
END
Output:
The TAB() function moves the print position to the 5th column of the screen. So, the
string constant “Nepal” will be printed from the 5 columns i.e. after 4 spaces in the
second line as below.

Kathmandu
Nepal

Computer Science : Grade 9 253


iii) LOCATE statement
Purpose: an I/O statement that moves the cursor to the specified position

Syntax:
LOCATE [row],[column]

- row and column to move the cursor


Example:
CLS
PRINT SPC(5); "NEPAL"
PRINT TAB(5); "NEPAL"
LOCATE 5, 2
PRINT "NEPAL"
END
Output:
Column→
1 2 3 4 5 6 7 8 9 10
Row ↓
Returns 5 spaces by
1 N E P A L SPC function
Moves the cursor to
2 N E P A L 5th Column
3
4
Prints from 5th row
5 N E P A L & 2nd column
6

Sample Program
i) To display the reverse of a string
CLS
INPUT "Type your name "; n$

254 Computer Science : Grade 9


FOR i = 1 TO LEN(n$)
c$ = MID$(n$, i, 1)
r$ = c$ + r$
NEXT i
PRINT "Reversed = "; r$
END

ii) REM To count the frequency of vowels


CLS
INPUT "Type any string "; s$
FOR i = 1 TO LEN(s$)
b$ = MID$(s$, i, 1)
IF b$ = "a" OR b$ = "e" OR b$ = "i" OR b$ = "o" OR b$ = "u" THEN
c=c+1
END IF
NEXT i
PRINT "Frequency of vowels = "; c
END

iii) To display the below pattern


EDUCATION
DUCATIO
UCATI
CAT
A
CLS
Computer Science : Grade 9 255
b$ = "EDUCATION"
n=9
FOR i = 1 TO 5
PRINT TAB(i); MID$(b$, i, n)
n=n-2
NEXT i
END

iv) To change the letters in uppercase without using UCASE$() function


CLS
s$ = "nepal"
FOR i = 1 TO 5
b$ = MID$(s$, i, 1)
c = ASC(b$)
d$ = d$ + CHR$(c - 32)
NEXT i
PRINT "In uppercase: "; d$
END

v) REM to calculate hex equivalent of a decimal no.


INPUT "DECIMAL NO:"; D
DO WHILE D <> 0
R = D MOD 16
IF R < 10 THEN
A$ = LTRIM$(STR$(R)) + A$
ELSE
256 Computer Science : Grade 9
R = R + 55
A$ = CHR$(R) + A$
END IF
D = D \ 16
LOOP
PRINT "HEXADECIMAL EQUIVALENT:"; A$

Exercises
1. Answer the following questions:
a) What is a function? Mention its types.
b) What are library functions? List the functions available in QBASIC library.
c) Differentiate between library function and user-defined function.
2. Debug the following programs:
a) REM Reversing a string
INPUT "Type any number "; n$
FOR p = LEN(n$) TO 1
b$ = MID$(n$, 1, p) + b$
NEXT q
PRINT "Reversed = "; b$
END

b) REM Printing a string in a pattern


DIM S AS STRING
S = HAMI NEPALI
FOR P = 1 TO LEN$(S)
PRINT LEFT (S, P)
Computer Science : Grade 9 257
NEXT S
END

c) CLS
BROWSER=”BROWSER”
BROWSERLEN$=LEN(BROWSER$)
FOR KOUNTER=1 TO BROWSERLEN
PRINT MID(BROWSER$,KOUNTER,1);
NEXT BOUNCER
END

3. Write down the output of the following programs:


a) CLS
FOR i = 1 TO 5
PRINT LEFT$("NEPAL", i)
NEXT i
END

b) CLS
ST$ = "PLNMPBENPLA"
FOR I = 1 TO 5
READ N
PRINT MID$(ST$, N, 1);
NEXT I
DATA 3,7,9,11,2
END

258 Computer Science : Grade 9


c) CLS
FOR I = 1 TO 5
READ N$, A
PRINT MID$(N$, A, 1);
NEXT I
DATA COMPUTER,4,ORACLE,1,WINDOW,6
DATA KEYBOARD,2,FORTRAN,5
END

4. Write down the QBASIC code for the following problems:


a) Write a program that checks whether the supplied string is palindrome or
not. [A string is a palindrome if it is same when spelled from reverse order
also. Eg. MADAM]
b) Write a program that asks any string and counts the frequency of the letter
‘a’ present in the supplied string.
c) Write a program that asks any string value and displays only the vowels
from the supplied string.
d) Write a program that asks any numbers and checks whether it is positive,
negative or zero.
e) Write a program that asks any number and checks whether it is a perfect
square or not.
f) Write a program that checks whether the supplied character is the capital
alphabet, small alphabet, numeric character or other symbol.
g) Write a program that asks any integer and calculates its binary equivalent.
h) Write a program that asks the date of birth of a person in MM-DD-YYYY
format and checks whether he/she was born in the current month or not.
i) Write a program that asks any decimal number and calculates its hexadecimal
equivalent.
j) Write a program that asks any hexadecimal number and calculates its decimal

Computer Science : Grade 9 259


equivalent.
k) Write a program that asks any string and counts the number of characters
present in the supplied string without using LEN() function.
l) Write programs to display the following string patterns:
i) N ii) N E P A L ii) N E P A L
N E N E P A E P A L
N E P N E P P A L
N E P A N E A L
N E P A L N L

iv) L v) N E P A L vi) L
A L E P A L A L
P A L P A L P A L
E P A L A L E P A L
N E P A L L N E P A L

vii) N viii) L ix) A


E A C A T
P P U C A T I
A E D U C A T I O
L N E D U C A T I O N

260 Computer Science : Grade 9


1.2.7 Array
It is a special type of variable that holds a collection of related data having the same
data-type. The individual data item in an array is called an Element.

Advantages of an Array
→ Array can store multiple values of same data type. So, it reduced the number of
variables.
→ Program will be more efficient and well managed.
→ Sorting and searching the data can be done easily.
Array Declaration
Before using an array, it must be declared. For this, we need to use DIM statement.

One dimensional array


Syntax:
DIM Array_Name(subscript)

- A subscript is a value that is used to declare the size of array.


Example:
DIM N%(5)

Here the array name is N with data-type integer and value of subscript is 5, that is you
can store maximum 5 integers in this array.

Storing data in an Array


CLS
DIM N%(5)
FOR i = 1 TO 5
INPUT "Any integer "; N%(i)
NEXT i
END

Computer Science : Grade 9 261


Note: If you use an array in your program without including the array in a DIM statement,
the maximum value of each subscript of the array is 10.

Here, the statement

INPUT "Any integer "; N%(i)

will be executed 5 times and if we supply 5 integers 45,67,17,32,12 respectively. The


integers will be stored in the array in this way.

45 67 17 32 12
N(1) N(2) N(3) N(4) N(5)

Sample Program
1. REM To find the sum and average of 10 integers
DIM n%(10)
FOR i = 1 TO 10
INPUT "Any integer "; n%(i)
sum = sum + n%(i)
NEXT i
avg = sum / 10
PRINT "Sum = "; sum
PRINT "Average = "; avg
END
Searching data in an Array
Linear search or sequential search
Once the data are stored in an array, we can search a particular data by comparing each
element stored in the array one after another in a sequential order. This type of search
method is called linear search. The search process stops when either the value is found
or the end of the array is encountered.

262 Computer Science : Grade 9


Program of Sequential/linear search
REM Linear search from the data

CLS
DIM n(10)
FOR i = 1 TO 10
READ n(i)
NEXT i
INPUT "Type a number to search"; x
FOR a = 1 TO 10
IF n(a) = x THEN
check = 1
EXIT FOR
END IF
NEXT a
IF check = 1 THEN
PRINT "Data Found!!!"
ELSE
PRINT "Data Not Found!!!"
END IF
DATA 44,34,21,56,76,87,44,51,29,39
END
Sorting data in an Array
Sorting means the arrangement of data in ascending or descending order numerically
or alphabetically. Data can be sorted in various methods like Quicksort, Insertion sort,
Bubble sort, Heap sort, Shell sort etc. But we are using only bubble sort. Normally, we

Computer Science : Grade 9 263


sort the data in order to search the data in an efficient manner.

Bubble sort
Bubble sort is a simple sorting algorithm that works by repeatedly stepping through
the list to be sorted, comparing each pair of adjacent items and swapping them if they
are in the wrong order. The pass through the list is repeated until no swaps are needed,
which indicates that the list is sorted. The algorithm gets its name from the way smaller
elements "bubble" to the top of the list.

Program of Bubble sort


REM Bubble sort
CLS
DIM n(10)
FOR i = 1 TO 10
READ n(i)
NEXT i
FOR x = 10 TO 1 STEP -1
FOR y = 1 TO x - 1
IF n(y) > n(y + 1) THEN SWAP n(y), n(y + 1)
NEXT y
NEXT x
PRINT "Sorted data..."
FOR x = 1 TO 10
PRINT n(x);
NEXT x
DATA 44,34,21,56,76,87,44,51,29,39
END

264 Computer Science : Grade 9


Two dimensional array
In two dimensional array, the data are stored in a tabular form in rows and columns.

Syntax:
DIM array_name(m,n)

- m, a number that declares the number of rows


- n, a number that declares the number of columns
Example:
DIM N%(3,4)
CLS
DIM N%(3, 4)
FOR x = 1 TO 3
FOR y = 1 TO 4
INPUT "Any number "; N%(x, y)
NEXT y
NEXT x
END
Here, the number of rows is 3 and number of columns is 4. So, the data will be stored
in the following format.

N(1,1) N(1,2) N(1,3) N(1,4)


N(2,1) N(2,2) N(2,3) N(2,4)
N(3,1) N(3,2) N(3,3) N(3,4)

Summary
The array is a data structure that holds a collection of data, all of the same type and
accessed using a common name.

 Types of Array: One-dimensional, Two-dimensional

Computer Science : Grade 9 265


 Array is declared using DIM statement.
 Array makes sorting and searching the data easy and fast.

Exercises
1. Answer the following questions:
a) What is an array? Write down its advantages.
b) Differentiate between one-dimensional and two-dimensional array.

2. Write down the QBASIC code for the following problems:


a) Write a program that asks any 10 numbers and stores into an array and find
their sum and average.
b) Write a program that asks any 10 numbers and stores into an array and
displays the smallest number among them.
c) Write a program that asks any 10 numbers and displays them in descending
order.
d) Write a program that stores name and email address of 5 students and stores
them in a two-dimensional array and display all the data in a tabular form.

266 Computer Science : Grade 9

You might also like