Professional Documents
Culture Documents
N
GATEWAY
TO
9
1. New Gateway to Computer Science-1
2. New Gateway to Computer Science-2
3. New Gateway to Computer Science-3
4. New Gateway to Computer Science-4
5. New Gateway to Computer Science-5
6. New Gateway to Computer Science-6
7. New Gateway to Computer Science-7
8. New Gateway to Computer Science-8
9. New Gateway to Computer Science-9
10. New Gateway to Computer Science-10
NEW GATEWAY
TO
COMPUTER SCIENCE
9
Authors
Dinesh Adhikari
Dilendra Prasad Bhatta
Shekhar Poudel
Laxman Adhikari
© : Publisher
No part of this book may be reproduced or transmitted by means (electronic, photocopying,
recording or otherwise) without prior written permission from the publisher. Any breach of this
condition will entail legal action and prosecution.
Printed in Nepal
Preface
Along with the evolution of human beings new thoughts, area of knowledge and
technology also developed together. Among the eruptions, ICT (Information and
Communication Technology) is one which has unquestionably become important
part of human beings. A person is not better than a caged pigeon if s/he is far
from computer technology in this century. New Gateway to Computer Science is
a complete package which obviously supports a lot to the students as this is one
of the most useful textbook, so far available in the market.
This book is completely prepared considering the level of the students. This text has
various salient features like it focuses on child psychology, pictorial descriptions,
practical sections, let’s Review, sufficient exercise, etc.
Comments and constructive suggestions are highly welcomed from the readers
and professionals to update this text book.
Dinesh Adhikari
dinesh.nayaghare@gmail.com
Content
Introduction to computer
Defination of computer
Characteristics of computer
Advantages and disadvantages of computer
Working principles of computer
Applications area of computer
The word ‘computer’ comes from the word ‘compute’, which means, “to calculate”.
Hence, people usually consider a computer to be a calculation device that can perform
arithmetic and logical calculations at a very high speed.
Nowadays computers have become an integral part of our lives. They play a vital role in
everyone’s life; their importance is so amazing that without it we will not be able to live
the way we do. They are basic tool of human beings these days. Computers have changed
the way that people work. Computers can handle many tasks in business, education,
manufacturing and other so many fields. Computer is an electronic machine/device which
can input data, process them according to the instruction given and then give out the
meaningful information.
The data consists of numbers, text, sound, images, animations, and video.
The process converts numbers, text, sound, images, animations, and video (data) into
usable data, which is called information.
The information consists of numbers, text, sound, images, animations, and video that
has been converted by the process.
The data can be given using an input device.
The Central Processing Unit (CPU) converts data into information.
The information can be displayed by an output device.
A storage device is a device for storing data and information. A basic computer
consists of four components: an input device, a CPU, output devices, and memory.
A computer is a programmable machine. It allows the user to store information and then
‘process’ that information, or data, with the help of instructions provided by the user. It is
also an electronic device that receives data from the input devices and processes the data,
to display the correct output which is always meaningful.
The computer is also called a data processor because it can store, process, and retrieve
data whenever needed. The activity of processing data using a computer is called data
processing. Data processing consists of capturing input data, manipulating the data, and
managing output results.
Characteristics of Computer
Speed
A computer can work very fast. It takes only few seconds for calculations but humans
take hours to complete their work. It can execute millions of instructions within Nano or
Pico second or even more than that. The speed that a CPU works at is measured in hertz
(Hz). Modern processors run so fast in term of gigahertz (GHz). One gigahertz is one
billion cycle per second. The following are the speed measurement units of computer.
Accuracy
The accuracy of results computed by a computer is very high. Due to digital
techniques the error is very less. The errors in computing may be due to logical mistakes
by a programmer or due to inaccurate data. The degree of accuracy of computer is very
high and every calculation is performed with the same accuracy but the degree of its
accuracy depends upon its design. If the input data is incorrect, the output will be incorrect
which is called GIGO (Garbage in Garbage Out).
No Intelligence
Computers do not have their own intelligence. They follow a set of instructions fed into
them by manufacturer. The user knows what to do and when to perform a specific task.
Computer in Education
Computers are commonly used in school and college for teaching and learning activities. A
teacher can make his teaching techniques easier and interactive with the help of computer
tools. Students can also use computer as their learning tools. They can search various
topics on the internet. Teachers also can take help of the internet to do research work so
that they can collect lots of ideas and information about learning process. A teacher can
prepare a slide and demonstrate it in the class. Students also can do research work in their
various subjects that they require. Computer Based Learning (CBL) and Internet Based
Learning (IBL) are more popular these days. Because of the use of computer online and
distance learning is also possible and has been implemented in our education system.
Computer in Bank
Computers are massively used in bank these days. With
the help of computers, we can keep records of customers;
we can calculate the money; check the balance, verify the
signature, deposit and withdraw money. Online banking,
mobile banking, ATM card, Electronic Fund Transfer
system are also available because of the use of computer
at bank.
Computer at Hospital
Hospitals use computers to keep the records of patients,
doctors and staff. These days, computers are used to
keep and display the duty roster of doctors. Computers
are used to check the various internal organs of human
so that it is easy to find out the health problems. X-Ray
, CT-Scan, test of heart, test of kidney, endoscopy,
ultrasound, etc. are possible to do within a second with the
Social Networking
Social networking sites like Facebook, Twitter and LinkedIn allow users to rapidly
generate content for people in their network to view. Rather than sending individual notes,
social networking provides us with a constant stream of updates and information. These
tools have taken communication a step further than email due to their ability to instantly
communicate life and status updates to an entire network of people who can respond and
comment in real time.
Let’s Review
The following are the modern application areas of computer.
computer in education
computer in bank
computer for entertainment
computer at hospital
computer in science and technology
computer in communication such as social networking, video chat, internet and
email.
2 Types of Computer
There are different types of computers available these days. The function of each type of
computer is to process the data and provide the users with output. However, the methods
used by these computers to process and handle the data may be different. Generally,
there are two types of computer they are general purpose computer and special purpose
computer. A general purpose computer can perform any kind of jobs with equal efficiency
simply by changing the application program stored in its main memory. A special purpose
computer is designed to perform only one special task. The program or instructions set is
permanently stored in special purpose computers.
Computers are broadly classified into the following four groups such as; on the basis of
work/function, size, brand, and model. Let’s discuss them in detail.
Analog Computer
An analog computer is that computer, which is used to process
continuous data.These computers are very fast in their operation and
allow several other operations to be carried out at the same time.
However, the results produced by these computers are not accurate.
Analog computers can be used in scientific and industrial applications
such as measure the electrical current, frequency and resistance of
capacitor, etc. They perform arithmetical operation by measurable
quantities, such as mechanical movement, the rotation of gears rather
than by number. In analog computers, data are transmitted for their operation in the form
Digital Computer
The digital computer is also known as the digital
information processing system. It is a type of computer that stores
and processes data in the digital form. Therefore, each type of
data are usually stored in these computers in the terms of 0 and
1. The output produced by these computers is also in the digital
form. The digital computers are also capable of processing the
analog data. However, the analog data should be first converted
to the digital form, before being processed by these computers.
Similarly, if we want the output in the analog form, the digital information produced
by these computers should be first converted to an analog form. These conversations
are generally carried out by the in-built components of digital computers. The different
hardware components of a digital computer are an Arithmetic- Logic Unit, a Control Unit
(CU), a memory unit and I/O units. IBM PC, Apple/Macintosh, etc. are the examples of
digital computers.
Hybrid Computer
A hybrid computer combines features of both analog and digital
computers. In this computer, some calculations are done in the analog
portion and some are done in the digital portion of the computer. The
hardware components of hybrid computers are usually the mixture
Let’s Review
Generally there are two types of computer they are general purpose computer and
special purpose computer.
An analog computer is that computer, which is used to process continuous data.
The digital computer is also known as the digital information processing system.
The hardware components of hybrid computers are usually the mixture of analog
and digital components.
Supercomputer
A super computer is the fastest type of computer that can
perform complex operations at a very high speed. It is the
most powerful computer in terms of performance and data
processing. It is specialized and task specific computer
used by large organizations. The super computers were first
presented in the year 1960AD by Seymour Cray at Control
Data Corporation (CDC). These computers are used in
research and for exploration purposes. The supercomputers
are very expensive and very large in size. It can be accommodated in large air-conditioned
rooms; some super computers can span an entire building. Some popular supercomputers
are IBM’s Sequoia, Fujitsu’s K, IBM’s Mira, IBM’s Super MUC, NUDT Tianhe-1A,
CRAY-3, Cyber 205, NEX SX-3, PARAM, etc.
Minicomputer
A minicomputer was first introduced in the year 1960 AD by
Digital Equipment Corporation (DEC). They were called mini
computers because they were smaller than the other computers
of those times. Minicomputers are used by small businesses and
firms. Minicomputers are also called “Midrange Computers”.
These computers are not designed for a single user. Individual
departments of a large company or organizations use mincomputers for specific purposes.
Mini computers can also be used as the web servers that can handle thousands of
transactions in a day. These computers are less expensive than mainframe computers. The
popular minicomputers are K-202, Texas Instrument TI-990, SDS-92, IBM 8000 Series,
PDP 11, VAX-7500, etc.
Mainframe Computer
A mainframe computer is a very large computer that is employed
by large business organizations for handling major applications
such as financial transactions, Enterprise Resource Planning
(ERP), industry and consumer statistics, census, etc. Mainframe
computers are not as powerful as supercomputers, but they are quite
expensive. Many large firms and government organizations use
mainframe computers to run their business operations. The Mainframe computers can be
accommodated in large air-conditioned rooms because of their size. As super-computers
are the fastest computers with large data storage capacity, Mainframe computers can also
process and store large amount of data. Banks, educational institutions and insurance
companies use mainframe computers to store data. Example of mainframe computers are
IBM 3000, VAX 8000 and CDC 66000, Fujitsu’s ICL VME, Hitachi’s Z800, etc.
Let’s Review
A supercomputer is the most powerful computer in terms of performance and
data processing.
Minicomputers are also called “Midrange Computers”.
A mainframe computer is a very large computer that is used by the large
business organizations.
Many large firms and government organizations use mainframe computers to
run their business operations.
Microcomputer
A microcomputer is a small and cheap digital computer that is
designed to be used by individuals. Desktop computers, laptops,
personal digital assistant (PDA), tablets and smartphones are
the types of microcomputers. The micro-computers are widely
used and the fastest growing computers. These computers
are the cheapest among the other types of computers. The
micro-computers are specially designed for general use. Microcomputers also include
several software programs such as operating system, system software and utility software.
The popular microcomputer manufacturing companies are IBM, Dell, Apple, Samsung,
Son, Toshiba, etc.
Types of Microcomputers
Desktop Computer
The desktop computer systems are designed to be used by
an individual at a single place. The desktop computer uses
keyboard, mouse, monitor, hard disk, peripheral devices and
system unit. These computers are very cheap and an individual
can easily purchase them for home or business use. The different
manufactures of desktop computers are Apple, IBM, Hewlett-
Packard(HP), etc.
Hand-Held Computer
Hand-held computer is also known as Personal Digital Assistant (PDA), converged
device, palmtop or mobile device. It is a very small sized computer that can be kept in
pocket. It has a small display screen and it uses input device like an electronic stylus or
finger. The storage capacity of hand-held computers is not very large. They generally use
small cards to store data and programs instead of disk drives. Therefore, they are less
powerful as compared to the desktop and laptop computers. Different examples of hand-
held computers are Apple Newton, Casio Cassiopeia, Franklin eBook Man, Samsung, etc.
Let’s Review
A microcomputer is a small and cheap digital computer that is designed to be
used by individuals.
The desktop computer systems are designed to be used by an individual at a
single place.
Laptop computer is also known as notebook, notepad or mobile computer.
The hand-held computer is a very small sized computer that can be kept in pocket.
There are three types of computers on the basis of brand which are explained below.
IBM PC
The computers that are manufactured by IBM (International
Business Machine) are IBM PC. It is one of the leading companies
of the world manufacturing computers. IBM was established in 1924
and started manufacturing mainframe, mini and microcomputer
from 1945 onwards. IBM PC is the brand name of the first popular
IBM Compatibles
The computers that are manufactured by the other computer
manufacturing companies but have the same technology and
features are known as IBM Compatibles computers. The term
compatible means “Able to exist together and work successfully”.
IBM compatible computer system is assembled form of different components developed
by different companies. It is based on IBM principle that can use standard hardware and
software designed for the IBM PC and its own additional features. Some IBM compatible
computers are AST, ALR, Sherry, etc.
Apple Macintosh
The computers that are manufactured by Apple Company
but have different architecture and configuration than
IBM Compatibles are known as Apple Macintosh. Apple
Macintosh computers were introduced by Steve Jobs and
Steve Wozniak of Apple Inc. on January 24, 1984. The first
computer was called Mac 128K. This computer has its own operating system which is
called Mac OS.
There are three types of computers on the basis of model which we are going to discuss
below.
XT Computers (Extended Technology)
The computers having 8086 or 8088 microprocessor and processing speed of 4.77 MHz
are known as XT Computers. These computers are out-dated now because they cannot run
on latest software versions.
AT Computers (Advanced Technology)
The computers having 80286 or later versions of microprocessors are known as AT
computers. Their storage capacity as well as speed is much higher than XT computers.
Besides that they have math co-processor to support main processors to perform complex
mathematical calculations.
PS/2 Computers (Personal System 2)
IBM developed another model of computer in 1990 that have more advanced architecture
design than AT computers. They are known as PS/2 computers. They are more faster than
AT computers. Most of the laptop computers based on PS/2 model use OS/2 or UNIX
operating system and 1.44 MB floppy diskette.
Let’s Review
The computers that are manufactured by IBM are IBM PC.
The term compatible means “Able to exist together and work successfully”.
Apple Macintosh computers were introduced by Steve Jobs and Steve Wozniak of
Apple Inc. on January 24, 1984.
The three types of computer on the basis of model are XT, AT and PS/2.
3 Computer System
A computer is the collection of parts, which are categorized on the basis of work that they
do. A computer is a system, an interrelated combination of components that performs the
basic system functions of input, processing, output, storage, and control, with a powerful
information processing tool. Computer systems include any software and peripheral
devices that are necessary to make the computer function. A computer system allows
users to input, manipulate and store data. Computer systems typically include a computer,
monitor, keyboard, mouse and other components. Without the programs, the computer
would not know how to process data that enters the system, and the data might be
discarded. It is very flexible, as it can process any task by loading a program from storage.
Computer systems can work by themselves or access other devices that are external or
connected with other computer systems.The major components of computer system are
explained below.
Software is a set of instructions that tells the computer what to do and when to do it.
The computer uses this instruction to manipulate data, and enhance the proper
functioning of the hardware components. It is designed to provide the potential capabilities
of the hardware to the user. It converts data into information and allows users to use
the computer in different ways. Computer programs are written by human beings.
The person who writes a program also decides on its functionality and behaviour. Software
also governs how the hardware is utilized; for example, how information is retrieved
from a storage device. The interaction between the input and output devices is controlled
by software which is called the Basic Input Output System (BIOS) software. Software
as a whole can be divided into a number of categories based on the types of work done
by programs. The two primary software categories are system software, and application
software.
Data Information
Data are used as input for the computer Information is the output of data.
system.
Data are unprocessed facts figures. Information is processed data.
Data don’t depend on Information. Information depends on data.
Data are not specific. Information is specific.
Data don’t carry a meaning. Information must carry a logical meaning.
Data are the raw material. Information is the product.
Understanding Users
People who are the computer operators are also known as users. A user is a person
who uses a computer or computing devices. The most majority of computer users are
application oriented. They have traing and experence with some computer basis sofware.
They understand the general concept of computer such as files and folder management,
storing, saving and editing the documents and so on. The person who uses the software
or hardware after it has been fully developed, marketed and installed are called the End
user. The term 'user' and 'end user' is the same thing. End users are seprate group from the
installer or administrators of the product. End users are usually support staff, management
professionals, data processing staff and end-user support personnel. We can say that end
users are not trained programming professionals.
Let’s Review
Input unit provides or fetches information and instructions to the computer.
An output unit consists of hardware that transfers information from the computer’s
CPU to the computer user.
Storage units provide permanent storage of information and programs for
retrieval to the computer.
Computer programs are written by human beings.
The interaction between the input and output devices is controlled by software
called the Basic Input Output System (BIOS) Software.
Data are the facts or details from which information is derived.
Information is processed data.
Assignment
1. Select the correct answer from the given options.
a. Which of the following is related to computer hardware?
i. Windows OS ii. Output devices iii. Software programs iv. Device driver
b. Which of the following is memory unit?
i. RAM ii. Motherboard iii. Power supply iv. Input devices
c. Which of the following is input unit?
i. OCR ii. MICR iii. OMR iv. All of them
d. Which of the following section is used to perform arithmetic and logical
calculations?
i. CU ii. MU iii. ALU iv. None of them
e. Which of the following is a permanent storage unit?
i. RAM ii. Hard drive iii. Input units iv. Output unit
2. Fill in the blanks with suitable words.
a. A ……………….. allows users to input, manipulate and store data.
b. CPU is also known as the ………………. of the any computer system.
c. ……… unit maintains the sequence of operations being performed by the CPU.
d. An ……………… unit consists of hardware that transfers information from the
computer’s CPU to the computer user.
e. ……………… are the facts or details from which information is derived.
f. ………………… is processed data.
3. State whether the given statements are true or false.
a. Computer software refers to the physical units or machine of functional units,
which makes up the computer configuration.
Understanding Motherboard
Understanding Microprocessor
Understanding Memory
Memory is one or more sets of chips that store data and program instructions, either
temporarily or permanently. Memory is a critical processing component in any computer
system. Personal computer uses several types of memory, but they use two most
important memory they are RAM and ROM which are included in primary memory.
These two types of memory work in very different ways and perform distinct function.
Primary memory is only not sufficient
in computer system but also we must Let’s Review
have secondary memory for storage. Characteristics of Main Memory
Here, we are going to discuss the types These are semiconductor memories.
computer memory. It is known as the main memory.
Primary Memory Usually volatile memory.
Data are lost in case power is switched
Primary memories are called the off.
main memory that is used to store
It is the working memory of the
data and instructions currently
computer.
required for processing. These
memories are manufactured by They are faster than secondary
using integrated electronic circuits memories.
or semiconductor device. It has A computer cannot run without the
limited capacity and data are lost primary memory.
Cache Memory
It is a small, fast and expensive semiconductor memory that stores the copies of data that
needs to be accessed frequently from the main memory. It acts as a buffer between the
CPU and the main memory. It is used to hold those parts of data and program which are
most frequently used by the CPU. The cache memory is always placed between CPU and
the main memory of the computer system. The transfer of data between the processor and
the cache memory is bidirectional. The availability of data in the cache is known as cache
hit. The capability of a cache memory is measured on the basis of cache hit.
Secondary Memory
This type of memory is also known as external memory or non-volatile memory. It is
slower than the main memory. This memory is permanent in nature. It is used for storing
data and information permanently. It is used to store different programs and the information
permanently. It holds the information till we erase it.CPU directly does not access these
memories; instead they are accessed via input-output routines. The contents of secondary
memories are first transferred to the main memory, and then the CPU can access it. Disk,
CD-ROM, DVD, etc. are the popular Let’s Review
secondary memories. The following are
the characteristics of secondary memory. Primary memories are called the
main memory that are used to store data
These are magnetic and optical
and instructions currently required for
memories.
processing.
It is known as the backup memory.
RAM is a volatile memory of the
It is a non-volatile memory. computer system.
Data is permanently stored even if ROM is called non-volatile memory
power is switched off. because it never loses its contents.
It is used for storage of data in a The contents of secondary memories
computer. are first transferred to the main
These are slower than primary memory, and then the CPU can access
memories. it.
Cache memory acts as a buffer between
Types of Secondary Memory the CPU and the main memory.
Magnetic Storage Device
Magnetic storage can be defined as the storage system that stores the data on a magnetised
medium with the help of magnetised particles. This type of memory is also known as
external memory. It is used for storing data and information permanently. There are many
types of computer storage, but the most common is the magnetic storage device. Magnetic
tapes, magnetic disks, hard disk, floppy disks, etc. are the examples of magnetic storage
system. The magnetic storage systems are non-volatile. Let’s discuss some magnetic
storage devices.
Advantages
It has low cost.
It has large storage capacity.
It is easily transportable.
It is very easy to handle and store.
Disadvantages
It has low data transmission speed due to sequential access.
It is not suitable for random access.
It requires protected environment for storage.
It is very difficult for updating, editing and deleting data.
Hard Disk
Hard disk is the main storage device of the computer which is fixed inside the CPU box.
Its storage capacity is very high that varies from 10 GB to 3 TB or even more than that.
As it is fixed inside the CPU box, it is not easy to move the hard disk from one computer
to another. A hard disk contains a number of metallic disks which are called platters.
Information is recorded on the surface of the platters in a series of concentric circles.These
circles are called Tracks. The hard disk platters spin at a high rate of speed, typically 5400
to 7200 revolutions per minute (RPM). The following are the basic components of hard
disk.
Disk platters
Read/ Write head
Head actuator mechanism
Logic board
Cable and connectors
Jumper/switches
Spindle motor
Data in the computer’s memory are represented by two digits 0 and 1.These two digits are
called Binary Digits or Bits. A bit is the smallest unit of computer’s memory. To represent
each character in memory, a set of 8 binary digits is used. This set of 8 bit is called a Byte.
So, one Byte is used to represent one character of data.
To represent a large amount of data in memory, higher data storage units are used
like KB (Kilobyte), MB(megabyte), GB(Gigabyte), TB(Terabyte), PB(Petabyte), etc.
Let’s discuss the memory units in detail.
Bit (Binary Digit): A binary digit is logical 0 and 1 representing a passive or an active
state of a component in an electric circuit.
Byte: A group of 8 bits is called byte. A byte is the smallest unit, which can represent a
data item or a character.
Word: A computer word, like a byte, is a group of fixed number of bits processed as a unit,
which varies from computer to computer but is fixed for each computer. The length of a
computer word is called word-size or word length. It may be as small as 8 bits or may be
as long as 96 bits. A computer stores the information in the form of computer words.
Below are the lists of all the standard units of measurement used for data storage, from
the smallest to the largest.
Input Devices
All computer peripheral devices which are used to input data and instructions to the
computer are called input devices. They are electromechanical devices that are used
to provide data to a computer for further processing. Input devices accept data and
instructions from the user and convert instructions or data in to a form which can be
understood by the computer. The basic task of an input device is to take the input from the
user and translate it into the machine readable from and then present it to the processing
unit of the computer for execution. A good input device should provide accurate, timely
and useful data to the main memory of the computer for processing.
Mouse
A mouse is a small hand-held ‘point and click’ device that basically
controls the two-dimensional movement of the cursor on the
displayed screen. It is connected to the CPU through a cable. It
was developed by Douglas Engelbart in 1963 AD. It is generally
used with personal computer. It rolls on a small ball and has two or
three buttons on the top. There are mainly two types of mouse they
are mechanical mouse, and optical mouse.
Mechanical mouse: A mechanical mouse consists of three buttons: left button, right button
and scroll button. Inside the plastic coating of the mouse, there is a ball, which is rolled
over a flat surface corresponding to which the cursor moves on the display screen.
Optical mouse : An optical mouse is a pointing input device in which the reflected light
determines the movement of the cursor on the displayed screen. The upper portion of the
optical mouse is similar to that of the mechanical mouse. The lower portion of the optical
mouse consists of a ball having Light Emitting Diodes (LEDs), an optical sensor and a
Digital Signal Processor (DSP).
Light Pen
It is an electro-optical pointing device that is used for selecting objects
on the display screen with the help of light sensitive pen. Light pen
consists of a stylus connected by a cable to the computer terminal. When
the stylus is brought into contact with the screen, a dot appears there on
the screen. By moving the stylus lines and curves can be drawn on the
screen. A light pen is similar to a mouse. With a this, you can move the pointer and select
objects on the display screen by directly pointing to the objects.
Scanners
Scanner is an input device that optically “reads” an image and
converts it into a digital signal. These are direct-entry input devices.
As the data entry is automatic, the scanners ensure more accurate
data entry. These scanners include optical scanners and magnetic
ink character readers. The optical scanners use light for sensing
input and they include OCR, OMR, Barcode reader, etc.
Touch pad
A touchpad is also called trackpad. It is a flat control surface used
to move the cursor and perform other functions on a computer.
Touchpads are commonly found on laptops and replace the
functionality of a mouse. A touchpad is designed to be controlled
with your finger. Similar to a mouse, touchpads can detect
acceleration as well as linear motion. This allows you to have refined control with slow
movements and quickly move the cursor across the screen using a fast motion.
Digital Camera
A digital camera is a handheld electronic device that is used to capture
the image of an object electronically. The digital camera consists of a
built in computer, which helps in recording the images electronically.
Whenever a user initiates the process of capturing an image by pressing
the button available on the camera, the image light enters the camera through the lens.
Microphone
It is an input device that basically converts the sound waves into
electrical signals with the help of sensors. The sound wave pattern
is converted into electrical pattern, which is either in the form of voltage or current. The
microphones are also called transducers as they transform one from of signal into another.
Digitizer Tablet
A digitizer tablet is a peripheral device that allows users to draw on
a computer screen. Tablets are typically used by artists working with
Let’s Review
A bit is the smallest unit of computer’s memory.
Input devices accept data and instructions from the user and convert information
or data in to a form which can be understood by the computer.
A mechanical mouse consists of three buttons: left button, right button and scroll
button.
Keyboard is the most popular input device for direct entry of data and instructions
into the computer.
Light pen consists of a stylus connected by a cable to the computer terminal.
The first joystick was invented in the U.S. by C. B. Mirick and patented in 1926.
Scanner is an input device that optically “reads” an image and converts it into a
digital signal.
OMR reads the presence or absence of a mark on a paper optically.
The barcode reader uses an optical scanner to read product code and converts it into
electrical pulses.
A digitizer tablet is a peripheral device that allows users to draw on a computer
screen.
A touch screen is an input device of an information processing system.
A QR code consists of black squares arranged in a square grid on a white
background.
Output devices are used to display the result for the user. They receive the processed data
from the CPU and present it to the user in desired format. Output devices are pieces of
computer hardware used to communicate the results of data processing performed by a
computer. Output hardware is responsible to convert the machine readable information
into human readable format that may be in the form of text, audio, graphics or video.
Types of Output Devices
There are two types of outputs which are explained below.
Softcopy Output
Soft copy is an electronic display of digital information. The soft copy devices allow the
viewing of information that can be rearranged, modified or corrected as the requirement
of the user. Some types of softcopy output devices are explained below.
Monitors / Display Units
These are the most commonly used softcopy output devices. They display character and
graphics on the screen. Different types of display monitors use different technology for
displaying the data. Let’s discuss different types of monitors.
Let’s Review
Output devices are computer hardwares used to communicate the results of
data processing performed by a computer.
The soft copy devices allow the viewing of information that can be rearranged,
modified or corrected as per the requirement of the user.
An LCD monitor is small in size and light in weight so it occupies less space on the
desk.
A CRT monitor has high contrast ratio colour depth because of which it displays the
actual colour.
An LED is an electronic device that emits light when an electrical current is
passed through it.
Hardcopy Output
A hard copy is a printed copy of information from a computer. The output that we get
from a printer or a plotter on a paper is also known as hardcopy output. Hardcopy output
are permanent outputs which we cannot edit, modify and change easily. We can use
hardcopy output for a long time as well. Let’s discuss some types of hardcopy output.
Printer
A printer is an external output device that takes data from a computer
and generates output in the form of graphics and text on the paper.
There are two types of printers which we are going to discuss below.
Impact Printers
Impact printers are those printers in which mechanical contact
between print head and paper exists. It usually forms the print image
by pressing an inked ribbon against the paper using a hammer or pins.
Dot-Matrix Printers
The dot-matrix printer uses print heads containing 9 to 24 pins.
These pins produce patterns of dots on the paper to form individual
characters. The 24 pin dot-matrix printer produces more dots that
a 9 pin dot-matrix printer, which results in much better quality and
clearer characters. The pins strike the ribbon individually as the print mechanism moves
across the entire print line in both directions. Dot-matrix printers are inexpensive and
typically print at the speed of 100-600 characters per second.
Daisy-wheel Printer
A daisy wheel printer is an impact printer that produces printout of
good quality character. It contains a metal or a plastic disk on which
the character reside on the outer edge of the petals. These printers are
capable of printing text only and not graphics. They are noisy as well
as very slow and can print approximately 10 to 75 characters per second.
Chain Printer
A chain printer uses a chain of print characters wrapped around two pulleys. Like the
drum printer, there is one hammer for each print position. The hammer then strikes the
page, pressing the paper against a ribbon and the character located at the desired print
position. The chain keeps rotating until all the required print positions on the line have
filled. Speeds of chain printers range from 400 to 2500 characters per minute.
Drum Printer
A drum printer consists of a solid, cylindrical drum that has
raised characters in bands on its surface. The number of print
positions across the drum equals the number available on the
page. This number typically ranges from 80-132 print positions.
Typical speeds of drum printers are in the range of 300 to 2000 lines per minute.
Non-Impact Printers
Non-impact printers are the printers in which mechanical contact between the print head
and paper does not exist. These printers spray ink on the paper with the help of nozzle.
Non-impact printers do not produce much noise than the impact printers. These printers
are faster than the impact printers. Some of the popular non-impact printers are explained
below.
Laser Printer
Laser printers are the popular non-impact printers that produce
images with the help of laser beam. It works like a photocopy
machine. Laser printers produce images on paper by directing a
laser beam at a mirror which bounces the beam onto a drum. The
drum has a special coating on it to which toner (an ink powder)
sticks. Using patterns of small dots, a laser beam conveys information from the computer
to a positively charged drum to become neutralized. Laser printers have a high speed and
resolution. They produce high quality printing without producing any noise.
Plotter
Plotter is a device used to print high quality images
and graphics. It uses one or more pens to produce a high quality
drawing. Plotters were the first type of printers that could
print with colour and render graphics and full-size engineering
drawings. Plotters are much more expensive than printers. They
are most frequently used for CAE (Computer Aided Engineering) applications, such as
CAD(Computer Aided Design) and CAM (Computer Aided Manufacturing). Instead
of toner, plotters use a pen, pencil, marker, or another writing tool to draw multiple,
continuous lines onto paper rather than a series of dots like a traditional printer.
Speaker
Speakers are popular output devices used with computer systems.
They receive audio input from the computer’s sound card and
produce audio output in the form of sound waves. Most computer
speakers are active speakers, they have an internal amplifier which
allows to increase the volume, or amplitude, of the sound. Speakers usually come in a
pair, which allows them to produce stereo sound from two separate audio channels.
Assignment
1. Select the correct answer from the given options.
a. Which of the following is a computer hardware?
i. Keyboard ii. Monitor iii. Mouse iv. All of the above
b. Which of the following helps to install the processor into the motherboard?
i. CPU socket ii. RAM iii. AT connector iv. Expansion cards
A computer system consists of hardware, the electronic devices that are capable of
computing and manipulating information, and software that carries out predefined tasks
to complete a given task. All computer systems consist of two major components that
are hardware and software. Hardware is the physical component and software is a set of
computer programs which enable hardware to function. We can say that software gives life
to the hardware and therefore, the software is popularly referred to as the soul of the computer
system while the hardware like the heart. We can define, software as the collections
of program and other associated documents that helps to control, manage and integrate
the components of computer system to accomplish a specific task. Computer system is
nothing without the software.
The computer software mainly performs two varieties of tasks. The first task is to control
and coordinate the hardware components and manage their performance and the second
one is to enable the users to accomplish their required task. Different types of computer
softwares are discussed below.
System Software
System softwares are those programs that manage the operating system with the
coordination of computer hardware and their resources. Systems software is a set of
instructions that serves mainly as an intermediary between computer hardware and
application programs. Systems software provides important self regulatory functions for
computer systems, such as loading operating system, managing hardware resources and
providing commonly used sets of instructions for all applications to use. System software
includes:
Operating system
Utility programs
Device drivers
Operating System
Operating sytem is a computer system software that acts as an intermediate between the
user and computer hardware. It controls and co-ordinates the overall operations of the
computer. This is the first software that we see when we turn on the PC. It manages the
computer's memory and co-ordinates with computer software and hardware. What we
can say is that, without an OS computer is just useless. The OS usually comes pre-loaded
on any computer when we purchase it. Most of the people uses the OS that comes with it
but they can change or upgrade as their requirements. Modern OS uses a graphical user
interface system so that it is very easy to use and operate. The OS provides services such
as process management, file management, etc.
Functions of an Operating System
Process Management: Process management means managing the programs that are
running on the processor at a given time. The operating system loads a program into
main memory and executes it. Some operating systems offer more sophisticated forms of
process management, such as multitasking, multithreading, and multiprocessing.
File Management: A file system is normally organized into directories for easy
navigation and usage. These directories may contain files and other directories. It keeps
track of information, location, uses, status, etc. It also allocates and de-allocates the
resources.
Let’s Review
Software is the collection of programs and other associated documents that helps
to control, manage and integrate the components of computer system to
accomplish a specific task.
Systems software is a set of instructions that serves mainly as an intermediary
between computer hardware and application programs.
Operating system provides services that include process management, virtual
memory, file management, security and the user interface.
A file system is normally organized into directories for easy navigation and
usage.
An OS provides an interface between user and machine.
Memory management refers to management of primary memory or main memory.
Device Drivers
A device driver is a software program that enables a specific hardware device to work
with an operating system. The device driver acts as a translator between the I/O devices. A
device driver may be required for internal components, such as video cards , optical media
drives as well as external peripherals, such as printers , monitors, etc.Most of the modern
hardware components are “plug and play,”. It means the devices will work without driver
installation. However, if a hardware device is not recognized by the operating system
itself we need to install the correct drivers so that the device functions properly.
Let’s Review
A real-time operating system must have well-defined, fixed time constraints,
otherwise the system will fail to work.
An operating system that allows a single user to perform just one task at a time
is called single user single tasking operating system.
A single-user, multi-tasking operating system is one that allows a single user to
perform two or more functions at a time.
UNIX is an example of a multiuser multitasking operating system.
Multitasking operating system is a powerful operating system that supports
more than one user at a time.
Utility programs refer to the small programs, which provide additional capabilities
to the computer system.
A device driver is a software program that enables a specific hardware device
to work with a computer’s operating system.
Most of the modern operating systems are Graphical User Interface (GUI) based. GUI is
a type of user interface that enables the users to interact with the operating system
by means of point-and-click operations. A GUI uses windows, icons, and menus to
carry out commands, such as opening, deleting, and moving files. Many GUI operating
systems are navigated through the use of a mouse; the keyboard can also be utilized
by using keyboard shortcuts or arrow keys. The GUI was first developed by Alan Kay,
Douglas Engelhard, and a group of other researchers in 1981 AD.
A windows desktop is the first display screen which appears when you load an operating
system. It has various icons like This PC, Recycle bin, Network, Control Panel, Internet
explorer, etc. The details of some default components of windows desktop are explained
below.
Recycle Bin: It temporarily stores deleted files until they are removed from the Recycle
Bin permanently.
Taskbar: It contains the minimized applications items like, documents, or other windows
which can be used to quickly switch from one program to another.
Notification Area: It is an area within the taskbar. It is used to indicate the time, as well as
display icons which may be used to quickly start programs, adjust settings, or determine
the status of a current task.
This PC: When we open this icon, it displays the components of the computer. It displays
disk drive, local hard drive, local CD, DVD, pen drive as well as network drives and
printers.
Network: When we open this icon, it displays all the resources available on the
network. It displays applications, data files, and printers. It also displays the computers in
your work group.
Internet Explorer: It is a default web browser application which is used to search and
browse internet content, web sites, etc.
User: When we open this icon it displays the files and objects which have been stored
within. My Documents is the default user storage folder for many software applications.
A dialog box is a user interface element that is used to communicate and interact between
a user and a software program. It is a movable window on the computer screen which
is seen when a user selects a menu option. There are two types of windows dialogue
box they are application window dialogue box and document windows dialogue box.
The application window dialogue box provides a framework for the whole application.
This can be opened, closed, resized, and moved around the desktop. All application
windows dialogue box are normally contained in the application windows. It also
contains the application menu bar and status bar. The document windows dialogue box
appears inside the application windows. A document window dialogue box is a section
of the screen used to display the contents of a document file on a GUI operating system.
Various components of dialogue box are title bar, status area, icon area, panel area, button
area, tab area, toolbar, menu area, etc.
The mouse is the primary input device which is used to interact with objects in windows.
A modern mouse typically has a primary button (left button), a secondary button (right
button), and a mouse wheel between the two. By positioning the pointer and clicking the
primary and secondary buttons on the mouse, users can select objects and perform actions
on them. The given table shows various mouse pointers with their functions.
Link select Used for text and graphics links because of their weak af-
fordance.
Text select Used for text to indicate a location between characters.
Working in back- Used to point, click, press, or select while a task com-
ground pointer pletes in the background.
Action Interaction
Pointing Place the pointer to a specific object without clicking any mouse buttons.
Place the pointer to a specific object without clicking any mouse buttons
Hovering
and without moving for at least a second.
Place the pointer to a specific, non-selectable object and press and release a
Clicking
mouse button without moving.
Place the pointer to a specific, selectable object and press and release a
Selecting
mouse button.
Place the pointer to a specific object and press a mouse button without re-
Pressing
leasing.
Wheeling Move mouse wheel.
File management is organizing and keeping track of files and folders. Windows
allows you to organize folders and files in a file hierarchy, like the way you store
paper documents in a record file. Just as a filing cabinet contains several folders,
each containing a set of related documents and folders together. A file hierarchy
allows you to place files in folders, then place folders in other folders, so that
your files are organized and easier to find. Windows provides you with a main file
management window called Windows Explorer. Windows Explorer provides access
to files, folders, drives, and disks on your local, Home group and network computers.
Let’s Review
A windows desktop is the first display screen which appears when you load an
operating system.
Taskbar contains the minimized application items like, documents, or other
windows which can be used to quickly switch from one program to another.
Internet Explorer is a default web browser application which is used to search
and browse internet content, web sites, etc.
A dialog box is a user interface element that is used to enable communication and
interaction between a user and a software program.
The application window dialogue box provides a framework for the whole
application. This can be opened, closed, resized, and moved around the desktop.
A document window dialogue box is a section of the screen used to display the
contents of a document file on a GUI operating system.
File management is an organizing and keeping track of files and folders.
Language Processor
A language processor is a type of a computer software program that has the capacity of
translating source code or program code into machine code. Language translator will
take a source program as input and then will convert it into object code so that it can be
understood by the computer. Different types of language processors are explained below.
Web application is a machine independent which is complex and a bit more different
than desktop application. In a web application, the application is loaded on the server
and lots of computers are connected with the server whose location is unknown.
In this application, user can use different applications without installing anything on the
personal computer. In this application data are remotely stored on the main server and
application can be accessed from any personal computers using any web browser.
There are various categories of apps available for the various users according to their
requirement. Some of the popular categories of apps are Gaming apps, Business apps,
Education apps, Life style apps, Utility apps, Entertainment apps, Travel apps, etc. Let's
discuss some types of apps below.
Mobile Apps
Mobile applications are also known as mobile apps. They are software programs
developed for mobile devices such as smart phones and tablets. Some of the devices come
preloaded with some mobile apps of their manufacturers or the mobile service providers
with which they are associated. Many more apps are available through device-specific
app stores. Apps are generally small, individual software units with limited function.
The use of apps software was popularized by Apple Inc. and its App Store, which offers
thousands of applications for the iPhone, iPad and iPod Touch. A mobile application also
may be known as an app, web app, online app, iPhone app or smart phone app. Some
types of mobile apps are listed below.
Native Apps
Native apps are developed for a single mobile operating system therefore they are
“native” for a particular platform or device. App built for systems like iOS, Android,
Windows phone, Symbian, Blackberry cannot be used on a platform other than their own.
In other words, you won’t be able to use Android app on iPhone.
Let’s Review
Desktop application is a machine dependent program that runs on a personal
computer device such as a desktop, laptop and personal workstations.
Web application is a independent machine which is more complex and a bit
different than desktop application.
There are various categories of apps available for various users according to their
requirement. Some of the popular categories of apps are Gaming apps, Business
apps, Education apps, Lifestyle apps, Utility apps, Entertainment apps, Travel
apps, etc.
Mobile applications are also known as mobile apps.
They are built using multi-platform web technologies such as HTML5, CSS and
Javascript.
Unit
There are various types of graphics file formats. Each type stores graphics data in a
different way. Raster, vector and metafile formats are most commonly used file formats.
Let’s discus some major file formats.
Let’s Review
The computer graphics is one of the most effective and commonly used ways to
communicate the processed information to the user.
Computer graphics is an art of drawing pictures on computer screens with the
help of various computer graphics programs.
Graphic designing software are used by graphic designers to create images in
different ways, to edit images, to create video, audio, images, etc.
There are various different types of graphics file formats. Each type stores
graphics data in a different way.
Bitmap graphics are also called raster files.
Vector graphics file formats are particularly useful for storing line-based
elements, such as lines and polygons.
Metafiles can contain both bitmap and vector data in a single file.
Choose the required image and click on Open button to display the image.
Select the location where you want to store your picture from Save in: options.
Type required file name in File name box and select the required file Format
that you want.
Finally click on Save button to save your image.
Photoshop Photoshop PDF files are extremely versatile, as they may contain
PDF bitmap and vector data. Images saved in the Photoshop PDF format
can maintain the editing capabilities of most Photoshop features,
such as vector objects, text, and layers, and most colour spaces are
supported. These files can be opened by users with the free Adobe
Reader software.
Pixel: A pixel is the smallest unit of a digital image or graphic that can be
displayed and represented on a digital display device. A pixel is also known as a picture
element. It is the basic logical unit in digital graphics. Pixels are combined to form a
complete image, video, text or any visible thing on a computer display. It is represented
by a dot or square on a computer monitor display screen. Depending on the graphics card
and display monitor, the quantity, size and colour combination of pixels vary and are
measured in terms of display resolution.
Resolution: Resolution is the sharpness and clarity of an image or picture. It is used to
measure the quality of monitors, printers, digital images and various other hardware and
software technologies. The resolution of monitor is measured by the number of pixels.
Printers also have a measure of resolution called DPI (dots per inch).
Let’s Review
Adobe Photoshop is an image editing software which allows the users to create
and edit raster images in multiple layers.
Photoshop has various tools for creating and editing picture.
JPEG is a common format for digital camera photographs and the primary format
for full-colour images shared on the web.
GIF files are used to display limited colour graphics on the Web.
The PNG format allows for use of millions of colorus as well as provides the
ability to have transparent backgrounds.
The Photoshop format (PSD) is the default file format.
TIFF supports most colour modes and can save images with alpha channels.
Photoshop PDF files can be opened by users with the free Adobe Reader software.
A pixel is the smallest unit of a digital image or graphic that can be displayed and
represented on a digital display device.
A pixel is also known as a picture element.
Resolution is the sharpness and clarity of an image or picture.
Resampling is the process of changing the amount of image data as you change
either the pixel dimensions or the resolution of an image.
In the above dialouge box, A. Original dimensions and resolution B. Decreasing the
resolution without changing pixel dimensions (no resampling) C. Decreasing the
resolution at same document size decreases pixel dimensions (resampling).
When we start Photoshop, we can see the tools panel. The tools panel appears at the left of
the screen. Some tools in the tools panel have options that appear in the context-sensitive
options bar. You can expand some tools to show hidden tools. A small triangle at the lower
right of the tool icon signals the presence of hidden tools.
Measurement Tools
Eyedropper Tool * ( I )
The Eyedropper Tool samples colours in an image. Increase "Sample Size" in
the Options Bar for a better representation of the sampled area's colour.
Paint over areas with the Sponge Tool to increase or decrease colour saturation.
Navigation Tools
Hand Tool * ( H )
The Hand Tool helps to click and drag an image around on the screen to
view different areas when zoomed in.
Rotate View Tool ( R )
You can use the Rotate View Tool in Photoshop to rotate the canvas, so you can
view and edit the image from different angles.
Zoom Tool * ( Z )
You can click on the image with the Zoom Tool to zoom in on a specific area.
Press and hold Alt and click the Zoom Tool to zoom out.
Lasso tool
This tool is used for free selection on the image as required.
Open the required image.
Click on the lasso tool from the tool box.
Click on the picture and drag the mouse to select the
required area.
Eraser Tool
Eraser tool is used to remove certain area or part of the
image.
Open the required image.
Click on the eraser tool from the tool box.
Click and drag the mouse to erase the required portion of
the image.
Blur Tool
You can also blur portions of your image to emphasize and focus
on a particular element. It is used to reduce the extra pixel contrast and make the image
dim.
Open the required image.
Click on the blur tool from the tool box.
Choose the required brush from the present picker.
Drag the mouse pointer over the part of the picture and
release the mouse.
Zoom Tool
This tool is used to enlarge the size of the image. This tool is
like a magnifying glass.
Open the required image.
Click on the zoom tool from the tool box.
Press CTRL + (+) for zoom in [Larger View] and CTRL + (-) for zoom out
[smaller view] of the image.
Select the Magic Wand tool . (If the tool isn’t visible,
access it by holding down the Quick Selection tool .)
Click on the area of an image to select.
Click the Text Colour picker, then choose the desired colour from the dialog box.
Click and drag anywhere in the document window to create a text box.
If you want to add a lot of texts to your document, you can work with multiple text layers
which will give you more control over the appearance of your text.
Let’s Review
Cropping the picture is a way of removing portions of a photo or image to create
focus or strengthen the composition.
Lasso tool is used for free selection on the image as required.
Eraser tool is used to remove certain areas or parts of the image.
Gradient tool is used to fill colours horizontally. We can use this tool to create
banners.
You can also blur portions of your image to emphasize and focus on a particular
element.
Zoom tool is used to enlarge the size of the image.
Hand tool is used to move the image horizontally or vertically on the screen.
We can use text tool to type the text, symbols, characters and sentence on selected
area.
Clone stamp tool allows you to copy one area of image onto another area of
image.
Dodge tool is used to apply more lightness on the image.
The spot healing brush tool can be used to clone areas from an image and
blend the pixels from the sampled area seamlessly with the target area.
Magic Wand tool is used to select a larger area of image having similar colour,
pixel and groups together.
The type tool allows you to add text to your image.
Assignment
1. Select the correct answer from the given options.
a. Which of the following is the example of bitmap image format?
i. BMP ii. PCX iii. TIFF iv. All of them
b. Which file can contain both bitmap and vector data in a single file?
i. Metafile ii. Raster iii. Vector iv. None of them
c. What is the default file extension of Photoshop document?
i. .PDS ii. .PSD iii. .PMD iv. .PMK
d. Which Photoshop tool brings lightness on the image?
i. Pen tool ii. Eraser tool iii. Dodge tool iv. Toggle tool
e. Which of the following is the smallest unit of a digital graphics that can be
displayed and represented on a digital display device?
i. Pixel ii. Resolution iii. DPI iv. None of them
f. What is the resolution of 19 inch common widescreen monitor?
i. 920 X 1080 ii. 1680 X 1050 iii. 2560 X 1440 iv. 1920 X 1080
g. Which of the tools is used to crop an image and remove unwanted areas?
i. Slice tool ii. Polygonal tool iii. Magic wand tool iv. Crop tool
h. Which tool is used to click and drag an image around on the screen to view
different areas when zoomed in?
i. Zoom tool ii. Hand tool iii. Line tool iv. Rotate view tool
i. Which tool is used to remove unwanted areas of an image?
i. Crop tool ii. Clone stamp tool iii. Eraser tool iv. Blur tool
j. Which of the following is used to insert text in the image?
i. Clone stamp tool ii. Magic wand tool iii. Line tool iv. Type tool
Introduction to web browser, search engine, web server, web site, web page,
uploading and downloading, URL, DNS, home page,
Components of WWW
Internet of things
Cloud computing
Components of WWW
World Wide Web is a large scale, online store of information. It is a system of creating,
organizing, and linking documents. The information stored on it as the collection of
documents that are interconneced with each other through the web links. The interconnected
documents may be located on one or more than one computer or worldwide.The WWW
uses the following components.
Search Engine
Search engines are used to search information and multiple resources on the
internet with the help of web browsers. Search engine is a service of internet
that allows the users to search the information and resources via the World Wide Web
(WWW). A user needs to enter the keywords or key phrases into a search engine and
receives a list of Web content results in the form of websites, images, videos or other data.
There are many different search engines available on the Internet, each with their own
abilities and features. The most popular and well-known search engine is Google. Other
popular search engines are AOL, Ask.com, Bing, and Yahoo.
Web Server
The main job of a web server is to display the website
content. Web server is a program that uses hypertext
transfer protocol to serve the files that form Web pages to
the users. Web server is a computer that runs websites. Web
server is a computer program that distributes web pages.
The basic objective of the web server is to store, process
and deliver web pages to the users. This intercommunication is
done using Hypertext Transfer Protocol (HTTP). These web pages are mostly static
Let’s Review
The Internet is a network of networks that allows computers on different kind
networks to interact with each other.
The information stored on www is the collection of documents that are
interconnected with each other through the web links.
The process of using browser to view information on the internet is known as
browsing or surfing.
The default web browser may be different according the operating system that is
used.
Search engine is a service of internet that allows the users to search the information
and resources through the World Wide Web (WWW).
Web server is a computer that runs websites. Web server is a computer program
that distributes web pages.
Web Site
A Web site is a collection of World Wide Web (WWW)
files such as text, graphics, images, audio and videos.
The first website was built at CERN by Tim Berners-
Lee and launched on August 6, 1991.Web sites are
the virtual location on WWW, which has several
webpages and data files accessible through a browser.
Each website has its own unique web address which
can be viewed through an internet connection. To view a website, we must have web
browsers like Internet Explorer. You can open a website by entering the URL in the
address bar. For example, typing “https://www.shubharambhapublication.com” opens the
home page of Shubharambha Publication. If you don’t know the URL of the website you
want to visit, you can use a search engine to find the website on the Internet.
Web Page
A web page is a document commonly written in HTML (Hypertext Mark-up
Language) that is accessible through the Internet or other networks using an
Internet browser. A web page is accessed by entering a URL address and may contain text,
graphics, and hyperlinks to other web pages and files. The information page that you read
is an example of a web page.
Let’s Review
A web site is a collection of World Wide Web (WWW) files such as text, graphics,
images, audio and videos.
Web page is accessed by entering a URL address and may contain text, graphics,
and hyperlinks to other web pages and files.
A URL is also a specific type of Uniform Resource Identifier (URI).
Uploading is the process of sending web pages, images and files onto a web
server.
Downloading is the process of getting web pages, images and files from a web
server.
A home page is the initial or main web page of a website or a browser.
DNS is an Internet service that translates domain names into IP addresses
because domain names are alphabetic and they are easier to remember.
Cloud computing is the delivery of different services through the Internet.
HTML stands for Hypertext Transfer protocol. Hypertext is text which contains links
to other text. It was first developed by Tim Berners-Lee in 1990 AD. It is used to create
electronic documents that are displayed on the World Wide Web. Every web page you
see on the Internet is written using one version of HTML code or another. HTML code
ensures the proper formatting of text and images so that internet browser displays them
as they are intended to look. Without HTML, a browser would not know how to display
text as elements, load images or other elements.
Features of HTML
HTML is a document layout and hyperlink specification language.
HTML tells the browser how to display the contents of a hypertext document.
HTML is a language that supports multimedia and new page layout features even it
has its some limitations.
HTML provides a small mark-up tag that helps to work with various font formatting
activities.
HTML is a page-layout and hyperlink specification language.
HTML Tag
A tag is a coded HTML command that indicates how the part of web pages should
be displayed. HTML tags are the hidden keywords within a web page which
define how the web browser displays the content. Most of the HTML tags have
Elements of HTML
HTML tag attributes allow you to customise a tag, and are defined within the opening tag,
for example: <img src=”image1.jpg”> or <p align=”center”> ... </p>
Attributes are often assigned a value using the equals sign, such as border=”0” or
width= ”50%”, but there are some that only need to be declared in the tag like this:
<hr noshade>. Most attributes are optional for most tags, and are only used when
you want to change something about the default way a tag is displayed by the browser.
However, some tags such as the <img> tag has required attributes such as src and alt
which are needed in order for the browser to display the web page properly.
Let’s Review
HTML is used to create electronic documents that are displayed on the World
Wide Web.
HTML tells the browser how to display the contents of a hypertext document.
A tag is a coded HTML command that indicates how part of web pages should be
displayed.
Each HTML file must have the essential tags for it to be valid, so that web
browsers can understand it and display it correctly.
An HTML element is an individual component of the HTML document.
HTML tag attributes allows you to customise a tag, and are defined within the
opening tag.
Structure of HTML
A basic HTML page is a document that typically has the file extension .html, though
HTML frequently appears
in the content of other file <!DOCTYPE html>
types as well. All HTML <html>
documents follow the same <head>
basic structure so that the <title>Page Title</title>
browser that renders the file </head>
knows what to do. The <body>
basic structure of an HTML <h1>Homepage Headline</h1>
document consists of 5 <p>This is a paragraph.</p>
elements: </body>
1. <!DOCTYPE>
2. <html>
3. <head>
4. <title>
5. <body>
A tag is a command in a web page that tells the browser to do something. Tags are enclosed
in less than (<) and greater than (>) signs.
<HTML>: It is a container element that identifies the document as an HTML document.
It is also called root element.To create the html element, we can use an opening <html>
tag followed by a closing </html> tag. Everything else in the web page goes between
these starting and ending tags.The general structure is given below.
<HTML>
--------------
Document area
---------------
----------------
</HTML>
<HEAD> : The head element contains information about the web page. There are many
elements that you can put inside the head element, such as title , link, meta, script, etc. The
general structure is given below.
<head>
<title> Learning Computer is Fun. </title>
</head>
Sample l
<!DOCTYPE html>
<html>
<head>
<title> We are working with HTML. </title>
</head>
<body>
The content of the document goes here!
</body>
</html>
Font Element
<font> : The <font> tag is used to change the format of the text on the web page. The
most important attributes are as follows:
face: This indicates the type of font. The default font is Times New Roman. There are
other so many fonts like Verdana, Helvetica, Preeti, Arial, etc.
size: This indicates the size of the text. The default text size in HTML document
is 3. It is used to set the absolute or relative value ranging from 1 to 7.
color: This indicates the color of the text. Either the color name or the
six-characer color code (RGB value) may be used to specify color.
Syntax: <font size =“value” color = “color name” face
=“font name”> ……………</font>
Sample 3
<!DOCTYPE html>
<html>
<head>
<title> working with font formatting element </title>
</head>
<body>
We are discussing html font formatting elements. <br><p>
<b> Making the text bold. </b><br>
<i> Making the text italic. </i><br>
<u> Inserting underline to the text </u><br><p>
I know the algebra formula a<sup>2</sup> + 2ab +
b<sup>2</sup><br>
I can use science formula like H<sub>2</sub> SO <sub> 4
</sub><br>
<P>
<big> This text is large </big><br>
<small> This text is small </small><br>
</body>
</html>
Let’s Review
The basic structure of an HTML document consists of 5 elements. They are
<!DOCTYPE>, <html>, <head>, <title> and <body>.
The first line of code, <!DOCTYPE html>, is called a doctype declaration
and tells the browser which version of HTML the page is written in.
A tag is a command in a web page that tells the browser to do something.
To create the html element, we can use an opening <html> tag followed by
a closing </html> tag.
The body element appears after the head element in the page.
The <font> tag is used to change the format of the text on the web page.
The most important font attributes are font face, size and color.
Sample 4
<!DOCTYPE html>
<html>
<head>
<title> working with heading element </title>
</head>
<body>
<h1 align=”center”>This is h1 (largest) heading text.</
h1>
<h2 align=”left”>This is h2 text.</h2>
<h3 align=”right”>This is h3 text.</h3>
<h4> This is h4 text.</h4>
<h5> This is h5 text.</h5>
<h6> This is h6 text.</h6>
</Body> </HTML>
Sample 6
<!DOCTYPE html>
<html>
<head>
<title> Background colour sample page</title>
</head>
<body bgcolor=”#af0000”>
<h1> This webpage has red colored background.</h1>
</body> </html>
Syntax: <HR align = “align position” noshade color = “color name” size =
“pixel” width = “pixel”>
Example: HR align = “Center” noshade color = “red” size = “5” width = “25%”>
Sample 7
<!DOCTYPE html>
<html>
<head>
<title> HTML hr tag</title>
</head>
<body>
<p>There is a horizontal rule below this
paragraph.</p>
<hr>
<p>This is a horizontal rule above this
paragraph.</p>
</body>
</html>
Marquee is a scrolling text displayed either horizontally across or vertically down on the
webpage depending on its settings. This can be done with the help of <marquee>………</
marquee> tag. It is one of the important tags introduced in HTML to support such
scrollable texts and images within a web page. The different attributes of <marquee> tag
are listed below.
Syntax: <MARQUEE behavior = "behavior name" direction = "direction way" bgcolor
="color name or value" scrolldelay = "scrolling time"> ……………………</marquee>
Example: <MARQUEE behavior = "slide" direction = "left" bgcolor ="red" scrolldelay
= "5"> ……………………</marquee>
Attribute Description
It provides the width or breadth of a marquee. For example
width
width="10" or width="20%".
It provides the height or length of a marquee. For example height="20"
height
or height="30%".
Let’s Review
HTML has six levels of heading tags. The header tags are written within <hn>
…….. </hn>.
The paragraph alignment uses <p align> ……………</p> to indicate the
paragraph alignment.
The <hr> tag in HTML stands for horizontal line and is used to insert a
horizontal line or a thematic break in an HTML page to divide or separate
document sections.
Marquee is a scrolling piece of text displayed either horizontally across or
vertically down on the webpage depending on its settings.
Sample 9
<!DOCTYPE html>
<html>
<head>
<title> Learning marquee Tag</title>
</head>
<body>
<marquee> Sample of marquee text.</marquee>
</body>
</html>
Sample 11
<!DOCTYPE html>
<html>
<head>
<title> Marquee Tag</title>
</head>
<body>
<marquee direction=”right”> This text will scroll from
left to right</marquee>
</body> </html>
Sample 12
<!DOCTYPE html>
<html>
<head>
<title> HTML marquee Tag</title>
</head>
<body>
<marquee direction=”up”>This text will scroll from bottom
to up </marquee>
</body> </html>
List Element
HTML has several ways for specifying lists of information. List elements are used to
present a list of information in a well-formed and semantic way. There are three different
types of lists in HTML and each one has a specific purpose and meaning.
Unordered List: It is used to group a set of related items without any particular
order. An unordered list is created by using the <ul> tag, and each list item starts
with the <li> tag.
Ordered List: It is used to group a set of related items, in a specific order. <ol> tag
can be used for ordered list. This will use different schemes of numbers to list the
items.
Definition List : The definition list created using <dl> tag. The <dl> tag is used
in conjunction with <dt> which defines the item in the list, and <dd> which
describes the item in the list. Definition list displays elements in definition form
like in dictionary. The <dl>, <dt> and <dd> tags are used to define description
list.
Unordered List:
Syntax: <ul type="disc|circle|square">
Attribute Values
Value Description
disc default filled circle
circle an unfilled circle
square a filled square
Sample 14
<!DOCTYPE html>
<html>
<head>
<title> HTML unordered list </title>
</head>
<body>
<ul type=”circle”>
<li> Dhading Bensi, Headquater of Dhading</li>
<li> Bidhur, Headquater of Nuwakoat</li>
<li> Bensisahar, Headquater of Lamjung</li>
<li> Hetauda, Headquater of Makawanpur</li>
</ul>
</BODY>
</HTML>
Value Description
1 Default decimal numbers like 1, 2, 3, 4 .......
a Alphabetically ordered list, lowercase like a, b, c, d ........
A Alphabetically ordered list, uppercase like A, B, C, D .....
i Roman numbers, lowercase like i, ii, iii, iv ..............
I Roman numbers, uppercase like I, II, III, IV .............
Sample 15
<!DOCTYPE html>
<html>
<head>
<title> HTML ordered list </title>
</head>
<body>
<ol type=”a”>
<li> Dhading Bensi, Headquater of Dhading</li>
<li> Bidhur, Headquater of Nuwakoat</li>
<li> Bensisahar, Headquater of Lamjung</li>
<li> Hetauda, Headquater of Makawanpur</li>
</Ol>
</BODY>
</HTML>
Sample 16
<!DOCTYPE html>
<html>
<head>
<title> HTML Definition list </title>
</head>
<body> <dl>
<dt> Dhading Bensi</dt>
<dd> The headquater of Dhading District</dd>
<dt> Bensisahar</dt>
<dd> The headquater of Lamjung District</dd>
<dt> Rampur, Palpa</dt>
<dd> The historical place of Palpa District</dd>
<dt> Illam</dt>
<dd> The place popular for tea garden</dd>
</dl> </body></HTML>
Sample 17
<!DOCTYPE html>
<html>
<body>
<ol>
<li> Computer Science </li>
<li> Environment Science </li>
<li> Optional Mathematics </li>
</ol>
<ol start=”10”>
<li> Computer Science </li>
<li> Environment Science</li>
<li> Optional Mathematics </li>
</ol>
</body> </html>
In HTML a hyperlink is created with the tag <a>, specifying the destination on the href
attribute. Therefore the text or elements before the closing tag </a> will be linked.
Anchor text is a type of hyperlink represented by plain text. Anchor text is very important
in search engine optimization. It is used to define the beginning and end of a hypertext
link. There are three anchor attributes you need to know to create functional hyperlinks.
These attributes are href, target, and download.
In the above tag the href attribute specifies the destination address (https://www.
shubharambhapublication.com/html/) of the link. The link text is the visible part
(Visit our official website). Clicking on the link text will send you to the specified address
Let’s Review
List elements are used to present a list of information in a well-formed and semantic
way.
There are three different types of lists in HTML they are Unordered list,
Ordered list and Definition list
The definition list is created using <dl> tag.
A hyperlink is an element in an HTML document that links to either another
portion of the document or to another document.
We can also define hyperlinks as they are special elements linked to another
location, either in the same page, the same website or an entirely different domain.
In HTML a hyperlink is created with the tag <a>, specifying the destination on
the href attribute.
Anchor text is a type of hyperlink represented by plain text.
Anchor text is used to define the beginning and end of a hypertext link.
Sample 20
Create a sample link with in various pages as given below.
Task 1: Design Home page as below and Task 2: Design Notice page as below
save it under file name home and save it under file name notice.
Home Page Notice Page
Welcome to our home page Welcome to our notice page
Click here for notice Back to home page
Click here for result Click here for result
Click here for admission Click here for admission
Task 3: Design result page as below and Task 4: Design admission page as below
save it under file name result. and save it under file name admission.
Result Page Admission Page
Welcome to our result page Welcome to our admission page
Back to home page Back to home page
Click here for notice Click here for notice
Click here for admission Click here for result
HTML code for home page HTML code for notice page
<!DOCTYPE html> <!DOCTYPE html>
<html> <body> <html> <body>
<Font color = “red”><b><h1> <Font color = “red”><b><h1>
<P align=center> Home Page <P align=center> Notice Page
</p></font></b></h1><br> </p></font></b></h1><br>
<h2> Welcome to our home
<h2> Welcome to our Notice
page </h2><br>
page </h2><br>
<A href = “notice.html”>
Click here for notice <A href = “home.html”> Back
to home page </a><br>
</a><br>
<A href = “result.html”>
<A href = “result.html”>
Click here for result Click here for result
</a><br> </a><br>
<A href = “admission.html”> <A href = “admission.html”>
Click here for admission Click here for admission
</a><br> </body> </html> </a><br> </body> </html>
An HTML table consists of a collection of rows and columns. The intersection of a row
and a column is called a cell. A single row contains one cell for each column. The <table>
element in HTML is used for displaying tabular data. It allows arranging data like text,
images, links, other tables, etc. into rows and columns of cells.The HTML tables are
created using the <table> tag in which the <tr> tag is used to create table rows and <td>
tag is used to create data cells. The elements under <td> are regular and left aligned by
default.
Table Attributes
Attribute Description
align It specifies the alignment of a table according to surrounding text.
bgcolor It specifies the background color for a table.
border It specifies whether or not the table is being used for layout purposes.
cellpadding It specifies the space between the cell wall and the cell content.
cellspacing It specifies the space between cells.
frame It specifies which parts of the outside borders should be visible.
rules It specifies which parts of the inside borders should be visible.
summary It specifies a summary of the content of a table.
width It specifies the width of a table.
Height It specifies the height of a table.
In the above code, the border is an attribute of <table> tag and it is used to put a border
across all the cells. If you do not need a border, you can use border = “0”.
Table Heading
Table heading can be defined using <th> tag. This tag will be put to replace <td> tag,
which is used to represent actual data cell. The headings, which are defined in <th> tag
are centered and bold by default.
Sample 23
<!DOCTYPE html>
<html> <head>
<title> Table Header in HTML </title></head>
<body>
<table border = “1”>
<tr>
<th> Name</th>
<th> Salary</th>
</tr> <tr>
<td> Ram Malakar</td>
<td>20,000</td>
</tr> <tr>
<td> Kripa Duwadi</td>
<td>35,000</td>
</tr> </table> </body> </html>
Cellpadding and cellspacing helps to adjust the white space in your table cells. The
cellspacing attribute defines space between table cells, while cellpadding represents the
distance between cell borders and the content within a cell.
Sample 24
<html>
<head>
<title> HTML Table </title>
</head>
<body>
<table border = “1” cellpadding = “5” cellspacing = “5”>
<tr>
<th> Name</th>
<th> Salary</th>
</tr>
<tr>
<td> Ram Malakar</td>
<td> 20,000</td>
</tr>
<tr>
<td> Kripa Dubadi</td>
<td> 30,000</td>
</tr>
</table>
</body>
</html>
You can use colspan attribute to merge two or more columns into a single column.
In a similar way, you can use rowspan if you want to merge two or more rows.
Sample 25
<!DOCTYPE html>
<html>
<head>
<title> HTML Table Colspan/Rowspan</title>
</head>
<body>
<table border = “1”>
<tr>
<th> Address</th>
<th> Name</th>
<th> Age</th>
</tr>
<tr>
<td rowspan = “2”> Dhading Bensi</td>
<td> Prayusha Nepal </td>
<td> 10 Years </td>
</tr>
<tr>
<td> Prem Nath Adhikari</td>
<td> 84 Years </td>
</tr>
<tr>
<td colspan = “3”>Birtamoad Jhapa</td>
</tr>
</table>
</body>
</html>
Sample 26
<!DOCTYPE html>
<html> <head>
<title> HTML Table Colspan/Rowspan</title>
</head>
<body>
<table border = “1” bordercolor = “RED” bgcolor =
“Pink”><tr>
<th> Address</th>
<th> Name</th>
<th> Age</th>
</tr> <tr>
<td rowspan = “2”> Dhading Bensi</td>
<td> Prayusha Nepal </td>
<td> 10 Years </td>
</tr>
<tr>
<td> Prem Nath Adhikari</td>
<td> 84 Years </td>
</tr> <tr>
<td colspan = “3”>Birtamoad Jhapa</td>
</tr>
</table>
</body>
</html>
You can set a table width and height using width and height attributes. You can
specify table width or height in terms of pixels or in terms of percentage.
Sample 27
<!DOCTYPE html>
<html> <head>
<title> Table Width and Height</title>
</head>
<body>
<table border = “2” width = “550” height = “200”>
<tr>
<td> Name of District</td>
<td> Capital City </td>
</tr>
<tr>
<td> Gorkha</td>
<td> Gorkha Bazaar</td>
</tr>
</table> </body> </html>
Let’s Review
The <img> tag is an empty tag, which means it can contain only a list of attributes
and it has no closing tag.
We should use the <img> tag inside <body>…</body> tag.
The src attribute is used to add the image source
An HTML table consists of a collection of rows and columns.
The intersection of a row and a column is called a "cell".
The <table> element in HTML is used for displaying tabular data.
Table heading can be defined using <th> tag.
Cellpadding and cellspacing help to adjust the white space in your table cells.
We can use colspan attribute to merge two or more columns into a single column.
We use rowspan if we want to merge two or more rows.
We can set a table width and height using width and height attributes.
The <form> element defines a form and attributes that determine the behavior of the form.
Each time you want to create an HTML form, you must start it by using this element,
putting all the contents inside.
There are various form elements available like text fields, text area fields,
drop-down menus, radio buttons, checkboxes, etc.The HTML <form> tag is used to create
form. The syntax is given below.
Syntax <form action = “Script URL” method = “GET|POST”> form elements like input,
textarea etc. </form>
Forms Elements
Text Input Controls: There are three types of text inputs used on forms. Let’s discuss
them below with some sample example.
Single Line Text Input Controls: It is used for items that require only one line of user
input, such as search boxes or names. Here is a basic example of a single-line text input
used to take first name and last name.
Sample 28
<!DOCTYPE html>
<html>
<head>
<title> Text Input Control</title>
</head>
<body>
<form>
First name: <input type=”text”name=”first_name”/>
<br>
Last name: <input type=”text”name=”last_name”/>
</form>
</body>
</html>
Password Input Controls: It is also a single-line text inputs but it masks the character as
soon as a user enters it.
Multi Line Text Input Controls : It is used when the user is required to give
details that may be longer than a single sentence.
Sample 30
<!DOCTYPE html>
<html>
<head>
<title> Multiple-Line Input Control</title>
</head>
<body>
<form>
Description :<br/>
<textarea rows=”5”cols=”50”name=”description”>
Enter description here...
</textarea>
</form>
</body>
</html>
Sample 31
<!DOCTYPE html>
<html>
<head>
<title> Checkbox Control</title>
</head>
<body>
<form>
<input type=”checkbox”name=”maths”value=”on”> Maths
<input type=”checkbox”name=”physics”value=”on”> Physics
</form> </body>
</html>
Radio buttons are used when out of many options, just one option is required to be selected.
They are also created using HTML <input> tag but the type attribute is set to radio.
Sample 32
<!DOCTYPE html>
<html>
<head>
<title> Radio Button Control</title>
</head>
<body>
<form>
<input type=”radio”name=”subject”value=”maths”> Maths
<input type=”radio”name=”subject”value=”physics”> Physics
</form> </body>
</html>
A select box is also called a drop down box which provides option to list down various
options in the form of drop down list, from where a user can select one or more options.
Sample 33
‑<!DOCTYPE html>
<html>
<head>
<title> Select Box Control</title>
</head>
<body>
<form>
<select name = “dropdown”>
<option value = “SEE subject list of Nepal” selected>
SEE subject list of Nepal</option>
<option value = “Comp. English”>Comp. English</option>
<option value = “Comp. Nepali”>Comp. Nepali</option>
<option value = “Comp. Social Studies”>Comp. Social
Studies</option>
<option value = “Comp. Mathematics”>Comp.
Mathematics</option>
<option value = “Comp. Science”>Comp.Science</
option>
<option value = “Optional Computer Science”>
Optional Computer Science</option>
<option value = “Optional Mathematics”>Optional
Mathematics</option>
<option value = “Optional Population”>Optional
Population</option>
<option value = “Optional Science”>Optional Science
</option>
<option value = “Optional Environment Science”>
Optional Environment Science</option>
</select> </form>
</body> </html>
If you want to allow a user to upload a file to your web site, you will need to use
a file upload box. It is also known as a file select box. This is created using the
<input> element but the type attribute is set to file.
Sample 35
<!DOCTYPE html>
<html> <head>
<title> File Upload Box</title>
</head>
<body>
<form>
<input type=”file”name=”fileupload”accept=”image/*”/>
</form> </body>
</html>
Button Controls
There are various ways in HTML to create clickable buttons. You can also create a
clickable button using <input> tag by setting its type attribute to button.
Sample 36
<!DOCTYPE html>
<html> <head>
<title> File Upload Box</title>
</head>
<body>
<form>
<input type=”submit”name=”submit”value=”Submit”/>
<input type=”reset”name=”reset”value=”Reset”/>
<input type=”button”name=”ok”value=”OK”/>
</form> </body>
</html>
Assignment
1. Select the correct answer from the given options.
a. Which of the tags is used to start html tagging?
i. <BODY> ii. <HEAD> iii. <HTML> iv. <!DOCTYPE>
b. Which of the following is used in enclosed HTML tags?
i. < and > ii. ^ and ^ iii. % and % iv. None of them
Introduction to CSS
Understanding CSS syntax
CSS measuring unit
Working with CSS colour
Working with CSS background
CSS font style
CSS text and image
CSS links and tables
CSS border and margin
CSS scrollbars
CSS stands for Cascading Style Sheets. It is a language that describes the style of an
HTML document like how HTML elements are to be displayed on screen. It can control
the layout of multiple web pages all at once. The external stylesheets are stored in CSS
files.
CSS Syntax
CSS is a set of rules that can be used to define what each of those elements will look. The
rules specify the display properties. A CSS comprises of style rules that are interpreted
by the browser and then applied to the corresponding elements in your document. CSS
rules can control many properties, called declarations, of an element. CSS declarations
are always contained in curly braces ({}) and each declaration will end in a semi-colon(;).
Each element is chosen in CSS by the ‘selector’ and defined in the ‘declaration’ by a
‘property’ and a ‘value.’
A CSS rule set contains a selector and a declaration block as given below. Let’s discuss
it in detail.
Property value
Selector
Selector indicates the HTML element you want to style. It could be any tag like <h1>,
<title> etc.CSS selectors are used to select the content you want to style. Selectors are the
part of CSS rule set. CSS selectors select HTML elements according to its id, class, type,
attribute, etc. There are several different types of selectors in CSS which are listed below.
CSS element selector
CSS Id selector
CSS class selector
CSS universal selector
CSS group selector
Declaration Block: The declaration block can contain one or more declarations separated
by a semicolon. In the above example, there are two declarations and they are color: red
and font-size:20 px. Each declaration contains a property name and value, separated by
a colon.
Property: a Property is a type of attribute of HTML element. It could be color, border,
etc.
Value: Values are assigned to CSS properties. In the above example, value “red” is
assigned to color property.
CSS has several different units for expressing a length. Many CSS properties take “length”
values, such as width, margin, padding, font-size, etc. Length is a number followed by
a length unit, such as 10px, 2em, etc. You need these values while specifying various
measurements in your style rules. A whitespace cannot appear between the number and
the unit. However, if the value is 0, the unit can be omitted. For some CSS properties,
negative lengths are allowed. There are two types of length units. They are absolute and
relative length unit.
Relative length: Relative length units specify a length relative to another length property.
Relative length units scale better between different rendering mediums. Some relative
length units are em, ex, ch, rem, vw, vh, etc. Let’s observe the given table with CSS
relative length units.
Unit Description
CSS Colors
CSS uses color values to specify a color. Typically, they are used to set a color either for
the foreground of an element or for the background of the element. They can also be used
to affect the color of borders and other decorative effects.
You can specify your color values in various formats. Following table lists all the possible
formats.
Sample 2
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image:url(“/publication matter/images/
computer.jpg”);
background-color:#ccddcc;
}
</style>
</head>
<body>
<h1> Learning CSS is FUN !</h1>
</body> <html>
Sample 3
<!DOCTYPE html>
<html> <head>
<style>
body{
background-image:url("/publication matter/images/
computer.jpg");
background-position:100px;
}
</style>
</head>
<body>
<p> LEARNING CSS IN HTML is always fun</p>
</body> </html>
Sample 4
<!DOCTYPE html>
<html> <head>
<style>
body{
background-image:url(“/publication matter/images/
computer.jpg”);
background-repeat: repeat;
}
</style>
</head>
<body>
<p> Learning HTML</p>
</body> </html>
Sample 5
<!DOCTYPE html>
<html>
<head>
<style>
body{
background-image:url(“/publication matter/images/
computer.jpg”);
background-repeat:no-repeat;
background-attachment:fixed;
}
</style>
</head>
<body>
<p>The background-image is fixed. Try to scroll down the
page.</p>
</body> </html>
CSS- Font
The font property is a shorthand property for font-style, font-variant, font-weight, font-
size, font-family, etc.
Property/Value Description
font-style It specifies the font style. Default value is "normal".
font-variant It specifies the font variant. Default value is "normal".
font-weight It specifies the font weight. Default value is "normal".
font-size/line- It specifies the font size and the line-height. Default value is
height "normal".
font-family It specifies the font family. Default value depends on the browser.
It uses the font that are used by captioned controls (like buttons,
caption
drop-downs, etc.).
icon It uses the font that are used by icon labels.
status-bar It uses the fonts that are used by the status bar.
status-bar It uses the fonts that are used by the status bar.
Sample 6
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “font-family:tiplo;”>
We are in grade nine , We are learning about CSS <br>
Learning CSS is fun.
</p>
</body>
</html>
Font Variant
Sample 7
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”font-variant:small-caps;”>
Learning HTM and CSS.
</p>
</body>
</html>
Font Weight: The font-weight property provides the functionality to specify how bold a
font is. Normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900, etc. are
the possible values for font weight.
Font Size: The font-size property is used to control the size of fonts. Possible values
could be xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger, size
in pixels or in %.
Sample 9
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”font-size:20px;”>
This font size is 20 pixels
</p>
<p style=”font-size:small;”>
This font size is small
</p>
<p style=”font-size:large;”>
This font size is large
</p> </body> </html>
Sample 10
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”font-size-adjust:0.61;”>
This text is using a font-size-adjust value.
</p>
</body>
</html>
Short Hand Property: You can use the font property to set all the font properties at once.
Sample 11
<!DOCTYPE html>
<html
<head>
</head>
<body>
<p style=”font:italic small-caps bold 15pxgeorgia;”>
Applying all the properties on the text at once.
</p>
</body>
</html>
Sample 12
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”color:red;”>
Text appear in red colour.
</p>
</body>
</html>
Text Direction
Sample 13
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style=”direction:rtl;”>
This text will be rendered from right to left
</p>
</body>
</html>
Text Shadow
Sample 16
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = "text-shadow:4px 4px 8px red;">
If your browser supports the CSS text-shadow
property,this text will have a red shadow.
</p> </body> </html>
Text Alignment
Sample 18
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “text-indent:5cm;”>
The font-weight property provides the functionality to
specify how bold a font is. Possible values could be
normal, bold, bolder, lighter, 100, 200, 300, 400,
500, 600, 700, 800, 900.
</p>
</body>
</html>
Sample 20
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “white-space:pre;”>
CSS uses color values to specify a color.
Typically, these are used to set a color
either for the foreground of an element or for
the background of the element. They can also
be used to affect the color of borders and other
decorative effects.
</p>
</body>
</html>
CSS – Images
Images play an important role in any webpage. It plays a good role to control
image display. You can set the following image properties using CSS.
Border: This property is used to set the width of an image border.
Height: This property is used to set the height of an image.
Width: This property is used to set the width of an image.
Moz-opacity: This property is used to set the opacity of an image.
Border Property
It is an image which is used to set the width of an image border. This property can
have a value in length or in percentage.
Sample 21
<!DOCTYPE html>
<html> <head>
</head>
<body>
<img style = “border:0px;” src = “logo.png” />
<br/>
<img style = “border:3px dashed red;” src = logo.png” />
</body> </html>
Sample 22
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img style = “border:1px solid red; height:100px;” src =
“logo.png” />
<br/>
<img style = “border:1px solid red; height:50%;” src =
“logo.png” />
</body>
</html>
Width Property
The width property of an image is used to set the width of an image. This property
can have a value in length or in percentage.
Sample 23
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img style = “border:1px solid red; width:150px;” src =
“/css/images/logo.png” />
<br>
<img style = “border:1px solid red; width:100%;” src = “/
css/images/logo.png” />
</body>
</html>
CSS – Links
Website contains a hyperlink inside a web page or any other website. The <link> tag
defines a link between a document and an external or even internal resource.The <link>
tag is used to link to external style sheets.All the link properties are kept in the header part
of the HTML document.There are four link states which are listed below.
a:link:This link is a normal and unvisited link
a:visited: This links where the user has visited
a:hover:The link on which the user shows the pointer over it
a:active: The link that is clicked by the user.
Setting Color for the Links
Sample 25
<!DOCTYPE html>
<html>
<head>
<style type = “text/css”>
a:link {color:#000000}
</style>
</head>
<body>
<a href = “”>Click here for Link</a>
</body> </html>
Sample 26
<!DOCTYPE html>
<html>
<head>
<style type = “text/css”>
a:visited {color: #006600}
</style>
</head>
<body>
<ahref = “”>Click here for Link</a>
</body> </html>
Sample 27
<!DOCTYPE html>
<html> <head>
<style type = “text/css”>
a:hover {color: #FFCC00}
</style> </head>
<body>
<a href = “”> Click here for Link</a>
</body> </html>
CSS –Table
Let’s discuss various table properties that we can use in CSS.
Border-collapse: It specifies whether the browser should control the appearance of the
adjacent borders that touch each other or whether each cell should maintain its style.
Border-spacing: It specifies the width that should appear between table cells.
Caption-side: The captions are presented in the <caption> element. By default, these are
rendered above the table in the document.
Empty-cells: It specifies whether the border should be shown if a cell is empty or not.
Table-layout: It allows browsers to speed up layout of a table.
The border properties allow you to specify how the border of the box representing an
element should look. There are three properties of a border.
Border-Color: It specifies the color of a border.The border color property allows you to
change the color of the border surrounding an element.
Sample 29
<!DOCTYPE html>
<html> <head>
<styletype=”text/css”>
p.example1 {
border:1px solid;
border-bottom-color:#009900;/* Green */
border-top-color:#FF0000;/* Red */
border-left-color:#330000;/* Black */
border-right-color:#0000CC;/* Blue */
}
p.example2 {
border:1px solid;
border-color:#009900;/* Green */
}
</style>
</head>
<body>
<pclass=”example1”>
This example is showing all borders in different colors.
</p>
<pclass=”example2”>
This example is showing all borders in green color only.
</p> </body> </html>
Border-Style: It specifies whether a border should be solid, dashed line, double line,
or one of the other possible values. The border-style property allows you to select one of
the styles of border like none, solid, dotted, etc.
Let’s Review
We can set the border, height, width, moz-opacity properties using CSS.
Border Property is an image used to set the width of an image border.
The width property of an image is used to set the width of an image
The height property of an image is used to set the height of an image.
The -moz-opacity property of an image is used to set the opacity of an image.
The <link> tag defines a link between a document and an external or even internal
resource.
The <link> tag is used to link to external style sheets.
Border-spacing specifies the width that should appear between table cells.
Empty cells specifies whether the border should be shown if a cell is empty or not.
CSS - Margins
The margin property defines the space around an HTML element. We have the following
properties to set an element margin.
Margin: It specifies a shorthand property for setting the margin properties in one
declaration.
Sample 33
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<pstyle=”margin-bottom:15px; border:1px solid black;”>
This is a paragraph with a specified bottom margin
</p>
<pstyle=”margin-bottom:5%; border:1px solid black;”>
This is another paragraph with a specified bottom
margin in percent
</p> </body> </html>
Sample 34
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<pstyle=”margin-top:15px; border:1px solid black;”>
This is a paragraph with a specified top margin
</p>
<pstyle=”margin-top:5%; border:1px solid black;”>
This is another paragraph with a specified top
margin in percent
</p>
</body>
</html>
Margin-Left: It specifies the left margin of an element. The margin-left property allows
you to set left margin of an element. It can have a value in length, % or auto.
Sample 35
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p style = “margin-left: 15px; border:1px solid black;”>
This is a paragraph with a specified left margin
</p>
<p style = “margin-left: 5%; border:1px solid black;”>
This is another paragraph with a specified top
margin in percent
</p>
</body>
</html>
CSS - Scrollbars
There may be chances when an element’s content might be larger than the amount of
space allocated to it. CSS provides a property which is called overflow that tells the
browser what to do if the box’s contents are larger than the box itself. Let’s discuss the
scrollbars values and its description.
Value Description
visible It allows the content to overflow the borders of its containing element.
hidden The content of the nested element is simply cut off at the border of the
containing element and no scrollbars is visible.
scroll The size of the containing element does not change, but the scrollbars are
added to allow the user to scroll to see the content.
auto The purposes of auto is the same as scroll, but the scrollbar will be shown
only if the content overflows.
Assignment
1. Select the correct answer from the given options.
a. Which of the following indicates the HTML element you want to style.
i.Selector ii. Declaration iii. Property iv. Value
b. A type of attribute of HTML element which could be colour, border, etc.
i. Value ii. Property iii. Declaration iv. All of the above
c. Which of the following unit defines a measurement as a percentage relative to
another value?
i. Ex ii. % iii. ch iv. Em
Introduction to programming
Programmer and programming language
Types of programming language
Low level programming language
High level language
Middle level programming language
Fourth generation language
Fifth generation language
Translator program and its types
Program development cycle
Computer is an electronic device that accepts data, processess them and generates the
required output. It can perform both simple and complex tasks with high accuracy.
However, a computer cannot perform task itself. It needs instructions to perform the task.
A set of instructions that instruct the computer the way the task is to be performed is
called a program. Computer program is a set of instructions written for performing a
specific task.
Computer programs are collections of instructions that tell a computer how to interact
with the user, interact with the computer hardware and process data.
A programmer needs to write programs for the computers or even for the machines.
We can define a programmer as a person who designs the algorithms and writes the
necessary codes to create a computer program. A programmer must have the knowledge
of programing language to develop a program. Computer programmers write and test
the code that allows computer applications and programs to function. Programming
language is the tool or means used by the programmer. Programming is the way of giving
instructions about what they should do next. These instructions are known as code, and
computer programmers write code to solve problems or perform a task.
To communicate with a person, we need a language. Like the same if you want to
communicate with the computer, you need a programming language. Without any
programming language, you cannot communicate with the computer.Thus, programming
language is the medium of communication between a person and a computer system. It is
a set of instructions written in a specific code to instruct the computer to do some specific
tasks.
Computer programming is the process of developing and implementing various sets of
instructions to enable a computer to do a certain task. These instructions are considered
computer programs and help the computer to operate smoothly. A programming language
is a set of commands, instructions, and other syntax used to create a software program.
Let’s Review
A set of instructions that instruct the computer that the way the task is to be
performed is called a program.
Computer programs are collections of instructions that tell a computer how
to interact with the user, interact with the computer hardware and process data.
A programmer must have the knowledge of programing language to develop
a program.
Without any programming language you cannot communicate with the computer.
A programming language is a set of commands, instructions, and other syntax use
to create a software program.
Machine Language
Machine Language is the only language that is directly understood by the
computer. It does not need any translator program. We also call it machine code and it is
written as strings of 1's (one) and 0’s (zero). When this sequence of codes is fed to the
computer, it recognizes the codes and converts them into electrical signals needed to run
it. It is not an easy language to learn because it is difficult to understand. It is efficient
for the computer but very inefficient for programmers. It is considered to be the first
generation language. It is also difficult to debug the program written in this language.
Let's discuss a few advantages and disadvantages of machine language.
Let’s Review
Low level languages are machine dependent programming languages.
Machine code does not need any interpreter or compiler to convert languages.
Assembly languages are low level languages.
High level programming languages are the machine independent programming
languages, which are easy to write, read, edit and understand.
The programming languages that have features of low level and high level
programming languages are called middle level language.
Fourth generation languages are commonly used in database programming
and scripts such as Perl, PHP, Python, Ruby, and SQL.
AI is a branch of the computer science in which the computer system is
programmed to have human intelligence characteristics.
Fifth generation language uses a visual or graphical development interface to
create source language that is usually compiled with a 3GL or 4GL language
compiler.
A translator takes a program written in source language as input and converts it into
a program in target language as output. It also detects and reports the error during the
translation process. A translator is a programming language that converts a computer
program from one language to another. It takes a program written in source code and
converts it into machine code. There are several types of translator programs, each are
able to perform different tasks.
Translator translates high-level language program into a machine language that the central
processing unit (CPU) can understand. It also detects errors in the program.
Compiler
A compiler is used to convert high-level programming language to low-level programming
language. It converts the whole program at a time and reports errors detected after the
conversion. A compiler is processor-dependent and platform-dependent. But it has been
addressed by a special compiler, a cross-compiler and a source-to-source compiler. Let’s
discuss some advantages and disadvantages of the compiler:
All
Object Code
High Level Complier
(Execulable)
Source Code
Error Report
Advantages
The whole program is validated so there are no system errors.
The executable file is enhanced by the compiler, so it runs faster.
Users do not have to run the program on the same machine it was created.
Disadvantages
It is slow to execute as you have to complete the whole program.
It is not easy to debug as errors are shown at the end of the execution.
It works on specific machine language and architecture.
Interpreter
An interpreter is used to convert high-level programming language to low-level
programming language. It converts the program one at a time and reports errors detected
1 line of
High Level Out
source Code Interpreter (Temporary)
Error Stop:
Error Report
Advantages
Program can be run before it is completed so you get partial results immediately.
You can work on small parts of the program and link them later into a whole
program.
Disadvantages
Program is not enhanced and may encounter data errors.
It may be slow because of the interpretation in every execution.
Assembler
An assembler is a translator used to translate assembly language to machine language. It
is like a compiler for the assembly language but interactive like an interpreter. Assembly
language is difficult to understand as it is a low-level programming language. An
assembler translates an assembly language to an even lower-level language, which is the
machine code. The machine code can be directly understood by the CPU.
Advantages
The symbolic programming is easier to understand.
It is easier to fix the errors.
Efficiency in execution of program just like in a machine level language.
Disadvantages
It is machine dependent so it cannot be used in other architecture.
A small change in design can invalidate the whole program.
It is difficult to maintain.
Let’s Review
A translator is a programming language that converts a computer program from
one language to another.
A translator translates high-level language program into a machine language
program.
A compiler is a program that translates source code into object code.
An interpreter is used to convert high-level programming language to low-level
programming language.
An assembler is a translator used to translate assembly language to machine
language.
An assembly language is difficult to understand as it is a low-level programming
language.
Let’s Review
The process of developing software, according to the desired needs of a user, by
following a basic set of interrelated procedures is known as Program
Development Life Cycle.
Program Development Life Cycle is a step by step process where each stage is
a building block of an effective and efficient program.
The computer user must figure out the problem, and then decide how to resolve
it.
While designing the program, it requires three steps. They are algorithm, flowchart
and pseudo code.
Coding the program means translating an algorithm into specific programming
language.
During the maintenance phase, the program is actively used by the users.
If any enhancements are found in the maintenance phase, all the phases are to be
repeated again to make the enhancements.
11 Programming Techniques
Algorithm
Advantages
It is a step wise step representation of a solution to a given problem, which makes
it easy to understand.
An algorithm uses a definite procedure.
It is not dependent on any programming language.
It is easy to understand for anyone even without the knowledge of programming
languages.
Every step in an algorithm has its own logical sequence so it is easy to debug.
The problem is broken down into smaller pieces or steps so that it is easier for
a programmer to convert it into an actual program.
Characteristics of an Algorithm
A good algorithm must have the following characteristics:
Input: An algorithm must have well defined inputs.
Output: An algorithm must have well defined outputs, and should match with the
desired output.
Feasibility: An algorithm must be terminated after a finite number of steps.
Independent: An algorithm must have step-by-step directions which must be
independent from programming code.
Unambiguous: An algorithm must be unambiguous and clear. Each of their steps
and input/outputs must be clear.
Algorithm Samples
Sample 1: Write an algorithm to add any two numbers entered by the user.
Step 1: Start
Step 2: Declare the variables num1, num2 and sum.
Step 3: Read the values of num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
Sample 5: Write an algorithm to find the largest number among three different
numbers.
Step 1: Start
Step 2: Declare variables a,b and c.
Let’s Review
An algorithm is defined as a step-by-step procedure or method for solving a
problem by a computer in a finite number of steps.
Algorithms can be expressed in many different notations, including natural
languages, pseudocode, flowcharts and programming languages.
Every step in an algorithm has its own logical sequence so it is easy to debug.
An algorithm must be terminated after a finite number of steps.
An algorithm must have step-by-step directions which is independent of any
programming code.
Flowchart
Let’s Review
Differences between algorithm and flowchart
An algorithm involves a combination of sequential steps to interpret the logic of
the solutionwhereas a flowchart is the pictorial illustration of the algorithm.
A flow chart is more understandable as compared to the algorithm.
The algorithm is written in a language that can be perceived by humans.
The flowchart is made up using different shapes and symbols.
There are no stringent rules implemented in the algorithms while the flowchart
is abided by predefined rules.
Errors are easily detected in the algorithm as compared to the flow charts.
Flow charts are simple to create but the construction of the algorithm is complex.
Types of Flowcharts
System Flowcharts
System flowcharts display how data flow inside a system and the execution
of decisions to control events. It is the graphical representation of the flow of data in the
system, and represents the work process of the system. Various symbols are used in the
flowchart to designate specific actions. System flowchart is the graphical representation
of the flow of data in the system, and represents the work process of the system.
Program Flowcharts
Program flowchart is a diagram which uses a set of standard graphic symbols to represent
the sequence of coded instructions. It is a great tool to improve the work efficiency. There
are four basic symbols in a program flowchart. They are start, process, decision and end.
Each symbol represents a piece of code written for the program.
start
end
Selection Structure
Selection structure is used in
flowchart to determine which
False/No True/Yes
particular step or set of steps is to Raining
be executed. This is also called a
‘decision structure’. A selection
statement can be used to choose
a specific path dependent on a Put on Take
condition. suncream umbrella
Repetition Structure
When a program goes through a loop for certain False
times repeatedly, it is known as repetition. Condition
Repetition is the process of repeating one or more
steps in a process. The branching decision is based
on a condition at the time that the branching test
True
is performed. The condition is normally based on
the value of a single variable known as the control
variable. The steps to be repeated are referred Process
to as the loop body.The step at which the body
starts is known as the loop entrance and the step
at which the test to branch back fails is known as
the loop exit.
Let’s Review
A flow chart is a graphical representation of a system that details the sequencing
of steps required to create an output.
Flow chart uses a set of basic symbols to represent various functions, and
shows the sequence and interconnection of functions with lines and arrows.
Each flow chart is concerned with one particular process or system.
Flowcharts are extremely useful in programming because it simplifies the
complicated algorithm and converts it into the understandable pictorial
representation.
With the help of the flowchart, the application designer can easily separate
different components of the process.
There are two types of flowcharts. They are system flowcharts and program
flowchart.
System flowchart is the graphical representation of the flow of data in the system,
and represents the work process of the system.
Stop
F: Temperature in Fahrenheit
Input value
Algorithm of C
Step-1: Start
Step-2: Input temperature in Celsius C F = (9.0/5.0 × C)+ 32
Step-3: F = (9.0/5.0 × C)+ 32
Step-4: Display temperature in Fahrenheit F Print F
Step-5: Stop
Stop
Stop
Algorithm
Area = L × B
Step-1: Start
Step-2: Input Length and breadth L, B PERIMETER
= 2 × ( L+B:
Step-3: Area = L × B
Print AREA,
Step-4: PERIMETER = 2 × ( L+B)
PERIMETER
Step-5: Display AREA, PERIMETER
Step- 6: Stop Stop
Start
Input Value
of NUM1
Input Value
of NUM2
Stop
is Yes
B > BIG BIG = B
No
is Yes
C > BIG BIG = C
No
Write BIG
Stop
ENDIF
Step-5: I = I + 1
D=1
Step- 6: GO To Step 3
Step- 7: Stop
If No
Stop
CTRL<N
Yes
If Yes
(N mod D=0) Print D
No
D = D+ 1
Stop
is Yes
I > 50
No
Yes Print
IF(I mod 2 = 0)
No
I=I+1
Stop
DO
IF (N mod D = 0) THEN is 1 > 10
PRINT D No
ENDIF PROD = NUM*1
D = D+1
I=I+1
Stop
Let’s Review
There are four basic symbols in a program flowchart. They are start, process,
decision and end.
Program flowchart can help programmers to find the bug in the process
before carrying out the task.
The sequence control structure is defined as the straight forward execution of one
processing step after another.
Selection structure is used in flowchart to determine which particular step or set of
steps is to be executed.
When a program goes through a loop for certain times repeatedly, it is known as
repetition which is the process of repeating one or more steps in a process.
The step at which the body starts is known as the loop entrance and the step at
which the test to branch back fails is known as the loop exit.
12 Programming in QBASIC
Introduction to Qbasic
Features of Qbasic and starting Qbasic
Qbasic Interface
Elements of Qbasic Programming
Qbasic Operators
Qbasic Expressions
Features of QBASIC
QBASIC Interface
File Menu
New:This menu clears the current program.
Save: Save the current program in the storage location.
Open: It loads the program from the storage location.
Save as: Save the program file under new name.
Print: Print the selected text or entire program.
Exit:It helps to quit from QBASIC working program.
Edit Menu:The menu provides most of the operations for the Qbasic editor
such as opening a file, saving a file, and so many others. The details are given below.
Cut: It removes the selected text and stores it in the clipboard.
Copy: Copies the text instead of removing it.
Paste: Adds the text in the clipboard to the current position of the cursor.
Clear: Removes the text without storing it to the clipboard.
New Sub: Enables you to create a new subroutine.
New Function: Enables you to create a new function.
View Menu
SUBs: It shows the list of current subroutines and functions.
Split: Displays the contents of the current program in two windows. If the window
is already split, this hides the second window.
Output Screen: Shows the Qbasic output screen.
Run Menu
Start: Executes the current program.
Restart: Starts from the beginning.
Debug Menu
Step: Processes the next command.
Procedure Step: Processes the next command, but does not show QBasic going
inside a subroutine or function.
Trace On: Shows the command that is being executed while the program is
running.
Toggle Breakpoint: Sets or removes a breakpoint.
Clear All Breakpoints: Removes all breakpoints in the program.
Set Next Statement: Allows you to continue execution at the specified line
QBASIC programming has some elements which are required to work with a program.
The element required to construct a QBASIC program consists of a set of characters,
keywords, constants, variables, operators and expressions. Let’s discuss them in details.
Character Set
The QBASIC Character Set consists of alphabets (both small and capital),
numbers (0 to 9) and special characters (; , = , + , / , ^ , (), % , $ , < , > , #). These
special characters have their own meaning and function. A set of characters
that are allowed to use in QBASIC is known as the QBASIC Character Set.
QBASIC keywords and variables are formed by using the characters defined in
the QBASIC Character Set.
Let’s Review
The element required to construct a QBASIC program consists of a set of
characters, keywords, constants, variables, operators and expressions.
The QBASIC Character Set consists of alphabets (both small and capital),
numbers (0 to 9) and special characters (; , = , + , / , ^ , (), % , $ , < , > , #).
Keywords are those words which have special meanings formed by using
characters of QBASIC characters set.
The keywords are also called reserved words.
Some reserved words are CLS, REM, INPUT, LET, PRINT, FOR, DO,
SELECT, MID$, ASC, SQR, LEN, LEFT$, TIME$, INT, etc.
Constants
Constants are defined as the values used in programs that do not change during the
execution of program. The constant data may be a letter, words, numbers, or special
characters. A constant can be stored in a variable when it is required to use in more
than one statement or expression. CONST statement is used to declare the constants
in QBASIC programming. For Eg: CONST pi=3.14. In QBASIC, these constants are
grouped into two main categories. They are sting constant and numeric constant.
String Constant
Sting Constant is a letter, words, numbers, combination of letters with numbers or special
characters enclosed in double quotes. Mathematical operations cannot be performed
on String Constants. “A”, “SHUBHARAMBHA”, “ROLL NO:10”, “ !Welcome to
Kathmandu !”, etc. are some examples of Sting Constants.
Numeric Constant
Numeric Constant refers to a number. A number with or without decimal point is a numeric
constant. Separators are not allowed to use in numeric constant. Numeric data should not
be enclosed in double quotes. Mathematical operations and logical operations can be
performed on the numeric constants. 110, 205.40, 420, 65503, etc. are some examples of
numeric constants. Numeric Constants may be integer, long integer, single precision or
double precision.
Let’s Review
Constants are defined as the values used in programs that do not change during the
execution of program.
CONST statement is used to declare the constants in QBASIC programming.
Sting constant is a letter, words, numbers, combination of letters with numbers or
special characters enclosed in double quotes.
A number with or without decimal point is a numeric constant. Separators are not
allowed to use in numeric constant.
Mathematical operations and logical operations can be performed on the numeric
constants.
A literal constant is just a value. It does not have a name; it is just a literal value.
Symbolic Constants assign a name to a constant value.
Variable
A variable is a quantity whose value changes during the execution of a program.
It is a quantity which can store value in computer memory. A program needs data to
Numeric Variable
Numeric variable has a number as its value. Salary!, Age%, Mark, Number1, Number2,
FirstNum, RollNumber, etc., are examples of Numeric variables. A numeric variable can
be Integer, Long integer, Single precision or Double Precision variables.
An integer variable can store only an integer number. Its type declaration sign is
percentage (%).
A long integer variable can store a large range of whole number.
A single precision variable can store a whole number as well as number with
decimal. Its type declaration sign is exclamation sign (!).
A double precision variable also stores a whole number as well as number with
decimal point. Its type declaration sign is hash (#).
String Variable
A string variable stores sting data. Its type declaration sign is dollar ($).Naam$, Address$,
Bookname$, GameName$, etc., are the examples of sting varibales.
Declaration of Variable
Variables in QBASIC can be declared in two different ways. They are explained below.
Implicit Declaration: Implicit declaration is the default method of declaring
variable in QBASIC. In this declaration, type declaration character is used in an assignment
statement. Using this method, we can declare variable at the time of assigning value to
the variable. We should take care of type declaration symbol during the declaration and
use of variable.
Explicit Declaration: Explicit declaration of variable is done before the use
of variables. In this declaration, a value is not assigned to the variable. DIM
statement is used to declare variables explicitly in QBASIC. Eg: DIM a AS
INTEGER, DIM b AS STRING, etc. It’s not mandatory to use type declaration
symbol while declaring variables explicitly. Also, as all variables are declared at
the top, programmers are less prone to use same variable name for different purposes.
Let’s Review
A variable is a quantity whose value changes during the execution of a program.
Numeric variable has a number as its value. Salary!, Age%, Mark, Number1,
Number2, FirstNum, RollNumber, etc., are the examples of Numeric Variables.
A numeric variable can be Integer, Long integer, Single precision or Double
precision variables.
A double precision variable also stores a whole number as well as number
with decimal point. Its type declaration sign is hash (#).
A string variable stores sting data. Its type declaration sign is dollar ($).
Implicit declaration is the default method of declaring variable in QBASIC.
Explicit declaration of variable is done before the use of variables. In this
declaration, a value is not assigned to the variable.
DIM statement is used to declare variables explicitly in QBASIC.
Variable names can have maximum 40 characters.
QBASIC Operators
Operators are the symbols that indicate the type of operation that has to be performed on
the data or on the values of variables.There are four types of operators in QBASIC. They
are Arithmetic Operators, Relational Operators, Logical Operators and Sting Operators.
Arithmetic Operators
Arithmetic Operators are used to perform mathematical calculations like addition,
subtraction, division, multiplication and exponential. The following table shows arithmetic
operators used in QBASIC.
Logical Operators
Logical Operators combine two or more relational expressions to evaluate a single value
as True or False. The result of evaluation is used to make decisions about the program
flow. The commonly used logical operators in QBASIC are AND, OR and NOT.
AND Operator
AND operator returns ‘True’ when all the results returned from individual relational
expressions are ‘True’ otherwise it returns ‘False’.The Truth Table of AND operator is
given below.
NOT Operator
NOT Operator operates on one operand and returns ‘True’ if the logical operation returns
‘False’. The NOT truth table is as given below
Let’s Review
Operators are symbols that indicate the type of operation that has to performed
on the data or on the values of variables.
There are four types of operators in QBASIC. They are arithmetic operators,
relational operators, logical operators and sting operators..
Arithmetic operators are used to perform mathematical calculations like addition,
subtraction, division, multiplication and exponential.
Relational operators are used to perform comparisons on two values of same type.
Logical operators combine two or more relational expressions to evaluate a single
value as True or False.
AND operator returns ‘True’ when all the results returned from individual
relational expressions are ‘True’ otherwise it returns ‘False’.
OR operator returns ‘True’ if any one of the relational expressions returns ‘True’.
NOT operator operates on one operand and returns ‘True’ if the logical operation
returns ‘False’.
Expressions
Let’s Review
A string expression consists of string constant, string variables and other string
expressions combined by string operators.
The assignment operator evaluates an expression on the right of the expression
and substitutes it to the value or variable on the left of the expression.
An expression is the combination of operators, constants and variables that is
evaluated to get a result.
A Boolean expression is a logical statement that is either TRUE or FALSE.
Boolean expressions can compare data of any type as long as both parts of the
expression have the same basic data type.
A string expression must begin with a concatenation operator ($) or with a string
constant in quotes (i.e., "...").
The concatenation operator combines components together, and must be between
all components of a string expression.
a. a2 + 2ab + b2
b. x + y
2 2
z2
c. 2x + 3y – 4c
d. 2�(r+h)
e. ax2 + bx + c
13 QBASIC Statements
QBASIC Statements
REM <remark> Here, remark may be any statement or phrase to define the program.
CLS Statement: This statement is used to clear the previous output from the display
screen and makes the screen blank. This command is given before the starting of any new
program. The general format of CLS statement is as given below.
<CLS>
<END>Practical Assignment
a. REM 'To add the number 30 and 40
CLS
LET a = 30
LET b = 40
sum = a + b
PRINT "The Sum is"; sum
END
b. REM 'To find the sum of any two numbers
CLS
INPUT "Enter the first number"; a
INPUT "Enter the second number"; b
sum = a + b
PRINT "The sum is"; sum
END
Let’s Review
A statement is a computer instruction written in a source language, which is
converted into one or more machine code instructions by a compiler.
The command or the set of instructions in the QBASIC is called a statement.
Qbasic statements are classified into two statements.They are executable
and non-executable.
Executable statement specifies actions whereas non-executable statements
specify characteristics, arrangements and initial values of data.
REM statement is used to insert explanatory remarks for the program that
we are writing.
REM is a non-executable statement where single quotation (‘) is used.
CLS statement is used to clear the previous output from the display screen and
makes the screen blank.
LET statement is used to assign the value in the variable. It is also called as
an assignment statement.
INPUT statement is used to receive input data from the keyboard during the
execution of the program.
PRINT statement is used to display the output on the screen.
END statement is used to indicate the end of the QBASIC program to terminate it.
Practical Assignment
a. CLS b. CLS
LINE INPUT "Enter the data"; n$ LINE INPUT "Enter a sentence"; n$
PRINT n$ PRINT n$
END END
LPRINT and LPRINT USING Statement: The LPRINT statement is used to print the
text to a printer and the LPRINT USING statement is used to print formatted output to a
printer. The general format of LPRINT and LPRINT USING statement is as given below.
READ….DATA Statement: This statement is used to read values from the DATA
statement and assign them to variables. It is used mostly when dealing with large quantities
of data in program.The DATA statement is to store the numeric and string constants that
are accessed by the READ statement. The general format of READ…..DATA statement
is as given below.
Practical Assignment
a. CLS b. CLS
READ a, b, c READ A, B, C, D
PRINT a, b, c Total = A + B +C + D
DATA 100,200,300 Avg = Total / 4
END PRINT "The total value is"; Total
PRINT "The average value is"; Avg
DATA 80,50,40,70
END
RESTORE[line number] Here, If line number is specified, the next READ statement
accesses the first item in the specified DATA statement and If line number is omitted, the
next READ statement accesses the first item in the first DATA statement.
Practical Assignment
a. CLS
READ a, b, c
PRINT a, b, c
RESTORE
READ d, e, f
PRINT d, e, f
DATA 10,20,30
END
Practical Assignment
a. CLS
LOCATE 5, 30
PRINT "New Gateway to Computer"
END
SWAP Statement :This statement is used to exchange the values of two variables. The
general format of SWAP statement is as given below.
SWAP variable1, variable2
Practical Assignment
a. CLS
INPUT "Enter the first number"; a
INPUT "enter the second number"; b
PRINT "Before using SWAP”; a, b
SWAP a, b
PRINT "After SWAP"; a, b
END
Let’s Review
PRINT USING statement is used to display string or number using a specified
format.
LINE INPUT statement allows inputting line of data at a time and assigning
in to single variable.
READ….DATA statement is used to read values from the DATA statement
and assign them to variables.
The RESTORE statement is used to reset the DATA pointer to the beginning
of the data.
LOCATE statement is used to move the cursor to the specified position on the
screen.
SWAP statement is used to exchange the values of two variables.
Program 1: Write a program to input any three numbers and display its sum
and average.
REM 'to calculate sum and average of three numbers
CLS
INPUT "Enter first number"; A
INPUT "Enter second number"; B
INPUT "Entre third number"; C
SUM = A + B + C
AVG = (A + B + C) / 3
PRINT "The sum is"; SUM
PRINT "The average value is"; AVG
END
Statements that specify the order in which actions are executed are called control
statements. A program consists of a number of statements which are usually executed
in sequence. Control statements allow you to change the computer's control from
automatically reading the next line of code to reading a different one. The control
statements are used for controlling the execution of the program. In a program, a control
structure determines the order in which statements are executed. Mainly, there are two
types of control statements in QBASIC. They are Branching Statement and Looping
Statement.
Branching statement
Branching statement is a decision making statement. Depending upon the decision,
branching statement can change the order of execution. Branching statements are divided
into two types.
2.
CLS
INPUT "Enter a number "; N
IF N MOD 2 = 0 THEN PRINT "It is Even Number"
IF N MOD 2 = 1 THEN PRINT "It is Odd Number"
END
3. CLS
INPUT "Enter first number "; A
INPUT "Enter second number "; B
INPUT "Enter third number "; C
IF A>B AND A>C THEN G=A
IF B>A AND B>C THEN G = B
IF C>A AND C>B THEN G= C
PRINT “The greatest number is:”; G
END
Practical Assignment
1. CLS
INPUT "Enter your marks in computer"; C
IF C >= 40 THEN
PRINT "You are passed."
ELSE
PRINT "You are failed ."
END IF
END
2. CLS
INPUT "Enter first number "; A
INPUT "Enter second number "; B
INPUT "Enter third number "; C
IF A> AND A>C THEN
PRINT "The greatest number is"; A
IF B>A AND B>C THEN
PRINT "The greatest number is"; B
ELSE
PRINT "The greatest number is:"; C
END
3. CLS
INPUT "Enter a number "; N
Practical Assignment
1.
CLS
INPUT "Enter First Number "; A
INPUT "Enter Second Number "; B
INPUT "Enter Third Number "; C
IF A>B AND A>C THEN
PRINT "The greatest number is "; A
ELSEIF B> A AND B>C THEN
PRINT "The greatest number is "; B
ELSE
PRINT "The greatest number is "; C
END IF
END
Practical Assignment
1. CLS 2. CLS
AA: n=1
INPUT "Enter the first Number"; A top:
INPUT "Enter the second Number"; B PRINT n;
Sum = A + B n=n+1
PRINT "The sum is"; Sum
IF n <= 20 THEN GOTO top
GOTO AA
END
END
FOR
COUNTER_VARIABLE = STARTVALUE
COUNTER_VARIABLE FALSE
<END_VALUE
COUNTER_VARIABLE =
COUNTER_VARIABLE +
Statement of Loop
STEPVALUE
NEXT
FOR……NEXT Statement
It is the fundamental looping statement in QBASIC. It provides a way to repeat a block
of statements over a predetermined number of times. The FOR…..NEXT loop is used
when we are required to perform repetitive tasks, such as to display addition of all values
between 100 to 200, display all prime numbers between 1 to 100, etc.
Syntax
For counter variable = <initial value>To <Ending Value> [step increment / decrement]
[statements]
[Exit For]
[statements]
Next
Let’s observe the given table to understand the parts of the syntax.
Practical Assignment
1. CLS 2. CLS
FOR I = 1 to 10 FOR I = 1 to 10 STEP 2
PRINT I; PRINT I;
NEXT NEXT
END END
3. CLS 4. CLS
FOR I = 10 to 1 STEP -2 FOR I = 1 to 10
PRINT I; PRINT "Computer";
NEXT NEXT
END END
5. CLS
FOR I = 1 to 3
FOR J = 1 to 3
PRINT "Computer"
NEXT
NEXT
END
Syntax TRUE
WHILE (TEST CONDITION) Statement of Loop
(Statements OF Loop)
WEND WEND
Let’s observe the given table to understand the part of the syntax.
Part Description
TEST CONDITION It is a numeric or string expression that evaluates whether
the statement is TRUE or FALSE.
Statements OF Loop It is a set of one or more QBASIC statements.
WHILE Statement It always checks the condition before it begins the loop.
LOOP It continues till the condition remains TRUE.
Practical Assignment
1.
REM to print series from 1 to 10 2.
REM to print series from 1 to 20
CLS CLS
C=1 C=1
WHILE C <= 10 WHILE C <= 20
PRINT C PRINT C
C=c+1 C=c+1
WEND WEND
END END
Part Description
It is numeric or string expression that evaluates whether the con-
TEST CONDITION
dition is TRUE or FALSE.
• It is a set of one or more QBASIC statements.
• If the condition is TRUE, all statements in statement in loop
are executed until the loop statement is encountered.
Statement of Loop
• Control then returns to the WHILE statement and Condition is
again checked.
• If the condition is still TRUE, then the process is repeated.
If the Condition is FALSE, then the loop statements are skipped
LOOP
and the statement after LOOP statement is executed.
Practical Assignment
1. REM to print the series from 1 to 10 2 REM to print the series from 1 to 20
CLS CLS
c=1 C=1
DO WHILE c <= 10 DO WHILE C <= 20
PRINT c PRINT C
c=c+1 C=C+1
LOOP LOOP
END END
LOOP
Let’s observe the given table to understand the part of the syntax.
Part Description
TEST CONDITION It is a numeric or string expression that evaluates
whether the statement is TRUE or FALSE.
Statement of Loop It is a set of one or more QBASIC Statements.
Practical Assignment
1.
REM a program to print the series from 1 to 10.
CLS
C=1
DO UNTIL C = 11 (this number will not be displayed)
PRINT C
C=C+1
LOOP
END
2.
REM a program to print the series from 1 to 20.
CLS
C=1
EXIT Statement:
Statement before
The EXIT Statement is used to terminate
the loop based on certain criteria before DO UNTIL
the expected number of iterations.
DO UNTIL
When the EXIT Statement is executed,
the control jumps to next statement
immediately after the loop. We can use
the EXIT Statement in all types of loops.
FALSE
CHECK CONDITION
Syntax: EXIT DO / FOR
TRUE
EXIT
Statement of Loop
DO
LOOP
Practical Assignment
1. CLS
X=1
DO
prod = x* 5
IF prod >50 THEN EXIT DO
PRINT prod
X=X
LOOP WHILE X<=10
END
Practical Section
Program 1: Write a Qbasic program to find out the simple Interest and the
Amount.
CLS
Input "Enter the Principal";P
Input "Enter the Rate";R
Input "Enter the Time";T
Let I = P*T*R/100
Let A= P + I
Print "The simple Interest = ";I
Print "The amount=";A
End
Program 2: Write a Qbasic program to find out the area of four walls of a
room.
CLS
Input "Enter the height";H
Program 3: Write a Qbasic program to enter any three numbers and calculate
their sum and average.
CLS
Input "Enter any number" ;A
Input "Enter any number" ;B
Input "Enter any number" ;C
Let Sum = A+B+C
Let Average =Sum/3
Print "The sum=" ;Sum
Print "The Average is" ;Average
End
Program 6: Write a Qbasic program to enter any number and find out whether
it is even or odd using select case statement.
CLS
Input "Enter any number" ;N
Rem=N mod 2
Select case Rem
Case = 0
Print "The number is Even number"
Case Else
Print "The number is odd number"
End Select
End
Program 8: Write a QBASIC program to enter any alphabet and test whether
the alphabet is ‘a’ or not using the select case statement.
CLS
Input "Enter the alphabet";A$
A$=UCase$ (A$)
Select Case A$
Case 'A'
Print "It’s alphabet A"
Case Else
Print "It’s not alphabet A"
End Select
End
Program 9: Write a QBASIC program to enter any alphabet and find out
whether the alphabet is vowel or not.
CLS
Input "Enter Letters"; A$
A$ = UCase $ (A$)
Select case A$
Case "A", "E", "I", "O", "U"
Print "It is vowel"
Case Else
Print "It is not a vowel"
End Select
End
Program 15: Write a QBASIC program to find out the factorial of a given
number (n).
CLS
REM' PROGRAM TO FIND THE FACTORIAL OF A GIVEN NUMBER
INPUT "ENTER A NUMBER:"; N
F=1
FOR I = 1 TO N
F=F*I
NEXT I
PRINT "THE FACTORIAL OF THE NUMBER IS", F
END
Program 16: Write a QBASIC program to find check whether the entered
number is palindromic or not.
CLS
INPUT "ENTER ANY NUMBER"; N
A=N
S=0
WHILE N <> 0
A palindromic number is a number that is the same when
R = N MOD 10
written forwards or backwards. The few palindromic
S = S * 10 + R numbers are 0 to 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101,
N = N \ 10 111, 121 and so on
WEND
Program 18: Write a QBASIC program to display the prime numbers from
2 to 100.
Method 1
CLS
FOR I = 1 TO 100
C=0
FOR J= 1 TO i
IF I MOD J = 0 THEN C = C + 1
NEXT J
IF C = 2 THEN PRINT I;
NEXT I
END
Program 20: Write a QBASIC program to check whether the entered number
is Armstrong or not.
The number which is formed by the sum of
Method 1:Using DO………LOOP cubes of its own digits is Armstrong number.
CLS 153, 370, 371, 407 are the Armstrong
numbers.
INPUT "Enter a number"; N
B=N Let’s take an example of 153.
DO WHILE N<> 0 153 = 13 + 53 + 33
R = N MOD 10 = 1 + 125 + 27
A = A +R ^ 3 = 153
1 CLS
222 FOR I = 1 TO 6
LOCATE I, 50 - I
33333 FOR J = 1 TO I * 2 - 1
4444444 PRINT USING "#"; I;
NEXT
555555555 PRINT
666666666666 NEXT
END
Assignment
1. Fill in the blanks with suitable words.
a. ……….. allow you to change the computer's control from automatically reading the
ext line of code to reading a different one.
b. …………… statement allows the selective execution of statements based on a
particular condition.
c. ………….. statement is also called two way decision making statements.
d. The IF….THEN…..ELSE statement is another form of ………….. statement in
which the conditions are evaluated from top to button.
e. The ………….. statement in QBASIC is used to transfer the program control
from one statement to another.
f. The ……………. loop is used when we are required to perform repetitive tasks.
g. A ………….. loop is used when you want to repeat a set of statements as long as
the condition is false.
2. State whether the given statements are true or false.
a. A program consists of a number of statements which are usually executed in
sequence.
b. Branching statement is not a decision making statement.
a. CLS b. CLS
INPUT "Enter your marks in computer"; C$ C=1
C >= 40 THEN DO NEXT C = 21
PRINT "You are passed." PRINT M
ELSE C=C+2
PRINT "You are failed ." LOOP WHILE
IF END
END
c. CLS
FOR I = 1 TO 6 f. CLS
LOCATE I, 50 - I A=1
FOR J = 1 TO I * 2 - 1 FOR I = 1 TO 5
PRINT USING "#"; I; FOR J = 1 TO I
NEXT PRINT A;
PRINT A = A+I
NEXT J
NEXT
PRINT
END
NEXT I
END
Here, DEF FN defines a single-line function. The name you must use to call your function
is FNname. If you use this, you will be able to calculate everything using one line.
Built in Function
Numeric Functions:
Numeric function provides a faster way to evaluate many mathematical functions. Some
of the numerical functions are listed below.
ABS Function : This function is used to obtain an absolute corresponding positive value
of a numerical expression. The syntax of ABS function is given below.
Practical Assignment
CLS
N = ABS(5 * (-3))
PRINT "The absolute value is:"; N
END
CINT Function: It is a mathematical function used to convert numeric expression to
an integer by rounding the fractional portion or it returns the integer to the given number.
The syntax of CINT function is given below.
CINT (x), where x is a numeric expression. If it is not in range ( -32768) to (+32767), an
overflow error message will appear.
Practical Assignment
CLS
INPUT "Enter an angle in degree"; A
R = A * 3.14 / 180
P = COS(R)
PRINT "COSINE OF"; A; "Degree"; "is"; P
END
SIN Function: It is also a mathematical function which is used to get the sine of x. To
convert degrees to radians use the formula: radian = degree*(Pi/180). Where, Pi=3.14.
The syntax of SIN function is given below.
Practical Assignment
CLS
INPUT "Enter an angle in degree"; A
R = A * 3.14 / 180
P = SIN(R)
PRINT "Sineof"; A; "Degree"; "is"; P
END
TAN Function: It is a mathematical function that returns the tangent of an angle expressed
in radians. To convert degrees to radians use the formula: radian = degree*(Pi/180).
Where, Pi=3.14. The syntax of TAN function is given below.
Let’s Review
A function is a built-in formula or a readymade program which helps us to perform
a certain task such as mathematical, statistical, financial, logical calculations, etc.
A function which is written and stored by the programmer to perform a specific
task is known as a user defined function.
Built in function is a pre-defined program which is provided by QBASIC to
perform some task easily.
Numeric function provides a faster way to evaluate many mathematical functions.
ABS function is used to obtain the absolute corresponding positive value of
a numerical expression.
CINT is a mathematical function used to convert numeric expression to an integer
by rounding the fractional portion.
COS is a mathematical function which is used to obtain the cosine of x.
TAN is a mathematical function that returns the tangent of an angle expressed in
radians.
INT Function: This function is used to obtain the largest integer that is less than or equal
to x. INT rounds negative numbers to the next more negative integer. The syntax of INT
function is given below.
Practical Assignment
CLS
INPUT "Enter a number"; N
Result = INT(N)
PRINT "The integer value is"; Result
END
Practical Assignment
CLS
INPUT "Enter a number"; N
Result = SGN(N)
PRINT "The SGN value is"; Result
END
SQR Function: It is used to calculate and return the square root of non-negative number.
If the number is negative, an illegal function will appear. The syntax of SQR function is
given below.
Practical Assignment
CLS
INPUT "Enter a number"; N
Result = SQR(N)
PRINT "The square root value is"; Result
END
String Functions
QBASIC program has various built in string functions that are mainly used to operate and
manipulate string expressions. Some of the string functions are listed below.
ASC Functions: It is a string processing function which is used to return a numeric
value that is the ASCII code for the first character of the string. The ASCII values of some
commonly used characters are given below.
Practical Assignment
CLS
A = ASC("SHUBHARAMBHA")
B = ASC("gatewaycomputer")
C = ASC("4302109")
PRINT A
PRINT B
PRINT C
END
CHR$ Function : This function returns a character that corresponds to specific ASCII
values in between -128 and 127 as arguments. The syntax of CHR$ function is given
below.
Practical Assignment
CLS
PRINT "The ASCII code of 80 is::"; CHR$(80)
PRINT "The ASCII code of 110 is::"; CHR$(110)
PRINT " The ASCII code of 50 is::"; CHR$(50)
END
LEN Function: It is a string processing function which is used to count and return to the
total number of characters in a string. The syntax of LEN function is given below.
Practical Assignment
CLS
A$ = "SCIENCE"
B$ = "C"
PRINT "In the word SCIENCE, The first letter C occurs at the position:"; INSTR(A$, B$)
PRINT "In the word SCIENCE, The second letter C occurs at the position:"; INSTR(3,
A$, B$)
END
VAL Function: It is a string processing function which converts a string expression
consisting of digits into value. The extracted value is numeric in nature and can be used
for mathematical calculation. If the first character of a string is not numeric, then VAL
will return 0(zero). The syntax of VAL function is given below.
VAL(N$), Where N$ is any string expression.
Practical Assignment
CLS
A$ = "20 Computer Books"
C = VAL(A$)
B$ = "40 Maths Books"
Practical Assignment
CLS
INPUT "Enter a Word"; C$
FOR I = 1 TO LEN(C$)
PRINT LEFT$(C$, I)
NEXT I
END
RIGHT$ Function:This string processing function is used to extract and return to
the numbers of characters from the right of a string. The syntax of RIGHT$ function is
given below.
RIGHT$ (String expression, n) where, string expression is a string constant, variable or
expression and n is an integer expression in the range.
Practical Assignment
CLS
INPUT "Enter a Word"; C$
FOR I = 1 TO LEN(C$)
PRINT RIGHT$(C$, I)
NEXT I
END
MID$ Function:This function is used to replace the part of the string variable with
another. The syntax of MID$ function is given below.
MID$(string expression,start,length) where, string expression is the string from which
the sub starting has to be extracted. Start is the starting position to extract from the string
expression and length is the number of characters to extract.
Let’s Review
INT function is used to obtain the largest integer that is less than or equal to x.
SQR function is used to calculate and return to the square root of non-negative
number.
ASC is a string processing function which is used to return to a numeric value that
is the ASCII code for the first character of the string.
LEN is a string processing function which is used to count and return to the total
number of characters in a string.
VAL is a string processing function which converts a string expression consisting
of digits into value.
LEFT$ is a string processing function which is used to extract and return to the
numbers of characters from the left of a string.
RIGHT$ is a string processing function which is used to extract and return to the
numbers of characters from the right of a string.
MID$ function is used to replace the part of the string variable with another.
Practical Assignment
CLS
FOR I = 1 TO 10
N$ = SPACE$(I)
PRINT N$, I;
NEXT I
END
Practical Assignment
CLS
INPUT "Enter a decimal number"; N
WHILE N <> 0
R = N MOD 2
S$ = STR$(R) + S$
N=N\2
WEND
PRINT "THE BINARY EQUIVALENT VALUE IS::"; S$
END
STRING$ Function:This function is used to return to a string of a specified length made
up of a repeating character. The syntax of STRING$ function is given below.
STRING$(x,y | z$)Where, x and y are the numeric expression and Z$ is any string
expression.
Practical Assignment
CLS
FOR I = 1 TO 6
PRINT STRING$(I, "*")
NEXT I
END
LCASE$ Function: This is a string processing function which converts the string into
lower case. The syntax of LCASE$ function is given below.
LCASE$(String expression)
Practical Assignment
CLS
INPUT "Enter a word or sentence in UPPER case"; C$
PRINT LCASE$(C$)
END
UCASE$ Function: This is a string processing function which converts the string into
upper case. The syntax of UCASE$ function is given below.
UCASE$(String expression)
Practical Assignment
CLS
INPUT "Enter your name in 5 digits"; N$
N$=INPUT$(5)
PRINT N$
END
Let’s Review
SPACE$ function is used to generate a string of spaces of a specified length.
STR$ is a string processing function that is used to convert a numeric expression
to string and return to the same.
STRING$ function is used to return to a string of a specified length made up of a
repeating character.
LCASE$ is a string processing function which converts the string into lower case.
UCASE$ is a string processing function which converts the string into upper case.
DATE$ is a string function used to display the system date.
TIME$ string function is used to display the system time.
LTRIM$ is a string processing function which removes the leading blank space
from the string expression.
RTRIM$ is a string processing function which removes the trailing blank space
of the string expression.
INPUT$ is a string processing function which waits until the specified numbers of
characters are pressed on keyboard.
Program: 12: Write a Qbasic program to calculate the square root of a given
number.
REM Program to calculate the square root of a given number
CLS
INPUT "Enter any number"; n
s = SQR(n)
PRINT "Square root of "; n; " is "; s
END
c. CLS d. CLS
INPUT "Enter a letter";A$ INPUT "ENTER A DECIMAL NUMBER"; N
16 Arrays in QBASIC
Introduction to array
Advantages of using array
Declaring and using an array
Arrays variables
Arrays elements
Types of array
Rules for declaring one dimensional array
Sorting data in array
Searching data in array
Working with single and double dimensional array
An array is a collection of variables of the same data type that are referred to by common
name. When there are large lists of variables and data, it is easier to contain the data in
an array than have large amounts of separate variables to hold the data. Array is a group
of related data items having a common variable name. An array is primarily used when
groups of data items must be stored and manipulated efficiently. An array is given a name
and also a specified number of data items that it will contain; each individual item is
referred to as an element. Each element is given a unique storage location in the array and
a subscript or index value is used to identify the position of a particular element.
An array declared should indicate the three main things.
a. Name of the array.
b. Type of value to be stored in an each element.
c. Number of elements in an array.
Arrays need to be declared before using in a program and to declare an array; we must
use a DIM statement. DIM statement plays the role of reserving internal memory space
for an array of any desired size. We have to remember the name of array, number of
elements required and data type required before declaring an array.
Syntax: DIM [SHARED] arrayname (subscript) [AS TYPE] [arrayname (subscript) [AS
TYPE]]
Here, SHARED is a keyword that is used to share the value of the variable with the
procedures. Arrayname is the name of the array variable. Subscript specifies the size of
an array and AS TYPE defines the type of array variable.
Examples
DIM age (20)
DIM name$(20)
In this example age and name$ are the name of array variables and 20 is the size of
variable which provides maximum 21 elements (o to 20) or subscripted variables for an
array.
Array Elements
Once an array is created, we have to put something in it. Each element or index has an
integer value associated with it. Each data item of an array is called array elements. Each
array element is individually referred to by its subscript. The number of elements that an
array can store is calculated using the given formula.
Number of elements = (upper bound – lower bound +1)
Example: Declare a string array variable that can store address of any 10 students.
DIM add$(9)
Or
DIM add(9) AS STRING
Here, add$ is the name of string type array variable and 9 is subscript. Its upper bound
is 9. It can store any 10 string values from 0 to 4. The add$ array can store the ten string
values in the given format.
Add$ Add$ Add$ Add$ Add$ Add$ Add$ Add$ Add$ Add$
(0) (1) (2) (3) (4) (5) (6) (7) (8) (9)
Pokhara Palpa Dhading Butwal Sarlahi Dhanusa Mugu Rolpa Sindhuli Parbat
Here the first element is represented by subscript 0. For example, Add$(0) = Pokhara
and the ninth element is represented by subscript 9 which is Add$(9) = Parbat. The upper
Practical Assignment
END
END
Practical Assignment
Program 7: Write a program to search data within an array.
CLS
DIM N(1 TO 5)
FOR I = 1 TO 5
READ N(I)
NEXT I
DATA 10,11,15,17,20
INPUT "Type the number to search"; N
h. To input any 15 numbers and display only the number that are divisible by
4.
i. To input the age of any 10 person and display the youngest one.
j. To read and print the 7 numbers in reverse order.
Project Work
Full Mark: 25