Nothing Special   »   [go: up one dir, main page]

New Gateway To Computer Science 10

Download as pdf or txt
Download as pdf or txt
You are on page 1of 289

New Gateway to Computer Science Book - 10

Our Computer Series


W
Our Computer Series N E BOOK 10
1. New Gateway to Computer Science-1
2.
3.
New Gateway to Computer Science-2
New Gateway to Computer Science-3
GATEWAY TO
4.
5.
New Gateway to Computer Science-4
New Gateway to Computer Science-5
COMPUTER SCIENCE
6. New Gateway to Computer Science-6
7. New Gateway to Computer Science-7
8. New Gateway to Computer Science-8
9. New Gateway to Computer Science-9
10. New Gateway to Computer Science-10

Price Rs. 423/-

Shubharambha Publication Pvt.Ltd.


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

NEW GATEWAY
TO
COMPUTER SCIENCE
10

Authors
Dinesh Adhikari
Dilendra Prasad Bhatta
Shekhar Poudel
Laxman Adhikari

Shubharambha Publication Pvt. Ltd.


Kathmandu, Nepal
Published by:

Shubharambha Publication Pvt. Ltd.


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

New Gateway to Computer Science Book-10

Authors : Dinesh Adhikari, Dilendra Prasad Bhatt,


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

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

Printed in Nepal
Preface
Preface

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


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

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

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

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


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

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

Unit 1 Introduction to Technology Fundamentals.............5-97


Lesson 1: Computer Networking & Telecommunications..................................6

Lesson 2: Ethical and Social Issues in ICT........................................................36

Lesson 3: Computer Security System................................................................53

Lesson 4: E-Commerce.....................................................................................66

Lesson 5: Contemporary Technology................................................................74

Lesson 6: Computer Number System...............................................................83

Unit 2 Database Management System (MS-ACCESS)......98-136


Lesson 7: Database Management System.........................................................99

Unit 3 Programming Language....................................137-283


Lesson 8: Review on Qbasic Programming....................................................138

Lesson 9 : Modular Programming in QBASIC...............................................164

 Practical Section on SUB Procedure.........................................178

 Practical Section on FUNCTION Procedure.............................205

Lesson 10 : File Handling in QBASIC............................................................232

 Practical Section on File Handling............................................242

Lesson 11 : Programming in C.......................................................................255

Practical Section in C Programming..........................................274

List of Abbreviations.........................................284-288
Introduction to
Technology Fundamentals
Unit

This unit covers the following topics:

Lesson 1: Computer Networking & Telecommunications


Lesson 2: Ethical and Social Issues in ICT
Lesson 3: Computer Security System
Lesson 4: E-Commrce
Lesson 5: Contemporary Technology
Lesson 6: Computer Number System
Lesson Computer Networking
1 & Telecommunications

Learning Outcomes

At the end of this lesson, students will be able to:


 define data communication and telecommunication.
 explain the components of data communication.
 tell about the data transmission mode and speed.
 explain transmission media.
 explain the elements of computer networking.
 explain computer networking.
 tell about networking topology.
 tell about network architecture.
 explain the types of computer networking.
 explain about internet and its services.

Simply, communication is the process of sharing


ideas, message or information with each other.
The term ‘communication’ is derived from the
word ‘communicare’ which means ‘to share’.
Data communication is the way of sharing
a virtual message. A conversation between
two or many more people is an example of
communication. Data communications refer to
the sharing of a virtual message with the help
of emails, messengers, phone calls and other
various electronic devices. Data communications technologies deal with the means
and methods of data transfer from one location to another using wired or wireless
transmission medium. The purpose of data communications is to provide us with the rules
and regulations that allow computers with different disk operating systems, languages,
cabling and locations to share resources.
Telecommunication systems are a specialized system for communication. The term
telecommunication sometimes is also referred to as telecom. Telecommunication devices
are telephones, telegraph, radio, fiber optics, satellites and the internet. Telecommunication
is a vast range of information-transmitting technology such as mobile phones, land lines

6 New Gateway to Computer Science Book -10


telephone, VOIP and broadcast network. Here, we are going to discuss some functions of
telecommunication.
 It transmits information to far distance and establish interface between sender and
receiver.
 Transmission of the data and reception of the message is done in an uninterrupted way.
 These systems also ensure that right message is received by the right user only and while
transmitting is also check for transmission errors.
 Telecommunication is responsible for converting and managing the speed of
transmission.
 It controls the flow of information that depends on the communication channels and the
terminals used to transmit information.

Components of Data Communication

A datum communication system has the following components:


Message or Data: It is the information or data to be communicated. It can consist of text,
numbers, pictures, sound, video or any combination of these. Communication of data
means a message or data will be transmitted from one device and will be received in the
destination or target device. The component in a data communication network is data or
message.
Sender: The computer or device that is used for sending data is called sender, source or
transmitter. A datum has to be sent to a destination from a source. The device that sends
data to the destination or target is the sender. It can be a computer, cell phone, video
camera and so on.
Receiver: The device that receives data is called receiver. It is the device or computer
that receives the message. The destination of a transmitted data is the receiver which
will receive the data. The device that receives the data that was sent by the sender is the
receiver. A receiver can be a computer, a cell phone, a video camera and so on.
Transmission Medium: It is the channel or physical path through which the message
is carried from sender to the receiver. The medium can be wired like twisted pair cable,
coaxial cable, fiber-optic cable or wireless like laser, radio waves, and microwaves.
Protocol: It is a set of rules that govern the communication between the devices. This
is like an arrangement between the two devices to successfully communicate with each
other. For example, how the data will be sent, how the data will be travelling, how to
ensure that full data has been received, how to handle errors in transmission, etc. Both
sender and receiver follow same protocols to communicate with each other.

New Gateway to Computer Science Book -10 7


For example, when you speak to your friend on telephone, you are the sender,
telephone is the medium, and your friend is the receiver. Similarly, in data communication,
sender and receiver are the machines and transmission medium is a wire or wireless data
communication channel.

Let’s Review
 Data communication technologies deal with the means and methods of data
transfer from one location to another using wired or wireless transmission medium.
 Telecommunication systems are a specialized system for communication.
 Transmission is the channel or physical path through which message is carried from
the sender to the receiver.
 The device that sends data to the destination or target is the sender.

Data Transmission Mode

Transmission mode means transferring of data between two devices. It is also known as
communication mode. The three modes of data transmission are simplex, half-duplex and
full duplex. They are explained below.

Transmission Mode

Simplex Mode Half Duplex Mode Full Duplex Mode

Simplex Mode
In a simplex communication mode, data
can transmit in one direction only. It One Direction
is suitable for connecting send-only
like keyboard or receive only like
monitor devices. In simplex mode, the
communication is unidirectional. The simplex mode can use the entire capacity of the
channel to send data in one direction. The best example of simplex mode is radio and
television broadcasting. In this mode, there is just one communication channel. So, we
can receive data on that channel but could not be able to transmit on the same channel.

8 New Gateway to Computer Science Book -10


Half-Duplex Mode
In a half-duplex communication mode, Send Receive
data can transmit in both directions A is sending, B is receiving
but only one direction at a time. It can
alternately send and receive data. When
one device is sending, the other device
can only receive, and vice versa. The
half-duplex mode is used in cases where
Receive Send
there is no need for communication in
both directions at the same time. The B is sending, A is receiving
entire capacity of the channel can be
utilized for each direction. The best
example of this communication mode
is Walkie-talkie in which message is sent one at a time and messages are sent in both the
directions.
Full-Duplex Mode
In full-duplex mode, a connection between two devices is capable of sending data in
both directions at the same time. In this transmission mode, the communication between
sender and receiver can occur simultaneously. The sender and receiver can both transmit
and receive data at the same time. The full duplex transmission mode is like a two-way
road in which traffic can flow in both directions at the same time. The best example of this
communication mode is telephone in which two people can communicate, and both are
free to speak and listen at the same time.
Let’s compare simplex, half-duplex and full duplex transmission mode.

Comparison Simplex Half Duplex Full Duplex


Direction of Unidirectional Two-directional, Two-directional,
Communication only one direction at simultaneously
a time
Send / Receive Sender can only Sender can send and Sender can send and
send data. receive data, but one receive data
a time. simultaneously
Performance Least performing Better than simplex Most performing
mode of mode of transmission
transmission
Example Radio, Television Walkie-talkie Telephone
broadcasting

New Gateway to Computer Science Book -10 9


Let’s Review

 In a simplex mode, signal is sent in one direction.


 In a half-duplex mode, signal is sent in both directions, but only one direction at a
time.
 In a full duplex mode, signal is sent in both directions at the same time.
 In a simplex mode, only one device can transmit the signal like this in a half-duplex
mode, both devices can transmit the signal, but one at a time and in a full duplex
mode, both devices can transmit the signal at the same time.
 Full duplex performs better than half-duplex and half-duplex performs better than
simplex mode.

Data Transmission Speed

The speed in which data can be transmitted from one device to another across a
communication channel is called data transmission rate. Data transmission rates are
measured in Kbps, Mbps, Gbps, etc.

The difference between the highest and the lowest frequencies on a transmission is called
bandwidth. Bandwidth of a communication system refers to its data transfer rate. The
data transfer capacity, or speed of transmission, of a digital communication system is
measured in bps (Bits Per Second). Based on the data transmission speed, there are three
basic categories of communication channels which we are going to discuss below.

Narrowband: Narrowband is used where data volume is relatively slow or fewer amounts
of data are to be transmitted. These utilize the channel frequency that is considered flat or
which will use a less number of frequency sets.

Wideband: Wideband channel has a medium capacity of data transmission rate. Wideband
channels can carry more information than narrowband channels, but they typically require
more power to do so.

Broadband: Broadband channel is a high speed, high capacity transmission medium


that supports a wide range of frequency and carries multiple signals at a time. Cable TV
networks, Microwave, Satellite, etc. are examples of broadband channels.

10 New Gateway to Computer Science Book -10


Analog and Digital Signal

A signal is a wave that is suitable for carrying information


over a transmission medium. Signals can be electric,
light, electromagnetic, or radio signals for carrying
information in free space. The electric signals have
limited bandwidth and cannot be used in long distance
communication. They need to be amplified or regenerated.
Here, we are going to discuss two major signals used in
data transmission.
Analog Signal: An analog signal is a wave that
continuously changes its information carrying properties
over time. An analog signal can be used to measure
changes in some physical phenomena such as light,
sound, pressure, or temperature. For example, an analog
microphone can convert sound waves into an analog signal. Even in digital devices, there
is typically some analog component that is used to take in information from the external
world, which will then get translated into digital form using an analog-to-digital converter.
Digital Signal: A digital signal is a wave that takes limited number of values at discrete
intervals of time. These signals are non-continuous, they change in individual steps. The
transfer of data in the form of digit is called digital signal or digital data transmission.
Digital signals consist of binary digits 0 & 1. Electrical pulses are used to represent binary
digits. Data transmission between computers is in the form of digital signals.

Let’s Review
 The speed in which data can be transmitted from one device to another across a
communication channel is called data transmission rate.
 The difference between the highest and the lowest frequencies on a transmission
is called bandwidth.
 There are three basic categories of communication channels. They are narrowband,
wideband and broadband.
 The electric signals have limited bandwidth and cannot be used in long distance
communication.
 An analog signal is a wave that continuously changes its information carrying
properties over time.
 A digital signal is a wave that takes limited number of values at discrete intervals of
time.

New Gateway to Computer Science Book -10 11


Transmission Media (Communication Channel)

The transmission media is also known as communication channel. In data communication


terminology, a transmission medium is a physical path between the transmitter and
the receiver. It is the channel through which data are sent from one place to another.
Transmission media is a pathway that carries the information from the sender to receiver.
We use different types of cables or waves to transmit data. Transmission Media is
broadly classified into two types. Let’s observe the given chart and explain the various
communication channels.
Guided Media
Guided media is also called bounded media or wire media. In this communication media,
data travel through the wire instead of wave. This transmission media are the cables that
are tangible or have physical existence and are limited by the physical geography. Popular
bound transmission media in use are twisted pair cable, co-axial cable and fiber optical
cable. Each of them has its own characteristics like transmission speed, effect of noise,
physical appearance, cost, etc.

Types of Transmission
Media

Guided Media Unguided Media

Twisted Pair Coaxial Optical Microwaves


Radio waves Infrared
Cable Cable Cable

Twisted Pair Cable: It consists of two separately insulated conductor wires wounded
about each other. Generally, several such pairs are bundled together in a protective sheath.
They are the most widely used transmission media. There are two types of twisted pair
cable.
Unshielded Twisted Pair (UTP): This type of cable has the
ability to block interference and does not depend on a physical
shield. It is used for telephonic applications. It is easy to install
and it has high capacity. It is a cable with wires that are twisted
together to reduce noise and crosstalk.

12 New Gateway to Computer Science Book -10


Shielded Twisted Pair (STP): This type of cable consists of a special jacket to block
external interference. It is used in fast-data-rate Ethernet and in voice and data channels
of telephone lines. It has better performance at a higher data rate in comparison to UTP
cable. This cable is more expensive than UTP cable.
Coaxial Cable: It has an outer plastic covering containing two
parallel conductors each having a separate insulated protection
cover. Coaxial cable transmits information in two modes: Baseband
mode (dedicated cable bandwidth) and Broadband mode (cable
bandwidth is split into separate ranges). Cable television and analog
television networks has coaxial cables. It has high bandwidth and it
is easy to install and expand.
Optical Fiber Cable: In this cable, data transmission rate is very high.
The data travel in the form of light. It uses the concept of reflection of
light through a core made up of glass or plastic. The core is surrounded
by a less dense glass or plastic covering called the cladding. It is
used for transmission of large volumes of data. It has more capacity
and bandwidth but it is difficult to maintain and install. The cost of
this cable is very high in the comparison to others. Optical fiber is
rapidly replacing copper wires in telephone lines, internet communication and even cable
television connections because transmitted data can travel to very long distances. Fiber
optic cable can have maximum segment length of 2 kms and bandwidth of up to 100
Mbps.
Unguided Media
Unguided media is also called unbounded media or wireless media. In this communication
media, data travel through the air instead of cable. An unguided transmission media
transmits the electromagnetic waves without using any physical medium. This media is
also known as wireless transmission. Unguided signals can be travelled from source to the
destination in several ways. These ways include ground propagation, sky propagation and
line of sight propagation. The commonly used unguided media are explained below.
Radio Waves: Radio waves are a type of electromagnetic radiation
used in communication technologies, such as television, mobile
phones and radios. These devices receive radio waves and convert
them into mechanical vibrations in the speaker to create sound
waves. Radio waves have frequencies as high as 300 gigahertz
(GHz) to as low as 30 hertz (Hz). Radio waves are generated
artificially by transmitters and received by radio receivers, using antennas. Radio waves
are widely used in modern technology for fixed and mobile radio communication,

New Gateway to Computer Science Book -10 13


broadcasting, radar, communications satellites, wireless computer networks and so many
other applications. The radio waves from many transmitters pass through the air
simultaneously without interfering with each other.
Microwaves: Microwave transmission refers to the technique
of transmitting information over a microwave link. It has
higher frequency than the radio waves. Microwave links are
widely used for point-to-point communications because their
small wavelength allows conveniently-sized antennas to
direct them in narrow beams, which can be pointed directly
at the receiving antenna. Microwave links are commonly
used by television broadcasters to transmit television programmes.
Infrared: Infrared waves are used for very short distance communication. In this
transmission media the frequency Range is from 300GHz – 400THz. Low frequency
infrared waves are used for very short distance communication like TV remote, wireless
speakers, automatic doors, hand held devices, etc. Infrared signals can spread within a
room. Due to such short range, it is considered to be one of the secure transmission
modes.
Satellite: In this mode of communication, the satellite station at
the space receives signals from the earth with the help of an
antenna. The signals are amplified to an optimum level and then
with the help of transponders they are retransmitted back to the
earth. The earth station then receives the signal from the satellite,
and re-amplifies it and helps in the communication. The satellites are generally equipped
with an antenna and transponder to facilitate the communication process.
Wi-Fi Technology: Wi-Fi which stands for Wireless Fidelity is one
of the most important technological developments of this modern
age. Wi-Fi is a technology that uses radio waves to provide network
connectivity. A Wi-Fi connection is established using a wireless
adapter to create hotspots areas in the area of a wireless router that
is connected to the network and allows users to access internet
services. Although Wi-Fi is typically used to access the internet on
portable devices like smartphones, tablets, or laptops. It also provides access to a local
network of connected devices.
Bluetooth Technology: Bluetooth is an open wireless technology
for transmitting fixed and mobile electronic device data over short
distances. Bluetooth works on radio waves, specifically in the
2.4GHz range. This short-range frequency is commonly used by

14 New Gateway to Computer Science Book -10


most appliances that need wireless connectivity, including Wi-Fi routers. When Bluetooth
connects two devices, it forms a Personal Area Network (PAN) which does not require an
internet connection or mobile service to transfer files or anything else.

Let’s Review
 Transmission media is a pathway that carries the information from the sender to
receiver.
 Guided media is also called bounded media or wire media. In this communication
media, data travel through the wire instead of wave.
 Unguided media is also called unbounded media or wireless media. In this
communication media, data travel through the air instead of cable.
 Radio waves are a type of electromagnetic radiation used in communication
technologies, such as television, mobile phones and radios.
 Shielded Twisted Pair cable consists of a special jacket to block external interference.
 Microwave transmission refers to the technique of transmitting information over a
microwave link.

Computer Network

A computer network is an interconnection of two or more computers that are connected


together to share the resources and information from one computer to several other
computers. The purpose of a computer network is to create a link between multiple
computer systems and support communication between them. Computers in a network
can share data with each other. Various types of networking topologies are used in
computer networks to exchange the information. A computer network is a set of connected
computers. Computers on a network are called nodes. The connection between computers
can be done through cabling or wireless through radio waves. Connected computers can
share resources, like access to the Internet, printers, file servers, and others. A network is
a multipurpose connection, which allows a single computer to do more.
Common uses of computer network
 To share the data and other peripheral devices.
 To back up the software and program files.
 For workgroup applications.
 Allows the electronic transfer of data.
Advantages of computer networks
 Sharing of information is easier.
 Sharing of different peripheral devices is possible.
 Easy to communicate with each other.
 Easy to control the computers in a network.

New Gateway to Computer Science Book -10 15


Disadvantages of computer networks
 It is difficult to establish.
 It is expensive to establish.
 A trained person is required to handle.
 Network faults can cause loss of data and resources.

Elements of Computer Network

There are various hardware and software elements used to create a networking mechanism
which we are going to discuss below.
Hardware Elements
NIC (Network Interface Card)
A NIC is a device that helps the computer to communicate
with another device. It is also called network card. NIC is a
printed circuit board which connects one of the expansion
slots of a computer and provides a port for attaching a network
cable. There are two types of network interface cards namely
wireless and wired. The wireless NIC is used by the modern
laptops devices. Wireless NIC is a connection that is made using the antenna which
employs the radio wave technology. Like this, the wired NIC uses wire to transfer data
over the medium.
Connectors
A connector is a device that terminates a segment of cabling or
provides a point of entry for networking devices such as computers,
hubs, and routers. Connectors can be distinguished according to their
physical appearance, such as jacks and plugs (male connectors) or
sockets and ports (female connectors).
Hub
A Hub is a multiport central connectivity networking device that
splits the network connection into multiple devices. When the
computer requests for information from a computer, it sends
the request to the hub. Hub distributes this request to all the
interconnected computers. Hub is a device that connects cables
from computers and other devices such as printers in a local area network. Hubs are used
in start topology networks but they are often used with other configuration to make it easy
to add and remove computers without bringing down the network.

16 New Gateway to Computer Science Book -10


Switches

A switch is a networking device that groups all the devices over


the network to transfer the data to another device. It is better than
hub as it does not broadcast the message over the network, i.e., it
sends the message to the device for which it belongs to. Therefore,
we can say that the switch sends the message directly from source
to the destination.

Router

A router is a device that connects the LAN to the internet. It


connects two different networks having the same protocol. The
router is mainly used to connect the separate networks or connects
the internet to multiple computers. The router organizes the network
in terms of logical network segment. Each network segment is
assigned an address so that every packet has both the destination
network address and destination device address. Routers determine whether the source
and destination are on the same network or whether data must be transferred from one
network type to another.

MODEM

The MODEM stands for Modulation and Demodulation. It connects the computer to the
internet over the existing telephone line. A modem is not integrated with the computer
motherboard. It is a separate part on the PC slot found on the motherboard. Modem speed
is measured in bps , Kbps, Mbps, etc. which is the speed in which the modem can send
and receive data. The common use for modems is to both sending and receiving of the
digital information between personal computers.

Repeater

A repeater is a networking device which is used to increase the length


of networking by amplifying weak signals. A repeater is applied
in computer networks to expand the coverage area of the network.
Repeaters amplify the received/input signal to a higher frequency
domain so that it is reusable, scalable and available. Repeaters were
introduced in wired data communication networks due to the limitation
of a signal in transmitting over a longer distance. Repeater are common installation in
wireless networks these days.

New Gateway to Computer Science Book -10 17


Let’s Review
 A computer network is an interconnection of two or more computers that are
connected together to share the resources and information.
 A NIC is a printed circuit board which connects to one of the expansion slot of a
computer and provides a port for attaching a network cable.
 A hub is a multiport central connectivity device that splits the network connection into
multiple devices.
 A router is a device that connects the LAN to the internet. It connects two different
networks having the same protocol.
 A repeater is a networking device which is used to increase the length of networking
by amplifying weak signals.

Gateway
A gateway is a node in a computer network.
It connects two networks having dissimilar
communication protocol. A gateway device provides communication to a remote network
or an independent system that is out of bounds for the host network nodes. Gateways serve
as the entry and exit point of a network; all data routed inward or outward must first pass
through and communicate with the gateway in order to use routing paths. Generally, a
router is configured to work as a gateway device in computer networks. For basic Internet
connections at home, the gateway is the Internet Service Provider that gives you access
to the entire Internet.
Bridge
A bridge is a type of computer network device
that provides interconnection with other bridge
networks using the same protocol. It reduces
the amount of traffic on a LAN by dividing it
into two segments. Bridge devices work at the
data link layer of the Open System Interconnect (OSI) model, connecting two different
networks together and providing communication between them. Bridges are similar to
repeaters and hubs in that they broadcast data to every node.

Software Elements
Network Operating System (NOS)
An operating system that enables a machine to participate in the network is called
networking operating system. Network operating systems are designed for client computers

18 New Gateway to Computer Science Book -10


and provide functions. There is difference between network operating systems and stand-
alone operating systems. Linux, Unix , Xenix , Windows 2000 server , Windows XP ,
Windows 7, Windows8, OS/2, etc. are the examples of network operating system. The
function of network operating systems are file and print sharing, account administration
for users and security, etc.
Communication Protocol
The set of rules and regulations that must be followed by the sender and the receiver while
communicating with each other over the network is called protocol. Network protocols
define rules and conventions for communication between different devices, participating
in a computer network. Devices participating in network communication should know
about the common network protocols and communicate according to the way, defined
by the network protocol. In other words, standard network protocol software must run
on both devices participating in network communication. TCP/IP, HTTP, FTP, SMTP,
POP, IPX/SPX, Apple Talk and NetBEUI are the types of network protocols which are
explained shortly below.
TCP / IP: Transmission Control Protocol / Internet Protocol (TCP/IP) are the most
commonly used protocols in the internet. They mainly deal with slicing the data into
small sized packets and routing them along the communication channel.
FTP: File Transfer Protocol (FTP) is used to transfer the files from one computer to
another even they run on different platforms or operating systems.
SMTP: Simple Mail Transfer Protocol (SMTP) is used for the delivery of E-Mail. It
enables the sender to keep a copy of the mail until it is actually delivered. It enhances the
reliability of message delivery.
HTTP: Hyper Text Transfer Protocol (HTTP) is used by web browsers and web servers
to communicate with each other.
POP: Post Office Protocol (POP) is the server where incoming mails are collected on
your mailbox. It allows single-user host to read mails from server.
IPX/SPX: Internetwork Packet Exchange / Sequential Packet Exchange is a networking
protocol that interconnects networks that use Novell’s NetWare clients and servers. This
protocol is not used for the internet. It exchanges the information between the network
clients, applications, and network peripherals.
Apple Talk: AppleTalk is a set of LAN communication protocol that is developed for
apple computers. This network can support up to 32 devices and data can be exchanged
at a speed of 230.4 Kbps.

New Gateway to Computer Science Book -10 19


Net BEUI: It stands for NetBIOS Extended User Interface. This network protocol is
used for small size LANs which do not require any configuration to implement. It is
a very small administrator. NetBEUI is supported by all Microsoft Windows network
operating systems; its implementation on Windows NT is called the NetBEUI Frame
(NBF) protocol.
Device Driver
A device driver is a software program that controls a particular type of hardware device
that is attached to the computer network. Many device drivers are available with an
operating system. However, if a user buys a new type of device that the operating system
does not detect, the new device driver will have to be installed. A device driver essentially
allows smooth communication between a connected hardware device and the operating
system.

Let’s Review
 A gateway is a node in a computer network. It connects two networks
having dissimilar communication protocol.
 A bridge is a type of computer network device that provides interconnection with
other bridge networks using the same protocol.
 The set of rules and regulations that must be followed by the sender and the receiver
while communicating with each other over the network is called protocol.
 A device driver is a software program that controls a particular type of hardware
device that is attached to the computer network.
 TCP/IP, HTTP, FTP, SMTP, POP, IPX/SPX, Apple Talk and NetBEUI are the types of
network protocols.

Types of Computer Network

On the Basis of Distance


Local Area Network (LAN)
A Local Area Network (LAN) is a network of computers,
which is limited within a very small geographical location
such as a room or a building. A LAN may contain small
number or large number of computers connected to
each other to share resources within a small geographic
location. The media used on LAN must be of the same type and the protocol used in it
is generally same. It is simpler and cheaper than other networking system. This network
cannot cover more than a kilometre. LANs are typically used for single sites where people
need to share resources among themselves but not with the rest of the outside.

20 New Gateway to Computer Science Book -10


Characteristics of LAN
 LAN is normally used by single organizations.
 LAN operate at relatively high speed when compared to the typical WAN.
 There are different types of Media Access Control (MAC) methods in a LAN, the
prominent ones are Ethernet, Token ring, etc.
 It connects computers in a single building or block, i.e. they work in a small
geographical area.
Metro Area Network (MAN)
A Metropolitan Area Network (MAN) is a network
that interconnects users with computer resources in
a geographic area such as within a city or a town.
This type of network is larger than LAN and smaller MAN
than WAN. Instead of using bounded media, it can
use unbounded media. For example, a bank having
branches in three different places within a city can
use MAN to interconnect each LAN of a branch.
The interconnection is done through phone line, any cable or wireless communication
system. This type of network is more flexible than the LAN. It has many more advantages
than LAN but has more chances of leakage of data. A MAN is often used to connect
several LANs together to form a bigger network, referred to as a campus area network,
or CAN.
Characteristics of MAN
 It generally covers a single town or city.
 Communication medium used for MAN are optical fibres, cables, etc.
 Data rates are adequate for distributed computing applications.
Wide Area Network (WAN)
A Wide Area Network (WAN) connects two or
more LANs together generally across a wide
geographical area. WANs can be used to connect
cities, states, or even countries. WANs are usually
owned by large organizations and government
agencies due to high cost in building and
maintaining them. A WAN connects the systems
of dissimilar types through telecommunication,
satellite or microwave relays in a large geographical area. The data transmission speed is

New Gateway to Computer Science Book -10 21


very slow which is measured in terms of kilobytes per seconds (Kbps). The internet is a
single, larger and global Wide Area Network.
Characteristics of WAN
 It generally covers large distances such as states, countries, continents, etc.
 Communication medium used are satellite and telephone networks which are
connected by routers.
 It is an expensive system compared to other networking types.
On the Basic of Architecture
Client / Server Network
A network in which one or more computers are designated as
a server(s) and the other computers on the network can request
service from the server is called client/server network. In this
network, a dedicate computer known as server provides sharing
resources. All other computers known as clients are used to
access the shared resources. This type of network is commonly
used in organizations. It provides great security features but requires special hardware
and software to setup.
Peer-to-Peer Network
A group of computers that functions both as a client and a
server is called peer-to-peer network. Sometimes it is also
called a workgroup computer. Such type of network is
commonly used in small organizations.
Centralized Network
Centralized networking systems use client/server architecture
where one or more nodes are directly connected to a central
server. This is the most commonly used in many organizations
where client sends a request to a company server and receives
the response. Centralized network model allows administrators
to manage the resources centrally. The network servers and
other critical network resources are located in a central location in a secure and dedicated
server room. In Centralized computer network model, the network resources are placed
and managed from a main location. Centralized network model provides Network and
System Administrators better access to network devices. In centralized network model,
network resources can be managed more easily and it provides better network security.

22 New Gateway to Computer Science Book -10


Let’s Review
 A Local Area Network (LAN) is a network of computers, which is limited within a
very small geographically location such as a room or a building.
 A Metropolitan Area Network (MAN) is a network that interconnects users with
computer resources in a geographic area such as within a city or a town.
 A Wide Area Network (WAN) connects two or more LANs together generally
across a wide geographical area.
 A network in which one or more computers are designated as a server(s) and the
other computers on the network can request service from the server is called client/
server network.
 Centralized networking systems use client/server architecture where one or more
nodes are directly connected to a central server.

Network Topology

Network topology refers to the layout of the network in which all the devices are
connected. The network topologies can be physical or logical. Physical topology refers
to the physical shape or design structure of a network including the nodes, devices
and cables. Logical topology refers to how data are transferred or exchanged between
computers within the network. Network topology also refers to the physical topology
where topology is the way in the cables and devices that connect the computers in the
network. The commonly used network topologies are Bus, Star and Ring which we are
going to discuss below.

Star Topology

In this topology, all the computers are connected to a centrally


placed device called hub or switch. This topology is mostly used
in LAN to connect several computers to the server that controls
communication between any two local computers by establishing
a logical path. In this topology all the workstations are connected
to central device with a point-to-point connection. So it can be
said that every computer is indirectly connected to every other
node with the help of hub.
Advantages
 It is less expensive networking mechanism.
 If any node other than the host node fails; remaining nodes are unaffected.
 It is easy to detect the failure link in star topology.

New Gateway to Computer Science Book -10 23


Disadvantages
 If the centre connectivity device like hub or switch fails to work, the entire network
system stops to work.
 Failure of the server causes the failure of entire computers in the network.
 The use of hub, a router or a switch as central connectivity devices increases the overall
cost of the network.
Ring Topology
In this topology all the computers are connected to each other
in a closed loop by a single cable with each other. The last
computer connects to the first one to from a ring like structure.
Each workstation is connected to two other components on either
side, and it communicates with these two adjacent neighbours.
Data travel around the network, in one direction. Sending and
receiving of data takes place with the help of TOKEN.
Advantages
 It supports optical fiber cable so that data transmission rate is very high.
 It is more reliable than a star topology because communication is not dependent on a
single central node.
 If a link between any two nodes fails or if one of the nodes fails, alternate routing is
possible.
Disadvantages
 Any node failure causes whole network failure.
 It is difficult to detect failure links.
 It requires more complicated control software than in star topology.
Bus Topology
In bus topology, all the nodes are connected to a single
cable, with the help of interface connectors. The cable used
in this topology is the backbone of the network. Every
workstation communicates with the other device through this
Bus. Peripheral devices and computers can be added to the
topology of the network in a linear fashion without the same
demands for cable length.
Advantages
 It requires less cable length so its cost is effective.
 The failure of a node does not affect communication among other nodes in the network.
 Addition of new nodes to the network is easy.

24 New Gateway to Computer Science Book -10


Disadvantages
 A broken connection brings the whole network down.
 It is difficult to find out the problem if the entire network shuts down.
 If the shared communication line fails, the entire network fails to work.

Let’s Review
 Network topology refers to the layout of the network in which all the devices are
connected.
 Topology refers to the physical shape or design structure of a network including
the nodes, devices and cables.
 In start topology, all the computers are connected to a centrally placed device called
hub or switch.
 In ring topology, all the computers are connected to each other in a closed loop with a
single cable with each other.
 In bus topology, all the nodes are connected to a single cable, with the help of
interface connectors.

Internet and Its Services

Internet is defined as an interconnection of networks. which allows computers on different


kind of networks to interact with each other. It is the largest computer network spread
all over the world including the connection of millions of computers. It is a network of
networks sharing a common mechanism for identifying computers, and a common set of
communication protocol for communication between two or more than two computers
on the network. In order to connect to the Internet, we must have access to an Internet
Service Provider (ISP), which acts as the mediator between user and the Internet. You can
get information, access data, communicate with others, play games and many more by
connecting your computer through Internet. Internet has been the main source in different
fields like Education, Science, research and others to develop, design and do many other
things.
In 1964, Paul Barren brought the concept of Internet. In 1969, the Advanced Research
Project Agency (DARPA) under the US Defence Department applied this concept and
constructed a computer network among four computers. The first computer network,
was called ARPANET (Advance Research Project Agency Network). After that different
technologies and techniques started to develop and their involvement with the Internet
brought today’s medium status.

New Gateway to Computer Science Book -10 25


Advantages and disadvantages of the internet
Advantages
 The internet is faster than any other communication services.
 The internet is the source of knowledge so all kinds of information can be displayed.
 The internet is the most popular form of entertainment. We can watch movies, songs,
videos, games, etc. that are available in the internet for free.
 The internet is massively used in social networking media such as facebook, twitter,
etc.
 The internet tools can be for E commerce services like online hotel reservations, online
ticket booking, online shopping, etc.
Disadvantages
 The information or any important files can be easily taken by the hackers.
 The unnecessary emails, advertisements, spam mails may slow down the system and
create lots of problems while working with computer.
 The malware or virus threats affects the system to a greater extent.
 More chances of social isolation problems.

Services of Internet

Search Engine
Search engines are the websites that allow the users to search
information based on keyword or a combination of keywords.
Search engines are used to locate web sites and information. To
search the information, users need to enter the desired search term
into the search field. After that, the search engine looks through its index for relevant
websites and displays them in the form of a list. www.google.com, www.yahoo.com,
www.bing.com, www.ask.com, etc. are some examples of search engines.
Web Browser
A browser is a software that is used to access the internet to view
the web pages. It allows us to visit websites and do the various
activities within them. The most common web browser software
are Microsoft Internet Explorer, Google’s Chrome, Mozilla
Firefox, Apple’s Safari, and Opera. The availability of browser
depends on the operating system that your computer system has used.

26 New Gateway to Computer Science Book -10


Downloading

The process of receiving information at your computer from another computer through
a network is called downloading. This is a process of transferring a copy of a file from
a remote computer to the requesting (local) computer. It is just the reverse of uploading.
Each time when you visit a webpage, your computer or mobile device must download
the HTML, CSS, images, and any other relevant data in order to display the page in your
web browser.

Uploading

The process of transferring the information from your computer to another computer
through a network is called uploading. This is a process of transferring a copy of a
file from a local computer to the requesting computer. The most common method of
uploading a file to another computer or server is by using FTP (File Transfer Protocol). If
you are uploading a file to another site, you must have permission to access the site and
the directory where the file is to be placed.

Let’s Review
 Internet is defined as an interconnection of networks. with allows computers on
different kind of networks to interact with each other.
 Search engines are the websites that allow the users to search information
based on keyword or a combination of keywords.
 Search engines are used to locate web sites and information.
 The most common web browser software are Microsoft Internet Explorer, Google’s
Chrome, Mozilla Firefox, Apple’s Safari, Opera, etc.
 The process of receiving information at your computer from another computer
through a network is called downloading.
 The process of transferring the information from your computer to another
computer through a network is called uploading.

Web Chat
A web chat is a system that allows users to communicate in real time using easily
accessible web interfaces. It is an online interactive communication mechanism that
allows people to have real time discussion with one or more people through the Internet.

New Gateway to Computer Science Book -10 27


Videoconference
A videoconference is a set of interactive
telecommunication technologies which allow two
or more locations to interact through the two-way
video and audio transmissions simultaneously. It is
the transmission of image/video and speech / audio
back and forth between two or more geographically
dispersed persons.
Domain Name
A domain name is the address where the internet users can access your website. A domain
name is used for finding and identifying computers on the internet. The popular domain
names are .com, .edu , .org , .net , .mil, etc. A domain name can be any combination
of letters and numbers, and it can be used in combination of the various domain name
extensions. The domain name must be registered before you use it. Every domain name is
unique. No two websites can have the same domain name. Let’s discuss the given points
how domain name works and how they are used.
 Domain names have two parts that are separated by a dot.
 A domain name can be used to identify a single IP address or group of IP addresses.
 A domain name is used as a part of a URL to identify a website.
 The IP address in the domain name’s background is converted to a recognizable,
alphanumeric domain name by a system known as the domain name system (DNS).
IP Address
Internet Protocol address, is an identifying number for network hardware that helps to
connect to a network. IP address allows a device to communicate with other devices.
An IP address provides an identity to a networked device on the internet. There are two
versions of IP and they are internet protocol version 4 (IPv4) and internet protocol version
6 (IPv6). IPv6 is the upgraded IP version of IPv4.

Let’s Review
 A web chat is a system that allows users to communicate in real time using easily
accessible web interfaces.
 A domain name is the address where the internet users can access your website.
 A domain name is used for finding and identifying computers on the internet.
 Internet Protocol address, is an identifying number for network hardware that
helps to connect to a network.
 IP address allows a device to communicate with other devices.

28 New Gateway to Computer Science Book -10


WWW

World Wide Web was invented by Tim Berners-Lee in 1989. This was invented initially
for scientists to easily share data available as part of their experiments. It is a collection
of web resources and pages found on the network. To access the www, we must have web
browser. Web consists of three main components they are listed below.
 HTML: Hypertext Mark-up Language is a standard mark-up language used to create
web pages.
 URL: Uniform Resource Locator is the understandable form of a web address
which is used to identify a resource.
 HTTP: Hyper Text Transfer Protocol acts as the foundation of the Web.
Telnet (Terminal Emulation Network)
Telnet was developed in 1969 to support in remote connectivity between computers over
a network. Telnet allows us to connect remote computers over a TCP/IP network. It is a
network protocol used on the Internet or local area networks to provide a bidirectional
interactive communications facility. The term telnet also refers to software which
implements the client part of the protocol.
Newsgroups
A newsgroup is an Internet-based online discussion forum where so many people can
put their views and ideas on a particular area of interested topic. It enables remotely
connected users to share, discuss and learn about their topic of interest by exchanging text
messages, images, videos and other forms of digital contents. It was created in 1979 by
some university students to exchange their messages with each other.
Electronic Mail
Electronic mail also called as an E- mail is a digital
message used for creating, sending, receiving and
storing textual data in the digital format over a
network. Electronic mail is one of the most widely
used features of the Internet. It allows us to send and
receive messages to and from anyone with an email
address, anywhere in the world. Instead of using a
pen to write a letter on paper, we are using keyboard
or voice to write an email message on an electronic
device like a phone or computer. Email addresses are written with a custom username at
the beginning followed by the email service provider’s domain name, with an @ sign.
Email system uses multiple protocols within the TCP/IP . When you configure an email

New Gateway to Computer Science Book -10 29


account, you must define your email address, password, and the mail servers used to send
and receive messages. E-mail messages are usually encoded in ASCII text. However,
you can also send non-text files, such as graphic images and sound files, as attachments.
Features and an E-mail
 You can send attachments with an email that contains important documents, images or
any files.
 It is simple and easy to use. It also allows for the easy and quick access of information
and contacts.
 The sent and received messages can be stored, and searched safely and easily.
 It can be accessed from anywhere when you are connected to the internet.
 It reduces the cost of paper. And also can be delivered within a second.
 Same message can be sent easily and quickly at a same time to many recipients.
 It allows for instant access of information and files.

Let’s Review
 Telnet was developed in 1969 to support in remote connectivity between
computers over a network.
 A newsgroup is an Internet-based online discussion forum where so many people
can put their views and ideas on a particular area of interested topic.
 Electronic mail is one of the most widely used features of the Internet.
 Email allows us to send and receive messages to and from anyone with an email
address, anywhere in the world.
 Hypertext Transfer Protocol is a set of rules for transferring files, such as text,
graphic images, sound, video, and other multimedia files, on the www.

Innovative Task
 Take a short interview with you principal and subject teacher about the ISP that is
being used at your school. Also ask them about the positive and negative aspects
of it. Then, prepare a project report.
 List out the name of various ISP of Nepal and make a short report.
 Prepare a project report about the networking mechanism that is being used in your
school.
 Visit some organizations nearby you and observe the networking structure over
there. Also prepare a report and submit to your teacher.
 Visit a computer shop and list out the various types of Wi-Fi router models available
there.

30 New Gateway to Computer Science Book -10


Assignment
1. Select the best answer from the given options.
A. Physical layout of computer:
a. Network b. LAN c. Topology d. MAN
B. Which of the following is protocol?
a. TCP / IP b. FTP c. HTTP d. All of the above
C. A networking device with multiple ports:
a. HUB b. MAN c. LAN d. WAN
D. Band-Width is measured in :
a. KBPS b. BPS c. KPS d. None of the above
E. Which is internet service?
a. Telnet b. Star c. Hub c. Ring
F. Which of the following is network topology?
a. Star b. Bus c. Ring d. All of the above
G. Newspaper and books are examples of :
a. Half duplex b. Full Duplex c. Simplex d. None of the above
H. One of the most expensive cables of the network:
a. Coaxial cable b. UTP c. UTP d. Optical fiber cable
I. Which of these domains is restricted to qualified organizations?
a. .com b. .org c. .net d. .edu
J. Yahoo ! is a :
a. Search engine b. Web browser
c. Home page d. Newsgroup
K. Which of the following is a valid E-mail ID?
a. dinesh@yahoo@com b. nayaghare.dinesh@com
c. Dinesh@Yahoo.com d. dinesh.nayaghare@gmail.com
L. Which of the following is a web browser?
a. Internet Explorer b. Mozilla Firefox
c. Opera d. All of the above

New Gateway to Computer Science Book -10 31


M. The process of transferring a copy of a file from a remote computer to the requesting
computer is:
a. Uploading b. Downloading
c. Searching d. File Transfer Protocol
N. ARPANET is related to:
a. Internet b. Operating System
c. Microsoft Office d. Adobe Programs
O. Actual internet address is numerical and is called:
a. Domain Name b. IP address c. DNS d. Domain Letter
P. Which of the following symbol is used in email?
a. # b. @ c. * d. +
Q. The website contains:
a. Dynamic pages b. Static Pages
c. Both of the above d. None of the above
R. Which of the following is a search engine?
a. google.com b. facebook.com c. ask.com d. both (a) and (c)
2. Fill in the blanks with correct words / phrases.
a. Transmission is the channel or physical path through which the message is carried
from …………. to the …………………...
b. In a ……………….., signal is sent in one direction.
c. ……………… is also called unbounded media or wireless media.
d. …………….. are a type of electromagnetic radiation used in communication
technologies, such as television, mobile phones and radios.
e. ……………… is a device that connects the LAN to the internet. It connects two
different networks having the same protocol.
f. A ……………. is a software program that controls a particular type of hardware
device that is attached to the computer network.
g. ………………. refers to the physical shape or design structure of a network
including the nodes, devices and cables.
h. In …………… topology all the computers are connected to each other in a closed
loop with a single cable with each other.

32 New Gateway to Computer Science Book -10


i. ……………….. is the largest computer network spread all over the world with
the connection of millions of computers.
j. ……………. stands for Wireless Fidelity.
k. Search engines are used to ………………. and information.
l. The process of transferring the information from your computer to another
computer through a network is called ……………….
m. Actually internet addresses are numerical and called as …………..….
n. The main page of any website should be named as ………………
3. State whether the following statements are true or false.
a. The device that sends data to the destination or target is the receiver.
b. In a simplex mode, only one device can transmit the signal.
c. In a full duplex mode, only one device can transmit the signal at the same time.
d. Guided media is also called unbounded media or wire media.
e. Gateway is a central connectivity device that splits the network connection into
multiple devices.
f. A bridge is a type of computer network device that provides interconnection with
other bridge networks using the same protocol.
g. TCP/IP, HTTP and FTP are the types of networking systems.
h. In bus topology, all the computers are connected to a centrally placed device called
hub or switch.
i. In 1964 Paul Barren brought the concept of Internet.
j. Web browsers are the websites that allow the users to search information based
on keyword or a combination of keywords.
k. The most common web browser software is Microsoft Internet Explorer, Google’s
Chrome, etc.
l. The process of receiving information at your computer from another computer
through a network is called uploading.
m. Telnet was developed in 1969 to support in remote connectivity.
n. Postal mail allows us to send and receive messages to and from anyone with an
email address, anywhere in the world.
o. Electronic mail is one of the most widely used features of the Internet.
p. Opera and safari are the names of search engines.

New Gateway to Computer Science Book -10 33


4. Write down the single technical term for the followings.
a. A set of rules with which computers communicate with each other over a network.
b. A form of wireless transmission in which signals are sent via pulses of infrared
light.
c. A device that connects multiple networks using the same protocol.
d. A device or software that converts data into dissimilar networks.
e. A device that is used to translate analog signals into digital and vice versa.
f. A networking architecture which covers a geographical location.
g. The differences between the highest and the lowest frequencies of a transmission
media.
h. Devices on one network that can communicate with devices on another network
through a device
i. The visual communication of parties around the world.
j. The huge collection of hypertext document on internet.
k. The service that allows sending text messaged, graphics/images using computer.
l. A program that allows to log into another computer on the Internet.
m. Online postal service.
n. The internal interface produced by adjacent pair of twisted pair cable.
o. A company that provides E-mail and Internet services to the user.
p. Message sent electrically through computer network.
5. Match the following.
Newsgroup Interconnection of several computers
Internet Online discussion group
Web chat Prevent unauthorized access to network
Firewalls Real time discussion zone
6. Write down the full form for the followings.
FAQ ISP DNS E-mail DARPA ARPANET
ADSL DSL FTP HTTP ASCII LAN
MAN WAN POP HTML HTTP WWW
IP TCP/IP FTP STP UTP MODEM
OSI bps PAN Wi-Fi Net BEUI

34 New Gateway to Computer Science Book -10


7. Answer the following questions.
a. Define simplex and half-duplex mode with examples.
b. What is communication media? Write with examples
c. What is a computer network? Define it with advantages.
d. What are the common uses of the computer network?
e. What are network transmission devices? Explain any two of them.
f. What do you mean by network topology? Draw a figure of ring topology and
mention its advantages.
g. Define star and bus topology with their advantages and disadvantages.
h. What do you mean by communication media? Differentiate between bounded and
unbounded media.
i. Define LAN, MAN and WAN with suitable examples.
j. What is a protocol? Write a few examples of protocol.
k. What is internet? What are the major functions of the internet?
l. What are the internet services? Explain few of them.
m. What is a search engine, Give some examples of search engines.
n. What do you mean by web chat? Define the term newsgroup.
o. What is e-mail? Mention any four features of e-mail.
p. What are the differences between the terms “Uploading” and “Downloading”?
q. Define web browser with examples.
r. What is World Wide Web? Mention any two advantages.
s. Define the following terms:
Router, Optical fibre, Bandwidth, Repeaters, Gateway, Firewall

New Gateway to Computer Science Book -10 35


Lesson

2 Ethical and Social Issues in ICT

Learning Outcomes

At the end of this lesson, students will be able to:


 tell about the ethical and social issues in ICT.
 know about the ICT policy of Nepal.
 tell about electronic transaction act.
 tell about digital citizenship.
 tell about digital footprint.
 explain about the opportunities and threats in social media.
 explain the different platforms of social media.

Ethical and social issues arising from the use of technology in all areas of our lives such
as business, health sector, education and so on. Because of the recent development in the
technology and their ability to transmit vast amounts of information in a short amount of
time, there is a great impact of ICT in the society. The implementations of technology in the
workplace create various social and ethical concerns so there should be further analysis of
technology in an organization. Information Communication Technology (ICT) has raised
new ethical concerns about the protection of personal privacy, protection of intellectual
property, user responsibility, acceptable access and use of information, software licenses
and piracy. A good ICT policy must be able to adequately consider these, and many other
associated issues.

ICT Policy – 2015

The first IT policy was introduced in 2057 B.S. which was related to the IT education
and some other activities. Ministry of Information and Communication, Government of
Nepal introduced second National Information and Communication Technology Policy In
2015AD. In this chapter we are going to discuss about it.

36 New Gateway to Computer Science Book -10


Background
Information and Communication Technologies are increasingly at the core of strategies
aimed at securing the goals of sustainable development and stimulating economic growth
in countries around the world. Among others, these technologies are shaping the way
social interaction takes place and public services are delivered in some fundamental ways.
It is precisely along these lines that the Government of Nepal has placed a great deal of
importance on transformative potential of ICTs and positioning these technologies within
the larger context of its far reaching developmental aspirations premised around poverty
reduction as an overarching goal.
ICTs assume particular significance in the light of fact that efficiency more than ever is
now an indicator of competitiveness. As such, nations, private sector entities and people
that find the means to become more efficient will advance and prosper.
Among others, ICTs hold the potential to help create conditions for better governance,
with more transparent and efficient bureaucracies. Similarly, ICTs can help address
structural problems in education systems enabling expanded access to education services
as well as help bridge quality gaps in education. ICTs can also significantly improve the
health sector by enabling expanded outreach to health care services and driving efficiency
through the system.
In addition to the roles these technologies play in development, the sector also offers
tremendous prospects for economic growth and employment creation through enablement
of IT-ITeS/BPO based business models.
It is within these contexts that the Government of Nepal has accorded high level of policy
emphasis for the development ICT sector. Nepal has the opportunity to make a difference
by adopting and using ICT as a tool available to reduce the development divide and
increase the chances of improving the quality of life of the citizens.
Apart from opportunities however, the ever evolving nature of ICTs also offers a host of
challenges from policy perspectives. For one, fast paced technological innovations in ICT
domain come attendant with far reaching policy implications which traditional policy
formulation approaches fail to address properly. As a result, existing policy provisions in
Nepal need to be revisited in the light of dynamism that characterizes the sector.
This policy is premised around the realization that there is an urgent need to formulate
strategic responses to account for technological trends shaping the ICT sector. Formulating
policy responses in alignment with the dynamism of the sector becomes all the more
important given the need to adequately factor in key strategic imperatives impinging
on faster uptake of ICTs in the country, namely issues surrounding cyber security,
data protection, privacy and respect for intellectual property rights. Equally important

New Gateway to Computer Science Book -10 37


is the need to address the challenges posed by technological convergence especially
from regulatory and governance perspectives. Given that telecom connectivity is fast
expanding across the country, inching closer to saturation point, the focus should now
should also shift on demand side fundamentals that need to be strengthened in order
to ensure strategic alignment of resourcefulness offered by ICTs with our growth and
development aspirations.
Key Issues and Challenges
The presence of disparate policy initiatives and institutional arrangements for the
development of ICT sector in Nepal however also points towards lack of coherent strategy
in line with the technological trends that have been shaping up the sector over the years.
Rapid take-up of Internet and mobile wireless communications has been some of the
key trends shaping the ICT landscape. These trends have come attendant with policy
implications of varied nature. For example, the Internet has truly become mainstream
with predominant use of social media, making it relevant for so many people in their
daily lives. Security concerns and concerns about privacy, personal saftey and intellectual
property rights have accompanied such technological changes. In addition, as indicated
earlier, the wider take-up and convergence of ICTs also raises new regulatory issues that
traditionally would be seen as separate from telecommunications policy and regulation.
In such a rapidly evolving field, it is necessary to ensure that policy and regulation adapt
to new developments.
The existence of a number of institutional arrangements with overlapping mandates and
spheres of influence surrounding the ICT sector in Nepal has resulted in project execution
difficulties and hampered smooth rollout of ICT projects.
Given the current state of telecommunications and information technology sector, Nepal
needs to enhance its overall readiness for effectively harnessing these technologies by
articulating its policy positions on new technologies like Voice over Internet Protocol
(VoIP), Internet Protocol Television (IPTV), new forms of social networking, etc.
This policy is formulated basically in response to the felt need for realigning the
underpinning substance of existing ICT related policy and regulatory regime with the
ramifications of ever-intensifying technological innovation. Among others, transformation
from circuit-based telecommunication networks to packet-based ones using the Internet
protocol (IP) has brought about digital convergence and offered a host of challenges and
opportunities from policy perspectives.
It has been observed that the lack of a coherent policy position befitting the technological
dynamism that has characterised the ICT landscape has offered many challenges for the
holistic development of the ICT sector. The current state of policy incongruence has
hindered, for example, the growth of IT and IT enabled services sector to the detriment
of economic growth prospects that this sector could open up. Similarly, government

38 New Gateway to Computer Science Book -10


transformation prospects anchored in potentialities offered by ICTs have not gained
traction on account of lack of a coherent policy framework grounded on latest development
in the sector.
It is precisely along those lines that this policy stresses the need for a well-defined
and consistent policy and regulatory framework for addressing converged regime of
telecommunications, broadcasting, and ICT.
Guiding principles of the proposed policy
The implementation of this Policy shall be guided, among other things by the right of access
to information as well as the need to promote transparency, fairness and accountability
in the delivery of government services and execution of roles and responsibilities of
government agencies. The following constitutes some of the guiding principles of the
policy:
 This policy is intended to create foundational groundwork for an overarching vision
of “Digital Nepal”. As per this vision, Information and Communication Technology
will be a key driving force in transforming Nepali society into knowledge and
information based society and strengthening Nepal’s pursuit of equality and sustainable
growth by leveraging Information and communication technology.
 This policy is primarily designed to guide and mainstream the use of ICTs in all sectors
of the Nepalese economy within the overall context of socio-economic development
and poverty reduction agenda pursued by the country.
 In order for this policy to make meaningful impact on social and economic development
of the country.
 The implementation of this policy shall take into account relevant regional and global
strategies and best practices in transforming the nation into a knowledge based society
by cultivating strong linkages with the UN Millennium Development Goals (MDGs),
WSIS beyond 2015, WTO, Broadband Commission, UN-ESCAP, post 2015
sustainable development agenda etc.
 Nepal will continue to uphold the principle of freedom of expression on the Internet
and net neutrality
 The policy intends to promote platform neutral services in e-governance
Goals of Information and Communication Technology policy
 Nepal will strive towards enhancing overall national ICT readiness with the objective
of being at least in the top second quartile of the international ICT development index
and eGovernment rankings by 2020.

New Gateway to Computer Science Book -10 39


 At least 75 present of the population will have digital literacy skills by the end of
2020.
 A universal broadband access to all people on an equitable basis will be in place. By
2020, 90 present of the population will be able to access the broadband services.
 The role and significance of ICT industries and services (including telecom services)
will increase in the Nepali economy with ICT value added (including digital content
and service industry) accounting for at least 7.5% present of GDP by 2020.
 By 2020, entire population of Nepal would have access to internet
 80% of all citizen facing government services would be offered on line by 2020
 E-procurement will be promoted as means of driving transparency through government
procurement processes covering all public procurement of goods and services
irrespective of cost and volume of such procurements by 2018
 G2G implementation would be promoted with a view to achieving complete automation
of the operations of land administration, revenue administration and management,
vital registration, passport and citizenship certificate services by 2020.
 Broadband access will be expanded across the country with the goal of achieving a
broadband Internet user penetration rate of 30% at a minimum of 512kbps and making
available at least 10 Mbps download speed on demand in urban areas by 2018.
 Special funding arrangements will be developed and implemented within 2018 to
support innovation and incubation of on-line businesses and start-ups
Policy
 Human Resource
 ICT in education, research & development
 Promoting public access and content development
 Developing the ICT Industry Sector
 ICT for Government service innovation and good governance
 ICT in SMEs & promotion of e-Commerce
 Telecommunications Infrastructure
 Convergence of Telecommunications, ICTs and broadcasting
 ICT in agriculture
 ICT in Health

40 New Gateway to Computer Science Book -10


 ICT in tourism
 Telecommunication and ICTs in mitigating the impact of Climate Change
 ICT in Environment and natural resources
 Telecommunications and ICTs for natural disaster preparedness, mitigation and relief
 Human Exposure to Electromagnetic fields and safe disposal of electronic waste
 Conformance, Interoperability and Standards in Telecommunications and ICTs
 Cloud computing
 Access to telecommunications and ICT services for rural and remote areas
 Access to Telecommunications and ICT services for persons with disabilities and
specific needs
 ICTs for Youth , women and Girls
 Building confidence and security in the use of ICTs
Vision
To transform Nepal into an information and knowledge-based society and economy
Mission
To create conditions for the intensified development and growth of ICT sector as a key
driver for Nepal’s sustainable development and poverty reduction strategies.
Objectives of National Information and Communication Technology Policy
 To empower and facilitate Nepal’s participation in the Global Knowledge Society.
 To transform Government service delivery regime by promoting transparency,
efficiency, inclusiveness and participation through effective utilization of information
and communication technologies
 To promote ICT to further productivity among the sectors that is key drivers of the
national economy.
 To promote research and innovation on the role of ICT on the resilience of low-income
communities amid potential environmental, economic and social shocks
 To create easily accessible, affordable and innovative public access points under a
comprehensive E-community / Village network initiative;
 To increase the institutional capacity along infrastructure and human resource
dimensions in public and private educational institutions including schools, colleges/
universities that offer ICT courses and use ICTs for pedagogical purposes;

New Gateway to Computer Science Book -10 41


 To create a conducive environment for increasing annual enrolment and output
of students in key professional skills areas such as telecommunications/electronics
engineering, computer science/IT, etc. and promote market driven skills development
initiatives in ICT
 To deploy ICTs at all levels of Nepali educational system in order to improve
educational outcomes while expanding access to education and training facilities
 To facilitate the participation of youths and women in ICTs particularly in media and
content development initiatives;
 To address gender-based inequalities and promote gender-sensitive measures to
encourage the active participation of women in national and community-based ICT
initiatives
 To promote the use of free and open source software as well as open standard in
software development for government agencies
 To create an innovative, market responsive, highly competitive and well regulated
ICT industry
 To help develop ICT business incubators and promote start-up projects in close
coordination with the private sector through the creation of a supportive eco-system
 To promote a stable, fair and competitive investment climate to facilitate the
development of e-Trade and E-Commerce activities in the country;
 To develop a highly competitive ICT industry capable of serving as the engine for
driving Nepal’s active participation in global trade;
 To increase the competitiveness of farmers in production, processing and marketing of
agricultural products and services through the effective and outcome oriented
utilization of ICTs;
 To improve communication systems across the country especially in areas of touristic
interest to support tourism development in the country
 To use ICTs in the documentation, promotion and effective marketing of the full
potential of Nepal’s world class and niche tourist destinations to the local, regional
and international market;
 To ensure that all ICT related activities have very minimal negative environmental
impact during construction, operation and disposal/de-commissioning;
 To conserve natural resources and safeguard Nepal’s heritage using ICT tools.
 To support formulation of development strategy for ICT converged services to support
and plan for mid-to-long term resolution for overcoming the digital divide
 To ensure all installed ICT infrastructure and capacity is utilized effectively and
contributes to resilience and redundancy.

42 New Gateway to Computer Science Book -10


Strategies
 Human Resource Development
 ICT in education, research & development
 Access, media and Content
 ICT Industry
 ICT for Government service innovation and good governance
 SMEs and e-Commerce
 Telecommunications infrastructure
 Convergence of Telecommunication, ICTs and broadcasting
 ICT in agriculture
 ICT in Health
 ICT in Tourism
 Telecommunication/ICTs in mitigating the impact of climate change
 ICT in environment and natural Resources
 Telecommunication/ICTs for natural disaster preparedness, mitigation and relief
 Human exposure to Electromagnetic fields and safe disposal of electronic waste
 Conformance, Interoperability and Standards in telecommunications/ICT
 Cloud Computing
 Access to telecommunications/ICTs in rural and remote areas
 Access to Telecommunications/ICT services for persons with disabilities and specific
needs
 ICTs for Youth, women and girls
 Building confidence and Security in the use of ICTs
Institutional arrangement
Implementation of policy and strategy framework
A National Information and Communication Technology Policy Implementation Steering
Committee will be formed at the Ministry of Information Technology and Communication
with the following structure.

New Gateway to Computer Science Book -10 43


Hon. Minister, Ministry of Information and Communication Technology Chairperson
Member, National Planning Commission Member
Secretary, Ministry of Education Member
Secretary, Ministry of Health Member
Secretary, Ministry of Agriculture Member
Secretary, Ministry of Finance Member
Secretary, Ministry of Local Development Member
Secretary, Ministry of Information and Communication Member
Chairman, Nepal Telecommunications Authority Member
Representative Private Sector / Domain Expert 2 Members
Joint-Secretary (Policy and Programme),
Ministry of Information and Communication Member-Secretary
The primary role of Information and Communication Technology Policy Implementation
Steering Committee is to provide overall coordination support for the effective
implementation of policy provisions along with monitoring and evaluation of policy
interventions.
The Steering Committee will form an ICT Policy Implementation Sub-Committee
comprising of representation from the stakeholder community and domain experts,
including the private sector, to provide it with domain specific expert advice and
recommendations in relation to the execution of policy provisions.
Formulation of National ICT Master Plan/National E-strategies
The policy and strategy framework will be implemented through National ICT Master
plan/National e-Strategies to be developed and endorsed by the Government of Nepal.
Resource Mobilization
The overall goals of Information and Communication Technology Policy will be achieved
through the mobilization of both public and private sector resources. The proposed
policy framework is expected to create conditions for private sector investment in the
sector complemented by public sector resource mobilization based, among others, upon
universal service obligation commitments through the use of RTDF. The possible grants
and technical assistance from bilateral, multilateral and other international agencies could
also be used.

44 New Gateway to Computer Science Book -10


Legal and regulatory arrangements
Appropriate Legal and regulatory arrangements will be made for the implementation of
this policy and provisions therein if deemed necessary.
Monitoring and evaluation
A framework will be developed within the fiscal year 2072/73 (2015/16) to serve as a
basis for carrying out periodic monitoring and evaluation of the execution of Information
and Communication Technology Policy and ICT master plan. It will be the primary
responsibility of Implementation Steering Committee to carry out monitoring and
evaluation of programs and policy provisions relating to ICT services and infrastructure
build-out.
Assumptions and Risks
The following constitutes key assumptions and risk perceptions in relation to the proposed
Information and Communication Technology Policy.
Assumptions:
 ICT as one of the core elements of development agenda will enjoy high level of
political commitment in the days ahead resulting in significant resource commitments on
harnessing ICTs to achieve policy outcomes across sectors
 There will be intensified demand for ICT services driven by increased public sector
deployment of ICT application and services, thereby creating conditions for more
private sector investment in the sector
 Necessary legal and regulatory reforms in the area of licensing and spectrum
governance will be taken in an urgent basis to promote investment in the sector
Risks:
 Overall investment climate might be compromised on account of delays in much
needed legal, regulatory and institutional reforms
 The continuing challenges associated with chronic power shortages could dampen the
overall demand for ICT services and create disincentive for investment
 Lack of oversight giving rise to skewed, purely market driven expansion of ICT
services resulting in exclusion of the communities outside urban areas resulting in
widening digital divide

New Gateway to Computer Science Book -10 45


Let’s Review
 Ethical and social issues arising from the use of technology in all areas of our lives,
business, health sector, education sector and so on.
 Nepal will continue to uphold the principle of freedom of expression on the
Internet and net neutrality is the guiding priciple of the ICT policy.
 At least 75 present of the population will have digital literacy skills by the end of
2020 is the goal of ICT policy.
 Telecommunication and ICTs in mitigating the impact of Climate Change is the
policy of ICT policy.
 The vision of ICT policy is to transform Nepal into an information and knowledge-
based society and economy.
 The mission of ICT policy is to create conditions for the intensified development
and growth of ICT sector as a key driver for Nepal’s sustainable development and
poverty reduction strategies.
 One of the objective of ICT policy is to empower and facilitate Nepal’s participation
in the Global Knowledge Society.
 The overall goals of Information and Communication Technology Policy will be
achieved through the mobilization of both public and private sector resources.

Electronic Transaction Act

Electronic Transaction Act deals with the issues that are related to cybercrime. This act
also helps to make and implement the laws. In Nepal, the House of Representatives
approved this act on December 4, 2063. At that time, ministry of environment, science
and technology formulated the Regulations. The new legislation has not only legalised all
forms of electronic transactions and digital signatures but has also clearly suggested out
the ways to regulate various computer-based activities and punish cybercrimes.
The electronic transaction and digital signature is valid not only for the private sector
but also for the government agencies. It allows the government offices to use electronic
medium for tender notice, vacancy announcement and others. It also validates public
procurement and acceptance of electronic applications.
The computer and cybercrimes such as hacking, piracy, copyright violation, fraudulent
and all other deceitful activities have been clearly defined and punishments are set
accordingly. The action against such crimes and punishment will be in the range of a
minimum Rs. 50,000 to a maximum Rs 3,00,000 in cash and six months to three years
custody.

46 New Gateway to Computer Science Book -10


Digital Citizenship
Digital citizenship refers to the responsible use
of technology by anyone who uses computers,
the internet, and digital devices to engage with
society on any level. As the rate of technological
advancement continues to increase, the world as a
whole is becoming more dependent on the Internet
for day-to-day activities like checking a bank
account, purchasing a product, or simply keeping
in touch with a friend. A good digital citizenship
engages students and shows them how to connect
with one another, empathize with each other, and
create relationships through digital tools. Bad digital
citizenship, involves cyber bullying, irresponsible
social media usage, and a general lack of knowledge about how to safely use the Internet.
The examples of digital citizenship are: communicating with respect, respecting other’s
privacy, seeing things from another perspective, adding helpful information, supporting
others by offering useful feedback, encouraging them, or sharing work they’re proud of,
etc.

Digital Footprint
A digital footprint is a track of data that you create while using the internet. It includes the
websites that you visit, email that you send, uploading videos or digital images and any
other form of transmission of information. Publishing a blog and posting social media
updates are another popular ways to expand your digital footprint. The status that you
have update and publish on Facebook or twitter contributes to your digital footprint. The
more you spend time on social networking websites, the larger your digital footprint will
be. Even “liking” a page or a Facebook post adds to your digital footprint, since the data
is saved on Facebook’s servers.
There are two types of digital footprint they are active and passive footprints which
depends on how your information is acquired. Posting on Facebook, Instagram, Twitter,
and other social media platforms, filling online forms, agreeing to install cookies on your
devices are the examples of active footprint.
In the same way, websites that install cookies in your device without disclosing it to you,
social media news channels and advertisers that use your likes, shares, and comments are
the examples of passive footprint.

New Gateway to Computer Science Book -10 47


Opportunities and Threats in Social Media
The use of social media is increasing
rapidly these days in our country.
Most of the people are using social
media mainly for communication
and to exchanging the information
with each other. It is very easy to
collect the information from the
one corner of the world to another
corner. Human life is being easier
due to the use of social media. In
general, social media refers to the websites and applications that are designed to allow
people to share content quickly, efficiently, and in real-time. All of the social media has
the ability to share photos, opinions, events, etc. in real-time has transformed the way
we live and, also, the way we do business. These days’ social media are the integral
part of the marketing strategy of many business organizations. If we do not use social
media in proper way, it may create lots of threats and social problems. Social media has
grown tremendously in the last few years. From 2006 AD onwards the growth rate is
unexpectedly very high. Especially Facebook and Twitter have grown much faster and
captured millions of users in just a few years. Social media has some opportunities and
threats which are listed below.
Opportunities of Using Social Media
 People from anywhere can connect with anyone. Regardless of the location and
religion.
 Millions of people are using social media platforms so it has a great opportunity to
promote business.
 Social media allows you to connect directly with your audience.
 It helps to create a brand of your company, product or a service.
 It is very fast way of exchanging the information.
 Communication mechanism is very simple and easy.
 You can share your ideas and views in a particular area of interest.
 Sharing and posting of pictures, videos and audio is very easy.
 It has a lot of benefits for the students and teachers.
 Social media also create awareness and innovate the way people live.

48 New Gateway to Computer Science Book -10


Threats of Using Social Media
 Personal data and privacy can easily be hacked and shared on the Internet.
 More chances of creating fake account.
 It can easily collapse someone’s reputation just by creating a false story and spreading
across the social media.
 Decrease the working efficiency of people.
 It may create health problems.
 More changes of spreading unnecessary rumour soon.

Different Platforms of Social Media

Facebook: Facebook is a one of the world’s largest social network platform. It is a free
social networking website which allows the user to register and create profiles, upload
photos, video, send messages and keep in touch with friends, family and colleagues.
Twitter: Twitter is a free micro-blogging service that allows registered members to
broadcast short posts called tweets. Twitter members can broadcast tweets and follow
other users’ tweets by using multiple platforms and device.
Google+: It is read as Google plus. It is a Google’s social networking project, designed
to replicate the way people interact offline more closely than is the case in other social
networking services.
Instagram: It is a free photo and video sharing apps that allows the users to apply digital
filters, frames and special effects to their photos and then share them on a variety of social
networking sites.
Wikipedia: Wikipedia was founded in 2001 January. It is a free, open content online
encyclopaedia created through the collaborative effort of a community of users known as
Wikipedians. Anyone registered on the site can create an article for publication; however,
registration is not required to edit articles.
Blogs: Blog is a platform for casual dialogue and discussions on a specific topic or opinion.
Flickr: It is an image and video hosting website and online community. Photos can be
shared on Facebook, Twitter and other social networking sites.
LinkedIn Groups: It is a place where groups of professionals with similar areas of
interest can share information and participate in the conversations.

New Gateway to Computer Science Book -10 49


Let’s Review
 Electronic Transaction Act deals with the issues that are related to cybercrime.
 The electronic transaction and digital signature is valid not only for the private
sector but also for the government agencies.
 Digital citizenship refers to the responsible use of technology by anyone who uses
computers, the internet, and digital devices to engage with society on any level.
 A digital footprint is a track of data that you create while using the internet.
 Human life is being easier due to the use of social media.
 Social media are the integral part of the marketing strategy of many business
organizations.
 Facebook is a one of the world’s largest social network platform.
 Wikipedia was founded in 2001 January.

Innovative Task
Ask with any 20 people in locality and prepare a report about what types of social
media that they are using? How long time they use it in a day? And what type of
information and content they like to read?

Assignment
1. Select the best answer from the given options.
a. The first IT policy was introduced in Nepal in:
i. 2057 BS ii. 2061 BS iii. 2052 BS iv. 2072 BS
b. Which of the following is social media?
i. Photoshop ii. Facebook iii. Graphics iv. Television
c. When Electronic Transaction Act was approved in Nepal?
i. 2054 BS ii. 2063 BS iii. 2073 BS iv. 2050 BS
d. Which of the following is related to digital citizenship?
i. Communicating with respect ii. Harming to others with technology
iii. Junk Mails iv. Doing piracy
e. Which of the following is active digital footprint?
i. Posting on facebook ii. Filling online forms
iii. Chatting with others iv. Both i and ii

50 New Gateway to Computer Science Book -10


2. Write down the full form for the followings.
ICT IPVT VoIP MDGs E-Commerce
3. State whether the following statements are true or false.
a. ICT stands for Information Computer Technology.
b. As the goal of ICT 99% of all citizen facing government services would be offered
on line by 2020 .
c. To create conditions for the intensified development and growth of ICT sector as
a key driver for Nepal’s sustainable development and poverty reduction strategies
is the mission of ICT policy of Nepal.
d. To promote ICT to further productivity among the sectors that is key drivers of the
national economy is the strategies of ICT policy of Nepal
e. The overall goals of Information and Communication Technology Policy will be
achieved through the mobilization of both public and private sector resources.
f. Electronic Transaction Act deals with the issues that are related to computer
software.
g. Social media allows you to connect directly with your audience.
4. Fill in the blanks with correct words / phrases.
a. ………………. issues arising from the use of technology in all areas of our lives,
business, health sector, education sector and so on.
b. The goal of ICT is at least ……………. present of the population will have digital
literacy skills by the end of 2020.
c. To transform Nepal into an information and knowledge-based society and
economy is the ……………. of ICT policy of Nepal.
d. Hon. Minister, Ministry of Information and Communication Technology will be
the…………… of National Information and Communication Technology Policy
Implementation Steering Committee.
e. A …………….. is a track of data that you create while using the internet.
f. Publishing a …………… and posting s………………. updates are another
popular ways to expand your digital footprint.
g. ……………… is a platform for casual dialogue and discussions on a specific
topic or opinion.

New Gateway to Computer Science Book -10 51


5. Answer the following questions.
a. When first ICT policy of Nepal was introduced?
b. Why ICT policy is needed in Nepal?
c. Write any three guiding principles of the ICT policy.
d. Write down the vision and mission of government related to ICT policy.
e. Write any ten policies of ICT policy.
f. List the working structure committee of A National Information and
Communication Technology Policy.
g. Write any five objectives of ICT policy.
h. What is electronic transaction act? When it was approved in Nepal?
i. What is digital citizenship? Write with examples.
j. Define digital footprint? What are the active and passive digital footprints? Write
with examples.
k. What do you mean by social media? What are the various social media and
popularly used in our country?
l. Mention any five opportunities and threats of using social media.
m. Name any five platforms of social media.

52 New Gateway to Computer Science Book -10


Lesson

3 Computer Security System

Learning Outcomes

At the end of this lesson, students will be able to:


 define computer security.
 tell about security threats and malicious code.
 explain the various security mechanism.
 tell about computer antivirus programs.
 tell about backup system .
 explain about various hardware security measures.

Computer security is also known as cyber security


or IT security. It is the way of protecting information
systems, computer hardware and software from theft
or damage. Computer security includes controlling
physical access to the hardware, as well as protecting
against harm that may come through network access,
data and code. Cyberspace is becoming a dangerous
place for all organizations and individuals to protect
their sensitive data. This is because of the many people and machines accessing it. The
protection given to the different types of hardware and software tools of the computer
system is known as computer security.
Prevention of data theft such as password, ATM pin, Credit card information, bank account
numbers, documents, etc. is essential since many of our day to day activities depend on
the security. The data stored in a computer can also be misused by an unauthorized user.
Anyone can modify and change the program source codes and can also use our pictures or
email accounts to do fake activities on you. Therefore, it is necessary to protect hardware
components and software programs of your computer system. Computer Security has
four main areas which are listed below.
The key principles of information security are listed below.
 Confidentiality: It means only authorized users can access the data resources and
information.

New Gateway to Computer Science Book -10 53


 Integrity: It means only authorized users should be able to modify and edit the data
when needed.
 Availability: It means data should be available to users when user is needed.
 Authentication: It means you are communicating with the one to whom you think to
communicate or not.

Let’s Review

 Computer security is also known as cyber security or IT security.


 Computer security is the way of protecting of information systems from theft or
damage.
 The data stored in a computer can also be misused by an unauthorized user.
 Confidentiality means only authorized users can access the data resources and
information.
 Integrity means only authorized users should be able to modify and edit the data
when needed.

Security Threats
We all have to be secure in our office, locality, home, city, country and in this global
world. These days, protecting the computer system from the threats is very challenging. A
threat refers to anything that has the potential to cause serious harm to a computer system.
A threat can be malicious program, a natural disaster or a thief. Security threats may occur
from the user computer hardware and computer software. The aims of some types of
threats are; to get information from the system (without affecting the system resources)
and to alter the system resources or affect its operations.

Malicious Codes

Malicious code is the term used to describe any code in any part of a software system or
script that is intended to cause undesired effects, security breaches or damage to a system.
Malicious code is an application security threat that cannot be efficiently controlled by
conventional antivirus software. Malicious code describes a broad category of system
security terms that includes attack scripts, viruses, worms, Trojan horses, backdoors and
malicious active content.
Malicious code can enter network drives and spread on another system as well. Malicious
code can also cause network and mail server overload by sending email messages;
stealing data and passwords; deleting document files, email files or passwords; and even
reformatting hard drives.

54 New Gateway to Computer Science Book -10


Security Mechanism

Security mechanisms deal with prevention, detection, and recovery from a security attack.
Prevention involves mechanisms to prevent the computer from being damaged. Detection
requires mechanisms that allow detection of when, how, and by whom an attacked
occurred. Recovery involves mechanisms to stop the attack, assess the damage done, and
then repair the damage. Security mechanisms are built using personal and technology.
Personal are used to frame security policy and procedures, and for training and awareness.
Security mechanisms use technologies like cryptography, digital signature, firewall,
user identification and authentication, and other measures like intrusion detection, virus
protection, data and information backup as countermeasures for security attack. Let’s
discuss some of the security mechanism below.
Authentication System
Authentication is the process of ensuring and confirming the identity of the user before
revealing any information to the user. It provides confidence in the identity of the user or
the entity connected. It also assures that the source of the received data is claimed.
Authentication is facilitated by the use of username and password, smart card, biometric
methods like retina scanning and fingerprints.
Password: Passwords are the most common tool for restricting
access to the computer system. It is a set of secret characters or
words used to authenticate access to a digital system. Passwords
help ensure that computers or data can only be accessed by
those who have been granted the right to view or access them.
Passwords are typically used with a username. It can vary in length and can contain
letters, numbers and some other special characters. There are many authentication options
available today so that users do not have to depend on passwords that can be easily
cracked or compromised.
Biometric: Biometric technology is mainly used for
identification and access control. Biometrics includes
physiological characteristics such as fingerprints or retinal
scans, and behavioural characteristics such as typing patterns
and voice recognition system. A biometric system is a
technological system that uses information about a person to
identify that person. Biometric systems depend on specific
data about unique biological behaviours in order to work effectively. Any government
organizations, businesses and other organizations can use biometric systems to get more
information about the individuals. Many biometric systems are developed for security

New Gateway to Computer Science Book -10 55


applications. An airport scanning device, a “bio-password” system, or an internal data
gathering protocol is an example of a biometric system that uses identifying data for a
security result.
Firewalls
A firewall is a security mechanism to protect a local network from the threats it may face
while interacting with other networks (Internet). You can implement a firewall in either
hardware or software form, or a combination of both. Firewalls prevent unauthorized
internet users from accessing private networks connected to the internet, especially
intranets. A firewall is the most basic and oldest form of network security. The primary
function of firewall is to monitor network traffic and to prevent unauthorized access
between computer networks. Some of the basic functions of firewall are given below.
 It provides security by examining the incoming data packets and allowing them to
enter the local network only if the conditions are met.
 It provide user authentication by verifying the username and password.
 It can be used for holding the structure and contents of a local network from external
users.
Cryptography
Cryptography is the science of writing information in a ‘hidden’ or ‘secret’ form and is an
ancient art. It is necessary when communicating data over any network, particularly the
Internet. It protects the data in transit and also the data stored on the disk. Cryptography
is technique of securing information and communications through use of codes so that
only those people for whom the information is intended can understand it and process
it. In Cryptography the techniques which are used to protect information are obtained
from mathematical concepts and a set of rule based calculations known as algorithms to
convert messages in ways that make it hard to decode it. Cryptography is often associated
with the process where an ordinary plain text is converted to cipher text which is the text
made such that intended receiver of the text can only decode it and hence this process is
known as encryption. The process of conversion of cipher text to plain text this is known
as decryption.
Encryption: Encryption is the process of converting plaintext to cipher text, using an
encryption algorithm. Encryption takes readable data and alters it so that it appears
random. Encryption requires the use of an encryption key which is a set of mathematical
values. Encryption is commonly used to protect data in transit and data at rest. Every time
someone uses an ATM or buys something online with a smartphone, encryption is used to
protect the information being relayed. Businesses are increasingly relying on encryption

56 New Gateway to Computer Science Book -10


to protect applications and sensitive information from Plaintext
reputational damage when there is a data crack. The primary
Benefits of encryption is to protect the confidentiality of
digital data stored on computer systems or transmitted
Encryption Decryption
over the internet or any other computer network.
Decryption: It is the reverse of encryption, i.e. converting
cipher text to plaintext, using decryption algorithm.
Decryption is the process of decoding encrypted Ciphertext
information so that is can be accessed again by authorized users. In decryption, the
system extracts and converts the garbled data and transforms it to texts and images that
are easily understandable not only by the reader but also by the system. Decryption may
be accomplished manually or automatically. It may also be performed with a set of keys
or passwords.
Antivirus Software
Antivirus software is a type of utility software. It is used
for scanning and removing viruses and malware from
your computer. The main use of antivirus program is to
protect computers from viruses and remove the viruses
that are detected. Most of the antivirus programs have both
automatic and manual scanning capacity. The automatic
scan check files are downloaded from the Internet, saved
using disk that are inserted into the computer, and files.
The automatic scan scans the entire hard drive on a regular
basis. The manual scan option allows you to scan individual files or your entire system
whenever required.
Backup System
The process of making duplicate copies of data or
programs so that these additional copies can be used to
restore the original one after data loss. These additional
copies of data and programs are typically called
“backups”. You can back up content, data, and settings
even from your android device with the help of Google
account. You can restore your backed-up information to
the concerned device connected or to another device. To
secure our data or information we can backup them like
in pen drive, memory card, external hard disk, Google drive, or even in cloud storage.

New Gateway to Computer Science Book -10 57


Let’s Review
 A threat refers to anything that has the potential to cause serious harm to a computer
system.
 Security threats may occur from the user computer hardware and computer
software.
 Malicious code can enter network drives and spread on another system as well.
 Security mechanisms deal with prevention, detection, and recovery from a security
attack.
 Security mechanisms use technologies like cryptography, digital signature, firewall,
user identification and authentication, and other measures.
 Authentication is the process of ensuring and confirming the identity of the user
before revealing any information to the user.
 A biometric system is a technological system that uses information about a person
to identify that person.
 Firewalls prevent unauthorized internet users from accessing private networks
connected to the internet, especially intranets.
 Cryptography is technique of securing information and communications through
use of codes so that only those people for whom the information is intended can
understand it and process it.
 Encryption is the process of converting plaintext to cipher text.
 Decryption is the process of decoding encrypted information so that is can be
accessed again by authorized users.

Hardware Security
The protraction or security given to different computer parts and other peripheral devices
is called hardware security. If any physical part of the computer stops to work, the entire
system may not respond. Dust, heat, low or high temperature, voltage fluctuations, etc.
may cause serious problem on the hardware components. We can apply the given security
mechanisms to protect the hardware components of the computer system.
Regular Maintenance
Regular maintenance of a computer means taking regular steps that make your computer
work faster and more secure. Computer may get slow down and be unable to perform the
task, at that moment we can do proper maintenance and fix the errors that occur. Regular
maintenance helps us to find the hardware problems and keep the individual parts of
computer in good condition.

58 New Gateway to Computer Science Book -10


Free from Dust
The dust particles from the external environment is the major cause of the failure of
different computer components such as keyboard, mouse, RAM, CD/DVD drive, USB
port, Hard disk, Memory cards, etc. Other internal parts like motherboard, chips or
transistors also may stop to work because of dust. To remove such issues mentioned
above, we must protect hardware components from dust. We can keep the room neat and
clean, flooring of computer room with carpet and cover the computer system when they
are not in use.
Air Condition System
A computer room with proper air condition maintains the temperature, air distribution
and humidity. Computer system produces more heat, so the room must have proper
ventilation system. The dust and small fiber materials get placed around the processor and
jams it so that its heat does not get dissipated. As a result, processor trips on overheating.
Similarly, the fan in the power supply is unable to dissipate heat and many parts of the
computer get so much of dust and may not work in a proper way. The temperature in the
computer system should be maintained between 21oC to 50oC and humidity of 50% with
5% variation.
Fire Protection Devices
The short circuit in electric wires may cause fire in a room which
may damage the parts of the computer or the entire computer system.
It is a serious problem of an individual user and of an organization.
To prevent from this accident, we must have fire extinguishers in
order to control fire. We can use fire detecting technology or fire
warning alarms technology to minimize such accidents.
Insurance Policy
Computer insurance provides cover for loss or damage of computer equipment that
may be desktop computers, laptop and handheld computers, peripheral components,
or networked system, and other portable equipment. Insurance is available for the cost
of replacing software and re-inputting any lost data. The valuable data and information
stored on computer for further use cannot recover with the insurance policy but a user can
claim for the cost of hardware damage and loss of software programs.
Use of Power Protection Devices
A computer needs constant source of electrical power to work. When an unexpected
power failure occurs and the computer shuts down improperly, that may damage the
hard drive and other internal components. Having a low or high power supply can cause
problems as well. High voltage can overheat the system and low voltage can prevent the
computer from preforming at its optimal level. Power protection devices help to protect
the computer system from the voltage fluctuation. Some of the power protection devices
are explained below.

New Gateway to Computer Science Book -10 59


Surge Suppressor
Surge suppressor helps to protect the device against the damage from
surges and spikes. These devices are used to filter the effects of voltage
spikes and surges that are present in power sources. A good surge
suppressor will protect your system from most of the voltage problems.
Uninterruptible Power Supply (UPS)
The UPS helps to protect against potential electrical power problems by
supplying a consistent level of electrical power to a computer or other
devices. The battery is constantly recharged while the UPS is in use. The
UPS provides a consistent power. Many UPS devices can communicate
directly with the computer operating system. This communication allows
the UPS to safely shut down the computer and save data during the power
failure. There are several types of UPS systems. Let’s discuss them in
short.
Standby UPS: It helps to protect against potential electrical power problems by providing
a backup battery to supply power when the incoming voltage drops below the normal
level.The battery is on standby during normal operation. When the voltage decreases, the
battery provides DC power to a power inverter, which converts it into AC power for the
computer.
Line Interactive UPS: This UPS has completely different design than the standby UPS.
This design replaces the separate battery charger, inverter, and source selection switch
with a combination inverter. When the line power is working, the inverter or converter
charges the battery; when the power fails, the system operates in reverse.
Double Conversion: It is an online UPS. It has no transfer time in the event of a power
failure.
Voltage Stabilizers
A voltage stabilizer stabilizes or regulates the voltage if the supply
voltage varies or fluctuates over a given range. It is an electrical
appliance that feeds constant voltage to a load during over and under
voltage conditions. This device detects these voltage conditions and
correspondingly brings the voltage to the desired range. Voltage
stabilizers provide a means to regulate the supply voltage to the load. These are not
meant to provide a constant voltage output; instead it operates the load or system in an
acceptable range of voltage. In case of modern digital type stabilizers, a microcontroller
or microprocessor is used as a central control unit.

60 New Gateway to Computer Science Book -10


Spike Guard
A spike guard has multiple sockets for connecting
electrical and electronic devices. In addition, they also
provide protection against spikes which can occur from
time to time. The sudden voltage is known as spikes. It has
extra-long cable length. It can be used to connect multiple
pins of electronic devices. The outer housing is made up of a fire retardant material so it
is safe to use. The main use of spike guard is to remove the sudden voltage and prevent it
from entering into the main system.
Volt Guard
Volt guard is also called a power protection device. It controls
the fluctuation of electric voltage. The volt guard provides
constant output voltage to the computer system if high input
voltage is supplied from the source. It provides constant
output voltage between the ranges of 220 to 240 volts.

Let’s Review

 The security given to different computer parts and other peripheral devices are
called hardware security.
 Regular maintenance of a computer means taking regular steps that make your
computer faster and more secure.
 A computer room with proper air condition maintains the temperature and
humidity.
 To prevent the computer from fire we must have fire extinguishers.
 Computer insurance provides cover for loss or damage of computer equipment.
 Surge suppressor helps to protect the device against damage from the surges and
spikes.
 The UPS helps to protect against potential electrical power problems by supplying
a consistent level of electrical power to a computer or other devices.
 A voltage stabilizer regulates the voltage if the supply voltage fluctuates over a
given range.
 A spike guard has multiple sockets for connecting electrical and electronic devices.
 Volt guard controls the fluctuation of electric voltage.

New Gateway to Computer Science Book -10 61


Innovative Task
 What are the various types of hardware and software security threats that may
occur in any organizations? How can we protect such threats? Prepare a project
report.

Assignment
1. Select the best answer from the list of choices.
a. Computer security is also called as ………..
i. cyber security ii. virus security ii. program security iv. File security
b. Which of the following is security threats?
i. Downloading software ii. Updating software
iii. Removing software iv. Computer Virus
c. Which of the following is authentication system?
i. Password ii. Biometric iii. Cryptography iv. All of the them
d. What do you mean by encryption?
i. Converting plain text to cipher text ii. Converting cipher text to plain text
iii. Both of them iv. None of them
e. Which of the following is related to back up?
i. Storing on secondary storage ii. storing on primary memory
iii. Storing on cloud storage iv. Both i and iii
f. The temperature in the computer system should be maintained between ....to ......
i. 21oC and 24oC iii. 22oC and 25oC
ii. 23oC and 26oC iv. None of the above
g. ....... protects the machine and peripheral hardware s from left, electronic intrusion
and damage.
i. Information security iii. Hardware security
ii. Software security iv. None of the above
h. To prevent the loss of data during power failures, use a(n):
i. encryption program. iii. surge protector.
ii. firewall. iv. UPS.

62 New Gateway to Computer Science Book -10


i. A(n)…………… can shield electronic equipment from power spikes.
i. encryption program iii. surge protector
ii. firewall iv. UPS
j. A device that protects your PC against power surges and spikes.
i. UPS iii. Voltage regulator
ii. Surge suppressor iv. All of the above
2. Fill in the blanks with correct words / phrases.
a. ……………is also known as cyber security or IT security.
b. The data stored in a computer can also be misused by an ……………..user.
c. …………means only authorized users should be able to modify and edit the data
when it is needed.
d. ………..may occur from the user computer hardware and computer software.
e. ……………..code can enter network drives and spread on another system as well.
f. A ………………. system is a technological system that uses information about a
person to identify that person.
g. ……………………… is the way of protecting information systems from theft
or damage.
h. ………………… means only authorized users should be able to modify and edit
the data when needed.
i. The protection or security given to different computer parts and other
peripheral devices is called ……………….. security.
j. A computer room with proper …………………. maintains the temperature, air
distribution and humidity.
3. State whether the following statements are true or false.
a. Confidentiality means only authorized user can access the data resources and
information.
b. Computer security is the way of protecting of information system.
c. A threat refers to anything that has the potential to cause serious harm to a computer
system.
d. Security mechanisms deal with prevention, detection, and recovery from a security
attack.
e. Antivirus programs are like a virus which may cause serious problem in the
computer system.

New Gateway to Computer Science Book -10 63


f. Backup is the process of making duplicate copy of information stored on computer.
g. Regular maintenance of a computer means taking regular steps that make your
computer faster and more secure.
h. To prevent the computer from fire we must have backup storage.
i. Surge suppressor helps to protect the device against damage from the surges and
spikes.
j. A voltage stabilizer stabilizes or regulates the voltage if the supply voltage varies
or fluctuates over a given range.
k. Hard disk controls the fluctuation of electric voltage.
l. Hardware security is a means of ensuring that data are kept safe from corrupt
and loss.
4. Give an appropriate technical term for the following.
a. An application security threat that cannot be efficiently controlled by conventional
antivirus software.
b. It deal with prevention, detection, and recovery from a security attack.
c. It is the process of ensuring and confirming the identity of the user before revealing
any information to the user.
d. The most common tool for restricting access to the computer system.
e. A technological system that uses information about a person to identify that
person.
f. It is the process of converting plaintext to cipher text.
g. It is the process of decoding encrypted information so that is can be accessed
again by authorized users.
h. A battery supported power unit which supplies power during the failure of
electricity.
i. Device used to protect electronic device from high voltage.
j. A branch of technology that protects the machine from theft, corruption, or natural
disaster.
k. A device which provides continuous power to the computer equipment and protects
them from power surges and voltage fluctuations.
l. A device that protects your PC against power surges and spikes.

64 New Gateway to Computer Science Book -10


5. Match the following
Backup power protection device
Antivirus secret word or phrase
Password cloud storage
UPS remove computer viruses
Search engine
6. Answer the following questions.
a. What is the computer security? Write down the key principles of information
security.
b. What is security threats? How it occur?
c. Define malicious code with its examples.
d. What do you mean by security mechanism? Write some security mechanism.
e. Define authentication system.
f. Define the terms biometric and password.
g. What is firewall? Write its basic functions.
h. What is cryptography? Define encryption and decryption.
i. What is anti-virus software? Write with few examples.
j. What is backup? Why it is important in data security?
k. What is the hardware security? What are the means of hardware security?
l. Define UPS. What are the functions of UPS?
m. What is a voltage regulator?
n. What is a voltage fluctuation? Which device do you recommend to protect your
PC from voltage fluctuation?
o. What is the role of the UPS in computer security?

New Gateway to Computer Science Book -10 65


Lesson
E-Commerce
4

Learning Outcomes

At the end of this lesson, students will be able to:


 define explain about e-commerce.
 tell the benefits and limitations of e-commerce.
 explain the types of e-commerce.
 tell about mobile commerce.
 tell about the online payment mechanism.

E-commerce is also known as electronic commerce or internet commerce. E-commerce


can be broadly classified as the set of business activities involving consumers, service
providers and manufacturers who use computer networks such as the Internet for
conducting their business transactions. It refers to any form of business transactions that
are conducted online. Ecommerce enables you to buy and sell products on a global scale,
twenty-four hours and 365 days. The most popular example of E-Commerce is online
shopping, which is defined as buying and selling of goods through the internet on any
device. However, E-Commerce can also involve other types of activities, such as online
sales, payment doorways, online ticketing, internet banking, etc.
It has become so convenient and easy, that anyone can shop for anything right from a living
room, with just a few clicks. This has evolved more with the emergence of smartphones,
where now, you can shop from anywhere and anytime, with a wireless device connected
to the Internet. Now you can search for almost any product or service online, without
having to go anywhere physically.
The primary goal of e-commerce is to bring the organizations closer to their actual
customers, thus providing the customers the products and services much faster and at
leaser cost than possible by the traditional business models. The other goals include
reduction in product and service cost, improve customer response time, improve the
quality of the products and services and improve customer satisfaction. Thus implementing
e-commerce has become a business necessity, as a company that fails to take advantage of
this technology will soon find themselves out of business.

66 New Gateway to Computer Science Book -10


Benefits and Limitations of E-Commerce

E-Commerce is massively used in the world these days. It has various benefits and
limitations. Let’s discuss some of the benefits and limitations of using E-Commerce.
Benefits
 Easy to reach on the global market.
 We can easily choice the products that we want.
 Customers can easily select products from different providers.
 It helps to save our time.
 Easy to start and manage a business.
 No need of physical company set-ups.
 Low operational costs and better quality of services.
Limitations
 Fraud and online insecurity is increasing rapidly.
 Data privacy issues are increasing.
 Customer cannot test or check the services or goods.
 It is totally dependent on electronic technologies.
 There is no guarantee of product quality.
 Unnecessary rumour may spread with in a second all over the world.

Types of E-Commerce

Business to Business (B2B)


B2B E-Commerce refers to all the electronic transactions of goods and sales that are
conducted between two companies. This type of e-commerce typically explains the
relationship between the producers of a product and the wholesalers who advertise the
product for purchase to consumer. In the context of communication, business to business
refers to methods by which employees from different companies can connect with one
another, such as through social media. This type of communication between the employees
of two or more companies is called B2B communication.

New Gateway to Computer Science Book -10 67


Business to Consumer (B2C )
B2C E-Commerce is the most common form of E-Commerce. It deals with electronic
business relationships between businesses and consumers. This e-commerce category
also enables businesses to develop a more personalized relationship with their customers.
Any business that trusts on B2C sales must maintain good relations with their customers.
B2C refers to the process of selling products and services directly between to consumers.
It is mainly used to refer to online retailers who sold products and services to consumers
through the Internet.
Consumer to Consumer (C2C)
This level of e-commerce encompasses all electronic transactions that take place between
consumers. Generally, these transactions are provided by online platforms but often are
conducted through the use of social media networks and websites. C2C represents a
market environment where one customer purchases goods from another customer using
a third-party business or platform to facilitate the transaction. C2C companies are a new
type of model that has emerged with E-Commerce technology.
Consumer to Business (C2B)
The C2B methodology completely transposes the traditional business-to-consumer (B2C)
model, where a business produces services and products for consumer consumption.
The C2B approach evolved from the growth of popular consumer-generated media and
content across different consumer segments, such as websites, blogs, podcasts, videos
and social networks. It is completely opposite to the concept of B2C where the companies
make goods and services available to the end consumers.
Business to Administration (B2A)
B2A E-Commerce category refers to all transactions between companies and public
administration. This is an area that involves many services, particularly in areas such as
social security, employment and legal documents. B2A e-commerce, also referred to as
B2G, is when a business provides an online service for the government, generally through
a website.
Consumer to Administration (C2A)
It is a popular E-Commerce category; C2A e-commerce encompasses all electronic
transactions between individuals and public administration. Examples of this include
taxes and scheduling an appointment using an online service. A C2A transaction can be
as simple as paying for parking tickets or ordering a new government ID. However, to be
considered a C2A E-Commerce transaction, this must be done online.

68 New Gateway to Computer Science Book -10


Let’s Review
 E-commerce is also known as electronic commerce or internet commerce.
 Ecommerce enables you to buy and sell products on a global scale, twenty-four
hours and 365 days.
 The primary goal of e-commerce is to bring the organizations closer to their actual
customers.
 E-Commerce is online shopping, which is defined as buying and selling of goods
through the internet on any device.
 E-commerce provides low operational costs and better quality of services.
 Unnecessary rumour may spread with in a second all over the world is the negative
aspects of e-commerce.
 B2B E-Commerce refers to all the electronic transactions of goods and sales that
are conducted between two companies.
 B2C deals with electronic business relationships between businesses and
consumers.
 C2C represents a market environment where one customer purchases goods from
another customer using a third-party business or platform to facilitate the
transaction.
 B2A E-Commerce category refers to all transactions between companies and
public administration.
 C2A e-commerce encompasses all electronic transactions between individuals
and public administration.

M-Commerce

Mobile commerce is popularly known as


M-commerce. It is a subset of E-Commerce. This
term was created in 1997 AD by Kevin Duffy.
It is essentially a way of carrying thousands
and millions of transactions in your pocket.
M-Commerce is the use of mobile phones to
conduct any type of business transaction. It is
the way of buying and selling of goods using
the mobile devices. These days most of the people are using their mobile devices more
often than their laptops or desktops to browse on the internet. There has been a huge
increase in transactions done through mobile devices in the last few years.

New Gateway to Computer Science Book -10 69


Due to the use of smartphone, online shopping has become very popular and trending
in Nepal these days. Every people has a mobile phone on their hand so just staying at a
corner of the room it is very easily to do the shopping of your desired products with lots of
choices. Even the suppliers feel comfortable to find you. So the future of E-commerce in
Nepal is very bright and charming. M-commerce has changed the thinking methodology
and the way of doing business by People through wireless technology. Besides, it is also
an integral part of the E-Commerce Platform, which ensures that marketplaces have
sufficient visions about their customer base. So, the current trends in the E-commerce
market boost future Mobile-Commerce or M-Commerce technology in Nepal.

Online Payment Mechanism

An online payment system is a way


of making transactions or paying
for goods and services through an
electronic medium, without the use
of cheques or cash. It’s also called an
electronic payment system or online
payment system. As the world advances
more with technology development, we
can see the rise of electronic payment
systems and payment processing devices. The electronic payment system has grown
gradually in our country Nepal these days. As this increase, the payment system by cheque
and cash is decreasing. One of the most popular payment forms online is credit and debit
cards. Besides them, there are also alternative payment methods, such as bank transfers,
electronic wallets, smart cards, etc.

An international online payment gateway from Nepal has just started from 2017 A.D.
which provides a safe, secure and easy payment solution. More and more successful
merchants are using this online payment system in Nepal to increase their business
potential. Online payment gateways work in fast and safe way, by allowing consumers
to pay directly using internet and their credit or debit card. By establishing an online
gateway portal from an application or website to the bank the sharing of information and
data becomes possible.

Some of the online payment service providers in Nepal are Esewa, Khalti, Ipay, IME Pay,
Qpay, PayWay, and so on.

70 New Gateway to Computer Science Book -10


Let’s Review
 Mobile commerce is popularly known as M-commerce.
 E-Commerce term was created in 1997 AD by Kevin Duffy.
 M-Commerce is the use of mobile phones to conduct any type of business
transaction.
 M-commerce has changed the thinking methodology and the way of doing
business by People through wireless technology.
 Online payment system is also called an electronic payment system or online
payment mechanism.
 The electronic payment system has grown gradually in our country Nepal these
days.
 An international online payment gateway from Nepal has just started from
2017 A.D.
 Online payment gateways work in fast and safe way, by allowing consumers to
pay directly using internet and their credit or debit card.
 Some of the online payment service providers in Nepal are Esewa, Khalti, Ipay,
IME Pay, Qpay, PayWay, etc.

Innovative Task
 Prepare a project report about any 5 popular e-commerce website those who are
providing e-commerce services in our country.
 Take a short audio interview with your school principal and teachers then present
in the class. (Sample questions are provided below. You can ask some more
questions as you like).
 What type of internet service you are using in your mobile?
 How long hours do you stay connect with internet?
 Do you know about internet banking?
 Are you using internet banking facility?
 Is there any apps installed in your mobile developed by the bank?
 Do you have SMS banking system?
 Do you have ATM card? Are you able to use it any time?
 Do you use credit card for shopping?
 Do you know about online-shopping? If yes, are you satisfied with their
services and product?
 Are you using any online payment system?
 What types of suggestions do you have for the students regarding the use
of technology?

New Gateway to Computer Science Book -10 71


Assignment
1. Select the best answer from the list of choices.
a. Which of the following is e-commerce service?
i. Online shopping ii. Uploading files
ii. Downloading files iv. Installing software
b. Which of the following is a benefit of e-commerce?
i. Low operational costs and better quality of services.
ii. Fraud and online insecurity is increasing rapidly.
iii. Data privacy issues are increasing.
iv. Customer cannot test or check the services or goods.
c. Which of the following is a limitation of e-commerce?
i. Easy to reach on the global market.
ii. It helps to save our time.
iii. Easy to start and manage a business.
iv. Customer cannot test or check the services or goods.
d. Which type commerce is mainly used to refer to online retailers who sold products
and services to consumers through the Internet?
i. B2B ii. B2C iii. C2C iv. C2B
e. When M-commerce term was created?
i. 1995 AD ii. 1996 AD iii. 1997 AD iv. 1998 AD
f. Which of the following is providing online payment system?
i. E-sewa ii. Khalti iii. IME Pay iv. All of them
2. Fill in the blanks with correct words / phrases.
a. E-commerce is also known as ………………………
b. The primary goal of ……………… is to bring the organizations closer to their
actual customers.
c. ……………………e-commerce refers to all the electronic transactions of goods
and sales that are conducted between two companies.
d. …………e-commerce category refers to all transactions between companies and
public administration.
e. E-Commerce term was created in …………………. AD.

72 New Gateway to Computer Science Book -10


f. ……………….. system is also called an electronic payment system or online
payment mechanism.
g. An international online payment gateway from Nepal has just started from
…………. A.D.
h. Mobile commerce is popularly known as ……………………
i. Online payment gateways work in fast and safe way, by allowing consumers to
pay ……………. using internet and their ……….. or debit card.
3. State whether the following statements are true or false.
a. Ecommerce enables you to buy and sell products on a global scale for a short time
period only.
b. E-Commerce is online shopping, which is defined as buying and selling of goods
through the internet on any device.
c. E-commerce provides high operational costs and better quality of services.
d. Unnecessary rumour may spread with in a second all over the world is the negative
aspects of e-commerce.
e. B2A deals with electronic business relationships between businesses and
consumers.
f. C2C represents a market environment where one customer purchases goods from
another customer using a third-party business or platform to facilitate the
transaction.
g. C2B e-commerce encompasses all electronic transactions between individuals
and public administration.
h. G-commerce is the use of mobile phones to conduct any type of business
transaction.
i. The electronic payment system has slow down gradually in our country Nepal
these days.
4. Answer the following questions.
a. What is E-Commerce? Explain in short.
b. What are the benefits and limitations of e-commerce?
c. What are the types of e-commerce? Define each in short.
d. What do you mean by m-commerce?
e. What is online payment system?
f. List out the various online payment services providers in Nepal.
g. List out the some popular e-commerce websites that are popularly used in our
country.

New Gateway to Computer Science Book -10 73


lesson
Contemporary Technology
5

Learning Outcomes

At the end of this lesson, students will be able to:


 explain about cloud computing.
 tell the services of cloud computing.
 explain about artificial intelligence.
 tell about virtual reality.
 explain about e-governance.
 explain about mobile computing.
 tell about E-learning.
 explain about e-banking.
 Tell about Internet of Things (IOT).

The uses of ICT tools are rapidly increasing these days in the world. Latest and updated
devices and software programs are introducing in the world. In this age of globalizations,
all of us must be updated with the latest technologies that are being used in the world. In
Nepal, the uses of ICT tools are increasing then before. People are using latest ICT tools
and software programs in our country as well. Here, we are going to discuss some of the
contemporary technologies that are used these days.

Cloud Computing

The cloud computing means storing and accessing data


and programs over the Internet instead of storing on
secondary storage devices. The cloud is just an image
for the Internet. Cloud computing is the delivery of
different services through the Internet. These resources
include tools and applications like data storage, servers,
databases, networking, and software. Cloud computing
can be both public and private. Public cloud services
provide their services over the Internet with some

74 New Gateway to Computer Science Book -10


charges. Private cloud services only provide services to a certain number of people. These
services are a system of networks that supply hosted services. There is also a hybrid
option, which combines elements of both the public and private services.
Following are the services of cloud storage.
 Email
 Storage, backup, and data retrieval
 Creating and testing apps
 Analysing data
 Audio and video streaming
 Delivering software on demand
Cloud computing is still a new service but is being used by a number of different
organizations from big corporations to small businesses, non-profits to government
agencies, and even individual consumers.

Artificial Intelligence

Artificial Intelligence (AI) is the area of computer science focusing on creating machines
that can engage on behaviours, that human consider intelligent. It refers to the simulation
of human intelligence in machines that are programmed to think like humans and simulator
their actions. The term may also be applied to any machine that displays qualities related
with a human mind such as learning and problem-solving.
The applications for artificial intelligence are endless. The technology can be applied to
many different sectors and industries. AI is being tested and used in the healthcare industry
and different treatment in patients, and for surgical procedures in the operating room.
The various application areas where AI is currently being used include game playing,
speech recognition, natural language processing, computer vision, expert systems, neural
networks, robotics, etc. Some of the business functions where AI is used are finance,
medicine, manufacturing industry, transportation, telecommunication, aviation, etc.

Virtual Reality

Virtual Reality (VR) is the use of computer technology to create a simulated environment.
It is an artificial environment that is created with software and presented to the user in such
a way that the user suspends belief and accept it as a real environment. On a computer,
VR is primarily experienced through two of the five senses: sight and sound. The simplest

New Gateway to Computer Science Book -10 75


form of virtual reality is a 3D image that can be explored interactively at a personal
computer, usually by manipulating keys or the mouse so that the content of the image
moves in some direction or zooms in or out. This is called non-immersive VR. Virtual
reality can be the simulation of a real environment for training and education and the
development of an imagined environment for a game or interactive story.
Virtual Reality’s most immediately-recognizable component is the head-mounted display
(HMD). Human beings are visual creatures, and display technology is often the single
biggest difference between immersive Virtual Reality systems and traditional user
interfaces.

E-Governance

E-governance is the integration of ICT in all the


processes, with the aim of enhancing government ability
to address the needs of the general public. The basic
purpose of e-governance is to simplify processes for all,
i.e. government, citizens, businesses, etc. at national,
State and local levels. In short, it is the use of electronic
means, to promote good governance. It connotes the implementation of information
technology in the government processes and functions so as to cause simple, moral,
accountable and transparent governance. It entails the access and delivery of government
services, dissemination of information, communication in a quick and efficient manner.
E-governance can only be possible if the government is ready for it. It is not a one day
task, and so the government has to make plans and implement them before switching to it.
E-Governance offers many benefits and advantages for the government, corporate sector
and society. E-Governance facilitates better delivery of government services to citizens,
improved interactions with business and industry, citizen empowerment through access
to information, or more efficient government management. Through e-governance, the
government plans to raise the coverage and quality of information and services provided
to the general public, by the use of ICT in an easy, economical and effective manner. The
process is extremely complicated which requires, the proper arrangement of hardware,
software, networking and indeed re-engineering of all the processes to facilitate better
delivery of services.
E-governance has a great role to play, that improves and supports all tasks performed by
the government department and agencies, because it simplifies the task and increases the
quality of work.

76 New Gateway to Computer Science Book -10


Let’s Review
 The uses of ICT tools are rapidly increasing these days in the world.
 The cloud is just an image for the Internet.
 Cloud computing is the delivery of different services through the Internet.
 Public cloud services provide their services over the Internet with some charges.
 Private cloud services only provide services to a certain number of people.
 Artificial Intelligence (AI) refers to the simulation of human intelligence in
machines that are programmed to think like humans and simulator their actions.
 The various application areas where AI is currently being used include game
playing, speech recognition, natural language processing, etc.
 On a computer, VR is primarily experienced through two of the five senses: sight
and sound.
 E-governance can only be possible if the government is ready for it.
 E-Governance offers many benefits and advantages for the government, corporate
sector and society.

Mobile Computing

Mobile computing is a generic term that refers to a variety of devices that allow people to
access data and information from wherever they are. Mobile computing transports data,
voice, and video over a network via a mobile device. Mobile devices can be connected to
a local area network (LAN), Wi-Fi or wireless technology by connecting via a wireless
local area network (WLAN). Mobile phone services also provide mobile computing
through their service plans. Mobile computing devices are portable devices capable of
operating, executing, providing services and applications like a computing device. There
are many benefits to mobile computing including the ability to get directions, entertain,
do business, and more, including:
 Connectivity: You can stay connected to all sources at all times.
 Social Engagement: You can interact with a variety of users via the Internet.
 Personalization: You can tailor your mobile computing to your individual needs.
The following are the features of mobile computing
 It a portable device so it can be used anywhere easily and it can be used at any time.

New Gateway to Computer Science Book -10 77


 It saves time of accessing data and information.
 It helps to increase the productivity of the users.
 It can be used for remote access and cloud computing.
 It can include GPS (Global Positioning System) receiver from navigation.
 It has camera, speaker and microphone.
 It uses operating system such as android, iOS, Palm OS, windows, etc. for its
operations.
 It has the ability to share data and collaboration between users.

E-learning

E-learning is a new concept of delivering digital contents in learner oriented environment


using information and communication technology (ICT). It is the way of delivering the
digital content. E-learning refers to a learning system that we can obtain through the
internet using an electronic device. We also call it online learning or online education.
E-learning can be done using an Internet connection, a network, an Intranet, or a storage
disk. It uses a variety of media like audio, text, virtual environments, video and animation.
It is far better than classroom learning methods as it is a one-on-one learning method, it
is self-placed and it has an experiential-learning format.
E-learning, web-based training, internet-based training and computer-based training are
the next generation instruction methods being developed today. With E-learning, users
can immerse themselves in a three-dimensional environment to further enhance their
learning experience. It can be done anywhere and anytime as long as the user has the
proper hardware and internet connectivity.
Recently in Nepal, Nepal Open University has started its online academic courses for
bachelor’s degree, master’s degree, M.Phil. and even PhD through E-learning.
Advantages of e-learning:
 It is less expensive to produce.
 It maintains the consistency of content.
 It is very easy for customization.
 It can work from any location and any time.
 It can be updates easily and quickly.
 It reduces travel costs to attend learning events.
 It reduces or removes need for classroom/instructor infrastructure.
 It can be easily managed for large groups of students.

78 New Gateway to Computer Science Book -10


E-Banking

Electronic Banking is an umbrella term for the process by which a customer may perform
banking transactions electronically without visiting an institution. All forms of banking
services and transactions performed through electronic means. E-banking includes the
systems that enable financial institution customers, individuals or businesses, to access
accounts, transact business, or obtain information on financial products and services
through a public or private network, including the internet.
E-banking is a safe, fast, easy and efficient electronic service that enables you access to
bank account and to carry out online banking services, 24 hours a day, and 7 days a week.
The customer using this facility can conduct transactional and non-transactional tasks
including:
 The customer can view account statements.
 The customer can check the history of the transactions for a given period by the
concerned bank.
 Bank, statements, various types of forms, applications can be downloaded.
 The customer can transfer funds, pay any kind of bill, recharge mobiles, etc.
 The customer can buy and sell on e-commerce platforms.
 The customer can invest and conduct trade.
 The customer can book transport, travel packages, and medical packages.
There are many different types of e-banking services which you can use for various bank
transactions. Let us discuss some of the most popular options.
Internet Banking
Internet Banking is a type of e-banking service which allows you to do several financial
and non-financial transactions through the internet. You can use your PC or laptop and an
internet connection to use this facility. With the help of Internet Banking, you can transfer
funds to another bank account, check your account statement, pay online bills, etc.
Mobile Banking
Most banks now also have an app for Mobile Banking. Just like the online portal of the
bank used for Internet Banking, you can use the app for many different types of banking
transactions. If you use an Android or iOS device, you can download the app of your bank
and use this facility. The apps can also be used for transferring funds, checking account
statements, locate the nearest ATM, and other banking services.

New Gateway to Computer Science Book -10 79


ATM
ATM or Automated Teller Machine is one of the most popular types of electronic
banking. The teller machine is also an electronic computerised telecommunication device
which enables you to withdraw funds, deposit funds, change PIN (Personal Identification
Number) and use other banking services.

Internet of Things (IOT)

Internet of Things is becoming an increasingly growing topic of discussion both in the


workplace and outside of it. The Internet of Things (IoT) is a system of interrelated
computing devices, mechanical and digital machines, objects, or people that are provided
with unique identifiers and the ability to transfer data over a network without requiring
human-to-human or human-to-computer interaction. The Internet of Things refers to
the ever-growing network of physical objects that feature an IP address for internet
connectivity, and the communication that occurs between these objects and other Internet-
enabled devices and systems.
IoT applications are used to address many real-world issues such as traffic jamming,
city services, economic development, citizen engagement, and public safety and security.
Smart cities often embed IoT sensors into the physical infrastructure, such as streetlights,
water meters and traffic signals, etc.

Let’s Review
 Mobile computing is a generic term that refers to a variety of devices that allow
people to access data and information from wherever they are.
 Mobile phone services also provide mobile computing through their service plans.
 Mobile computing devices are portable devices capable of operating, executing,
providing services and applications like a computing device.
 E-learning is a new concept of delivering digital contents in learner oriented
environment using information and communication technology (ICT).
 E-learning can be done using an Internet connection, a network, an Intranet, or a
storage disk.
 Electronic Banking is an umbrella term for the process by which a customer may
perform banking transactions electronically without visiting an institution.
 Internet Banking is a type of e-banking service which allows you to do several
financial and non-financial transactions through the internet.
 The Internet of Things refers to the ever-growing network of physical objects that
feature an IP address for internet connectivity, and the communication that occurs
between these objects and other Internet-enabled devices and systems.

80 New Gateway to Computer Science Book -10


Innovative Task
 Visit a bank nearby you and prepare a project report about what types of banking
facilities that they are provided to their customers.
 Take a short audio interview with any banker about the ATM card, Debit card,
Credit card, Remittance services, Online banking, SMS banking and present in
your class.

Assignment
1. Select the best answer from the list of choices.
a. What do you mean by contemporary technology?
i. Latest and update technology ii. Traditional type of technology
iii. Online technology iv. Phase out technology
b. Which of the following is the services of cloud computing?
i. Email ii. Audio and Video
iii. Creating and testing apps iv. All of them
c. Which of the following is related to AI?
i. Natural language processing ii. Operating system
iii. Hardware only iv. Software only
d. Which of the following is closer to E-Governance?
i. Providing computer ii. Proving water supply
iii. Providing E-Services iv. Providing loan
e. Which of the following is closer to E-learning?
i. General education ii. Online education
iii. Copyright iv. Offline education
f. Which of the following is E-Banking service?
i. Providing cheques ii. Providing voucher
iii. ATM card, SMS banking iv. All of them
2. Fill in the blanks with correct words / phrases.
a. The cloud is just an ……………. for the Internet.
b. .…………….. cloud services provide their services over the Internet with some
charges.
c. ……………………..refers to the simulation of human intelligence in machines
that are programmed to think like humans and simulator their actions.

New Gateway to Computer Science Book -10 81


d. On a computer, ……………… is primarily experienced through two of the five
senses: sight and sound.
e. ……………………. offers many benefits and advantages for the government,
corporate sector and society.
f. Mobile phone services also provide ……………… through their service plans.
g. ……………. is a new concept of delivering digital contents in learner oriented
environment using information and communication technology (ICT).
h. ……………….. is an umbrella term for the process by which a customer may
perform banking transactions electronically without visiting an institution.
3. State whether the following statements are true or false.
a. The uses of ICT tools are rapidly decreasing these days in the world.
b. Cloud computing is the delivery of different services through the Internet.
c. Public cloud services only provide services to a certain number of people.
d. The various application areas where AI is currently being used include game
playing, speech recognition, natural language processing, etc.
e. E-governance can only be possible if the government is not ready for it.
f. Mobile computing is a generic term that refers to a variety of devices that allow
people to access data and information from wherever they are.
g. E-learning can be done using an Internet connection, a network, an Intranet, or a
storage disk.
h. Internet Banking is a type of offline banking service which allows you to do
several financial and non-financial transactions through the internet.
4. Answer the following questions.
a. What is cloud computing? Write down the services of cloud storage.
b. What is artificial intelligence? Where it can be used?
c. Define virtual reality with its some supplication area.
d. What is e-governance? How its helps to the citizens?
e. Define mobile computing with its features.
f. What is e-learning? Write some advantages of e-learning.
g. Define e-banking. Write some e-banking services.
h. What are the uses of e-banking services?
i. Define internet banking and mobile banking.
j. Explain in short about IoT.

82 New Gateway to Computer Science Book -10


Lesson
Computer Number System
6

Learning Outcomes

At the end of this lesson, students will be able to:


 describe the history of number system.
 tell the types of computer number system.
 convert different numbers into different bases.
 do the addition, subtraction, multiplication and division of binary numbers.

When we type some letters or words, the computer translates them in numbers as
computers can understand only numbers. A computer can understand positional number
system where there are only a few symbols called digits and these symbols represent
different values depending on the position they occupy in the number. Number systems
use different number bases. A number base indicates how many different digits are
available when using a particular numbering system. For example, the base of decimal
number is 10, which means it uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. The base of
binary number is 2, which means that it uses two digits that are 0 and 1.
A number system in base r or radix r uses unique symbols for r digits. One or more digits
are combined to get a number. The base of the number decides the valid digits that are
used to make a number. In a number, the position of digits starts from the right-hand side
of the number. The right most digits has position 0, the next digit on its left has position1,
and so on. The digits of a number have two kinds of values they are face value and
position value.
The face value of a digit is the digit located at that position. For example, in decimal
number 87, face value at position 0 is 7 and face value at position 1 is 8.

Types of Number System


 Binary number system
 Octal number system
 Decimal number system
 Hexadecimal number system

New Gateway to Computer Science Book -10 83


Binary Number System
A Binary number system has only two digits that are 0 and 1. Every number (value)
represents 0 and 1 in this number system. The base of binary number system is 2, because
it has only two digits. (10101)2, (111000)2, (101110)2, etc. are the examples of binary
number system. This is a positional notation numbering system. Each position in a binary
number system represents a positive power of 2 i.e. 20, 21, 22, 23, 24, 25 and so on. The
position value and quantity of a digit at different positions in a number are shown in the
given table.

Position 3 2 1 0
Position Value 23 22 21 20
Quantity 8 4 2 1
Decimal Number System
Decimal number system has only ten (10) digits from 0 to 9. Every number (value)
represents 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 in this number system. The base of decimal number
system is 10, because it has only 10 digits. This is a positional notation numbering system.
Each position in a decimal number system represents a positive power of 10 i.e. 100, 101,
102, 103, 104, 105 and so on. (55)10, (799)10, (8459)10, etc. are the examples of decimal
number system. The position value and quantity of a digit at different positions in a
number are shown in the given table.

Position 3 2 1 0
Position Value 103 102 101 100
Quantity 1000 100 10 1
Octal Number System
Octal number system has only eight (8) digits from 0 to 7. Every number (value) represents
0, 1, 2, 3, 4, 5, 6 and 7 in this number system. The base of octal number system is 8,
because it has only 8 digits. (27)8, (760)8, (5473)8, etc. are the examples of octal number
system. This is a positional notation numbering system. Each position in a octal number
system represents a positive power of 8 i.e. 80, 81, 82, 83, 84, 85 and so on. The position
value and quantity of a digit at different positions in a number are shown in the given
table.

Position 3 2 1 0
Position Value 83 82 81 80
Quantity 512 64 8 1

84 New Gateway to Computer Science Book -10


Look at the decimal-octal-binary conversion table below.
Decimal Octal Binary
0 0 000
1 1 001
2 2 010
3 3 011
4 4 100
5 5 101
6 6 110
7 7 111
Hexadecimal Number System
A hexadecimal number system has sixteen (16) alphanumeric values from 0 to 9 and
A to F. Every number (value) represents 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F
in this number system. The base of hexadecimal number system is 16, because it has
16 alphanumeric values. Here A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15.
This is a positional notation numbering system. Each position in a hexadecimal number
system represents a positive power of 16 i.e. 16°, 161, 162, 163, 164, 165 and so on. (985)16,
(DAD1)16, (1F73)16, etc. are the examples of hexadecimal number system. The position
value and quantity of a digit at different positions in a number are shown in the given
table.

Position 3 2 1 0
Position Value 163 162 161 160
Quantity 4096 256 16 1
Look at the decimal-hexadecimal-binary conversion table below.

Decimal Binary Hexadecimal


0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8

New Gateway to Computer Science Book -10 85


9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

Let’s Review
Number system with their base, used digits and example.
Number System Base Used Digits Example
Binary 2 0 and 1 (10101111)2
Octal 8 0, 1, 2, 3, 4, 5, 6 and 7 (755)8
Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 (7921)10
Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, (D1FB)16
A, B, C, D, E and F

Number Conversion

Converting from Binary, Octal and Hexadecimal into Decimal


We use the following steps to convert a number in any other base to a base 10 (decimal)
number:
Step1: Determine the positional value of each digit (this depends on the position of the digit
and the base of the number system).
Step 2: Multiply the obtained value (in step 1) by the digits in the corresponding place.
Step 3: Sum up the products calculated in step 2. The total is the equivalent value in
decimal.
Binary to Decimal
Example: Convert (11011)2 into (? )10
Digits 1 1 0 1 1
Power of (2) 24 23 22 21 20
= (1 × 24) + ( 1 × 23) + (0 × 22) + ( 1 × 21) + ( 1 × 20)
= 16 + 8 + 0 + 2 + 1
= 27
Thus: (11011)2 = (27)10

86 New Gateway to Computer Science Book -10


Octal to Decimal
Example: Convert (417)8 into (?)10
Digits 4 1 7
Power of (8) 82 81 80
= (4×82) + (1×81) + ( 7 × 80)
= (4×64) + (1× 8) + (7×1)
= 256 + 8 + 7
= 271
Thus: (417)8 = (271)10
Hexadecimal to Decimal
Example: Convert (AB1)16 into (?)10
Digits A (10) B(11) 1
Power of (16) 162 161 160
= (10×162) + (11×161) + (1×160)
= (10×256) + (11×16) + (1×1)
= 2560 + 176 + 1
= 2737
Thus: (AB1)16 = (2737)10
Converting from Decimal to Binary, Octal and Hexadecimal
We use the following steps to convert a base 10 (decimal) number to a number in any
other base:
Step 1: Divide the decimal number by the value of the new base.
Step 2: Record the reminder from step 1 as the rightmost digit (least significant digit) of the
new base number.
Step 3: Divide the quotient of the previous division by the new base.
Step 4: Record the remainder from step 3 as the next digit (to the left) of the new base
number.
Step 5: Repeat steps 3 and 4, recording remainders from right to left, until the quotient
becomes zero in step 3.

New Gateway to Computer Science Book -10 87


Decimal to Binary
Example 1: Convert (104)10 into (?)2 Example 2: Convert (90)10 into (?)2
2 104 Remainder 2 90 Remainder
2 52 0 2 45 0
2 26 0 2 22 1
2 13 0 2 11 0
2 6 1 2 5 1
2 3 0 2 2 1
2 1 1 2 1 0
0 1 0 1
=1101000 = 1011010
Thus: (104)10 = (1101000)2 Thus: (90)10 = (1011010)2
Decimal to Octal
Example 1: Convert (1341)10 into (?)8 Example 2: Convert (1910)10 into (?)8
8 1341 Remainder 8 1910 Remainder
8 167 5 8 238 6
8 20 7 8 29 6
8 2 4 8 3 5
0 2 0 3

= 2475 = 3566
Thus: (1341)10 = (2475)8 Thus: (1910)10 = (3566)8
Decimal into Hexadecimal:
Example 1: Convert (494)10 into (?)16 Example 2: Convert (945)10 into (?)16

16 494 Remainder 16 945 Remainder


16 30 14(E) 16 59 1
16 1 14(E) 16 3 11 (B)
0 1 0 3

= 1EE = 3B1
Thus: (494)10 = (1EE)16 Thus: (945)10 = (3B1)16

88 New Gateway to Computer Science Book -10


Binary into Octal
Step 1: Separate the digits of a given binary number into group of 3 digits from right to
left.
Step 2: Add 0’s to the left, if the last group doesn’t contain 3 digits.
Step 3: Find the equivalent octal number for each group.
Step 4: Write the all groups octal numbers together to determine the value in octal.
Example: 1 Convert (101010)2 into octal
Binary number: 101010
Binary grouping of 3 digits from right to left: 101 010
Octal equivalent: 5 2
Thus: (101010)2 = (52)8
Example: 2 Convert (1111000111)2 into octal
Binary number: 1111000111
Binary grouping of 3 digits from right to left: 001 111 000 111
Octal equivalent: 1 7 0 7
Thus: (1111000111)2 = (1701)8
Octal into Binary
Step 1: Separate the digits of the given octal number.
Step 2: Find the equivalent binary number for each digit of octal number.
Step 3: Write the all group’s binary numbers together, maintaining the same group order
provides the equivalent binary for the given octal number.
Example: 1 Convert (175)8 into binary
Octal number: 175
Individual octal digit: 1 7 5
Binary equivalent of individual octal digit: 001 111 101
Thus: (175)8 = (001111101)2
Example: 2 Convert (7631)8 into binary
Octal number: 7631
Individual octal digit: 7 6 3 1
Binary equivalent of individual octal digit: 111 110 011 001
Thus: (7631)8 = (111110011001)2

New Gateway to Computer Science Book -10 89


Hexadecimal into Octal
Step 1: Separate the digits of the given hexadecimal number.
Step 2: Find the equivalent binary number for each digit of hexadecimal number.
Add 0’s to the left if any of the binary equivalent is less than 4 digits.
Step 3: Write the all groups binary numbers together, maintaining the same group.
Step 4: Separate the binary digits into groups, each containing 3 digits from right to left.
Add 0’s to the left, if the last group contains less than 3 digits.
Step 5: Find the octal equivalent for each group.
Step 6: Write all octal equivalent of each digit together.
Example: 1 Convert (AC2)16 into octal
Hexadecimal number: AC2 A C 2
Binary equivalent of individual hexadecimal digit: 1010 1100 0010
Writing all the groups of binary numbers together: 101011000010
Grouping with 3 digits for octal equivalent: 101 011 000 010
Octal equivalent: 5 3 0 2
Thus: (AC2)16 = (5302)8
Example: 2 Convert (B5A)16 into octal
Hexadecimal number: B5A B 5 A
Binary equivalent of individual hexadecimal digit: 1011 0101 1010
Writing all the groups of binary numbers together: 101101011010
Grouping with 3 digits for octal equivalent: 101 101 011 010
Octal equivalent: 5 5 3 2
Thus: (B5A)16 = (5532)8
Octal into Hexadecimal
Step 1: Separate the digits of the given octal number.
Step 2: Find the equivalent binary number for each digit of octal number. Add 0’s to the
left if any of the binary equivalent is shorter than 3 digits.
Step 3: Write the all groups binary numbers together, maintaining the same group order.
Step 4: Separate the binary digits into groups, each containing 4 digits from right to left.
Add 0’s to the left, if the last group contains less than 4 digits.
Step 5: Find the hexadecimal equivalent for each group.
Step 6: Write all hexadecimal equivalent of each digit together.

90 New Gateway to Computer Science Book -10


Example: 1 Convert (753)8 into hexadecimal
Octal number: 753 7 5 3
Binary equivalent of individual octal digit: 111 101 011
Writing all the groups of binary numbers together: 111101011
Grouping with 4 digits for hexadecimal equivalent: 0001 1110 1011
Hexadecimal equivalent: 1 14(E) 11(B)
Thus: (753)8 = (1EB)16
Example: 2 Convert (523)8 into hexadecimal
Octal number: 523 5 2 3
Binary equivalent of individual octal digit: 101 010 011
Writing all the groups of binary numbers together: 101010011
Grouping with 4 digits for hexadecimal equivalent: 0001 0101 0011
Hexadecimal equivalent: 1 5 3
Thus: (523)8 = (153)16
Binary into Hexadecimal
Step 1: Separate the digits into groups from right to left. Each group should contain 4
digits of binary number.
Step 2: Add 0’s to the left, if the last group has less than 4 digits.
Step 3: Find the equivalent hexadecimal number for each group.
Step 4: Write the all groups hexadecimal numbers together, maintaining the group order
provides the equivalent hexadecimal number for the given binary.
Example: 1 Convert (1010000111)2 into hexadecimal
Binary number: 1010000111
Binary grouping of 4 digits from right to left: 0010 1000 0111
Hexadecimal equivalent: 2 8 7
Thus: (1010000111)2 = (287)16
Example: 2 Convert (1111101011011111)2 into hexadecimal
Binary number: 1111101011011111
Binary grouping of 4 digits from right to left: 1111 1010 1101 1111
Hexadecimal equivalent: 15 (F) 10 (A) 13 (D) 15 (F)
Thus: (1111101011011111)2 = (FADF)16

New Gateway to Computer Science Book -10 91


Hexadecimal into Binary
Step 1: Separate the digits of the given hexadecimal, if more than 1 digit.
Step 2: Find the equivalent binary number for each digit of hexadecimal number.
Step 3: Add 0’s to the left if any of the binary equivalent is less than 4 digits.
Step 4: Write the all groups binary numbers together, maintaining the same group order
provides the equivalent binary for the given hexadecimal.
Example: 1 Convert (A01)16 into binary
Binary number: A01
Binary grouping of 4 digits from right to left: A 0 1
Hexadecimal equivalent: 1010 0000 0001
Thus: (A01)16 = (101000000001)2
Example: 2 Convert (DAF)16 into binary
Binary number: DAF
Binary grouping of 4 digits from right to left: D A F
Hexadecimal equivalent: 1101 1010 1111
Thus: (A01)16 = (110110101111)2

Binary Arithmetic

The arithmetic operations like addition, subtraction, multiplication and division performed
on the number is called binary arithmetic.
Binary Addition
It works in the same way, except that only 0’s and 1’s can be used, instead of the whole
range of 0-9. This actually makes binary addition much simpler than decimal addition.
The rules of binary additions are as follows:
0+0=0 As an example of binary addition we have,
0+1=1 101
1+0=1 +1 0 1
1 + 1 = 0 (plus a carry of 1 to next higher 1 0 1 0
column
Carry overs are performed in the same manner as in decimal arithmetic. Since 1 is the
largest digit in binary number system, any sum greater than 1 requires a digit to be carried
over. In the above example to add the number (1+1), we first consider the “ones” column

92 New Gateway to Computer Science Book -10


and calculate 1 + 1, which (in binary) results in 10. We “carry” the 1 to the “tens” column,
and the leave the 0 in the “ones” column.
Moving on to the “tens” column, we calculate 1 + (0 + 0), which gives 1. Nothing “carries”
to the “hundreds” column, and we leave the 1 in the “tens” column.
Another example of binary addition
1011
+ 1011
10110
Note that in the “tens” column, we have 1 + (1 + 1), where the first 1 is “carried” from the
“ones” column. Recall that in binary, 1 + 1 + 1 = 10 + 1 = 11
Add the following numbers
a. 101111+10110 b. 110111+11111
101111 110111
+1 0 1 1 0 +1 1 1 1 1
1000101 1010110

Binary Subtraction
Binary subtraction is also similar to that of decimal subtraction with the difference that
when 1 is subtracted from 0, it is necessary to borrow 1 from the next higher order bit and
that bit is reduced by 1.
The rules of binary subtraction are as follows:
0-0=0
1-0=1
1-1=0
0 - 1 = 1 with a borrow of 1 from the next column.
Subtract the following numbers:
a. 101 from 1001 b. 111 from 1000
Solution: Solution:
101 from 1001 111 from 1001
1 Borrow 1 Borrow
1001 1000
−1 0 1 −1 1 1
0100 0001

New Gateway to Computer Science Book -10 93


Binary Multiplication
Multiplication in binary number system also follows the same general rules as in decimal
number system.
The rules of binary multiplication are as follows:
0x0=0
0x1=0
1x0=0
1x1=1
Multiply the following numbers:

a. 11011 by 101 b. 101 by 111

Solution: Solution:
11011 101
×101 ×111
11011 101
00000 101
+1 1 0 1 1 +1 0 1
10000111 100011

Binary Division
The rules of binary dicision are as follows:
0 ÷ 0 = Divide by zero error
0 ÷ 1 = 0
1 ÷ 0 = Divide by zero error
1 ÷ 1 = 1
Note that since division by 0 in any number system is meaningless, computers deal with
this problem by raising an error condition called ‘Divide by zero’ error.
Some rules for binary division are listed below.
Step 1 : Start from the left of the dividend.
Step 2 : Perform a series of subtractions, in which the divisor is subtracted from the
dividend.
Step 3 : If subtraction is possible, put a 1 in the quotient and subtract the divisor from the
corresponding digits of dividend.
Step 4 : If subtraction is not possible, record a 0 in the quotient.

94 New Gateway to Computer Science Book -10


Step 5 : Bring down the next digit to add to the remainder digits. Proceed as before in a
manner similar to long division.
Divide the following numbers:
a. 1011 divided by 11. b. 10010 divided by 11
11 (Quotient) 1 1 0 (Quotient)
)
11 1011 11) 1 0 0 1 0
-11 −1 1

101 11
− 11
-11
00
10 (Remainder) − 0
0 (Remainder)

So that, in the above example ‘a’ the quotient is 11 and remainder is 10. Like this in the
above example ‘b’ the quotient is 110 and remainder is 0.

Innovative Task
 Prepare a decimal-octal-binary conversation table and decimal-hexadecimal-
binary conversation table in a chart paper and submit to your teacher as your
project work.

Assignment
1. Select the best answer from the list of choices.
A. A positional number system that utilizes the symbols 0 and 1.
i. Decimal number system iii. Binary number system
ii. Octal number system iv. Hexadecimal system
B. The decimal equivalent of binary number (1100110)2 is:
i. (102)10 iii. (103)10
ii. (104)10 iv. (105)10
C. The hexadecimal digits are 0 to 9 and A to:
i. E iii. F
ii. G iv. H

New Gateway to Computer Science Book -10 95


D. A combination of 8 bits.
i. 0 and 1 iii. Byte
ii. Byte iv. Nibble
E. A unit of computer memory or data storage capacity equal to 1024 MB.
i. Petabyte (PB) iii. Megabyte(MB)
ii. Gigabyte(GB) iv. Kilobyte(KB)
F. A unit of information or computer storage equal to 1024 ZB.
i. Yota byte(YB) iii. Megabyte(MB)
ii. Gigabyte(GB) iv. Kilobyte (KB)
2. Fill in the blanks with correct words / phrases.
a. The……….. number system is a number system in which each symbol represents
the same value, regardless of its position in the number.
b. ………..is positional number system having base 2.
c. The ………..is used in computing as a simple means of expressing binary
quantities.
d. A ……….can represent a single character, such as a letter, a digit, or a punctuation
mark.
e. ………is a unit of computer memory or data storage capacity equal to 1024 KB.
f. A …….is a unit of information or computer storage equal to 1024 ZB.
3. State whether the following statements are true or false.
a. Number system is an organized and systematic way of representing numbers.
b. The most common positional number system is the Roman number system.
c. Binary number system is a positional number system having base 10.
d. Decimal number system is a positional number system having base 10.
d. The combination of two bits is called a crumb.
e. Yottabyte is a unit of computer memory or data storage capacity equal to 1024 PB.
4. Convert the following as indicated.
a. (1010111)2 into Decimal
b. (11001111)2 into Octal
c. (110001100)2 into Hexadecimal

96 New Gateway to Computer Science Book -10


d. (7541)8 into Decimal
e. (5432)8 into Binary
f. (3102)8 into Hexadecimal
g. (901)10 into Binary
h. (971)10 into Octal
i. (109)10 into Hexadecimal
j. (AO1F)16 into Binary
k. (B89)16 into Decimal
l. (DAD101) 16 into Octal
5. Do the following activities given below.
a. (10101) + (1101)
b. (1001) + (101) + (11)
c. (11101) – (11001)
d. (1001010) – (110101)
e. (1101) × (11)
f. (1110101) ÷ (101)
g. (1011) × (11) + (10101)
h. (1010) – (11) × (11)
i. (101010) – (111) ÷ (11)
j. (111) + (111) – (10)

New Gateway to Computer Science Book -10 97


Database Management
System
Unit

This unit cover the following lesson:

Lesson 7: Database management system (MS-ACCESS)


Lesson
Database Management System
7 MS-Access

Learning Outcomes

At the end of this lesson, students will be able to:


 define the terms such as data, database, information, etc.
 tell about the database management system.
 write the advantages and disadvantage/s of database.
 tell about the elements of database.
 discuss about RDBMS.
 discuss the objects of MS-Access.
 work with Microsoft Access.

Database is an organized collection of related information or data, where we can store


organized information for multiple purposes. A telephone directory is one of the most
common examples of database, where the names of telephone subscribers are given in an
alphabetical order. Likewise dictionary, school student’s record, teacher’s salary record
etc. are also given. Databases are structured to facilitate storage, retrieval, modification,
and deletion of data in conjunction with various data-processing operations. A database
consists of a file or a set of files that can be broken down into records, each of which
consists of one or more fields. DBMSs can manage any form of data including text,
images, sound and video. Database and file structures are always determined by the
software.

Data and Information


Data are raw, unorganized facts that need to be processed which have no meaning. When
data are processed, organized, structured or presented in a given context to make it
useful that is called information. Here, we can say data are meaningless but information
is meaningful. Data are the source of information. Without data information cannot be
formed.

New Gateway to Computer Science Book -10 99


Database Management System (DBMS)

DBMS is a software that stores data, processes them and provides information in an
organized way. A database management system (DBMS) is designed to manage a large
volume of information. It is a computerized system that stores data, processes them and
provides information in an organized form. Some of the popular DBMS softwares are
MS-Access, Oracle, FoxPro, SQL Server, My SQL, DBASE etc. Data management
involves both defining structures for storing information and providing mechanisms
for manipulating the information. Examples of the use of database systems are airline
reservation systems, company payroll, employee information systems, banking systems,
credit card processing systems, and sales and order.
Advantages of Database Systems
 It reduces the data redundancy on the file. Redundant data are repeated and necessary data
exist on the file. So, we have to reduce it to save the memory of the computer.
 Data stored on the DBMS are highly consistent. They are constant in nature.
 It is possible to share data using DBMS. Various users are allowed to share data
according to their needs using the same database file.
 It is possible to apply the centralized security system on DBMS.
 It has a very high data integrity. We can retrieve data on complete form using
DBMS.
Disadvantages of Database Systems
 High initial investment in hardware, software, and training.
 Overhead for providing security, recovery, and integrity functions.
 Cost for the hardware-upgrade to allow for the extensive programs and the workspaces
required for their execution and storage.
 Cost for the maintenance of the software which remains forever.
 An additional cost is required to transfer from a traditionally separate application
environment to an interpreted one.
 High cost for backup and recovery.
Elements of Database

The core component of the database is a table. Database is the combination form of one
or more than one table. Tables are the basic blocks of database. A single table is used to
store data of a specific purpose or subject such as telephone directory, book records, etc.

100 New Gateway to Computer Science Book -10


Since, entire data are managed and kept in a table for the future retrieval process, it is also
called the primary object of database. The various elements of database are listed below.
Tables
A database table is composed of records and fields that hold data. Tables are also called
datasheets. Each table in a database holds data about a different, but related, subject.
Table stores a large volume of data into rows and column format as below. In the given
table, SN, Book_Name , Quantity and Rate are the field names and the information stored
on each field is called record.

SN Book_Name Quantity Rate


1 Computer Science 10 100
2 Social Studies 15 150
3 Moral Science 25 125
4 Optional Mathematics 28 275
5 Nepali 20 185

Records
Data are stored in records. A record is composed of fields and contains all the data about
one particular person, company, or item in a database. Records appear as rows in the
database table. A record for S.N. 5 is given as below from the above table.

SN Book Name Quantity Rate


5 Nepali 20 185
Fields
A field is part of a record and contains a single piece of data for the subject of the record. A
field or column contains information about a certain type for all records. In the given table
SN, Book_Name, Quantity and Rate are the fields of table where Book Name contains the
name of each book in the table.

Book Name
Computer Science
Social Studies
Moral Science
Optional Mathematics
Nepali

New Gateway to Computer Science Book -10 101


Value
Each specific piece of information in a table is known as value. For example, in the table
given below, Computer Science is a value in Book Name field and 10 is a value in the
Quantity field. Value is located at the cell of table which is also called the intersection of
row and column.

Quantity Rate
10 100

Relational Database Management System (RDBMS)

It is a collection of related data. It is defined as a method of viewing information for


several, separated database that relate one to another through keywords or values.
RDBMS are database management systems that maintain data records and indices in
tables. Relationships may be created and maintained across and among the data and
tables. MS-ACCESS and Oracle are the best examples of RDBMS software.

Introduction to Microsoft Access

Microsoft Access is a Relational Database Management System (RDBMS) that helps us


to store information for reference, reporting, and analysis. Access is known as a desktop
database system because it’s functions are intended to be run from a single computer. We
can use various ways to create a database by using MS-Access. Access was developed
by Microsoft Company. This software is distributed along with the Microsoft Office
application package. Microsoft Access 2010 is the latest version available in the market.

Features of Microsoft Access


 It provides very useful database features such as tables, forms, reports and queries.
 It works as front end development tool.
 It provides end-user applications developer environment.
 It shares data with other applications such as Microsoft Word or Excel.
 It support three computer programming languages such as: SQL, Macros and Visual
BASIC, etc.

Objects of MS-Access

Table: Table is a collection of various records. A table is a feature, comprising of parallel


columns and rows, which is used to store, organize, and view data on a particular topic. A

102 New Gateway to Computer Science Book -10


single database may contain numerous tables containing information about related topics,
such as customer addresses, product prices, and other information.
Form: A form is an object of database which shows only the information you want to see.
A form is used to view data in a database, enter new data into the database, or edit data.
We can create from in database by using Design View , Auto form tabular , Auto form
Columnar, Form Wizard, etc.
Report: A report is used to show and print selected information from a table in a
customized manner. A report differs from a form because it does not allow you to make
any modifications or edits to the actual records within the table or tables.
Query: A query is a question that you ask about the data in your table(s). Query is also
used to perform various mathematical calculation is the database records.
Let’s Review
 Database is an organized collection of related information or data.
 A database consists of a file or a set of files that can be broken down into records,
each of which consists of one or more fields.
 Data are raw, unorganized facts that need to be processed which have no meaning.
 A database management system (DBMS) is designed to manage a large volume
of information.
 The core component of the database is a table.
 A database table is composed of records and fields that hold data.
 Each table in a database holds data about a different, but related, subject.
 A record is composed of fields and contains all the data about one particular
person, company, or item in a database.
 A field is a part of a record and contains a single piece of data for the subject of
the record.
 Microsoft Access is a Relational Database Management System (RDBMS) that
helps us to store information for reference, reporting, and analysis.
 Table is a collection of various records.
 A query is a question that you ask about the data in your table.
 A report is used to show and print selected information from a table in a
customized manner.
 Form is an object of database which shows only the information you want to see.

New Gateway to Computer Science Book -10 103


Opening Microsoft Access 2010
 Click on Start.
 Select All Programs.
 Choose Microsoft Office folder.
 Now choose Microsoft Access 2010 from the list.
 We will get windows with various choices.
 Select blank database and type the required database file name on the file name box.
 Finally click on Create button.

We can create table in various ways such as:


 Design view : to create custom table design
 Datasheet View : to enter data into datasheet
 Table Wizard: to select sample table
 Import Table : to import external data from other application format
 Link Table : to link to an existing data source

Creating Table in Design View

In this view, you can add, edit and delete fields in a table. You can create as many fields
as required and select the data types for each field, add field description, set primary key
field and set field properties like data entry rules, validations, etc.
 Click on Create Tab on menu.
 Click on Table Design Button.

104 New Gateway to Computer Science Book -10


 You will see the table designation windows .
 Enter fields name and it’s data type as below:

 Set field SN to Primary Key (Not allowed to duplicate data for SN) by Right Click on
that field and choose Primary Key

New Gateway to Computer Science Book -10 105


 Click Ctrl+S to save the table.
 Type the required table name and click on ok.

Data Types

Data type is a field property that specifies and limits what kind of data can be entered
into that field. For example, values that are stored in a text field can contain only letters,
numbers, and a limited set of punctuation characters. After you enter the valid field name,
it allows a user to select the data type for the field. You can use the data type property to
specify the type of data stored in a table field such as text for name field, number for class
field, date and time for DOB field, etc. Each field can store data consisting of only a single
data type. The various data types are given below.

Maximum Default
Data
Description Data Field
Type
/ Space Size
Text It is used for text or combinations of text Up to 255 50 (2003
and numbers as well as numbers don’t Characters Version)
require calculations, such as phone num- 255
bers. (2007/10
Version)
Memo It is used for lengthy text and numbers. Up to 65,536 _
Characters
Number It is used for data to be included in 1,2,4 or 8 Long Integer
mathematical calculations. Bytes
Byte It stores numbers from 0 to 255 without 1 byte
decimals.
Integer It stores numbers from -32768 to +32768 2 bytes
without decimals.

106 New Gateway to Computer Science Book -10


Long It stores numbers from -2147483648 to 4 bytes
Integer +2147483647 without decimals.
Single It is a single precision floating point num- 4 bytes, 7
bers from -3.4 × 10- 38 to 3.4 × 1038. decimal
places
Double It is a double precision floating point 8 bytes, 15
numbers from -1.797 × 10-308 to 1.797 × decimal
10308. places
Date/Time It is used for dates and time data. 8 Bytes
Currency It is used for currency values. 8 Bytes Long Integer
Auto It is used for unique sequential 4 Bytes _
Number (incrementing by 1).
Yes/No It is used for data that can be only one of 1 Bit _
two possible values, such as Yes/No.
OLE Object It is used for OLE objects (such as MS- Up to 1 GB _
Word documents, MSExcel spreadsheets,
pictures, sounds).
Hyperlink It is used for hyperlinks. Up to 64,000 _
Characters
Attachments You can attach data from other _ _
programs to this type of field, but you
cannot type or otherwise enter text or
numeric data.
Lookup It is used to create a field that allows you 4 Bytes _
Wizard to choose a value from another table.

Field Description

You can enter the description of each field in the description column. It helps you to
remember the use and purpose of a particular field. This is an optional part in a database.
It is displayed in the status bar when you select this field on a form.

New Gateway to Computer Science Book -10 107


Primary Key

The primary key uniquely identifies each record in the table. Primary key does not accept
null (0) value. It can either be a normal attribute that is guaranteed to be unique (such as
class roll number in a table with no more than one record per person). Primary keys may
consist of a single attribute or multiple attributes in combination. Primary key are used
for:

 to uniquely identify a record, as every primary key value must be unique.


 to ensure every record has a key, as a primary key cannot be left blank.
 to be used in creating relationships.
 for sorting and searching records.

Setting the Primary Key

There are a number of ways to create a field as a primary key field. Some of them are,
 Select the field to be used as a primary key and select the Primary key button.
 Select the field to be used as a primary key and select the Primary key option from the
Edit menu.
 Place the cursor on the field selection cell and right click on it, then you can click on
Primary Key option from the list.

Note: If we do not select any key as a primary key and try to save the table, by default
access creates an auto number field that can be used as the primary key.

108 New Gateway to Computer Science Book -10


Field Properties

Field properties are the attribute that describe and


define a field. Field properties are the characteristics
which are related to each field. After creating a field
and setting its data type, we can set additional field
properties. For example, we can control the size of a
text field by setting its field size property. The field
size property also determines how much disk space
does each number field value require. Depending on
the field size, the number can use exactly 1, 2, 4, 8,
12, or 16 bytes.
Different types of field properties are listed below.

Field Property Purpose

Format It determines the way that the field appears when it is displayed or
printed in datasheets or in forms or reports that are bound to the
field. You can use any valid number format. In most cases, you
should set the format value to currency.
Decimal Places It specifies the number of decimal places to use when displaying
numbers.
Input Mask It displays editing characters to guide data entry. For example, an
input mask might display a dollar sign ($) at the beginning of the
field.
Caption It displays the label text that is displayed for this field by default in
forms, reports, and queries. If this property is empty, the name of
the field is used.
Default Value It automatically assigns the specified value to this field when a new
record is added.
Validation Rule It supplies an expression that must be true whenever you add or
change the value in this field. It is used in conjunction with the
validation text property.
Validation Text It displays when a value that is entered violates the expression in
the validation rule property.
Required It requires that data are entered in the field.

New Gateway to Computer Science Book -10 109


The Basic Properties of Fields
Field Size
You can use the field size property to set the maximum size for data stored in the field that
is set to the text or number data type. The default value of field size is 255. For numeric
data, the field size can be set depending upon the type and range of value you want to
store. The given table explains about the numeric data range and storage.

Field Size Setting Range of Values Decimal Storage Size


Places (in Bytes
Byte 0 to 255 None 1
Integer -32768 to 32767 None 2
Long Integer 2147483648 to 2147483647 None 4
Single -3.4 × 10-38 to 3.4 × 1038. 7 4
Double -1.797 × 10-308 to 1.797 × 10308 15 8
Format
It is basically used to specify the layout for a field. Format field property allows you
to display data in a format different from the way it is actually stored in a table. It is
also known as display layout for a field. The format property uses different settings for
different data types.
For Text and Memo Data Types

Format Symbol Meaning Format Setting


$ Indicates text character is optional $
@ Text character in the form of character @@@-@@-
or space or number not meant for @@@@
calculation is required.
& Text character is not required. &&-&&-&&
< It converts all characters to lowercase. <
> It converts all characters to uppercase. >

For Numeric and Currency Data Types


You can format the number and currency data with predefined formats. You can choose the
pre-defined formats and many other symbols for creating your own customized numeric
and currency data format given below.

110 New Gateway to Computer Science Book -10


Format Meaning Data Entered Data
Setting Displayed
General It displays number as entered 45689.123 45689.123
Number without changes. It is default for −33615.234 −33615.234
number field.
Currency It displays the number with currency 255.45 $255.45
symbol with separator. It is default
for currency field.
Euro It displays number with Euro curren- 6455 €6,455.00
cy symbol and separator.
Fixed It displays at least one digit 3456.789 3456.79
Standard It displays thousand separator. 456789.12 456,789.12
Percent It displays the value multiplied by 2 200.00%
100 with added % sign. .22 22.00%
Scientific It uses standard scientific notation 2345.678 2.35E +03
with exponents.
For Date and Time Data Types

Setting Description/Example
General DateHere, if the value is date only, no time is displayed and if the value is
time only, no date is displayed. This setting is the combination of the
short date and long time. eg. 6/19/2012 (MM/DD/YYYY) and
7:34:23 PM (HH:MM:SS)
Long Date Long date setting, eg. Monday, August 25, 2012
Medium Date Medium date setting, eg. 26-Jun-07 (DD-MM-YY)
Short Date Short date setting, eg. 9/4/2012 (MM/DD-YYYY)
Long Time Long time setting, eg. 7:30:20 PM (HH:MM:SS)
Medium Time Medium time setting, eg. 7:30 PM (HH:MM)
Short Time Short time setting, eg. 17:34, 7:15 (HH:MM)
For Format String

Format String Data Entered Data Displayed


$#,##0.00 1234.56 $1,234.56
$#,##0.00 0 $0.00
##.00% 5.678 567.80%
##.00% 0 .00

New Gateway to Computer Science Book -10 111


For Logical (Yes/No) Data Types
A logical format allows only two possible values. The default setting is Yes/No. You can
use format as Yes/No or ON/OFF or True/False which displays with checkbox. A checked
checkbox represents Yes or True or On. An unchecked checkbox represents No or False
or Off.
Input Mask
Input Mask is a field property that determines what kind of data can be entered in the field
how it looks and how can it be entered in a field. It is simply the control over the data
entry. The task of input mask are:
 It helps to enter field values in a specified pattern.
 It can fill in constant characters like dash (-), parenthesis ( ) and slash (/) and optionally
store these characters as part of the field value as you do not have to enter these characters
at the time of data entry.
Create your own (custom) Input Mask
Input mask wizard can be the easiest option for certain fields like, pin code, phone
numbers, date and time. You can create your own input masks if you need to format other
kinds of values. The rules for creating input masks are :
 It contains three possible parts, separated by semicolons (;).
 It uses special characters in a mask to impose limits on what can be entered in a
field.
Input Mask Characters
The input mask characters are used to indicate how to limit the data that gets entered in a
field. The following input mask characters are allowed to use in the input mask.

Character Description/Function
0 Number is entered and required (0-9), no plus or minus sign.
9 Number is entered and optional (0-9), no plus or minus sign.
# Optional number or space, plus and minus sign is allowed.
L Letter is entered and required (A-Z).
? Letter is entered and optional (A-Z).
A Letter or number entered and required.
a Letter or number entered and optional.
& Any character or space required.

112 New Gateway to Computer Science Book -10


C Any character or space optional.
< Characters get converted to lowercase.
> Characters get converted to uppercase.
! A mask that displays characters from right to left but characters are
always entered left to right.
\ The mask helps display the next character in it as constant; for
example \B appears as B.
Password Creates a password entry text box. Any character typed in the text
box is stored as the character but is displayed as an asterisk (*).
Caption
Adding captions to fields helps both you and future database administrators to understand
the design and content of your database. It is one of the most common filed properties of
all data types. It is used to assign a descriptive name for a field. The maximum size for
this is 2048 characters. If caption is not entered, field name is used for label for a field on
a form.
Default Value
Default value field property displays the value automatically for the field when you add
a new record to the table. Default value can be changed during the data entry time. For
example, if you want to add records of class 10 students, in the class field you can set
the default value as 10 so that you do not have to enter the class each time you enter the
records.
Validation Rule
A validation rule limits or controls what users can enter in a table field or a control on a
form. Access provides several ways to validate data, and you often use several of those
techniques to define a validation rule.
Types of Validation Rules
Field Validation Rules
It uses a field validation rule to check the value that you enter in a field when you leave
the field. For example, suppose you have a date field, and you enter >=#01/01/2017# in
the validation rule property of that field. Your rule now requires users to enter dates on or
after January 1, 2017.

New Gateway to Computer Science Book -10 113


Record (or table) Validation Rules
It uses a record validation rule to control when you can save a record (a row in a table).
Unlike field validation rules, record validation rules refer to other fields in the same table.
You create record validation rules when you need to check the values in one field against
the values in another.

Expression Example Description


Validation expression for numbers
< <100 Entered value must be less than 100.
> >50 Entered value must be less than 50.
<> <>0 Entered value must not be equal to 0.
<= <=100 Entered value must be less than or equal to 100.
>= >=50 Entered value must be less than or equal to 50.
= =10 Entered value must be equal to 10.
Between ... and .. Between 0 Entered value must be within the range of 0 to 100.
and 100
Validation Text
Validation text is a field property which displays the error message when the user fails to
use the validation rule. If the data entered is invalid according to the specified validation
rule it displays the validation text.
Required
Required property is used to specify whether a value is required in a field or not. So, Yes
and No are the options for required property. If this property is set to Yes for a field, the
field must receive a value during data entry. If this property is set to No for a field, the field
can be left blank without any value during data entry.
Allow Zero Length
Allow zero length property is only for the text and memo data types. This property works
with the required property. If you set the required property to ‘Yes’ and allow zero length
to ‘No’, data must be entered during data entry.
Indexed
This property speeds up searching and sorting of records based on a field. For example,
if you search for specific student name in the first name field, you can create an index for
this field to speed up search for the specific name. Default indexed property is set as No.
It also uses other two settings.

114 New Gateway to Computer Science Book -10


Let’s Review
 In design view, you can add, edit and delete fields in a table.
 Data Type is a field property that specifies and limits what kind of data can be
entered into that field.
 Field description helps you to remember the use and purpose of a particular field.
 The primary key uniquely identifies each record in the table. Primary key does
not accept null (0) value.
 Field properties are the attributes that describe and define a field.
 You can use the field size property to set the maximum size for data stored in the
field that is set to the text or number data type.
 A logical format allows only two possible values. The default setting is Yes/No.
 Input mask is a field property that determines what kind of data can be entered in
the field how it looks and how it can be entered in a field.
 Default value field property displays the value automatically for the field when
you add a new record to the table.
 A validation rule limits or controls what users can enter in a table field or a control
on a form.
 Validation text is a field property which displays the error message when the user
fails to use the validation rule.

Working with Table

As we discussed above, table is the basic object of database.


Without creating table, we will be unable to create a database.
Now, we will discuss about creating table in database.
There are various ways to create a table. The various ways
of creating tables are explained below.
Creating table using design view
After creating a blank database, we need to create a table.
The steps are as follows:
 Create a database file.
 Click on Create tab.
 Choose Table Design from the ribbon.
 A blank table will display.

New Gateway to Computer Science Book -10 115


 Type the required Field name and Data type.

 Press CTRL + S to save the table under a new name.


 Type the required name for Table Name and click on OK .

(Note: If you want to set primary key , press ‘Yes’ button or press ‘No’ button if you don’t
want to set primary key.)
To enter records on table:
 Double click on the table name.

 You will get a table that you have created with the name of fields.
 Enter records on the table and press CTRL + S again to save it.

116 New Gateway to Computer Science Book -10


To modify the fields on the table:
 Right click over the name of table.

 Select the Design view option.


 Now you will get the previous design box, you can change the structure of the table as
required and press CTRL + S to save it.
Working with Lookup Fields:
 Open the table on design view.
 Set the field data type as Lookup Wizard.
 A box will display as below.

 Select the option “I will type in the values that I


want” and click on next button.
 Enter the value for number of columns and
type the values on column. Press Tab button
to change the row.
 Finally click on Finish to apply it.

New Gateway to Computer Science Book -10 117


Creating Table Using Datasheet View:
 Open any database.
 Choose the Table command in the Tables group on the Create tab.
 Add your table fields.

 Next, for each field you add, you’ll want to check and change the assigned data type.
 Select the first field.
 Show the Data Tools Datasheet Contextual tab.
 Check, and if necessary, change the Data Type and Format in the Data Type &
Formatting group
 Repeat the steps as before.
 Click the Save command on the Quick Access Toolbar.
 Enter a table name.
 Finally click on OK.
Adding Records in a Datasheet
 Open datasheet, type the required data in the field.

 Press Tab or Arrow to move to the next field. Or, simply place the mouse cursor in
the desired field.
 While entering the data in a field next row for next record will be automatically
displayed. Repeat the above steps to enter the data in fields till it is required.
 After finishing adding records in the datasheet, you can close the datasheet
simply by clicking on File tab and select Close option.

118 New Gateway to Computer Science Book -10


Modify Records in a Datasheet
 Place the mouse cursor at the required location.
 Select the content of the cell that you want to change.
 If you want to change the part of the cell content, place the mouse cursor in the desired
insertion point within the cell and use backspace key or delete key of the keyboard
as required and enter the new content.

Delete Records from a Datasheet

To remove the unwanted records from the datasheet, you can use this options. The contents
of cell can be deleted by selecting and pressing the delete button on keyboard.
 To delete the record :
 Position the cursor and select the record or records (rows) that you want to delete.
 Select Delete record option that appears when you click the right button on mouse.
 To delete the fields:
 Position the cursor over the field name and select the field or fields (columns) that
you want to delete.
 Select Delete Field option that appears when you click the right button on mouse.
 Computer will ask for confirmation whether you want to delete or not.
 Click on ‘Yes’ option to delete the records or fields.

Hiding the Columns or Fields

You can temporarily hide a column(s) or field(s)


so that you can view more columns in a larger
datasheet. Steps to hide column(s) in datasheet
are as follows.
 Position the cursor on the column heading
(field name) and click the right button to
open the shortcut menu.
 Select and click on Hide Fields.
Adjusting Column Width
We can adjust the column width as required to fit the data in the field. By dragging the
field sizing line from the right most corner of the field header also we can adjust the
column width.

New Gateway to Computer Science Book -10 119


 Double clicking on the field sizing line.
 Set the fixed width in a column width
dialog box. We can also use the best fit
option in the dialog box that automatically
adjusts the required size of the column.
The standard width option is 11.75 in MS-Access
2010.
Adjusting Row Height
We can set the row height in a Row Height dialog
box. We can select the Standard Height option in the
dialog box that automatically adjusts the standard
height of the row that is 14.25 in office 2010 version.
Sorting Records
The process of arranging all the records in a table either in ascending or descending order
based on field or fields is known as sorting.
 Text types of data are sorted in an alphabetical order (ie. A to Z).
 Date and Time data are sorted from oldest to newest.
 Number/Currency types of data are sorted in smallest to largest order.
The steps for sorting the data are:
 Open the table.

 Click on Home tab and over click on the field name.


 Select the required option as required.
 Sort smallest to largest or Sort largest to smallest as above.

120 New Gateway to Computer Science Book -10


Filtering Records
Filtering is the process of viewing required record of a table that matches the specified
criteria. While filtering, you can use criteria to search values in one or more than one field.
We can use the following options to filter the record.
 Filter by selection
 Filter by form
 Advance Filter or sort

Creating a Relationship
A primary feature of relational databases is that they contain multiple tables, each of
which can have a relationship with any of the other tables. Relationships are ties that are
created between tables in the database so that MS-Access can combine data from more
than one table to create reports. It is how tables determine how they correspond to each
other. To create a relationship, first we have to create the related tables as below.

Be sure to set a format and default value for the date created fields on both tables (you
shouldn’t need to enter this field - the system can do that). Now, to create the relationship
between all three tables we can do as below.

New Gateway to Computer Science Book -10 121


 Click on Design, and select the Relationships options.

 A Show Table dialog box will appear,


displaying all three tables. Select all of them and
click Add.
 Click Close to close the dialog box.
 You will now see three boxes which
represent your three tables. Click and drag the
CustomerId from the Customers table cross to the
corresponding CustomerId field on the orders table.

 The Edit Relationships dialog will appear. Click Enforce Referential Integrity so that
it is checked. Check that the values are the same as the following screenshot and click
OK.

122 New Gateway to Computer Science Book -10


 You will now see a line established between the CustomerId field on the Customers table
and the CustomerId on the Order stable.
 Now do the same for the Products table. That is, click and drag the ProductId from the
Products table across to the corresponding ProductId field on the Orders table.

Types of Relationship
 One-to-one relationship: For each record in one table, there is one and only one
matching record in a different table. It is as if two tables have the exact same primary
key. Typically, data from different tables in a one-to-one relationship will be combined
into one table.
 One-to-many relationship: For each record in one table, there may be zero, one or
many records matching in a separate table. For example, you might have an invoice
header table related to an invoice detail table. The invoice header table has a primary
key, Invoice Number. The invoice detail table will use the invoice number for every
record representing a detail of that particular invoice. This is certainly the most
common type of relationship you will encounter.
 Many-to-many relationship: This relationship cannot be defined in MS-Access without
the use of a mapping table. This relationship states that records in both tables can
have any number of matching records in the other table.

Query on Database

Queries are database objects that can be used to retrieve information from multiple tables
by joining these tables using common fields. Simply, queries are used to change, view,
and analyse the data. In MS-Access you can use queries to extract information (data)
from one (or more) tables (or from other queries). For example you can write a query
that returns all students that have a percentage that is less than 40. Besides limiting the
number of records with queries, you can also limit the number of columns (fields). For
example instead of returning all fields from the student table you can only select the
student ID, Student Name, Student percentage and Student email address.

New Gateway to Computer Science Book -10 123


There are different types of queries, they are:
 Select Query
 Parameter Query
 Crosstab Query
 Action Query
 SQL Query

Select Queries

A query asks a question about data


stored tables and returns a result set
in the form of a datasheet without
changing the data. It retrieves data
from one or more tables and displays
the results in a datasheet where we
can update records. A select query
can contain specifications for the
fields (columns) to return, the records (rows) to select, the order to put the records in, and
the way to group (summarize) information. Select query can be used to:
 view subset of records.
 retrieve data form one (or more) tables.
 display the results in a datasheet.
 update the records from within the datasheet.
Parameter Queries
A parameter query is a query that displays a
dialog box prompting users for information, that
information can be used for retrieving records or a
value you want to insert in a field. You can design
the query to prompt you for more than one piece of
information; for example, you can design a query
to prompt a user for two dates (beginning and end
date). Access can then retrieve all records that fall
between those two dates. Parameter queries are also
can be used as the basis for forms, reports, and data
access pages. For example, you can create a monthly

124 New Gateway to Computer Science Book -10


earnings report based on a parameter query. When you print the report, Access displays a
dialog box asking for the month that you want the report to cover. You enter a month and
MS-Access prints the appropriate report.
Crosstab Query
Crosstab query is used when you want to calculate and restructure summary data to make
it easier to read and understand. Crosstab queries calculate a sum, average, count, or other
type of aggregate function to calculate data that is grouped by two types of information
one down the left side of the datasheet and another across the top. If you want to use
values from a Date/Time field for column headings, but want to group the dates into
intervals that the wizard does not provide, such as fiscal year or biennium, do not use the
wizard to create your query. Instead, create the crosstab query in design view, and use an
expression to create the intervals.
Action Query
An action query is a query that makes changes to or removes many records in just one
operation. Below are the four different types of action queries.
 Delete Query
 Update Query
 Append Query
 Make Table Query
Delete Query: A delete query deletes a record or group of records from one or more
tables. For example, you can delete the records of those students who have got marks less
than 40 in each subject in the marks database.
Update Query: An update query makes entire changes to a record or group of records in
one or more tables. For example, you can change the class of students from 9 to 10 when
students are promoted to 10th grade in the student database. With an update query, you
can change data in existing tables.
Append Query: An append query adds a group of records in one or more tables to the end
of records. For example, suppose that some new students have been admitted in school
and you need to keep the records of those students in the school’s database. To avoid
typing all this information into your database, you’d like to append it to your students
table of school’s database.

New Gateway to Computer Science Book -10 125


Make-Table Query: Make-table query creates a new table from all or part of the data in
one or more tables.
Structured Query Language (SQL)
You can use SQL to query, update, and manage relational databases such as MS-Access. In
MS-Access you can write queries in SQL format. Queries written in SQL are also known
as SQL statement. When you create a query in design view, MS-Access automatically
makes the equivalent SQL statement. You can view it selecting the SQL view shortcut
menu option. In below figures, you can see two queries created in design view option and
their equivalent SQL query. In MS-Access you can write queries in SQL format. Queries
written in SQL are also known as SQL statement. When you create a query in design
view, MS-Access automatically makes the equivalent SQL statement. You can view it
selecting the SQL view shortcut menu option. In below figures, you can see two queries
created in design view option and their equivalent SQL query.

Creating Queries Using Design View


 Select the queries object from the database window.
 Select and click on Query Design option from Create menu.
 You can see the Show Table dialog box.
 Select and add the source for designing
query. Source can be Tables or existing
queries
or both. After you add table as a source it
displays as below.
 Double click on the field(s) or simply
drag the field(s) to the bottom half of the
window in the proper order that you want
to view in query datasheet.

126 New Gateway to Computer Science Book -10


 Click on Run option to view the result of the query created.

 You can also set conditions in the criteria


section on the bottom half of the window.
For example, if you want to view only
the records of passed students you can
give criteria as >=40.
After you follow all the above mentioned steps, for all the queries except select query
you have to select from shortcut menu list or from the quick access toolbar as shown in
the figure.
Wildcard characters and operators in query

Wildcards/ Example Meaning


Operators
# Represents any single digit, 0-9.
> >50 Shows the record where the specified field is
greater than 50.
< <100 Shows the record where the specified field is less
than 100.
>= >=100 Shows the record where the specified field is
greater than or equal to 100.
<= <=400 Shows the record where the specified field is less
than or equal to 400.
<> <>20 Shows the record where the specified field is not
equal to 20.
Between.... Between Shows the record between 02/04/10 to
And #02/04/10# 04/07/12 date.
And #04/07/12#
In In(“Gita”, “Dee- Shows the record that has the field value as
pa”) Gita or Deepa.

New Gateway to Computer Science Book -10 127


AND >60 And <=80 Shows the record that has specific value from 61
to 80
OR “Bus” OR Shows the record that has specific value as Bus or
“Train” Train.
Query Calculation Sample
Prepare a query that displays those student’s record who have secured more than 90 in
computer.

 Create a database and create a table in design view with the information such as
Student Roll , Name , Class, Math , Computer, English and Social then save the table.
 Click on Create tab and select Query Design option.
 Add the table and add the table field by double clicking over it.
 Set the criteria as >90 under the computer field and save it.
 Now, just click on the query, then you can see those records who have secured more
than 90 in computer.

Working with Forms

Form is a type of database object


mostly used to create an interface for
entering data in a table or multiple
linked tables. Forms are basically
GUI (Graphical Users Interface) using
which users interact with MS-Access
database. Form also displays complete

128 New Gateway to Computer Science Book -10


record one at a time, with the help of form you can view and modify records. Forms in
MS-Access are created using the given options.
 Create form in design view.
 Create form by using wizard.
Creating Form by Using Wizard
The wizard enables you to select the fields from a table or
multiple linked tables, layout, and user interface for the form.
You have to follow the given steps to create forms using the
wizard option.
 Select the Forms object from the database
window.

Select and click on Form Wizard option
from Create menu.
 After this it displays the Form Wizard
dialogue box as shown in the figure.
Here, at first you have to select the existing
tables or queries from the drop down list.
 Now, you have to select the fields that you want to keep in the form from the
Available Fields box. To select fields as per the requirement, click on field option in
the Available Fields list and click on single arrow button.
You can also select all the available fields at once by clicking on double arrow button.
 Click on Next button.
 In the next dialogue box as in the figure, you can select
the layout of the form. The available options for the
layout are Columnar, Tabular, Datasheet and
Justified. After choosing the layout click on Next
.
 Apply suitable title for the form. By default
MS-Access gives the title of table or query
hosen for the creation of form. Finally click on the Finish button. Here you can still
change the form design if you select Modify the form design and click on the Finish
button. If you do so it opens the form in design view.

New Gateway to Computer Science Book -10 129


Entering Data Using a Form
After the form is created, you can enter the
data simply typing in the text box. Whereas
MS-Access form also contains various control
options while entering the data. These control
options are, Text box, Combo box, List box,
Check box, Label, Command button, Tabcontrol,
Image, hyperlink etc. Steps to add records in
form datasheet are as follows.
 After you open form datasheet mouse cursor
will be placed in the first field of first record. Type the required data in the field.
 Press Tab or enter to move to the next field. Or, simply place the mouse cursor in the
desired field.
 When you finish entering the all the data for the first record, MS-Access automatically
prompts for entering the second record and so on.

Working with Report

Report is a type of access database object


used to present information in an effective
and organized format that is ready for
printing. Using the report, you can display
the information the way you want to view
it. Create report by using wizard.
Creating Report by Using Wizard
The wizard enables you to create a
report in a desired format. The report
wizard provides you to choose the
tables and fields, group the data, sort
the data, summarize the data, choose
a layout and orientation, apply a style,
and title your report.
 Select the Reports object from the
database window.

130 New Gateway to Computer Science Book -10


 Select and click on Report Wizard option from Create menu.
 After this it displays the Report Wizard
dialog box as shown in the figure. Here, at first
you have to select the existing tables or queries
from the drop down list.
 Now, you have to select the fields that you
want to keep in the form from the available
fields box. To select fields as per the
requirement, click on field option in the available
fields list and click on single arrow button or double
arrow button. After selecting fields click on Next button.
 On the next wizard screen, you can further group
records in the report by a particular
field. To group by a field, click the field and then
click the arrow button. You can select
several grouping levels in the order you want them.
Then click Next to move on.
 The wizard then asks whether you would like to
sort the records in the report as in figure.
 If you want to sort the records by a particular field
or fields, open the top drop down list and select a
field to sort with and click Next button.
 Now, in the next dialog box, you can select the
layout of the form then click on Next button.
 Now, you have to give the title of report.
 Finally click on the Finish button.
You can change the report design if you select Modify the report design and click on the
Finish button. If you do so it opens the report in the design view.
 The final report will display as below.

New Gateway to Computer Science Book -10 131


Let’s Review
 You can temporarily hide a column(s) or field(s) so that you can view more
columns in a larger datasheet.
 Filtering is the process of viewing required record of a table that matches the
specified criteria.
 Relationships are ties that are created between tables in the database so that
Ms-Access can combine data from more than one table to create reports.
 Queries are database objects that can be used to retrieve information from multiple
tables by joining these tables using common fields.
 A query asks a question about the data stored tables and returns a result set
in the form of a datasheet without changing the data.
 A parameter query is a query that displays a dialog box prompting users for
information, that information can be used for retrieving records or a value you
want to insert in a field.
 Crosstab query is used when you want to calculate and restructure summary data
to make it easier to read and understand.
 The types of action queries are delete query, update query, append query and make
table query.
 An update query makes entire changes to a record or group of records in one or
more tables.
 You can use structured query language to query, update, and manage relational
databases such as MS-Access.
 Queries written in SQL are also known as SQL statement.
 When you create a query in design view, MS-Access automatically makes the
equivalent SQL statement.
 Form is a type of database object mostly used to create an interface for entering
data in a table or multiple linked tables.
 Report is a type of access database object used to present information in a
effective and organized format that is ready for printing.

132 New Gateway to Computer Science Book -10


Innovative Task
 Visit any organization nearby you and observe what type of database
management system they are using.
 Prepare a short project report about what types of software programs are being
used in your school for accounting, result processing and attendance system.

Assignment
1. Choose the correct answer.
a. Access is used to develop
i. DBMS ii. software iii. Database iv. Word
b. What is the extension of Access database file?
i. DB ii . MDB iii. DBF iv. ADB
c. The name of caption can be declared upto
i. 2048 characters ii. 2063 characters
iii. 64,000 characters iv. 2005 characters
d. The logical data type of access is
i. Yes/no i. True/False iii. on/Off iv. All of the above
e. The OLE object can store graphics, sound upto….GB:
i. 1 ii. 2 iii.3 iv. 4
f. Which of the following is not a relational database?
i. dBase IV ii. FoxPro iii. Oracle i v. Reflex
g. Which of the following is a field property?
i. Indexed ii. Field Size iii. Caption iv. All
h. Integer needs ……..bytes space to store its values.
i. 8 ii. 2 iii. 3 iv. 4
i. Default field size of “Number” data type is:
i. Integer ii. Long Integer iii. Auto Number iv. Byte
j. Size of database are usually measured in term of:
i. Kilobyte ii. Terabyte iii. Megabyte iv. Gigabyte

New Gateway to Computer Science Book -10 133


k. Which of the following is not field property?
i. Indexed ii. Field Size iii. Colour iv. Format
l. MS-Access 2010 can support ………types of data.
i. 9 ii. 8 iii. 10 iv. 12
m. A piece of information about a object or individual is called …….
i. Form ii. Field iii. Record iv. Report
n. …. accelerates the query and sort operation.
i. Index ii. Sort iii. Number iv. Filter
o. The field size of logical field is ……. bit in MS-Access.
i. 0 ii. 1 iii. 2 iv. 3
p. Field Name can be up to ……………… characters long.
i. 64 ii. 16 iii. 128 iv. 40
q. The default field size of “AutoNumber” data type is ………………
i. Byte ii. Integer iii. Long Integer iv. Double
r. Which is a data type of MS-Access?
i. Memo ii. Hyperlink iii. Lookup Wizard iv. All
2. Write true or false for the following statements.
a. OLE is a data type of Ms- Access.
b. We cannot enter duplicate value in the primary key field.
c. Cell is interconnection of rows and columns.
d. We can use ‘auto number’ data type for salary field.
e. The appropriate field type to store “Date of Birth” is date and time.
f. Form is designed for data input.
g. True/ False is a logical data type.
h. Hyperlink data type occupies up to 2042 characters.
i. The logical data type of access is Yes / No.
j. Index accelerates the query and sort operations.

134 New Gateway to Computer Science Book -10


k. Only one table can be created in MS- Access.
l. Hyperlink is a field property.
m. Maximum field size of memo field is 256 characters.
n. A collection of record for a single subject is a table.
o. Caption is a database object.
p. Report is an object that allows to define print format.
3. Fill in the blanks with correct words / phrases.
a. dBASE is an example of ………
b. A table is a part of ……
c. The default size of text field is ………
d. …………helps to print the output through the printer.
e. ………….is suitable data type for picture Field.
f. Large collection of files is called ………….
g. Ms-Access is a ………..software.
h. The Yes/No data type need ……..space to store its value.
i. ………….is suitable data type for Roll_ NO field.
j. The value automatically enters for the new record is …………….
k. The primary key does not accept …….. value.
l. …………….. is an expression that limits the value to be entered in the field.
m. …….. is an object of MS-ACCESS that allows to enter, edit and view data.
n. …….is the data type that allows to store up to 65,535 characters.
o. Update query is a type of ……….query.
4. Match the followings.
a. Data Redundancy i. Error Message
b. Validation Text ii. Input Mask
c. Field Properties iii. Lookup Wizard
d. Validation Rule iv. Data Repetition
v. Limits the values

New Gateway to Computer Science Book -10 135


5. Answer the following questions.
a. Define DBMS with example.
b. What is a primary key? What is the importance of primary key in MS-Access?
c. Why is report created? How you can create using report wizard? Write with steps.
d. Define database and DBMS.
e. What is data sorting? How does it differ from filtering?
f. What is a form? Write any two advantages of forms.
g. Define Database Management System (DBMS). List some of the popular DBMS.
h. Differentiate between a database and a table.
i. Write the importance of using form in access.
j. Define relational database management system with its examples.
k. What is a report? What is the purpose of a report in MS-Access?
l. What is a database? Define table and report.
m. While designing table structure which data types are suitable to store information
about teacher’s name, address, salary and data of birth?
n. Write down any two advantages of query.
o. Define database and DBMS with one example of each.
p. How can data redundancy be controlled in MS- Access?
q. What is the importance of using query in MS-Access?
r. What is a select query?
s. What does field size mean? Name any two data type that can be defined in MSaccess.
t. Define relationship with its types.

136 New Gateway to Computer Science Book -10


Programming Language

Unit

This unit covers the following lessons:



Lesson 8 : Review on Qbasic Programming
Lesson 9 : Modular Programming in QBASIC
 Practical Section on SUB Procedure
 Practical Section on FUNCTION Procedure
Lesson 10 : File Handling in QBASIC
 Practical Section on File Handling
Lesson 11 : Programming in C
 Model Question Paper
 List of Abbreviations
Lesson

8 Review on Qbasic Programming

Learning Outcomes

At the end of this lesson, students will be able to:


 define Qbasic programming and tell its features.
 explain the Qbasic operators.
 identify the Qbasic statements with syntax.
 explain the types of control statement.
 write Qbasic programming using some control statements.

QBasic is a high level programming language developed by Microsoft Corporation


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

Features of QBASIC

 It is simple and easy to learn and understand.


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

138 New Gateway to Computer Science Book -10


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 String Operator.
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.

Operation Operator Example Output


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

Name of Operator Relation Example


= Equal to 5 = 5 , A = B , A$=B$
> Greater than 10>5, A>B
< Less than 5<10, B<A
>= Greater than or equal to 10>=5, A>=B
<= Less than or equal to 5<=10, B<=A
<> Not equal to 6<>5 , A<>D
Logical Operators
Logical Operators combine two or more relational expressions to evaluate a single value
as True or False. The result of evaluation is used to make decisions about the program
flow. The commonly used logical operators in QBASIC are AND, OR and NOT.

New Gateway to Computer Science Book -10 139


AND Operator
AND operator returns ‘True’ when all the results returned from individual relational
expressions are ‘True’ otherwise it returns ‘False’. The Truth Table of AND operator is
given below.

Input A Input B Output A AND B


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

Input A Input B Output A OR B


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

Input A Output NOT A


False True
True False
String Operators (+)
A string expression consists of string constant, string variables and other string
expressions combined by string operators. There are two classes of string operations.
They are concatenation and string function. The act of combining two strings is called
concatenation. The plus (+) symbol is the concatenation operator for string. For example,
the following program fragment combines the string variables A$ and B$ to produce the
value ShubharambhaPublication.

140 New Gateway to Computer Science Book -10


A$ = “Shubharambha” : B$ = “Publication”
Print A$+B$
Print “Our” + A$+B$
The output is :
From Print A$+B$: ShubharambhaPublication
From Print “Our” + A$+B$: OurShubharambhaPublication
Assignment Operators (=)
The assignment operator evaluates an expression on the right of the expression and
substitutes it to the value or variable on the left of the expression. For Example : x = a +
b, Here the value of a+b is evaluated and substituted to the variable x.

QBASIC Statements

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


remarks for the program that we are writing. It can be used at any part of the program. The
general format of REM statement is given below.
REM <remark> Here, remark may be any statement or phrase to define the program.
CLS Statement: This statement is used to clear the previous output from the display
screen and makes the screen blank. This command is given before the starting of any new
program. The general format of CLS statement is given below.
<CLS>
LET Statement: This statement is used to assign the value in the variable. It is also called
assignment statement. This is also an optional statement is Qbasic. The general format of
CLS statement is given below.
LET <variable> = <expression> Here, variable is the name of a numeric or string variable
which receives the value and expression is a numeric or string expression whose value
will be assigned to a variable.
INPUT Statement: This statement is used to receive input data from the keyboard during
the execution of the program. It will prompt the user to input data and then place the
inputted data into a variable. INPUT string and the variable must be separated by either
a comma or a semicolon. The semicolon will print a question mark at the end of the text.
The general format of INPUT statement is given below.
INPUT [“Message”] ; list of Variables Here, message is a string constant enclosed in a
double quotes and list of variables contain the numeric or string variable which stores the
data input by the user.

New Gateway to Computer Science Book -10 141


PRINT Statement: This statement is used to display the output on the screen. Question
mark (?) also can be used instead of PRINT statement to display on the screen. The
general format of PRINT statement is given below.
PRINT[list of expressions][{; | ,}]
END Statement: This statement is used to indicate the end of the QBASIC program to
terminate it.The general format of END statement is given below.
<END>
PRINT USING Statement: This statement is used to display string or number using a
specified format. The general format of PRINT USING statement is given below.
PRINT USING string expressions;list of expressions[;] Here, string expressions
is a string literal or variable consisting of special formatting characters. The formatting
characters determine the field and the format of printed strings or numbers and list of
expressions consists of the string or numeric expressions separated by semicolons.
The string formatting characters are given in the table below.

! Displays only the first character of string.


\n\ Prints first n+2 characters from the string.
& Displays all the string.
# Digit position is specified.
&& Prints leading & sign.
^^^^ Prints the number in exponential format.
. Decimal point position specification.
LINE INPUT Statement : This statement allows to input line of data at a time and assign
in to single variable. The general format of LINE INPUT statement is given below.
LINE INPUT “prompt”; variable Here, prompt is a string constant that will be displayed
when the statement is executed and variable is the name of a string variable or array
element to which the line will be assigned.
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 given below.
LPRINT [expression [, \; expression]……] [;]
LPRINT USING “string”: expression [, \;expression]…... [;] Here, expression is a numeric
or string to be printed and string is a string constant or variable that identifies the format
in which expression is to be printed.

142 New Gateway to Computer Science Book -10


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 given below.
READ [Variable1, variable 2, variable 3…..]
------
------
------
DATA [constant1, constant2, constant 3….
RESTORE Statement: The RESTORE statement is used to reset the DATA pointer to
the beginning of the data. Once the data element is read, it cannot be read again until the
program resets it. The RESTORE statement is used to reset the data in the program. The
general format of RESTORE statement is given below.
RESTORE[line number] Here, If the line number is specified, the next READ statement
accesses the first item in the specified DATA statement and if the line number is omitted,
the next READ statement accesses the first item in the first DATA statement.
LOCATE Statement: This statement is used to move the cursor to the specified position
on the screen.
LOCATE [row][,[col][,[cursor][,[start] [,stop]]]] Here, row is the screen line number, col
is the screen column number, cursor is a Boolean value indicating whether the cursor is
visible or not. Start is the cursor start scan line, stop is the cursor stop scan line.
SWAP Statement :This statement is used to exchange the values of two variables. The
general format of SWAP statement is given below.
SWAP variable1, variable2

Types of Control Statements

Branching Statement
Branching statement is a decision making statement. Depending upon the decision
branching statement can change the order of execution. Branching statements are divided
into two types.
Conditional Branching Statement
This statement allows the selective execution of statements based on a particular condition.
This statement directs the computer to another part of the program based on the results

New Gateway to Computer Science Book -10 143


of a compare. High-level language statements, such as IF….. THEN, IF…..THEN…..
ELSE, IF ... THEN ... ELSE IF, SELECT ... CASE, are the popular conditional branching
statements. We are going to discuss more about them.
IF ... THEN Statement
This statement is a decision making conditional branching statements which
executes a block of statements only if the given expression or condition is true. If
the condition is false, then the IF blocks will skip and execution continues with the
rest of the program.
Syntax :IF [conditional expression] THEN [statement block]
Practical Assignment
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
IF ... THEN .... ELSE Statement
It is also a control statement which is used to execute multiple statements depending on
the condition. It is also called two way decision making statements. In this statement if
the condition is true the statements after THEN will be executed and if the condition is
false, the statements in the ELSE block will be executed.
Syntax :IF [conditional] THEN[statement 1]ELSE[statement 2]
……………….
END IF

Practical Assignment
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

144 New Gateway to Computer Science Book -10


PRINT “The greatest number is”; B
ELSE
PRINT “The greatest number is:”; C
END
IF ... THEN ... ELSEIF Statement
This statement is another form of IF….THEN…..ELSE statement. The conditions are
evaluated from top to bottom. The syntax is given below.
Syntax :
IF [condition] THEN
[statement 1]
ELSEIF
[statement 2]
ELSEIF
[statement n]
........................
.......................
ELSE
[statement n]
END IF

Practical Assignment
CLS
INPUT “Enter your percentage “; P
IF P>= 80 THEN
Result$ = “Distinction”
ELSEIF p >= 60 THEN
Result$ = “First Division”
ELSEIF p >= 40 THEN
Result$ = “Second Division”
ELSEIF p >= 35 THEN
Result$ = “Third Division”
ELSE
Result$ = “Sorry! No result found”
END IF

New Gateway to Computer Science Book -10 145


PRINT “Division ::: “; Result$
END
SELECT CASE Statement
This statement is a multi-way branching statement which makes the control jump to one
of the several statements based on the value of an expression.
Syntax :
SELECT CASE
CASE test 1
[statement1]
CASE test 2
[statement 2]
........................
.......................
CASE ELSE
[statements]
END SELECT
Practical Assignment
CLS
INPUT “Enter your choice (1 – 3)”; N
SELECT CASE N
CASE 1
PRINT “Baishak”
CASE 2
PRINT “Jestha”
CASE 3
PRINT “Ashad”
CASE ELSE
PRINT “Invalid Value”
END SELECT
END

146 New Gateway to Computer Science Book -10


Unconditional Branching Statement
Unconditional branching statement is used when the programmer forces the execution of
a program to jump to another part of the program. This can be done using the combination
of loops and if statements. You can avoid such unconditional branching and use this
technique only when it is very difficult to use a loop.
GOTO Statement
This statement in QBASIC is used to transfer the program control from one statement to
another. It is an unconditional branching statement.
Syntax : GOTO [line number / line label]
Practical Assignment
CLS
AA:
INPUT “Enter the first Number”; A
INPUT “Enter the second Number”; B
Sum = A + B
PRINT “The sum is”; Sum
GOTO AA
END
Looping Statement
Looping statement is the statement that executes one or more statements repeatedly in a
several number of times. In QBASIC there are three types of loops they are for, while and
do-while. When you need to execute a block of code several number of times you need to
use looping. Let’s discuss the major looping statements in QBASIC.
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

New Gateway to Computer Science Book -10 147


Practical Assignment
CLS CLS
FOR I = 1 to 10 FOR I = 1 to 10 STEP 2
PRINT I; PRINT I;
NEXT NEXT
END END
WHILE……WEND Statement
The WHILE…WEND loop is the fundamental loop statement in QBASIC. It provides a
way to repeat a block of statements, as long as the condition is true. It is used to perform
a repetitive task based on a condition. The condition usually results from a comparison
of two values, but it can be any expression that evaluates to a Boolean value (TRUE or
FALSE).
Syntax
WHILE (TEST CONDITION)
(Statements OF Loop)
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
REM a program to print series from 1 to 10
CLS
C=1
WHILE C <= 10
PRINT C
C=c+1
WEND
END

148 New Gateway to Computer Science Book -10


DO….WHILE LOOP Statement
A DO….WHILE loop is used when we want to repeat a set of statements as long as the
condition is true. The condition usually results from a comparison of two values, but it
can be any expression that evaluates to a Boolean value (TRUE or FALSE). The condition
may be checked at the beginning of the loop or at the end of the loop.
Syntax
DO WHILE (TEST CONDITION)
(Statements Of Loop)
LOOP
Let’s observe the given table to understand the part of the syntax
Part Description
It is a numeric or string expression that evaluates whether the
TEST CONDITION
condition is TRUE or FALSE.
It is a set of one or more QBASIC statements.
• If the condition is TRUE, all statements 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
REM a program to print the series from 1 to 10
CLS
c=1
DO WHILE c <= 10
PRINT c
c=c+1
LOOP
END

DO….UNTIL LOOP Statement


A DO….UNTIL loop is used when you want to repeat a set of statements as long as the
condition is false. The condition may be checked at the beginning of the loop or at the
end of the loop.

New Gateway to Computer Science Book -10 149


Syntax
DO UNTIL (TEST CONDITION)
(Statements of Loops)
REPORT THIS AD
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
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
EXIT Statement
The EXIT statement is used to terminate the loop based on certain criteria before the
expected number of iterations. 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.
Syntax: EXIT DO / FOR

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

150 New Gateway to Computer Science Book -10


Practical Section

Program 1

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

Write a program to display the area of a square.


REM program to display area of square
CLS
INPUT “ENTER LENGTH”; L
A=L^2
PRINT “AREA OF SQUARE”; A
END
Program 3

Write a program to display the perimeter of a rectangle.


REM program to display perimeter of rectangle
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
P = 2 * (L + B)
PRINT “PERIMETER OF RECTANGLE”; P
END

New Gateway to Computer Science Book -10 151


Program 4

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


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

Program 5

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


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

Program 6

Write a Qbasic program to find out the area of four walls of a room.
CLS
Input “Enter the height”;H
Input “Enter the length”; L
Input “Enter the Breadth”;B
Let AR= 2 * H * (L+B)
Print “The area of four walls =”;AR
End

152 New Gateway to Computer Science Book -10


Program 7

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 Avg =Sum/3
Print “The sum=” ;Sum
Print “The Average is” ;Avg
End
Program 8
Write a Qbasic program to input student’s name, marks obtained in five different
subjects and find the total and average marks.
CLS
Input “Enter the name” ;N$
Input “Enter the marks in English” ;E
Input “Enter the marks in Computer” ;C
Input “Enter the marks in Maths” ;M
Input “Enter the marks in Science” ;S
Input “Enter the marks in Nepali” ;N
T=E+C+M+S+N
Let A=T/5
Print “The name of the student is” ;N$
Print “The total marks is” ;T
Print “The Average marks” ;A
End

Program 9
Write a Qbasic program to enter any number and check whether it is negative or
positive number.
CLS
Input “Enter the number”; N

New Gateway to Computer Science Book -10 153


If N>0 Then
Print “The number is positive”
Else
Print “The number is negative”
EndIf
End

Program 10

Write a Qbasic program to enter any number and find out whether it is even or odd
using the 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 11

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


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

154 New Gateway to Computer Science Book -10


Case 5
Print “This is number 5”
Case else
Print “Invalid number range “;
End select
End

Program 12
Write a QBASIC program to enter any alphabet and test 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 13
Write a QBASIC program to generate the following series using For….Next…..
Loop.
1,3,5,7,9, 11, 13, 15………………...99
CLS
For I = 1 to 99 Step 2
Print I
Next I
End

New Gateway to Computer Science Book -10 155


Program 14

Write a QBASIC program to print numbers from 1 to 100 using WHILE…WEND


statement.
CLS
I=1
While I<=100
Print I ;
I=I+1
WEND
END
Program 15

Write a QBASIC program to print series as below using WHILE… WEND statement.
1,4,9,…upto 10th term.
CLS
I=1
While I < =10
Print I^2;
I=I+1
WEND
END
Program 16

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

156 New Gateway to Computer Science Book -10


Program 17
Write a QBASIC program to find 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 18
Write a QBASIC program to check whether the entered number is palindromic or
not.
CLS
INPUT “ENTER ANY NUMBER”; N
A=N
S=0
WHILE N <> 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
IF A = S THEN
PRINT A; “This is a palindromic number.”
ELSE
PRINT A; “This is not a palindromic number.”
END IF
END

New Gateway to Computer Science Book -10 157


Program 19

Write a QBASIC program to check whether the entered number is prime or


composite.
CLS
INPUT “Enter any number”; N
A=0
FOR I = 1 TO N
IF N MOD I = 0 THEN A = A + 1
NEXT I
IF A = 2 THEN
PRINT “It is prime number”;
ELSE
PRINT “It is composite number”;
END IF
END
Program 20

Write a QBASIC program to display the prime numbers from 2 to 100.


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

Write a QBASIC program to display the Fibonacci sequence up to 10th terms.


CLS
A=1
B=1

158 New Gateway to Computer Science Book -10


PRINT A, B,
FOR I = 1 TO 10
C=A+B
PRINT C,
A=B
B=C
NEXT I
END

Program 22
Write a QBASIC program to check whether the entered number is Armstrong or
not.
CLS
INPUT “ENTER ANY NUMBER”; N
A=N
S=0
WHILE N <> 0
R = N MOD 10
S=S+R^3
N = N \ 10
WEND
IF A = S THEN
PRINT A; “It is an ARMSTRONG number.”
ELSE
PRINT A; “It is not an ARMSTRONG number.”
END IF
END

New Gateway to Computer Science Book -10 159


Program 23

Write a QBASIC program to display the output as below.


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

Program 24

Write a QBASIC program to display the reverse of a given number.


CLS
INPUT “Enter the number to reverse”; N
WHILE N <> 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
PRINT “The reverse of the given number is”; S
END

Innovative Task
 Prepare a chart paper including various QBASIC statements with their syntax and
submit to your teacher.

160 New Gateway to Computer Science Book -10


Assignment
1. Write down the function and syntax for the following statements.
a. INPUT statement b. PRINT statement
c. PRINT UNING statement d. LINE INPUT statement
e. READ…..DATA statement f. IF…….THEN statement
g. IF…….THEN……ELSE statement h. SELEST CASE statement
i. GOTO statement j. FOR….NEXT statement
k. WHILE…….WEND statement l. DO….WHILELOOP statement
m. DO………UNITL LOOP statement o. EXIT statement
2. Debug the given programs.
a. CLS
INPUT “Enter the name of student” ; n$
INPUT “Enter the marks of English”; e
INPUT “Enter the marks of Nepali” ; n
INPUT “Enter the marks of Computer”; c
TO = e + n - c
PER = e + n + c / 300 * 100
PRINT “Student’s name” ; n
PRINT “Total marks of student” ; TOTAL
PRINT “ Percentage of student”; PR
END

b. CLS
INPUT “Enter your choice (1 – 3)”; N
SELECT CASE Z
CASE 1
PRINT “Baishak”
CASE 2
PRINT “Jestha”
CASE 5
PRINT “Ashad”

New Gateway to Computer Science Book -10 161


ELSE CASE
PRINT “Invalid Value”
SELECT END
END
3. Write down the output of the given program.
a. CLS
b. CLS
READ A, B, C, D
x$ = “Ram”
Total = A + B +C + D
y$ = “Krishna”
Avg = Total / 4
z$ = “Malakar”
PRINT “The total value is”; Total
PRINT USING “!”; x$; “.”;
PRINT “The average value is”; Avg
PRINT USING “!”; y$; “.”;
DATA 90,110,50,130
PRINT USING “&”;z$;
END
END

d. CLS
c. CLS
FOR I = 1 TO 6
I=1
LOCATE I, 50 - I
While I < =10
FOR J = 1 TO I * 2 - 1
Print I^2;
PRINT USING “#”; I;
I = I + 1
NEXT
WEND
PRINT
END
NEXT
END

4. Study the given program and answer the given questions.


a. CLS
INPUT “Enter the first number”; a
INPUT “enter the second number”; b
PRINT “Before using SWAP”; a, b
SWAP a, b
PRINT “After SWAP”; a, b
END
i. If the user input the first number as 50 and second number as 70, what will be
the output?

162 New Gateway to Computer Science Book -10


ii. What are the variables used in the above program?
iii. What is the statement uses in the above program to exchange the value?
b. CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
P = 2 * (L + B)
PRINT “PERIMETER OF RECTANGLE”; P
END
i. If the user inputs the length 150 and breadth 60, what will be the output?
ii. What are the operators used in the above program?
iii. List out the variables used in the above program.
5. Write a QBASIC program for the followings.
a. To input any three numbers and display its sum.
b. To display the area of a rectangle.
c. To display the area and perimeter of a rectangle.
d. To enter a number and check whether it is odd or even using select case statement.
e. To find the factorial of a given number.
f. To check whether the entered number is prime or composite.
g. To check whether the given number is divisible by 5 or not.
h. To check whether the given number is palindromic or not.
i. To display the Fibonacci sequence up to 20th term.
j. To check whether the given number is Armstrong or not.
k. To display the reverse of a given number.
l. To print the sum of square of odd numbers upto 200.
m. To input any number and count the total even numbers present in it.
6. Write the program to display the given series.
a. 1, 4, 9, 16, 25
b. 5, 10, 15, 20, 25
c. 100, 90, 80, 60, 50
d. 1, 3, 5, 7, 9 , 11, 13, 15
e. 2, 2, 4, 6, 10, 16

New Gateway to Computer Science Book -10 163


Lesson

9 Modular Programming in Qbasic

Learning Outcomes

At the end of this lesson, students will be able to:


 describe about modular programming.
 define Qbasic programming and tell its features.
 tell about the Qbasic operators.
 explain the Qbasic statements with syntax.
 tell work with the types of control statement.
 write Qbasic programming using some control statements.

Modular programming can be used to break up a large program into small units,
or to create code that can be easily reused. A modular program consists of a main module
and one or more auxiliary modules. Each module originates from a separate source
code file. The main module is compiled as an EXE, and calls functions in the auxiliary
modules. Modular programming is a technique or method which is used to divide
a program into many small, logical and functional modules or blocks. In a QBASIC
program module is a block of statements that is used to solve a particular problem. The
following are the advantages of using modular programming. When a program becomes
too large then it becomes difficult to write and debug the program. Thus, modular
programming helps a programmer to write and debug easily.
 Different programmers can design different program modules independently.
 It is easy to code the program and testing is very easy.
 A module can be used in multiple places, which reduces the program codes.
 Debugging of the program is easier and faster because they are divided into different
modules.
 It is possible to use a single module in different places which reduces program codes.

164 New Gateway to Computer Science Book -10


Parts of Module

A modular programming has two parts of modules they are main module and sub module.
Main Module: This module contains the entry point and the ending point of the program.
The top-level module which is located at the top of all procedures such as SUB-Procedures
or FUNCTION is called main-module. Procedure names and parameters are declared and
called from the main-module.
Sub Module: Sub module is a program which is written under the main module. A
program may have one or more sub modules under the main module. A sub-module may
have other sub-modules. It is also called a procedure. It is an isolated part of modular
program used for specific purposes. Sub module is controlled by the main module.

Main
Module

Sub Sub Sub


Module Module Module
1 2 3

Sub Sub Sub Sub Sub Sub


Module Module Module Module Module Module
1A 1B 2A 2B 3B 3B

Procedure and its Types

Procedure is a small, logical and manageable functional part of a program. It is a block


of statements that solves a particular problem given by the user. It is a self-contained and
independent manageable part of the program. A procedure is also known as a sub program
or a sub module contains codes for performing a special task.
Types of Procedures
 Sub procedure
 Function procedure

New Gateway to Computer Science Book -10 165


Understanding Sub Procedure

Sub procedure is a method to divide a large program into small programs. It is a small,
logical and manageable and functional part of a program that performs specific tasks and
does not return a value to the calling module. A sub procedure is needed to be declared
before it is used in a program. A CALL statement is used to call the sub procedure in a
program. It is written with SUB....END SUB statement. It has three parts, the first one
is the declaration part where we declare sub procedure, the second part is the main part
from where sub part is called and the third part is SUB part where we define our specific
tasks to do.
Features of sub procedure
 Sub procedure does not return any value.
 It does not have data type.
 It always starts with the key word, SUB and ends with the keyword END SUB.
 The parameters can be passed either by reference or by value.
To understand these 3 parts, look at the following example.
Example 1
DECLARE SUB SUM
CLS
CALL SUM
END
SUB SUM
Input “Enter the first number”; A
Input “Enter the second number”; B
S= A+B
Print “The sum is:” ; S
END SUB
In the above program we declared the sub procedure by using DECLARE keyword and
statements between CLS and END part. It is the main part where code runs and control
flow transfers to sub part by CALL keyword followed by sub name as a result the sub
part gets executed and we see output like (Enter the first number, ....). Again, when
SUB part ends then the control flow goes to the main part where we find END statement.
Finally, program is terminated. Let’s see another example of sub procedure. We can pass
value in sub procedure from the main part of the program by using parameters.

166 New Gateway to Computer Science Book -10


Example 2
DECLARE SUB AREA (L, B)
CLS
INPUT “Enter the length”; L
INPUT “Enter the breadth”; B
CALL AREA (L, B)
END
SUB AREA (L, B)
A=L*B
PRINT “The area is::”; A
END SUB
In the above program, two parameters are used. They are L and B which are enclosed with
small brackets as (L, B) in DECLARE line.
To create a sub procedure, we have to do three main things they are declaring a sub
procedure, defining sub procedure and calling a sub procedure.

Let’s Review
 Modular programming is a technique or method which is used to divide a
program into many small, logical and functional modules or blocks.
 In a QBASIC program module is a block of statement that is used to solve a particular
problem.
 A modular programming has two parts of modules. They are main module and sub
module.
 The top-level module which is located at the top of all procedures such as
SUB-Procedures or FUNCTION is called the main-module.
 Procedure names and parameters are declared and called from the main-module.
 A sub module is a program which is written under the main module.
 A procedure is a small, logical and manageable functional part of a program.
 There are two types of procedures. They are sub procedure and function
procedure.
 A CALL statement is used to call the sub procedure in a program.

New Gateway to Computer Science Book -10 167


Declaring a SUB Procedure
Declaring a sub procedure means specifying the name of sub procedure, number of
arguments and parameters that they use. The syntax is given below.
Syntax: DECLARE SUB Name (Parameter List) Here, Name is the name of sub procedure
which you want to create. Parameter List indicates the number of arguments and its data
type which are used while creating the sub procedure. We always have to use parentheses
to enclose the parameters. This is also an optional list of variables.
In the above example 1, DECLARE SUB SUM where SUM is the name of the sub
procedure without parameter list. Like this in example 2, DECLARE SUB AREA (L, B)
where AREA is the name of the sub procedure with two parameters with argument types.
Defining a SUB Procedure
After the deceleration of sub procedure we have to define it. It is the main body part of the
sub procedure. The syntax is as below.
SUB sub procedure _name (Parameter lists)
Local variable and constant declaration
[Sub procedure statements]
END SUB
In the first line syntax given above, SUB is the QBASIC statement that makes the
beginning of the sub procedure definition. Sub procedure _name is the name of the sub
procedure which is used to call the sub procedure. We cannot use any keywords or the
same variable name or procedure name in the program. Parameter lists are the optional
list of variables which must be enclosed in parentheses.
In the second line syntax given above, Local variable and constant declaration are used
within only the sub procedure.
In the third line syntax given above, Sub procedure statements are the working part of the
sub program.
In the fourth line syntax given above, END SUB indicates the end of the sub program
definitions.
Calling a SUB Procedure
The call statement is used to call the sub procedure. It can be executed from anywhere
in the program by referring to the procedure name. This is known as calling a procedure.
The CALL statement is used to transfer control to another procedure. The syntax is given
below.

168 New Gateway to Computer Science Book -10


Syntax: CALL NAME (Parameter List) where, name is the name of the sub program that
is to be called and parameter list is the data that can be either variable or constant passed
to the sub programs parameter.
Example 3

A sub procedure to find the sum of any three numbers:

DECLARE SUB SUM (A, B, C)


CLS declaring sub procedure

CALL SUM calling sub procedure


END

SUB SUM
INPUT “Enter the first number”; A
INPUT “Enter the second number”; B defining sub procedure
INPUT “Enter the third number”; C

Arguments and Parameters

When a procedure is called from the main module, data or variables need to supply to the
procedure where they are needed to use. The arguments are the parameters that pass to
the procedure. The argument is also known as actual parameter and the parameter is also
known as formal parameter. The calling procedure can pass arguments to the procedure
in two ways. They are passing arguments by value and passing arguments by reference.
Passing Arguments by Value
When arguments are passed by value, it does not make any effect to the value of the
variables which are passed to a procedure as they are changed in the procedure. This
method is useful when we have to pass the same value to more than one procedure without
changing the values of the original variables in the calling program.
Example 4
DECLARE SUB SUM (A, B)
CLS
CALL SUM (50, 60)
END

New Gateway to Computer Science Book -10 169


SUB SUM (A, B)
S=A+B
PRINT “The sum is”; S
END SUB
In the example 4 above, 50, 60 are called and passed with the arguments A and B into the
sub procedure respectively.
Passing arguments by reference
When the argument is sent by reference, the address of each variable is copied to the
procedure’s variable and the changes made in the procedure’s variable will affect on
the variables used at the called program. Passing arguments by reference is the default
mode of passing argument. In this method, the address of the variables are passed to
the procedure which means the variable of procedure uses the memory location of the
argument which is passed to it.
Example 5
DECLARE SUB sum (A, B)
CLS
INPUT “Enter the first number”; x
INPUT “Enter the second number”; y
CALL sum(x, y)
END
SUB sum (A, B)
S=A+B
PRINT “The sum is”; S
END SUB
Differentiate between passing argument by value and passing argument by reference

Passing arguments by value Passing arguments by reference


When arguments are passed by value it When arguments are passed by reference
makes a duplicate copy of arguments and the address of the variables are passed to
their values are used directly in parameter. the procedure.
To pass the argument by value, variable is By default the value is passed by refer-
enclosed in parenthesis. ence.
It doesn’t make any effect on values of The changes made in the procedure’s vari-
variable which are passed to a procedure able will affect the variables used at call-
even they are changed in the procedure. ing module.

170 New Gateway to Computer Science Book -10


Parameters
A parameter represents a value that the procedure expects you to pass when you call it.
The procedure’s declaration defines its parameters. When you define a function or sub
procedure, you specify a parameter list in parentheses immediately following the procedure
name. For each parameter, you specify a name, data type, and a passing mechanism. The
calling code does not have to pass a value for it. The name of each parameter serves as a
local variable in the procedure. The way you use the parameter name is the same way to
use any other variable. Study the following program.
Example 6
DECLARE SUB SUM (A, B)
CLS
CALL SUM (50, 60)
END
SUB SUM (A, B)
S=A+B
PRINT “The sum is”; S
END SUB
Here, in this program the variables A and B are the parameters of sub module SUM and
the values 50 and 60 are the arguments. While invoking the module, the arguments are
passed to the sub module.
Types of Parameters
Formal Parameters
The variables which are used to specify or declare types of data to pass to the procedures
are formal parameters. In other words, formal parameters are those variables that are used
inside parenthesis immediately after the procedure name in the declaration part. A formal
parameter is always a variable. The name of each parameter serves as a local variable in
the procedure. This parameter receives a value sent by the actual parameters.
Actual or Real Parameters
Actual parameters are also called real parameters. These are the arguments which are
used to pass real value or data to the procedures. Actual parameters may be variables
or constant values. The data type of arguments and the formal parameters should match
according to the order they are passed to the procedure.
Example 7
DECLARE SUB SUM (A, B) [A and B are formal parameters]
LET X= 50

New Gateway to Computer Science Book -10 171


LET Y= 60
CALL SUM (X, Y) [X and Y are actual parameters]
END
SUB SUM (A, B)
S=A+B
PRINT S
END SUB
Example 8
DECLARE SUB interest (x, y, z) [Here x, y, z are the formal parameters]
CLS
INPUT “Enter principal amount”; p
INPUT “Enter time ratio”; t
INPUT “Enter rate”; r
CALL interest (p, t, r) [Here p, t, r are the actual parameters]
END
SUB interest (x, y, z)
I = (x * y * z) / 100
PRINT “Simple interest = “; I
END SUB

Scope of Variables
This variable type determines the size and layout of the variable’s memory. It also
determines the range of values which need to be stored inside that memory and nature
of operations that can be applied to that variable. Variable is an element of QBASIC
programming. A variable is a quantity whose value changes during the execution of a
program. It is a named location in the memory that is used to store a value during a
program execution. There are two categories of a variable. They are local variable and
global variable which we are going to discuss below.
Local Variable
A variable which is declared inside a module and cannot be accessed by other modules
is known as local variable. The value of local variable destroys when the program flows
out of procedures. The local variable can be used within the module where it is defined.
Local variable is the variable declared and used inside the procedure by default. Let’s
study the given program.

172 New Gateway to Computer Science Book -10


Example 9
DECLARE SUB SUM (A, B)
CLS
CALL SUM (50, 60)
END
SUB SUM (A, B)
S=A+B
PRINT “The sum is”; S
END SUB
In the above given program, ‘S’ is the local variable because the value of ‘S’ is limited to
be accessed in the sub module only.
Global Variable
Global variable is the variable that can be accessed from any procedure or module used
on the program. They are declared with the keyword SHARED, DIM SHARED,
COMMON SHARED. A variable declared in a COMMON or DIM statement with the
SHARED attribute is a global variable to module. Let’s study the given program.
Example 10
DECLARE SUB average ( )
DIM SHARED n(5)
CLS
FOR i = 1 TO 5
INPUT “Enter a number”; n(i)
NEXT i
CALL average
END
SUB average
FOR i = 1 TO 5
s = s + n(i)
NEXT i
a=s/5
PRINT “Average of numbers =”; a
END SUB
In the above given program, as the array variable n has been declared as global variable,
it is accessible in SUB procedure ‘average’ without passing n as parameter from calling
program.

New Gateway to Computer Science Book -10 173


Here, are some fundamental differences between Local and Global variables.

Parameter Local Global


Scope It is declared inside a function. It is declared outside the function.
Parameters Parameters passing is required Parameters passing is not necessary
for local variables to access the for a global variable as it is visible
value in other function. throughout the program.
Modification When the value of the local When the value of the global variable
of variable variable is modified in one func- is modified in one function, changes
value tion, the changes are not visible are visible in the rest of the program.
in another function.
Accessed by Local variables can be accessed You can access global variables by
with the help of statements, any statement in the program.
inside a function in which they
are declared.
DIM SHARED, SHARED and COMMON SHARED Statement
 DIM SHARED statement is used to declare global variable in the main module.
Syntax: DIM SHARED [List of variables]
Example: DIM SHARED A
 SHARED statement is used to declare global variable in the sub module. It is used to make
the variable accessible which is declared at the module level without passing them as
parameters.
Syntax: SHARED [List of variables]
Example: SHARED A
 The COMMON SHARED is a non-executable statement that declares global variables
for sharing between modules (main program to sub program or function and vice versa).
This statement declares the variable as global so that all modules can use this variable.
Syntax: COMMON SHARED [List of variables]
Example: COMMON SHARED A
Example 11
A program to find the sum and difference of any two numbers using SHARED statement.
DECLARE SUB SUM ()
DECLARE SUB Diff () In this program, no any parameter is passed but the
CLS variables A and B are shared in the both module
by SHARED statement to calculate their values. A
INPUT “Enter the first no”; A
and B are global variables in this program.
INPUT “Enter the second no”; B

174 New Gateway to Computer Science Book -10


CALL SUM
CALL Diff
END
SUB Diff
SHARED A, B
D=A-B
PRINT “The difference is”; D
END SUB
SUB SUM
SHARED A, B
S=A+B
PRINT “The sum is”; S
END SUB
Example 12
A program to reverse a word in the main module using COMMON SHARED statement
COMMON SHARED A$
DECLARE SUB Rev()
In this program, the string variable A$ is not
CLS
declared as parameter at the declaration part but its
INPUT “Enter any string”; A$ value is accessed in the modules so it is a global
CALL Rev(A$) variable.
END
SUB Rev(A$)
END
SUB Rev(A$)
FOR I = LEN(A$) to 1 Step-1
B$=B$ + MID$(A$,I,1)
NEXT I
PRINT “Reverse string is”; B$
END SUB

New Gateway to Computer Science Book -10 175


Let’s Review
 Declaring a sub procedure means specifying the name of sub procedure, number of
arguments and parameters that they use.
 After the deceleration of sub procedure we have to define it. It is the main body part of
the sub procedure
 The CALL statement is used to call the sub procedure.
 The CALL statement is used to transfer control to another procedure.
 The arguments are the parameters that pass to the procedure.
 The argument is also known as actual parameter and the parameter is also known as
formal parameter.
 Passing arguments by reference is the default mode of passing argument.
 A parameter represents a value that the procedure expects you to pass when you call it.
 The two types of parameters are formal parameters and actual parameters.
 The variables which are used to specify or declare types of data to pass to the
procedures are formal parameters.
 Actual parameters are also called real parameters.
 A variable is a quantity whose value changes during the execution of a program.
 A variable which is declared inside a module and cannot be accessed by other
modules is known as local variable.
 Global variable is the variable that can be accessed from any procedure or module
used on the program.

Understanding Function Procedure

Function procedure is a block of statement that performs specific task and return a value
whenever it is called. It is a small, logical and manageable functional part of a program
which performs specific tasks and returns single value to the main program or calling
module. It has three parts, first one is declaration part where we declare FUNCTION
procedure, second one is main part, from where FUNCTION procedure is called and
last one is FUNCTION part where we define our specific task to do. The syntax of this
procedure is given below.
Syntax:
DECLARE FUNCTION NAME [Parameter list]
[List of statements]
Function Name = Expression
[Statements…….]
END FUNCTION

176 New Gateway to Computer Science Book -10


Where, name is the name of the function-procedure which we want to create. Parameter is
a list of variables which indicates the number of arguments and its data types that is used
when calling the function. Expression is the return value of the function. Let’s understand
the parts of function procedure in the given example.
Example 13
DECLARE FUNCTION AREA (L, B) [Declaration Part]
CLS
INPUT “Enter the length”; L
INPUT “Enter the breadth”; B
Main Module
AR = AREA (L, B)
PRINT “The area is”; AR
Calling Function Procedure
END
FUNCTION AREA (L, B)
A=L*B
AREA = A Calling Function Procedure
END FUNCTION

In the above program, we declared the FUNTION procedure by using DECLARE keyword
and statements between CLS and END part. It is the main part where code runs and when
interpreter reads fifth line, flow of program jumps to the FUNCTION procedure. Inside
the function procedure, it calculates the area and returns the value in the main module.
After that it prints the area and when it reads END statements it terminates the program.
Difference between function procedure and sub procedure

Function Procedure Sub Procedure


A function must return a value. Sub procedure does not return value.
It is a block of code placed between SUB It is a block of code placed between
FUNCTION and END FUNCTION
and END SUB statement. statement.
A function is called by statement and Sub procedure is called by CALL
expression method. statement.
It has a data type which is the return value
It does not have a data type of the function
The print statement is mostly used in sub The print statement is mostly used in main
module. module.

New Gateway to Computer Science Book -10 177


Practical Section on SUB Procedure

Program 1 Program 2
Write a program to enter any two numbers Write a program to enter any two numbers
and display its sum. and display its difference.
DECLARE SUB SUM (A, B) DECLARE SUB DIFF (A, B)
CLS CLS
INPUT “ENTER FIRST NUMBER”; A INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER SECOND NUMBER”; B
CALL DIFF (A, B)
CALL SUM(A, B)
END
END SUB DIFF (A, B)
SUB SUM (A, B) D=A-B
S=A+B PRINT “DIFFERENCE”; D
PRINT “SUM OF TWO NUMBERS”; S END SUB
END SUB

Program 3 Program 4
Write a program to enter any two Write a program to find the area of four
numbers and display their average. walls.
DECLARE SUB AVERAGE (A, B) DECLARE SUB AREA (L,B,H)
CLS CLS
INPUT “ENTER FIRST NUMBER”; A INPUT “ENTER LENGTH” ; L
INPUT “ENTER SECOND NUMBER”; B INPUT “ENTER BREADTH” ; B
CALL AVERAGE (A, B)
INPUT “ENTER HEIGHT” ; H
END
CALL AREA (L,B,H)
SUB AVERAGE (A, B)
END
AVG = (A + B) / 2
SUB AREA (L,B,H)
PRINT “AVERAGE OF TWO NUM”; AVG
A=2*H*(L+B)
END SUB
PRINT “AREA IS”; A
END SUB

178 New Gateway to Computer Science Book -10


Program 5
Program 6
Write a program to calculate the simple Write a program to calculate the area of a
interest. square.
DECLARE SUB SI(P,T,R)
DECLARE SUB AREA (L)
CLS
CLS
INPUT “ENTER PRINCIPLE” ; P
INPUT “ENTER TIME” ; T INPUT “ENTER LENGTH”; L
INPUT “ENTER RATE” ; R CALL AREA(L)
CALL SI(P,T,R) END
END SUB AREA (L)
SUB SI(P,T,R)
A=L^2
I=(P*T*R)/100
PRINT “THE AREA OF SQUARE IS”; A
PRINT “THE INTEREST AMT IS ” ; I
END SUB END SUB

Program 7 Program 8
Write a program to calculate the area of a Write a program to convert Nepalese
rectangle. currency into Indian Currency.
DECLARE SUB AREA (L, B) DECLARE SUB CON(N)
CLS CLS
INPUT “ENTER LENGTH”; L INPUT “ENTER NC ” ; P
INPUT “ENTER BREADTH”; B CALL CON(P)
CALL AREA(L, B) END
END SUB CON(P)
SUB AREA (L, B)
C=P/1.6
A=L*B
PRINT “INDIAN CURRENCY ”; C
PRINT “AREA OF RECTANGLE ”; A
END SUB
END SUB

New Gateway to Computer Science Book -10 179


Program 9 Program 10
Write a program to calculate the area of Write a program to calculate the
a circle. perimeter of a rectangle.

DECLARE SUB AREA (R) DECLARE SUB PERI (L, B)

CLS CLS

INPUT “ENTER RADIUS”; R INPUT “ENTER LENGTH”; L

CALL AREA(R) INPUT “ENTER BREADTH”; B

END CALL PERI(L, B)

SUB AREA (R) END

A = 3.14 * R ^ 2 SUB PERI(L, B)

PRINT “AREA OF CIRCLE ”; A P = 2 * (L + B)

END SUB PRINT “THE PERIMETER IS”; P


END SUB

Program 11 Program 12
Write a program to calculate the area and Write a program to calculate the area and
perimeter of a rectangle. perimeter of a square.
DECLARE SUB AREA (L, B)
DECLARE SUB AREA (L)
DECLARE SUB PERIMETER (L, B)
DECLARE SUB PERIMETER (L)
CLS
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B INPUT “ENTER LENGTH”; L
CALL AREA (L, B) CALL AREA (L)
CALL PERIMETER(L, B) CALL PERIMETER(L)
END END
SUB AREA (L, B) SUB AREA (L)
A=L*B A=L^2
PRINT “AREA OF RECTANGLE ”; A PRINT “AREA OF SQUARE”; A
END SUB END SUB
SUB PERIMETER (L, B) SUB PERIMETER (L)
P = 2 * (L + B) P=4*L
PRINT “PERIMETER OF RECT ”; P PRINT “PERIMETER OF SQUARE ”; P
END SUB END SUB

180 New Gateway to Computer Science Book -10


Program 13 Program 14
Write a program to check whether the Write a program to display the prime
input number is prime or not. numbers from 1 to 100
CLS DECLARE SUB PRIME()
DECLARE SUB PRIME(A) CLS
CLS CALL PRIME
INPUT “ENTER A NUMBER” ; N
END
CALL PRIME(N)
SUB PRIME
END
SUB PRIME(A) FOR I = 1 TO 100
FOR I = 1 TO A C=0
IF A MOD I = 0 THEN C=C+1 FOR J = 1 TO I
NEXT I IF I MOD J=0 THEN C=C+1
IF C=2 THEN NEXT J
PRINT “IT IS A PRIME NUMBER” IF C=2 THEN PRINT I;
ELSE NEXT I
PRINT “IT IS NOT A PRIME NUMBER” END SUB
ENDIF
END SUB

Program 15 Program 16
Write a program that accepts three different
Write a program to check whether the
numbers and display the smallest number.
given number is positive or negative.
DECLARE SUB SMALL(A,B,C)
CLS DECLARE SUB TEST(N)
INPUT “ENTER FIRST NUBER” ; A CLS
INPUT “ENTER SECOND NUMBER” ; B INPUT “Enter a number”; N
INPUT “ENTER THIRD NUMBER” ; C CALL TEST(N)
CALL SMALL(A,B,C)
END
END
SUB SMALL(A,B,C) SUB TEST(N)
IF A<B AND B<C THEN IF N>0 THEN
PRINT “THE SMALLEST NUMBER IS” ; A PRINT N; “It is positive number.”
ELSE IF B<A AND A<C THEN ELSE
PRINT “THE SMALLEST NUMBER IS” ; B
PRINT N; “It is negative number”
ELSE
PRINT “THE SMALLEST NUMBER IS” ; C END IF
END SUB END SUB

New Gateway to Computer Science Book -10 181


Program 17 Program 18
Write a program to check whether the
input number is Armstrong or not. Write a program to input a string and
DECLARE SUB ARM (N) count the total numbers of vowels.
CLS DECLARE SUB COUNT (S$)
INPUT “ENTER ANY NUMBER”; N CLS
CALL ARM (N) INPUT “ENTER ANY STRING”; S$
END CALL COUNT(S$)
SUB ARM (N) END
A=N
SUB COUNT (S$)
S=0
WHILE N < > 0 VC = 0
R = N MOD 10 FOR I = 1 TO LEN(S$)
S = S + R ^ 3 B$ = MID$(S$, I, 1)
N = N \ 10 C$ = UCASE$(B$)
WEND IF C$ = “A” OR C$ = “E” OR C$ = “I”
IF A = S THEN OR C$ = “O” OR C$ = “U” THEN
PRINT A; “IT IS ARMSTRONG” VC = VC + 1
ELSE END IF
PRINT A; “IT IS NOT ARMSTRONG”
NEXT I
END IF
END SUB PRINT “TOTAL NUM OF VOWEL”; VC
END SUB

Program 19 Program 20
Write a program to reverse the given Write a program to display 2 3 5 8 12
string. ……upto 10th term.
CLS DECLARE SUB series ()
INPUT “ENTER A WORD” ; W$ CLS
CALL REV(W$) CALL series
END
END
SUB series
SUB REV(N$)
I=2
FOR I = LEN(N$) TO 1 STEP-1 FOR J = 1 TO 10
C$=C$+MID$(N$,I,1) PRINT I;
NEXT I I=I+J
PRINT “REVERSED STRING IS” ; C$ NEXT J
END SUB END SUB

182 New Gateway to Computer Science Book -10


Program 21
Program 22
Write a program to display the first Write a program to display the series
10 Fibonacci series numbers. Such as in the given pattern.
1,1,2,3,5,8,13…. 5
DECLARE SUB series () 5 5
CLS 5 5 5
CALL series 5555
END 55555
SUB series DECLARE SUB series ()
A=1 CLS
CALL series
B=1 END
PRINT A; SUB series
PRINT B; N=5
FOR I = 1 TO 10 I=1
C=A+B DO
PRINT C; PRINT N
A=B N = N * 10 + 5
B=C I=I+1
NEXT I LOOP WHILE I <= 5
END SUB
END SUB

Program 23 Program 24
Write a program to display the series as 2 Write a program to display reverse of
22 222 2222 22222 . input-string.
DECLARE SUB series () DECLARE SUB REV(A$)
CLS CLS
CALL series INPUT “ENTER ANY STRING”;A$
END CALL REV(A$)
SUB series END
I=2 SUB REV(A$)
FOR I= LEN(A$) TO 1 STEP -1
FOR J = 1 TO 5
B$=MID$(A$,I,1)
PRINT I;
W$=W$+B$
I = I * 10 + 2
NEXT I
NEXT J
PRINT “REVERSED STRING=”W$
END SUB END SUB

New Gateway to Computer Science Book -10 183


Program 25
Program 26
Write a program to display the given series
pattern. Write a program to ask a word in upper
1 case and convert it into lower case.
22 DECLARE SUB convt (W$)
333
4444 CLS
55555
INPUT “Enter a word in Uppercase”; W$
DECLARE SUB series ()
CLS CALL convt(W$)
CALL series
END END
SUB series SUB convt (W$)
FOR i = 1 TO 5
FOR j = 1 TO i R$ = LCASE$(W$)
PRINT i;
PRINT R$
NEXT j
PRINT END SUB
NEXT i
END SUB

Program 27 Program 28
Write a program to display the series in the
given pattern. Write a program to display the series as 3
1 12 27 48 upto 10th terms.
121 DECLARE SUB series ()
12321
1234321 CLS
123454321 CALL series
12345654321
END
DECLARE SUB series ()
CLS SUB series
CALL series I=3
END
SUB series FOR j = 1 TO 10
FOR I# = 1 TO 6 PRINT I * j ^ 2;
A# = A# * 10 + 1
NEXT j
PRINT A# ^ 2
NEXT END SUB
END SUB

184 New Gateway to Computer Science Book -10


Program 29 Program 30
Write a program to display the series in the Write a program to display the series in
given pattern. the given pattern.
1 12345
12 1234
123 123
1234 12
12345 1
123456 DECLARE SUB series ()
DECLARE SUB series () CLS
CLS CALL series
CALL series END
END
SUB series
SUB series
FOR I = 5 TO 1 STEP -1
FOR I = 1 TO 6
FOR J = 1 TO I
FOR j = 1 TO I
PRINT j; PRINT J;
NEXT NEXT
PRINT PRINT
NEXT NEXT
END SUB END SUB

Program 31 Program 32
Write a program to check whether a
Write a program to display the series as supplied number is perfect square or
3 12 27 48 upto 10th terms. not.
DECLARE SUB series () DECLARE SUB PSQR(N)
CLS CLS
INPUT “ENTER A NUMBER” ; N
CALL series CALL PSQR(N)
END END
SUB series SUB PSQR(N)
S=SQR(N)
I=3
IF S = INT(S) THEN
FOR j = 1 TO 10 PRINT “it is perfect square”
PRINT I * j ^ 2; ELSE
PRINT “it is not perfect square”
NEXT j
ENDIF
END SUB END SUB

New Gateway to Computer Science Book -10 185


Program 33 Program 34
Write a program to input a string and
Write a program to input string and display
display only the vowel letters.
only the consonant letters.
DECLARE SUB VLETTER (S$)
DECLARE SUB DISPC (S$)
CLS
CLS
INPUT “ENTER ANY STRING”; S$
INPUT “ENTER ANY STRING”; S$
CALL VLETTER(S$)
CALL DISPC(S$)
END
END
SUB VLETTER(S$)
SUB DISPC(S$)
FOR I = 1 TO LEN(S$)
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
C$ = UCASE$(B$)
IF C$ = “A” OR C$ = “E” OR C$ = “I”
IF C$ <> “A” AND C$ <> “E” AND C$ <>
OR C$ = “O” OR C$ = “U” THEN
“I” AND C$ <> “O”AND C$ <> “U” AND
PRINT B$
C$ <> “ ” AND C$ <> “.” THEN
END IF
PRINT B$
NEXT I
END IF
END SUB
NEXT I
END SUB
Program 35
Write a program to display the given Program 36
pattern.
L Write a program to check whether the
AL input number is even or odd.
PAL DECLARE SUB CONV(N)
EPAL CLS
NEPAL INPUT “ENTER A NUMBER ” ; N
DECLARE SUB pat () CALL CONV(N)
CLS END
CALL pat SUB CONV(N)
END IF N MOD 2 = 0 THEN
SUB pat PRINT “IT IS EVEN NUMBER”
A$ = “NEPAL” ELSE
FOR I = 1 TO LEN(A$) PRINT “IT IS ODD NUMBER”
PRINT RIGHT$(A$, I)
ENDIF
NEXT I
END SUB
END SUB

186 New Gateway to Computer Science Book -10


Program 37 Program 38
Write a program to display the given Write a program to display the given
pattern. pattern.
COMPUTER R
OMPUTER ER
MPUTER TER
PUTER UTER
UTER PUTER
TER MPUTER
ER OMPUTER
R COMPUTER
DECLARE SUB pat () DECLARE SUB pat ()
CLS CLS
CALL pat CALL pat
END END
SUB pat SUB pat
A$ = “Computer” A$ = “COMPUTER”
C = 20: S = 30 C = 20: S = 30
FOR I = 1 TO 8 FOR I = 1 TO 8
PRINT MID$(A$, I, C) PRINT RIGHT$(A$, I)
C = C - 2: S = S + 1 C = C - 2: S = S + 1
NEXT I NEXT I
END SUB END SUB

New Gateway to Computer Science Book -10 187


Program 39 Program 40
Write a program to display the given Write a program to display the hston(
pattern. ) to print 7 , 22 , 11 , 34 , 17 , 52 , 26 ,
C 13 , 40 , 20 without passing parameters.
CO DECLARE SUB number ()
COM CLS
COMP CALL number
COMPU END
COMPUT SUB number
COMPUTE
a=7
COMPUTER
FOR i = 1 TO 10
DECLARE SUB pat ()
PRINT a;
CLS
CALL pat IF a MOD 2 = 0 THEN
END a=a/2
SUB pat ELSE
A$ = “Computer” a=a*3+1
C = 20: S = 30 END IF
FOR I = 1 TO 8 NEXT
PRINT LEFT$(A$, I) END SUB
C = C - 2: S = S + 1
NEXT I
END SUB

Tips: Consider a number; if it is exactly divisible by 2 then write the quotient for the
next number. If it is not exactly divisible by 2 then multiply the number by 3 and add
1 which will be the next number. Repeat the same process for the second and so on.
Here, first number itself is 7.
7
2 = 3×7+1 = 11
22
2 = 11
22
2 = 11×3+1 = 34
34
2 = 17
17
2 = 17×3+1 = 52, So on.

188 New Gateway to Computer Science Book -10


Program 41
Write a program to enter the age of a person and display different messages using
the given conditions:
Age Message
< 15 Children
16-21 Adult
22-30 Matured
31- 44 Family Growing
>45 Old
DECLARE SUB age (A)
CLS
INPUT “Enter your age:”; A
CALL age(A)
END
SUB age (A)
SELECT CASE A
CASE IS < 15
R$ = “Oh ! I am children”
CASE 16 TO 21
R$ = “Hurray! I am adult now, Common!”
CASE 22 TO 30
R$ = “Now! I am matured, I have to care all.”
CASE 31 TO 44
R$ = “Yes! Yes! Yes! I have children now.”
CASE ELSE
R$ = “Alas! Now I am old.....hey god save me.”
END SELECT
PRINT R$
END SUB

New Gateway to Computer Science Book -10 189


Program 42
Write a program to input name of passenger and destination. Calculate total fare
using the following rates.
Destinations Rate per person
Dhading Bensi 180/-
Palpa 800/-
Pokhara 500/-
Malekhu 120/-
Also provide 5% discount if there are more then 10 passengers.
DECLARE SUB fare (p, d$)
CLS
INPUT “Enter number of passenger”; p
INPUT “Enter the destination to go”; d$
CALL fare(p, d$)
END
SUB fare (p, d$)
IF d$ = “Dhading Bensi” THEN
t = 140 * p
ELSEIF d$ = “Palpa” THEN
t = 190 * p
ELSEIF d$ = “Pokhara” THEN
t = 200 * p
ELSEIF d$ = “Malekhu” THEN
t = 80 * p
END IF
IF p >= 10 THEN d = 5 / 100 * t
f=t-d
PRINT “total bus fare is Rs:”; f
END SUB

190 New Gateway to Computer Science Book -10


Program 43 Program 44
Write a program to convert Write a program to enter any two numbers
hexadecimal into decimal. and display its sum, difference, product and
average.
DECLARE SUB Z(B$) DECLARE SUB SUM (A, B)
CLS DECLARE SUB DIFF (A, B)
DECLARE SUB PROD (A, B)
INPUT “ENTER HEXA VALUE”;B$
DECLARE SUB AVERAGE (A, B)
CALL Z(B$) CLS
END INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
SUB Z(B$)
CALL SUM (A, B)
FOR I=LEN(B$) TO 1 STEP -1 CALL DIFF (A, B)
A$=MID$(B$,I,1) CALL PROD (A, B)
CALL AVERAGE (A, B)
C=VAL(A$)
END
IF A$=”A” THEN C=10 SUB SUM (A, B)
S=A+B
IF A$=”B” THEN C=11
PRINT “SUM OF TWO NUMBERS”; S
IF A$=”C” THEN C=12 END SUB
IF A$=”D” THEN C=13 SUB DIFF (A, B)
D=A-B
IF A$=”E” THEN C=14
PRINT “DIFFERENCE OF TWO
IF A$=”F” THEN C=15 NUMBERS”; D
H=H+C*16^P END SUB
SUB PROD (A, B)
P=P+1 P=A*B
NEXT I PRINT “PRODUCT OF TWO NUM”; P
END SUB
PRINT “DECIMAL VALUE IS”;H
SUB AVERAGE (A, B)
END SUB AVG = (A + B) / 2
PRINT “AVERAGE OF TWO NUM”; AVG
END SUB

New Gateway to Computer Science Book -10 191


Program 45 Program 46
Write a program to convert decimal number Write a program to display the below
into binary. output.
DECLARE SUB A (N) * DECLARE SUB display ()
** CLS
CLS CALL display
*** END
INPUT “ENTER A NUMBER”; N
**** SUB display
CALL A(N) FOR i = 1 TO 5
*****
FOR j = 1 TO i
END * PRINT “*”;
SUB A (N) ** NEXT j
PRINT
WHILE N <> 0 *** NEXT i
**** FOR i = 1 TO 5
E = N MOD 2
FOR j = 1 TO i
*****
B$ = STR$(E) PRINT “*”;
* NEXT j
N = FIX(N / 2) PRINT
*
C$ = B$ + C$ NEXT i
* FOR i = 1 TO 5
WEND * PRINT “*”
NEXT i
PRINT “BINARY EQUIVALENT IS”; C$ *
END SUB
END SUB

192 New Gateway to Computer Science Book -10


Assignment
1. Answer the following questions.
a. What do you mean by modular programming?
b. What are the parts of module?
c. Define main module and sub module.
d. Define procedure and write its types.
e. Write down the features of SUB procedure.
f. Write down the syntax for declaring a SUB procedure and for Defining a SUB
procedure.
g. What is a parameter?
h. Define local and global variable.
i. Write differences between sub procedure and function procedure.
j. What is an argument? What do you mean by arguments passing by value and
passing by reference?
2. Write a Qbasic program for the following questions.
a. Write a program to declare a sub procedure to find the average of any three
numbers.
b. Write a program to enter any two numbers and display its sum, difference, product
and average.
c. Write a program to declare a sub procedure to find the greatest number among 5
different numbers.
d. Write a program to declare a sub procedure to find the cube of a given number.
e. Write a program to calculate the circumference of circle.
f. Write a program to convert the meter into kilometre.
g. Write a program to calculate the simple interest and total amount.
h. Write a program to find the perimeter of a rectangle.
i. Write a program to check whether the given number is odd or even.
j. Write a program to check whether the given number is exactly divisible by 3 and 5 or
not.
k. Write a program to check whether the given number is prime or composite.

New Gateway to Computer Science Book -10 193


l. Write a program to find the sum of the first ten natural numbers.
m. Write a program to check whether the entered letter is a vowel or consonant.
n. Write a program to display the area of four walls.
o. Write a program to check whether the given number is perfect cube or not.
p. Write a program to check whether the given number is perfect square or not.
q. Write a program to print the factorial of a given number.
r. Write a program to display the sum of individual digit. [756] [7+5+6 = 18].
s. Write a program to input a string and count the total numbers of vowels.
t. Write a program to check whether the given number is positive or negative.
u. Write a program to find the sum of natural numbers from 1 to 10.
v. Write a program to find the factors of any input number.
w. Write a program to check whether the input number is prime or not.
x. Write a program to display the prime numbers from 1 to 100.
y. Write a program to reverse a given string.
z. Write a program to check whether the input number is Armstrong or not.
3. Write a Qbasic program to display the given pattern.
a. 2, 4 , 6, 8 , 10 up to 100.
b. 3,6,9,12………20th terms
c. 1 , 11, 111, 1111, up to 5th terms.
d. 1, 4, 9, 16……..upto 10th terms.
e. 5, 55, 555, 5555, 5555
f. 100,99,98,97,96, ………….1
g. 99, 97, 95, 93, ……..20th terms.
h. 5, 10, 15, 20……10th terms.
i. 50, 45, 40, 35 ………5

j. 1 k. 3 l. 5
12 33 54
123 333 543
1234 3333 5432
12345 33333 5432

194 New Gateway to Computer Science Book -10


m. C n. EDUCATION o. COMPUTER
CO EDUCATIO OMPUTER
COM EDUCAT MPUTER
COMP EDUCA PUTER
COMPU EDUC UTER
COMPUT EDU TER
COMPUTE ED ER
COMPUTER E R

p. 30 q. 2 4 6 8 10
4 6 8 10
28 30 6 8 10
26 28 30 8 10
10
24 26 28 30
22 24 26 28 30
4. Write down the output of the given program.
a. DECLARE SUB OUTP () b. DECLARE SUB OUTP ()
CLS CLS
CALL OUTP CALL OUTP
END END
SUB OUTP SUB OUTP
A=1 W$ = “DHADING”
B=1 FOR I = 1 TO LEN(W$) STEP 1
DO PRINT LEFT$(W$, I)
PRINT A; NEXT
IF B MOD 3 = 0 THEN PRINT END SUB
B=B+1
A=A+1
LOOP UNTIL B > 9
END SUB

New Gateway to Computer Science Book -10 195


c. DECLARE SUB OUTP () d. DECLARE SUB pat ()
CLS CLS
CALL pat
CALL OUTP
END
END
SUB pat
SUB OUTP A$ = “COMPUTER”
W$ = “DHADING” t=5
FOR I = 1 TO LEN(W$) STEP 1 FOR I = 1 TO LEN(A$) STEP 2
PRINT RIGHT$(W$, I) PRINT TAB(t); MID$(A$, t, I)
t=t-1
NEXT
NEXT I
END SUB
END SUB

f. DECLARE SUB series ()


e. DECLARE SUB series ()
CLS
CLS
CALL series
CALL series
END
END SUB series
SUB series FOR I = 1 TO 6
I = 3 FOR j = 1 TO I
FOR j = 1 TO 10 PRINT j;
PRINT I * j ^ 2; NEXT
NEXT j PRINT
END SUB NEXT
END SUB
g. DECLARE SUB series ( ) h. DECLARE SUB PATTERN (S$)
CALL series CLS
END S$ = “NEPAL”
SUB series CALL PATTERN(S$)
X=1 END
FOR K = 1 TO 4 SUB PATTERN (S$)
PRINT X; FOR I = 1 TO LEN(S$)
PRINT TAB(I); MID$(S$, I, 1)
X=X+K
NEXT I
NEXT K
END SUB
END SUB

196 New Gateway to Computer Science Book -10


i. DECLARE SUB PATTERN1 (S$)
DECLARE SUB PATTERN (S$)
CLS
S$ = “****”
CALL PATTERN(S$)
CALL PATTERN(S$)
CALL PATTERN1(S$)
END
SUB PATTERN (S$)
FOR I = 1 TO LEN(S$)
PRINT LEFT$(S$, I)
NEXT I
END SUB
SUB PATTERN1 (S$)
FOR K = 1 TO LEN(S$)
PRINT MID$(S$, K, 1)
NEXT K
END SUB
j. DECLARE SUB VLETTER (S$)
CLS
INPUT “ENTER ANY STRING”; S$
CALL VLETTER(S$)
END
SUB VLETTER(S$)
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ = “A” OR C$ = “E” OR C$ = “I” OR C$ = “O” OR C$ = “U” THEN
PRINT B$
END IF
NEXT I
END SUB

New Gateway to Computer Science Book -10 197


5. Study the given program and answer the following questions.
a. DECLARE SUB SUM (N)
N = 5 i. In the program how many times does the
FOR NEXT loop execute?
CALL SUM (N)
END ii. Write the name of the procedure used in the
program.
SUB SUM (N)
FOR X = 1 TO N S = S + X iii. What are the operators used in the program?
iv. What will be the output of the program?
NEXT X
PRINT S
END SUB

b. DECLARE SUB Stde (N$ U)


FOR Loop = 1 to 5
RED NM$ (Loop)
NEXT Loop
DATA RAM, PRATIM, PRASANT
DATA NISHA, RUDHAR
CALL Stde (NM$U)
END
SUB Stde (N$U)
Print “Name starting from P”
FOR J = 1 TO 5
C$ = MID$ (N$, (J), 1, 1)
If C$ = “P” THEN
PRINT N$ (J)
END IF
NEXT J
END SUB
i. List out the library functions used in the above program.
ii. List the conditional statements used in the above program.
iii. What are the string variables used in the above program?
iv. What will be the output of the given program?

198 New Gateway to Computer Science Book -10


c. DECLARE SUB EXAM (N$)
CLS
INPUT “Enter word”, WO$
CALL EXAM (WO$)
END
SUB EXAM (N$)
FOR I =1 TO LEN (N$)
PRINT RIGHTS (N$, I)
NEXT I
END SUB
i. Write the names of the two built in functions used in the above program.
ii. List the real parameter in the given program.
iii. Name the string variable used in the above program.
iv. What is the name of the looping used in the above program?
v. What is the function of the LEN(N$) in the above program?

d. DECLARE SUB ABC (S,Y,Z)


FOR P = 1 TO 3
READ A,B,C
CALL ABC (A,B,C)
NEXT P
DATA 5, 4, 3, 2, 1, 6, 7, 8,4
END
SUB ABC (X,Y,Z)
T=X+Y+Z
IF T MOD 2 = 0 THEN
PRINT T
END IF
END SUB
i. List any two variables used in the above program.
ii. How many time SUB-procedure will be called when the program is executed ?
iii. How many parameters are used in the above program?

New Gateway to Computer Science Book -10 199


e. DECLARE SUB SUM(N)
INPUT “Enter any number”; N
CALL SUM (N)
END
SUB SUM (N)
WHILE N <> 0: R=N MOD 10
S=S+R
N = N\10
WEND
PRINT “SUM”; S
END SUB
i. In which condition the statements within the WHILE….WEND looping statement
will not be executed?
ii. Will the output be same if we use “/” instead of “\” in the above program?
iii. List out the operators used in the above program?
iv. If a user enters the number 50, what will be the output of the above program?
f. DECLARE SUB WORD(N$)
CLS
N$=”PABSON”
CALL WORD(N$)
END
SUB WORD(N$)
B=LEN(N$)
C=1
WHILE C<B
M$=MID$(N$, B, 1)
PRINT M$
C=C+2
WEND
END SUB
i) List the string and numeric variables used in the program.
ii) What is the value of B in the program?
iii) What are the string functions used in the above program?
iv) List out the operators used in the above program.

200 New Gateway to Computer Science Book -10


g. DECLARE SUB TEST (W$)
CLS
INPUT “ENTER A WORD”;A$
CALL TEST (A$)
END
SUB TEST (W$)
FOR K = 1 TO LEN (W$)
U$ = MID$ (W$, K, 1) +U$
NEXT K
PRINT U$
END SUB
i. List out the arguments and parameters used in the above program.
ii. List the library functions used in the above program.
h. DECLARE SUB SUM(N)
INPUT “Enter any number”; N
CALL SUM(N)
END
SUB SUM(N)
S=0
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
PRINT “SUM”;S
END SUB
i. In which condition, the statements within the WHILE….WEND looping statement
will not be executed?
ii. Will the output be the same if we place “/” instead of”\” in the above program?

New Gateway to Computer Science Book -10 201


6. Re-write the given program after correcting the bugs.
a. REM to display a word by extracting characters of even position.
CLS
DECLARE SUB POS$(X$, Y$)
INPUT “ENTER A WORD:”; X$
CALL SUB POS$ (X$, Y$)
END
SUB WORD$(X$, Y$)
FOR P = 1 TO LEN (X$) STEP 2
E$ = LEFT$ (X$, 1, P)
WORD$ = E$ + WORD$
NEXT P
Y$ = WORD$
END SUB

b. REM to display a word by extracting characters of even position


CLS
DECLARE SUB NAME$(X$,Y$)
INPUT”ENTER A WORD”;X$
CALL SUB NAME$(X$,Y$)
PRINT Y$
END
SUB WORD$(X$,Y$)
FOR P=1 TO LEN (X$) STEP 2
E$=LEFT$(X$,1,P)
WORD$=E$+WORD$
NEXT P
Y$=WORD$
END SUB

202 New Gateway to Computer Science Book -10


c. DECLARE SUB FIBO ( )
CLS
EXECUTE FIBO
END
SUB FIBO
REM Program to generate 2, 2, 4, 6, 10…upto 10th terms.
A=2
B=2
FOR Ctr = 5 TO 1
DISPLAY A; B;
A=A+B
B=A+B
NEXT Ctr
END FUNCTION

d. DECLARE SUB CUBE(N) e. Series()


CLS CLS
FOR I = 1 TO 5 EXECUTE Series
READ END
CALL CUBE(No) SUB Series()
NEXT X REM program to generate 1 1 2 3 5….
Up to 20th terms
DATA 3, 5, 2, 6, 4
A=1
END
B=1
SUB CUBE( )
FOR ctr= 10 TO 1
DISPLAY N^3
DISPLAY A;B;
END SUB
A=A+B
B=A+B
EXT ctr
END Series()

New Gateway to Computer Science Book -10 203


Practical Session on FUNCTION Procedure

Program 1
Write a program to calculate the average of three numbers.
DECLARE FUNCTION AVGE (A, B, C)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
AV = AVGE(A, B, C)
PRINT “AVERAGE OF THREE NUMBERS”; AV
END
FUNCTION AVERAGE (A, B, C)
AVGR = (A + B + C) / 3
AVERAGE = AVGR
END FUNCTION
Program 2
Write a program to find the area of four walls.
DECLARE FUNCTION AREA(L,B,H)
CLS
INPUT “ENTER LENGTH” ; L
INPUT “ENTER BREADTH” ; B
INPUT “ENTER HEIGHT” ; H
PRINT “THE AREA OF FOUR WALLS= ” ; AREA(L,B,H)
END
FUNCTION AREA(L,B,H)
AREA=2*H*(L+B)
END FUNCTION
Program 3
Write a program to calculate the circumference of a circle.
DECLARE FUNCTION CIR(A)
CLS

204 New Gateway to Computer Science Book -10


INPUT “enter radius of a circle”; R
PRINT “circumference is” ; CIR(R)
END
FUNCTION CIR(A)
P=3.14
CIR=2*P*A
END FUNCTION

Program 4
Write a program to calculate the simple interest.
DECLARE FUNCTION SI(P,T,R)
CLS
INPUT “ENTER PRINCIPLE” ; P
INPUT “ENTER TIME” ; T
INPUT “ENTER RATE” ; R
PRINT “SIMPLE INTEREST IS = ” ;SI(P,T,R)
END
FUNCTION SI(P,T,R)
SI=(P*T*R)/100
END FUNCTION

Program 5
Write a program to convert the Nepalese currency into Indian currency.
DECLARE FUNCTION Convert (N)
CLS
INPUT “Enter NC”; p
PRINT “IC”; Convert(p)
END
FUNCTION Convert (p)
conv = p / 1.6
Convert = conv
END FUNCTION

New Gateway to Computer Science Book -10 205


Program 6
Write a program to define a function procedure to display the area of sphere [Hint: Area of
sphere: 4*PI*R^2]
DECLARE FUNTION AREA(R)
CLS
CONST PI= 3.14
INPUT “Enter radius”; R
PRINT “The area of sphere=”; AREA(R)
END
FUNCTION AREA(R)
A=4*PI*R^2
AREA=A
END FUNCTION
Program 7
Write a program to enter any 5 numbers and display their product.
DECLARE FUNCTION PRO (N( ))
CLS
FOR I = 1 TO 5
INPUT “ENTER THE NUMBERS”; N(I)
NEXT I
PRINT “PRODUCT OF 5 NUMBERS”; PRODUCT (N( ))
END
FUNCTION PRO (N())
FOR I = 1 TO 5
P = P * N(I)
NEXT I
PRO = P
END FUNCTION

Program 8
Write a program to calculate the volume of a cylinder using [Hint: PI*R^2*H]
DECLARE FUNCTION VOL(R,H)
CLS
CONST PI=3.14

206 New Gateway to Computer Science Book -10


INPUT “Enter radius and height”; R, H
PRINT “The volume=”; VOL(R,H)
END
FUNCTION VOL(R,H)
V=PI*R^2*H
VOL=V
END FUNCTION

Program 9
Write a program to display the greater number among any two numbers.
DECLARE FUNCTION GREAT(A,B)
CLS
INPUT “Enter any two number”; A,B
PRINT “The greater number is”; GREAT(A,B)
END
FUNCTION GREAT(A,B)
IF A>B THEN
GREAT= A
ELSE
GREAT=B
END IF
END FUNCTION

Program 10
Write a program to check whether an input number is even or odd.
DECLARE FUNCTION CONV$(N)
CLS
INPUT “ENTER A NUMBER ” ; P
PRINT CONV$(P)
END
FUNCTION CONV$(P)
IF P MOD 2 = 0 THEN
CONV$= “EVEN NUMBER”

New Gateway to Computer Science Book -10 207


ELSE
CONV$=“ODD NUMBER”
ENDIF
END FUNCTION

Program 11
Write a program that asks any three numbers and displays the difference between the
greatest and the smallest among the three numbers.
DECLARE FUNCTION DIF(A,B,C)
CLS
INPUT “Enter three numbers”; A, B, C
PRINT “THE DIFFERENCE=”; DIF(A, B, C)
END
FUNCTION DIF (A, B, C)
G=0
S=0
IF A > B AND A > B THEN
G=A
ELSEIF B > A AND B > C THEN
G=B
ELSE
G=C
END IF
IF A < B AND A < C THEN
S=A
ELSEIF B < A AND B < C THEN
S=B
ELSE
S=C
END IF
DIF = G – S
END FUNCTION

208 New Gateway to Computer Science Book -10


Program 12
Write a program to display vowels and consonants of the entered string.
DECLARE FUNCTION VOW(S$)
DECLARE FUNCTION CON(S$)
CLS
INPUT “Enter a word”; S$
VO= VOW(S$)
CO= CON(S$)
END
FUNCTION VOW(S$)
PRINT “The vowels are”
FOR I = 1 TO LEN(S$)
B$=MID$(S$,I,1)
C$=UCASE$(B$)
IF C$= “A” OR C$= “E” OR C$= “I” OR C$= “O” OR C$=”U” THEN PRINT B$
NEXT I
END FUNCTION
FUNCTION CON(S$)
PRINT “The consonant are”
FOR I = 1 TO LEN(S$)
B$=MID$(S$,I,1)
C$= UCASE$(B$)
IF C$<> “A” AND C$<> “E” AND C$<> “I” AND C$<> “O” AND C$<> “U” THEN
PRINT B$
NEXT I
END FUNCTION
Program 13
Write a program to check whether the input number is divisible by 3 and 5 or not.
DECLARE FUNCTION CH$(N)
CLS
INPUT “ENTER A NUMBER” ; N
PRINT CH$(N)

New Gateway to Computer Science Book -10 209


END
FUNCTION CH$(N)
IF N MOD 3 =0 AND N MOD 5=0 THEN
CH$= “It is divisible by both numbers”
ELSE
CH$=“It is not divisible by both numbers”
ENDIF
END FUNCTION
Program 14
Write a program to declare a user defined function to return to a given number in reverse
order.
DECLARE FUNCTION REV(N)
CLS
INPUT “Enter a number”; N
PRINT “The reverse form is”; REV(N)
END
FUNCTION REV(N)
S=0
WHILE N<>0
R=N MOD 10
S=S*10+R
N=N\10
WEND
REV=S
END FUNCTION
Program 15
Write a program to print the following series: 1,4,7,……. up to 10th term.
DECLARE FUNCTION SERIES
CLS
D= SERIES
END
FUNCTION SERIES
FOR I = 1 TO 10

210 New Gateway to Computer Science Book -10


PRINT A;
A=A+3
NEXT I
END FUNCTION
Program 16
Write a program to input number and find the sum of individual digits.
DECLARE FUNCTION SUM (N)
CLS
INPUT “ENTER ANY NUMBER”; N
SU = SUM (N)
PRINT “SUM OF DIGITS”; SU
END
FUNCTION SUM (N)
S=0
WHILE N < > 0
R = N MOD 10
S=S+R
N = N \ 10
WEND
SUM = S
END FUNCTION
Program 17
Write a program to input number and find the sum of odd digits.
DECLARE FUNCTION SUMODD (N)
CLS
INPUT “ENTER ANY NUMBER”; N
SU = SUMODD (N)
PRINT “SUM OF ODD DIGITS”; SU
END
FUNCTION SUMODD (N)
S=0
WHILE N < > 0
R = N MOD 10

New Gateway to Computer Science Book -10 211


IF R MOD 2 = 1 THEN S = S + R
N = N \ 10
WEND
SUMODD = S
END FUNCTION
Program 18
Write a program to input a number and count the total number of digits.
DECLARE FUNCTION COUNT (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT “TOTAL NUMBER OF DIGITS”; COUNT (N)
END
FUNCTION SUM (N)
C=0
WHILE N < > 0
C=C+1
N = N \ 10
WEND
COUNT = C
END FUNCTION
Program 19
Write a program to check whether the input number is perfect square or not.
DECLARE FUNCTION square (S)
CLS
INPUT “ENTER ANY NUMBER”; N
S = SQR(N)
PR = square (S)
IF PR = S THEN
PRINT “It is perfect square”
ELSE
PRINT “ It is not perfect square “
END IF
END

212 New Gateway to Computer Science Book -10


FUNCTION square (S)
PERFECT = INT (S)
END FUNCTION
Program 20
Write a program to input a string and count the total number of consonants.
DECLARE FUNCTION COUNT(W$)
CLS
INPUT “Enter a Word”; W$
PRINT “The total number of consonant is”; COUNT(W$)
END
FUNCTION COUNT (W$)
C=0
FOR I = 1 TO LEN(W$)
B$ = MID$(W$, I, 1)
C$ = UCASE$(B$)
IF C$ <> “A” AND C$ <> “E” AND C$ <> “I” AND C$ <> “O” AND C$ <> “U”
THEN C = C + 1
NEXT I
COUNT = C
END FUNCTION
Program 21
Write a program to display H.C.F of any two numbers.
DECLARE FUNCTION HCF(A, B)
CLS
INPUT “ENTER ANY TWO NUMBERS”; A, B
PRINT “H.C.F=”; HCF (A, B)
END
FUNCTION HCF (A, B)
WHILE A MOD B < > 0
T = A MOD B
A=B
B=T
WEND
HCF = B
END FUNCTION

New Gateway to Computer Science Book -10 213


Program 22
Write a program to display the reverse of an input string .
DECLARE FUNCTION REV$(N$)
CLS
INPUT “ENTER A STRING” ; W$
PRINT “REVERSED STRING::”;REV$(W$)
END
FUNCTION REV$(N$)
FOR I = LEN(N$) TO 1 STEP -1
D$=D$+MID$(N$,I,1)
NEXT I
REV$=D$
END FUNCTION
Program 23
WAP to check whether the first character of the input string is a number, an uppercase
or lowercase character or none of them.
DECLARE FUNCTION CHTR$(A$)
CLS
INPUT “ENTER A STRING” ; C$
PRINT CHTR$(C$)
END
FUNCTION CHTR$(A$)
D$=LEFT$(A$)
A=ASC(D$)
IF A>=65 AND A<=90 THEN
CHTR$= “FIRST LETTERIS UPPERCASE LETTER”
ELSEIF A>=97 AND A<=122 THEN
CHTR$=“FIRST LETTER IS LOWERCASE”
ELSEIF A>=48 AND A<=57 THEN
CHTR$=“FIRST LETTER IS NUMBER”
ELSE
CHTR$=”NONE OF THEM”
END FUNCTION

214 New Gateway to Computer Science Book -10


Program 24
Write a program to check whether the given number is Armstrong or not.
DECLARE FUNCTION CHECK(N)
CLS
INPUT “Enter any number”; N
A=N
ARM=CHECK (N)
IF A=ARM THEN
PRINT “Armstrong number”
ELSE
PRINT “Not Armstrong number”
END IF
END
FUNCTION CHECK (N)
S=0
WHILE N<>0
R=N MOD 10
S=S+R^3
N=N\10
WEND
CHECK=S
END FUNCTION
Program 25
Write a program to display the factorial of a given number.
DECLARE FUNCTION FACT(N)
CLS
INPUT “Enter any number”; N
PRINT “The factorial is”; FACT (N)
END
FUNCTION FACT (N)
F=1
FOR I=1 TO N

New Gateway to Computer Science Book -10 215


F=F*I
NEXT I
FACT=F
END FUNCTION
Program 26
Write a program to check whether the given number is prime or composite.
DECLARE FUNCTION PC (N)
CLS
INPUT “Enter any number”; N
P=PC (N)
IF P=2 THEN
PRINT “Prime number”
ELSE
PRINT “Composite number”
END IF
END
FUNCTION PC (N)
C=0
FORI=1 TO N
IF N MOD I=0 THEN C=C+1
NEXT I
PC=C
END FUNCTION
Program 27
Write a program to check whether the entered letter is uppercase or lowercase.
DECLARE FUNCTION UC$ (A$)
CLS
INPUT “Enter a letter”; A$
PRINT UC$(A$)
END
FUNCTION UC$ (A$)
CH$ = UCASE$(A$)
IF A$ = CH$ THEN

216 New Gateway to Computer Science Book -10


UC$ = “It is capital letter”
ELSE
UC$ = “It is small letter”
END IF
END FUNCTION
Program 28
Write a program to convert Binary into Decimal.
DECLARE FUNCTION Z (B$)
CLS
INPUT “ENTER A BINARY NUMBER”; B$
PRINT “DECIMAL VALUE IS “; Z(B$)
END
FUNCTION Z (B$)
FOR I = LEN(B$) TO 1 STEP -1
A$ = MID$(B$, I, 1)
C = VAL(A$)
M=M+C*2^P
P=P+1
NEXT I
Z=M
END FUNCTION
Program 29
Write a program to display the following series:
2,1,3,4,7,11,18....up to the 10th term.
DECLARE FUNCTION ser ()
CLS
v = ser
END
FUNCTION ser
a=2
b=1
FOR i = 1 TO 10
PRINT a;

New Gateway to Computer Science Book -10 217


c=a+b
a=b
b=c
NEXT i
END FUNCTION
Program 30
Write a program to print the following output.
N
NE
NEP
NEPA
NEPAL
DECLARE FUNCTION out ()
CLS
v = out
END
FUNCTION out
S$ = “NEPAL”
FOR i = 1 TO LEN(S$)
PRINT LEFT$(S$, i)
NEXT i
END FUNCTION
Program 31
Write a program to print the series:1,4,7,……. up to 10th term.
DECLARE FUNCTION SERIES
CLS
D= SERIES
END
FUNCTION SERIES
FOR I = 1 TO 10
PRINT A;
A=A+3
NEXT I
END FUNCTION

218 New Gateway to Computer Science Book -10


Program 32
Write a program to check whether the given word is palindrome or not.
DECLARE FUNCTION palindrome$ (w$)
CLS
INPUT “Enter any word”; w$
a$ = w$
IF a$ = palindrome$(w$) THEN
PRINT w$; “ is palindrome word”;
ELSE
PRINT w$; “ is not palindrome word”;
END IF
FUNCTION palindrome$ (w$)
FOR i = LEN(w$) TO 1 STEP -1
rev$ = rev$ + MID$(w$, i, 1)
NEXT i
palindrome$ = rev$
END FUNCTION
Program 33
Write a program to display the given series:
5 10 15 20 25 30 35 40 45 50 …….100
DECLARE FUNCTION series (i)
CLS
FOR i = 5 TO 100 STEP 5
PRINT series(i);
NEXT
END
FUNCTION series (i)
s=s+i
series = s
END FUNCTION

New Gateway to Computer Science Book -10 219


Program 34
Write a program to display the following series:
1 4 7 10 13 16 19
DECLARE FUNCTION series (i)
CLS
FOR i = 1 TO 20 STEP 3
PRINT series(i);
NEXT
FUNCTION series (i)
S=S+i
series = S
END FUNCTION
Program 35
Write a program to display the following pattern:
1 8 27 64 125
DECLARE FUNCTION series (i)
CLS
FOR i = 1 TO 5
PRINT series(i);
NEXT
END
FUNCTION series (i)
s=i^3
series = s
END FUNCTION
Program 36
Write a program that asks series of string value and displays the initial letter from such
word using a function procedure.
For e.g.
Input: Central Processing Unit
Output: CPU

220 New Gateway to Computer Science Book -10


DECLARE FUNCTION initial$ (s$)
CLS
INPUT “Type words “; w$
PRINT initial$(w$)
END
FUNCTION initial$ (s$)
x$ = MID$(s$, 1, 1)
FOR i = 1 TO LEN(s$)
b$ = MID$(s$, i, 1)
IF ASC(b$) = 32 THEN
x$ = x$ + MID$(s$, i + 1, 1)
END IF
NEXT i
initial$ = x$
END FUNCTION

Innovative Task

 Write any ten sub-procedures and ten function-procedures programming in A4


size paper and submit to your teacher as your project work.

Assignment
1. Write a FUNCTION program for the following questions.
a. Write a program to display the product of any three numbers.
b. Write a program to read the length, breadth and height of a box. Calculate its volume
and surface area.
c. Write a program to calculate the average of three numbers.
d. Write a program to get temperature in Celsius from the user and then print the
temperature in Fahrenheit. (Hint: F=9C/5+32).
e. Write a program to get a word from the user and then print it in reverse order.
f. Write a program to input a string and count the total number of consonants.
g. Write a program to get radius of the circle and display the area.
h. Write a program to display the factorial of a given number.
i. Write a program to display the greater number among any two numbers.

New Gateway to Computer Science Book -10 221


j. Write a program to check whether an input number is even or odd.
k. Write a program to check whether the input number is divisible by 5 and 7 or not.
l. Write a program to input number and find the sum of individual digits.
m. Write a program to check whether the number given by the user is positive,
negative or zero.
n. Write a program to display the longest string among three input strings.
o. Write a program to display the sum of numbers from 50 to 100.
p. Write a program to display the first 20 prime numbers.
q. Write a program to count the number of digit in a number entered by the user.
r. Write a program to display the HSTON number as 7 , 22, 11, 34, 17, 52, 26, 13, 40,
20.
s. Write a program to display the given series.
1. 4 , 40, 400, 4000, 40000, 400000
2. 10, 20, 30 , 40 , 50 ………10th terms
3. 5, 10, 15, 20 ,25, 30.
4. 100, 200, 300, 400…… upto 20th terms.
5. 1000, 900, 800, 700…..100.
6. 4 , 8, 12, 16, 20 upto 10th terms.
7. 1,2,4,8,16,32………….10th terms.
2. Write a program to display the given pattern.
a. 1 b. 5 5 5 5 5 5
1 2 5 5 5 5 5
1 2 3 5 5 5 5
1 2 3 4 5 5 5
1 2 3 4 5 5 5
1 2 3 4 5 6 5

c. 1 2 3 4 5 d. L
1 2 3 4 AL
1 2 3 PAL
1 2 E PAL
1 N E PAL

222 New Gateway to Computer Science Book -10


e. C O M P U T E R f. D H A D I N G
C O M P U T E HADING
C O M P U T ADING
C O M P U DING
C O M P ING
C O M NG
C O G
C
g. P R O G R A M M I N G
ROGRAMMIN
OGRAMMI
GRAMM
RAM
A
3. Write the output of the given program.
a. DECLARE FUNCTION TEST(N)
CLS
FOR J=3 TO 9 STEP 2
X= TEST(J)
PRINT X
NEXT J
END
FUNCTION TEST(N)
TEST= (N^2)+2
END FUNCTION

New Gateway to Computer Science Book -10 223


c. DECLARE FUNCTION Interest(p,t,r) d. DECLARE FUNCTION AREA(L,B)
CLS CLS
LET p=30 LET L =100
LET t=40 LET B = 20
LET r=6 LET ans = AREA(L,B)
LET d=Interest(p,t,r) PRINT “The area=”,ans
PRINT “The simple interest will be”; END
d
END FUNCTION AREA(L,B)
FUNCTION Interest(p,t,r) ar=L*B
answer = (p*t*r)/100 AREA=ar
Interest=answer END FUNCTION
END FUNCTION

e. DECLARE FUNCTION xyz (n)


CLS
FOR i = 1 TO 5
READ n
z = xyz(n)
s = s + z
NEXT
PRINT s
DATA 10 , 13 , 15 , 4 , 6
END
FUNCTION xyz (n)
IF n MOD 2 = 0 THEN
xyz = n
END IF
END FUNCTION

224 New Gateway to Computer Science Book -10


4. Re-write the given programs after correcting the bugs.
a. DECLARE FUNCTION xyz$ (N$) b. DECLE FUNCTION CIR(A)
CLS CLS

INPUT “Enter your Name”; N$ INPUT “enter radius of a circle”; R

FOR i = 1 TO 10 PRINT “circumference is” CIR(R)

NV$ = yz$(N$) END FUNCTION

PRINT N FUNCTION CIR(B)

NEXT P=3.14

END CIR=2*PI*A

FUNCTION xyz$ (y$) FUNCTION

xyz$ = c$
END FUNCTION

c. DECLARE FUNCTION CHECK(N)


CLS d. DECLARE FUNCTION series (i)
INPUT “Enter any number”; N
IF A=ARM THEN CLS
A=N FOR i = 1 TO 5
ARM=CHECK (T)
PRINT “Armstrong number” PRINT series(n);
ELSE END
PRINT “Not Armstrong number”
END IF NEXT
END
FUNCTION series (i)
FUNCTION CHECK (N)
S=5 s=i^3
WHILE N<>0
R=N MOD 10 S = series
S=S+R^3 FUNCTION END
N=N\10
END
S = CHECK
END FUNCTION

New Gateway to Computer Science Book -10 225


e. DECLARE FUNCTION FACT(N)
CLS
INPUT “Enter any number” N
END
PRINT “The factorial is” FACT (N)
FUNCTION FACT (N)
F=10
F=F*I
NEXT I
FOR I=1 TO N
FACT=F
END FUNCTION
5. Study the following programs and answer the given questions.
a. DECLARE FUNCTION AB(n)
CLS
INPUT “Enter any number”; x
PRINT “Result=”; AB(x)
END
FUNCTION AB(n)
WHILE n<>0
r= n mod 10
s=s*10+r
n=n\10
WEND
AB=s
END FUNCTION
i. What output will be displayed by the computer if you enter 54?
ii. List out the arithmetic operators used in the above program.
b. DECLARE FUNCTION ADD(N)
CLS
FOR CNT= 1 TO 3
READ NUM

226 New Gateway to Computer Science Book -10


PRINT ADD(NUM)
NEXT CNT
DATA 8, 7, 3
END
FUNCTION ADD(N)
S=0
FOR G= 1 TO N
S=S+G
NEXT G
ADD=S
END FUNCTION
i. Name the actual and formal parameter used in the above program.
ii. What is the value of NUM when the value of CNT is 2?
c. DECLARE FUNCTION Num (N)
INPUT N
S = Num (N)
PRINT S
END
FUNCTION Num (N)
x = int 917/N)
Y = 15 MOD N
Num = X + Y
END FUNCTION
i. Write the name of the function used in the above program.
ii. List out the mathematical function (Library) used in the above program.
d. DECLARE FUNCTION COUNT (A$)
Input “Enter a word”; w$
END
FUNCTION Count (A$)
B = LEN (A$)
C$ = UCASE$ (A$)
FOR = 1 TO B
E$ = MID$ (C$ I, 1)
IF E$ = “A” OR E$ = “E” OR E$ = ‘i’

New Gateway to Computer Science Book -10 227


OR E$ = “O” OR E$ = “U” THEN
C=C+1
END IF
NEXT I
Count = C
END FUNCTION
i. List the string library functions used in the above program.
ii. Write down the missing statement in the main module to execute the program.
e. DECLARE FUNCTION NUM(N)
CLS
N=14
PRINT NUM(N)
END
FUNCTION NUM(N)
WHILE N<>0
R=N MOD 2
S=S+R*10^P
P=P+1
N=N\2
WEND
NUM=S
END FUNCTION
i. List the local variable used in the function procedure.
ii. What will be the output of the program?
iii. Name of operators used in the above program.
f. DECLARE FUNCTION JPT (N)
FOR ctr = 1 TO 6
READ N
J = JPT (N)
Sum = Sum + J
NEXT ctr
PRINT Sum
DATA 10, 20, 30, 40, 50, 60
END

228 New Gateway to Computer Science Book -10


FUNCTION JPT (N)
IF N MOD 2 = 0 THEN JPT = N
END FUNCTION
i) What is name of the function used in the above program?
ii) How many times will the function be executed in the above program?
g. DECLARE FUNCTION Diff(A,B)
CLS
INPUT “Enter first number”; A
INPUT “Enter second number”; B
PRINT “The difference of the two number=”;Diff(A,B)
END
FUNCTION Diff(A,B)
D=A-B
Diff=D
END FUNCTION
i) What will be the output of the program if the user enters 200 as the first number
and 100 as the second number?
ii) Will the program run if the first line (i.e. DECLARE…..) is deleted?
h. DECLARE FUNCTION Prod(A,B)
CLS
INPUT “Enter first number:”;A
INPUT “Enter second number:”;B
PRINT “the product of two number=”;Prod(A,B)
END
FUNCTION Prod(A,B)
P=A*B
Prod=P
END FUNCTION
i) List all the numerical variables used in the program.
ii) List all the local variables used in the program.
i. DECLARE FUNCTION count(N$)
Input “Enter a word”; R$
C= Count(R$)
Print C

New Gateway to Computer Science Book -10 229


END
FUNCTION count(N$)
For k=1 to LEN(n$)
X$=MID$(N$,K,1)
IF UCASE$(X$)=”A” then
X=X+1
End if
Next K
Count = X
END FUNCTION
i) List any two library functions used in the above program.
ii) Write the use of variable ‘C’ in line 3 [i.e. C=Count(R$)] given above.
j. DECLARE FUNCTION check(a)
CLS
FOR i=1 TO 4
READ n
IF check(n) = 1 THEN PRINT n
NEXT i
DATA 256, 432, 125, 361
FUNCTION check(n)
s=SQR(n)
IF s=INT(s) THEN
check = 1
ELSE
check = 0
END IF
END FUNCTION
i. What is the output of the above program?
ii. Does the program give the same output if INT() function is replaced by FIX()
function?
iii. If FOR I = 1 to 4 is changed as FOR i=1 to 5, then will the program run? Why?
iv. Replace the FOR…NEXT loop with WHILE….WEND loop.

230 New Gateway to Computer Science Book -10


k. DECLARE FUNCTION NUM (N)
CLS
N = 14
PRINT NUM(N)
END
FUNCTION NUM (N)
WHILE N <> 0
R = N MOD 2
S = S + R * 10 ^ P
P=P+1
N=N\2
WEND
NUM = S
END FUNCTION
i. List out the local variables used in the above program.
ii. What will be the value of S if the value of N = 10?
iii. What will be the output of the above program?
iv. List out the name of the operators used in the above program.

New Gateway to Computer Science Book -10 231


Lesson

10 File Handling in QBASIC

Learning Outcomes

At the end of this lesson, students will be able to:


 tell about file handling.
 explain program file and data file.
 describe the types of files.
 use file handling statements with syntax.
 work with file modes in Qbasic.

File is a collection data or information. Almost all information stored in a computer must
be in a file. In our daily life, we create different types of files such as paint file, word pad
file, excel file, text file, etc. We also save our QBASIC programs with .BAS file extension
that is also a type of file. So, we can say that everything in computer is stored in a file. File
handling is a process to create data file, write data to the data file and read data from it. It
is simply a writing program and storing information in files for future use which helps in
managing data and working with data, we can search data from files, delete it, and so on.
The file of the computer can be categorized into two types which are explained below.

Program File
Program file is a set of instructions written in a computer language for data processing
under unique file name. Program files are associated with providing access and execution
of a program on the computer system. A program file extension is added to a file name by
the program itself. It contains instructions which are used to manipulate data and display
the output. The program files extension of Qbasic is .BAS is extension.

Data File
Data file are a collection of data such as name, address, phone, etc. that are required for
data processing. In data file, related data are stored in a row known as a record. Data file
are stored separately from the program file. It provides data to the program files. Data
files are linked to a program file during the execution. Let’s discuss some advantages of
data files.

232 New Gateway to Computer Science Book -10


 The data stored in data file can be reused as required.
 Single data file can be used by different programs.
 Data file provides flexibility to recover saved data whenever required.
 The data files can be created, modified or deleted as required.

Types of Files

Sequential Access Files


Sequential data file is a file that must be accessed in a sequential order. Data from these
files are read sequentially, item after item, starting at the beginning. Sequential access
file is easy to handle. In the sequential file, we cannot change the existing entry or insert
a new entry. To do this, we should copy the entire content to another file making the
changes on the way and then copy the correct data back in to the original file. We cannot
simply locate or go back to read a particular data item. A disk consists of a number of
concentric circles known as tracks. The data items are stored on these tracks sequentially.

Random Access Files


Random access means the ability to read and write anywhere in the file, where data are
simply appended to the end of the file and is accessed by crossing from the start of the
file in sequential order. Random access files are created on disks that allow us to read or
write from the files in random order. Random access files allow more flexible access than
the sequential files. You can read or write any record directly in a random file without
searching through all the records.

Statements and their Functions with Syntax

OPEN statement: This statement is used to open sequential data file for writing data to the
data file or reading data from the data file using Output, Input, or Append mode.
Syntax: OPEN “FILENAME.DAT” FOR <MODE> AS #FILE NUMBER
WRITE # statement: This statement is used to send or store one or more data items to
the specified file using either output or append mode. It inserts commas between the data
items and it encloses strings in double quotation marks.
Syntax: WRITE # File number, Variable list
PRINT # statement: This statement is used to add spaces between data items while storing
data and it does not enclose strings in double quotation marks.

New Gateway to Computer Science Book -10 233


Syntax: PRINT # Variable list
CLOSE # statement: This statement is used to close only specific files.
Syntax: CLOSE #File number
INPUT # statement: This statement is used to read data of the existing sequential data file
and stores them in a variable.
Syntax: INPUT # File number, variable list
LINE INPUT # Statement: This statement reads the entire line or maximum 255 characters
from the keyboard or sequential file.
Syntax: LINE INPUT # File number, Variable List
EOF () function: This function is used to check the end of file marker while reading the
data from the open sequential file. It returns true if the end of file has been reached and
returns FALSE when the end of file has not been reached.
Syntax: EOF(File Number)
INPUT $ () Statement: This statement returns a specified number of characters from a
data file.
Syntax: INPUT$ (N,# File number)
FILES statement: This statement displays the list of file names of a current directory.
Syntax: FILES(Specs)
NAME AS statement: This statement is used to rename a file.
Syntax: NAME “old name” AS “new name”.
KILL statement: This statement is used to delete a file from the specified disk or directory.
Syntax: KILL “File name”
MKDIR statement: This statement is used to create new directory in a specified location
to manage a file.
Syntax: MKDIR “path”
CHDIR statement: This statement is used to change the default directory on a specified
drive location.
Syntax: CHDIR “location name”
RMDIR statement: This statement is used to delete a directory from a disk. It can remove
only empty directory.
Syntax: RMDIR “Path Name”

234 New Gateway to Computer Science Book -10


File Modes in QBASIC

The purpose of opening data files is called file mode. The Common modes of opening
data files are listed below.
OUTPUT: In file handling this mode is used to create a new sequential file and writes data
into it. It starts writing data always from the beginning of the file.
Syntax: OPEN “filename” FOR file mode AS # file number
Where, file name refers to the name of file that is to open, file mode refers to output,
input or append modes of opening file, file number refers to a reference number to the file
opened.
Example: OPEN “file.dat” FOR OUTPUT AS #2orOPEN “O”, #2, “file.dat”
It opens the file file.dat file in output mode the file is referenced to as file number #2. Here,
the user creates a new file file.dat for the purpose of writing data into the file.
INPUT: In file handling this mode is used to read / display data from the existing data
files.
Example: OPEN “file.dat” FOR INPUT AS #2 or OPEN “I”, #2, “file.dat”
APPEND: In file handling this mode is used to add more records in the existing data file.
It starts adding data after the last record of the previous file.
Example: OPEN “file.dat” FOR APPEND AS #2 or OPEN “A”, #2, “file.dat”

Creating a Sequential File

Creating a file has three stages that we are going to discussed below.
a. Creating a file for output by using a statement such as:
Open “file.dat” FOR OUTPUT AS #1
b. Store the data
This is typically achieved by accepting input from the keyboard and then writing it to
the file using a WRITE#1 statement. The statements that are written to the file must include
the correct channel number. An example of how to store a single record is included
below.
INPUT “Enter the name”; Name$
INPUT “Enter the address” Add$

New Gateway to Computer Science Book -10 235


INPUT “Enter the telephone number”; T
‘ Write data to the file ‘
WRITE #1, Name$, Add$,T
This block of statement will only store one record. If you want to store more records
you need to put these statements inside a loop.
c. Close the file
Sequential files need to be closed when you have finished with them. If you forget
to close it, you will be unable to open the file. To perform this operation you can use the
statement as given below.
CLOSE#1

Example 1

Write a program to store only one record of an employee including his / her employee ID,
name, post and department in data file EMP.DAT
OPEN “EMP.DAT” FOR OUTPUT AS #1
CLS
INPUT “ENTER ID”;I
INPUT “ENTER NAME”; N$
INPUT “ENTER POST”; P$
INPUT “ENTER DEPARTMENT”;D$
WRITE #1,I, N$, P$, D$
CLOSE #1
Example 2
Write a program to store the records of employee including their Employee ID, name,
post and department in a data file EMP.DAT
OPEN “EMP.DAT” FOR OUTPUT AS #2
TOP:
CLS
INPUT “ENTER ID”;I
INPUT “ENTER NAME”; N$
INPUT “ENTER POST”; P$
INPUT “ENTER DEPARTMENT”;D$

236 New Gateway to Computer Science Book -10


WRITE #2,I,N$, P$, D$
INPUT “DO YOU WANT TO CONTINUE? Y/N”;CH$
IF UCASE$(CH$)=“Y” THEN GOTO TOP
CLOSE #1
Example 3
Write a program to store the records of any 10 customers along with their name, address,
product name and price in a sequential data file “product.txt”.
OPEN “product.txt” FOR OUTPUT AS #2
FOR I = 1 TO 10
CLS
INPUT “ENTER CUSTOMER’S NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “ENTER PRODUCT’S NAME”; P$
INPUT “ENTER PRICE” ; P
WRITE #1, N$,A$,P$,P
NEXT I
CLOSE #2
END

Reading a Sequential File

Data read from a sequential file is read in order starting from the beginning of the file. You
should make sure that the statement read the file, read the fields in the same order, they
were written to the file and you stopped reading when the end of file reached. Reading a
sequential file consists of the following three stages.
a. Open the file for reading
OPEN “file.dat” FOR INPUT AS#1
b. Read records from the file
INPUT #1, Name$, Add$, T = Will read an entire records and store the results in
string variables.
PRINT “Name:” Name$ = Print out values to screen in an appropriate format.
PRINT “Address”; Add$
PRINT “Telephone Number”; T

New Gateway to Computer Science Book -10 237


You need to place these statements inside a loop. But how do you know when it is time to
finish reading? You can test for End-of-File using EOF function as below.
DO UNTIL EOF(1)
‘ Read a record
‘ Print it
LOOP
c. When all processing has been done you need to close the file as given below.
CLOSE#1

Example 1
Write a program to display all the records of data file “STUDENT.DAT”.
CLS
OPEN “STUDENT.DAT” FOR INPUT AS #1
DO WHILE NOT EOF(1)
INPUT #1, N$,R,C,S
PRINT “NAME”,“ROLL NO”,“CLASS”,“SECTION”
PRINT N$,R,C,S
LOOP
CLOSE #1
END
Example 2
Write a program to display those records whose salary is greater than 15000 from the data
file “STAFF.DAT”.
OPEN “STAFF.DAT” FOR INPUT AS #1
DO WHILE NOT (EOF)
INPUT #1,N$,ADD$,A,S
IF S>=15000 THEN
PRINT N$,ADD$,A,S
ENDIF
LOOP
CLOSE #1
END

238 New Gateway to Computer Science Book -10


Example 3
Write a program to display all the records from “rec.dat”. Also count how many records
have been displayed.
OPEN “REC.DAT” FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1,A$
C=C+1
WEND
CLOSE#1
PRINT “NO. OF RECORDS DISPLAYED=”;C
END

Adding Records to a Sequential File

Sometimes, we need to go back to a file and add records to the end of it. This is done in a
similar manner to creating a file and adding records. But in this case the file is opened in
a different mode.
OPEN filename FOR APPEND AS #n
Here, the APPEND keyword indicates that any output is going to the end; rather than the
beginning of a file. In #n, n indicates the file number.
Appending records to the end of file consist of the following stages.
a. Open the file
OPEN “file.dat” FOR APPEND AS #1
b. Writing records to the file
INPUT “Enter the name”; N$
INPUT “Enter the address”; Add$
INPUT “Enter telephone number”; T
WRITE #1, N$, Add$, T
c. Closing the file when you have finished
CLOSE #1

New Gateway to Computer Science Book -10 239


Example 1
Write a program to add some data in an existing sequential data file “emp.dat” having
field name, post and salary.
OPEN “EMP.DAT” FOR APPEND AS #1
CLS
DO
INPUT “ENTER NAME” ; N$
INPUT “ENTER POST” ;P$
INPUT “ENTER SALARY” ; S
WRITE #1, N$,P$,S
INPUT “ADD MORE DATA ? (Y/N)” ; C$
CH$=UCASE$(C$)
LOOP WHILE UCASE(CH$)=“Y”
CLOSE#1
END

Example
A sequential data file “STUDENT.DAT” contains few records under the fields name, roll
no and marks for three subjects. WAP to add few more records into the same data file.
OPEN “STUDENT.DAT” FOR APPEND AS #1
TOP :
CLS
INPUT “ENTER ROLL NUMBER”;RN
INPUT “ENTER NAME”; N$
INPUT “ENTER MARKS OF ANY THREE SUBJECTS”;X,Y,Z
WRITE #1,RN,N$,X,Y,Z
INPUT “DO YOU WANT TO CONTINUE?”;CH$
IF UCASE$(CH$) = “Y” THEN GOTO TOP
CLOSE #1
END

240 New Gateway to Computer Science Book -10


Searching for Records

If you are interested in certain records, you have to start at the beginning of the file and
read a record at a time in order. You can read the file of a record at a time and only print
out those records which meet your requirements.

Example 1

WAP to search record according to the supplied name from the data file “RESULT.DAT”
where fields are student’s name, class and marks secured in three subjects.
OPEN “RESULT.DAT” FOR INPUT AS #1
TOP:
CLS
FLAG = 0
INPUT “ENTER NAME TO SEARCH”;S$
WHILE NOT EOF(1)
INPUT #1,N$,C,X,Y,Z
IF UCASE$(S$)=UCASE$(N$) THEN
FLAG =1
PRINT N$,C,X,Y,Z
END IF
WEND
IF FLAG = 0 THEN PRINT “DATA NOT FOUND”
INPUT “DO YOU WANT TO RETRY?”; CH$
IF UCASE$(CH$)= “Y” THEN GOTO TOP
CLOSE #1
END

New Gateway to Computer Science Book -10 241


Practical Section on File Handling

Program 1
Write a program to create a sequential data file “RESULT.DAT” to store name, address
and marks obtained in 3 different subjects of students.
OPEN “RESULT.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$, A$, M1, M2, M3
INPUT “Do you want to continue(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=“Y”
CLOSE #1
END

Program 2
Create a sequential data file “std.dat” to store name and marks obtained in English, Maths
and Science for a few students.
OPEN “STD.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter marks in English”; E
INPUT “Enter marks in Maths”; M
INPUT “Enter marks in Science”; S
WRITE #1, N$, E, M, S
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$) =“Y”
CLOSE #1
END

242 New Gateway to Computer Science Book -10


Program 3
Write a program to create a data file “result.dat” to store name, address and obtained
Marks in three different subjects of students.
OPEN “RESULT.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$, A$, M1, M2, M3
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=“Y”
CLOSE #1
END

Program 4
Create a sequential data file “HOTEL.DAT” to store customer’s name, address, and phone
number. Program should terminate with the user’s choice.
OPEN “HOTEL.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter customers name”; CN$
INPUT “Enter address”; A$
INPUT “Enter phone number”; P#
WRITE #1, CN$, A$, P#
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END

New Gateway to Computer Science Book -10 243


Program 5
WAP to create sequential file “Person.DAT” containing information like name, age, DOB
and sex. Add records in this data file as per the users choice.
OPEN “PERSON.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter age”; A$
INPUT “Enter date of birth”; D$
INPUT “Enter Sex”; S$
WRITE #1, N$, A$, D$, S$
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=“Y”
CLOSE #1
END

Program 6
Create a sequential data file “Price.dat” to store item name, quantity and rate. Also
calculate the total amount. Program should terminate according to the user’s choice.
OPEN “PRICE.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter item name”; N$
INPUT “Enter quantity”; Q
INPUT “Enter rate”; R
T= Q*R
WRITE #1, N$, Q, R
INPUT “Do you want to continue(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=“Y”
CLOSE #1
END

244 New Gateway to Computer Science Book -10


Program 7
Create a sequential data file’post.dat’ to store name and marks of any three subjects. Also
calculate total and percentages only for 15 students.
OPEN “POST.DAT” FOR OUTPUT AS #1
FOR I= 1 TO 15
CLS
INPUT “Enter your name”; N$
INPUT “Enter marks in three different subjects”; M1, M2, M3
T=M1+M2+M3
P= T/3
WRITE #1, N$, M1, M2, M3, T, P
NEXT I
CLOSE #1
END
Program 8
A sequential data file named “rec.dat” contains name, post and salary. Write a program to
display all the records for the employees whose salary is more than 8000.
OPEN “REC.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S>8000 THEN PRINT N$, P$, S
WEND
CLOSE #1
END
Program 9
A sequential data file named “record.dat” contains first name, last name and age. Write a
program to display all the records whose age is more than 60.
OPEN “RECORD.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, FN$, LN$, A

New Gateway to Computer Science Book -10 245


IF A>60 THEN PRINT FN$, LN$, A
WEND
CLOSE #1
END
Program 10
Write a program to open a data file “RECORD.DAT” that contains name, address, date
of birth, e-mail and telephone number of some employees. Now display all those records
whose date of birth is in current month.
OPEN “RECORD.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, D$, E$, T#
B$=LEFT$(D$, 2)
C=VAL(B$)
E$=LEFT$(DATE$, 2)
F=VAL(E$)
IF C=F THEN PRINT N$, A$, D$, E$, T#
WEND
CLOSE #1
END

Program 11
Write a program to display all records having salary less than 2500 from the data file
“ADD.INF” having the field’s name, post and salary.
OPEN “ADD.INF” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S<2500 THEN PRINT N$, P$, S
WEND
CLOSE #1
END

246 New Gateway to Computer Science Book -10


Program 12
WAP to delete some records from “neps.dat” file where computer ask user to enter the
record, which is to be deleted. (Fields are name, address, and telephone number).
OPEN “NEPS.DAT” FOR INPUT AS #1
OPEN “TEMP.DAT” FOR OUTPUT AS #1
CLS
INPUT “Enter name which is to be deleted”; D$
WHILE NOT EOF(1)
INPUT #1, N$, A$, T#
IF UCASE$(D$)<>UCASE$(N$) THEN
WRITE #2, N$, A$, T#
ELSE
PRINT “Deleted data=”; N$, A$, T#
END IF
WEND
CLOSE #1, #2
KILL “NEPS.DAT”
NAME “TEMP.DAT” AS “NEPS.DAT”
END

Program 13
Write a program to open a data file “STUDENT.DAT” that contains name, address,
telephone number and parent’s name of some students. Now display all those records
whose address is “LALITPUR”.
OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, T#, PN$
IF UCASE$(A$) =“LALITPUR” THEN PRINT N$, A$, T#, PN$
WEND
CLOSE #1
END

New Gateway to Computer Science Book -10 247


Program 14
Write a program to search and display only those record whose percentage is more than
60% from the data “RESULT.DAT” which contains student’s symbol number, date of
birth, total marks, percentage and division.
OPEN “RESULT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, SN, D$, T, P, DA$
IF P>60 THEN PRINT SN, D$, T, P, DA$
WEND
CLOSE #1
END
Program 15
A sequential data file “SALARY.DAT” contains the information, employee code,
employees name, post, and basic salary. Write a program to display those records whose
basic salary is in between 10000 to 15000 and post is ‘OFFICER’
OPEN “SALARY.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, EC, EN$, P$, S
IF B$>=10000 AND B$<=15000 AND UCASE$(P$)= “OFFICER” THEN
PRINT EC, EN$, P$, S
END IF
WEND
CLOSE #1
END
Program 16
A sequential data file ‘student.dat’ contains ten students name, roll, house, address. Write
a program to read and display last five student’s record.
OPEN “SALARY.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,n$,r,h$,ad$

248 New Gateway to Computer Science Book -10


FOR I = 1 TO 10
IF I >5 THEN
PRINTn$,r,h$,ad$
NEXT i
WEND
CLOSE#1
END
Program 17
A data file named “Staff.dat” contains staff name, department, post and salary of some
staff. Write a program to count and display total number of records in a file.
OPEN “STAFF.DAT” FOR INPUT AS #1
CLS
C=0
WHILE NOT EOF(1)
INPUT #1, N$, D$, P$, S
C=C+1
WEND
PRINT “Total number of records=”; C
CLOSE #1
END
Program 18
A sequential data file named “Nabil.txt” contains record of clients of a bank including
depositor’s name, deposited amount, time and rate of interest. WAP to display detail of all
depositors including simple interest
OPEN “NABIL.TXT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A, T, R
I=(A*T*R)/100
PRINT N$, A, T, R, I
WEND
CLOSE #1
END

New Gateway to Computer Science Book -10 249


Program 19
WAP that asks a post of the employee and displays his/her records from the sequential
data file “XYZ.REC” having fields name, post, dept and salary.
OPEN “XYZ.REC” FOR INPUT AS #1
CLS
INPUT “Enter post to be searched”; S$
FLAG=0
WHILE NOT EOF(1)
INPUT #1, N$, P$, D$, S
IF UCASE$(S$)=UCASE$(P$) THEN
PRINT N$, P$, D$, S
FLAG=1
END IF
WEND
IF FLAG=0 THEN PRINT “Data not found”
CLOSE #1
END
Program 20
WAP to search record according to the supplied name from the data file “RESULT.DAT”
where fields are student’s name, class and marks secured in three subjects.
OPEN “RESULT.DAT” FOR INPUT AS #1
TOP:
CLS
FLAG = 0
INPUT “ENTER NAME TO SEARCH”;S$
WHILE NOT EOF(1)
INPUT #1,N$,C,X,Y,Z
IF UCASE$(S$)=UCASE$(N$) THEN
FLAG =1
PRINT N$,C,X,Y,Z
END IF
WEND
IF FLAG = 0 THEN PRINT “DATA NOT FOUND”

250 New Gateway to Computer Science Book -10


INPUT “DO YOU WANT TO RETRY?”; CH$
IF UCASE$(CH$)= “Y” THEN GOTO TOP
CLOSE #1
END
Program 21
WAP to delete unnecessary record from the data file named “STUDENT.DAT” according
to the input name and display message if data are not found. The data file contains fields
for student’s name, address and class.
OPEN “STUDENT.DAT” FOR INPUT AS #1
OPEN “TEMP.DAT” FOR OUTPUT AS #2
TOP:
CLS
INPUT “ENTER NAME TO DELETE DATA”; D$
FLAG = 0
WHILE NOT EOF(1)
INPUT #1,N$,A$,C
IF UCASE$(N$) = UCASE$(D$) THEN
PRINT “DATA DELETED”
FLAG = 1
ELSE
WRITE #2,N$,A$,C
END IF
WEND
IF FLAG = 0 THEN PRINT “DATA NOT FOUND”
INPUT “DO YOU WANT TO DELETE ANOTHER DATA?”;CH$
IF UCASE$(CH$) = “Y” THEN GOTO TOP
CLOSE
KILL “STUDENT.DAT”
NAME “TEMP.DAT” AS “STUDENT.DAT”
END

Innovative Task
 Write any five file handling programming in A4 size paper and submit to your
teacher as your project work.

New Gateway to Computer Science Book -10 251


Assignment
1. Answer the following questions.
a. What is file in file handling?
b. Define data file and program file.
c. What are the types of file? Explain them in short.
d. What are the different modes to open a sequential data file?
e. Define output, input and append mode in short.
f. What is the EOF() function?
g. What are the differences between WRITE# and PRINT#?
h. Write down the function of the following statements.
i. OPEN statement ii. PRINT # statement iii. INPUT # statement
iv. INPUT $ () Statement v. NAME AS statement vi. KILL statement
vii. MKDIR statement viii. CHDIR statement ix. RMDIR statement
2. Debug the given program.
a. REM COPY DATA OF “SCR. INF” TO “DEST.INF”
OPEN .SCR.INF. FOR INPUT AS#1
OPEN .DEST.INF. FOR OUTPUT AS #2
WHILE NOT EF( )
INPUT#3, NM$, RN, AGE
WRITE#1, NM$, RN, AGE CLOSE #3, #2
END
COLSE #1, #2
b. REM to input the name of a person, post and salary and store them in a sequential
data file “SAL.DAT”.
OPEN “SAL.DAT” FOR OUTPUT AS #1
DO
INPUT “ENTER THE NAME ” ; N
INPUT “ENTER THE POST” ; P$
INPUT “ENTER THE SALARY” ; S$
PRINT #1 , N$,P,S$
INPUT “DO YOU WANT TO STORE MORE RECORDS ? (Y/N)” ; CH$
LOOP WHILE UCASE(C$)=”Y”
END
CLOSE#1

252 New Gateway to Computer Science Book -10


c. REM to display those record whose salary is greater than 15000 from the data file
“STAFF.DAT”
OPEN “STAFF.DAT” FOR INPUT AS #1
INPUT #1,N$, ADD$, A, S
IF S>=15000 THEN
DO WHILE NOT (EOF)
ENDIF
PR INT N$,ADD$,A,S
NEXT
CLOSE #6
END
3. Write a Qbasic program for the followings.
a. Write a program to store Roll no., Name, Class and Address of any five students.
b. Create a data file to store the records of few employees having name, address, post,
gender and salary fields.
c. A Sequential data file called ‘Marks. dat’ contains NAME, AGE, CITY and
TELEPHONE field. Write a program to display all the contents of that data file.
d. Create a sequential data file “std.dat” to store name and marks obtain in English,
Maths and Science for a few students.
e. A sequential data file called ‘marks.dat’ has stored data under the field heading
Roll No., Name, English, Nepali and Maths. Write a program to display all the
information of those students whose marks in Nepali is more than 50.
f. A Data file “Salary. Dat” contains the information of employee regarding their
Name, Post and Salary. Write a program to display all the information of employee
whose salary is greater than 15,000 and less than 40,000.
g. A sequential data file “Staff.dat” contains the name, address, post and salary of
employees. Write a program to read and display all the records stored in the data
file.
h. Write a program to store Member’s Name, Telephone Number, Age and E-mail ID
in sequential data file MEMBER.TXT. The program should continue or terminate
according to user’s choice.

New Gateway to Computer Science Book -10 253


i. Write a program to search and display only those records whose percentage is
more than 60% from the data file .RESULT.DAT which contains Student’s Symbol
number, Date of birth, Total Marks, Percentage and Division.
j. Write a program to display only those records whose price is 300 or more from a
sequential data file “library.dat” that contains book name, publisher’s name, author’s
name and price.
k. A data file “STAFF. DAT” has stored records of few employees with email ID, First
name, Last name, post and salary. Write a program to display all the records of the
employees whose salary is more than 40,000.
l. A data file “LIB. TXT” consists of Book’s name, Author’s name and price of books.
Write a program to count and display the total number of records present in the
file.
m. A data file “ENFO INF” has numerous records with name, address and telephone
numbers in each record. Write a program to scan all the records form that file and
display only the records with address “DHADING”.
n. A sequential data file named “Nabil.txt” contains record of clients of a bank
including depositor’s name, deposited amount, time and rate of interest. WAP to
display detail of all depositors including simple interest.

254 New Gateway to Computer Science Book -10


Lesson

11 Programming in C

Learning Outcomes

At the end of this lesson, students will be able to:


 identify C programming with its advantages and disadvantages.
 tell the features of C programming.
 explain the elements of C programming.
 define constant, variable, and statements in C programming.
 explain the C programming operators.
 tell the data types and sizes.
 list out the input and output functions used in C.
 write various C programs.

C programming is a machine-independent general-purpose structured programming


language which is very popular and flexible. It was originally developed by Dennis
Ritchie for the UNIX operating system. It was first implemented on the Digital Equipment
Corporation PDP-11 computer in 1972. It is a powerful programming language which is
strongly associated with the UNIX operating system. Even most of the UNIX operating
system is coded in ‘C’. Initially ‘C’ programming was limited to the UNIX operating
system, but as it started spreading around the world, it became commercial, and many
compilers were released for cross-platform systems. C programming runs under a variety
of operating systems and hardware platforms, these days.
C programming is also called a structured programming language because it is used
to solve a large problem, C programming language divides the problem into smaller
modules called functions or procedures each of which handles a particular responsibility.
The program which solves the entire problem is a collection of such functions.
Advantages
 It is simple and easy to understand and implement.
 It is a building block for many other programming languages.
 It is flexible which helps us to run code on any machine without making any changes.
 It has many built-in functions that are helpful when building a program in C.
 It is a structured programming language where complex problems are divided into
smaller blocks or functions.

New Gateway to Computer Science Book -10 255


Disadvantages
 In the C programming language, the errors or the bugs aren’t detected after each line
of code.
 It does not have concept of OOPs so that next programming language C++ was
developed.
 There is no runtime checking in C language.
 As the program extends it is very difficult to fix the bugs.

Structured Programming

Structured programming is also known as modular programming. It is a subset of


procedural programming that applies a logical structure on the program being written
to make it more efficient and easier to understand and modify. Structured programming
frequently employs a top-down design model, in which developers map out the overall
program structure into separate subsections. A defined function or a set of similar functions
is coded in a separate module or sub module, which means that code can be loaded into
memory more efficiently and that modules can be reused in other programs.

Features of C Programming
 C programming is a simple language in the sense that it provides a structured approach,
library functions, data types, etc.
 It is a machine independent language so it can be executed on different machines with
some machine specific changes.
 It is a structured programming language.
 It has lots of inbuilt functions that make the development fast.
 It supports the feature of dynamic memory allocation.
 It provides the feature of pointers. We can directly interact with the memory by using
the pointers. We can use pointers for memory, structures, functions, array, etc.
 In C, we can call the function within the function. It provides code reusability for
every function.

Elements of C Programming

C Character Set
C programming uses the uppercase English alphabets A to Z, the lowercase letters a to z,
the numeric digits 0 to 9, and certain special characters such as !, * , +, - , % , <, > , & , [
], { }, ; , ?, @, “ “, ^ , #, !#, etc.

256 New Gateway to Computer Science Book -10


Identifiers and Keywords
Identifiers are names given to various items in the program, such as variables, functions
and arrays. An identifier consists of letters and digits, in any order, except that the first
character must be a letter. Both upper and lowercase letters are allowed. Some of the valid
identifiers are A, dd234, name_of_std, area, average, TOT, etc.
Keywords are the reserved words in the programming which are defined in the C
compiler. We cannot use the C keywords as the name of variable’s and function’s name,
etc. C has 32 keywords which are listed below in the table.

auto case break char


const continue default void
double else enum extern
float goto for do
long int register return
short signed sizeof static
struct switch volatile while
unsigned if typedef Union

Constants
Constants are those values which never change during the execution of the program. There
are various constants in C programming. Some of the constants are explained below.
Character constant: Character constant is always enclosed in single quotes such as ‘A’. It
indicates only one character such as char = ‘B’
Integer constant: A normal integer constant is written as 5647. It includes both positive
and negative numbers such as int num = 150, int num = -140.
Long integer constant: A long integer is recognized by the presence of L (uppercase or
lowercase) at the end of the constant, for example: 2748723L.
Floating point constants: A floating point constant contains a decimal point (555.102)
or an exponent (1e-2) or both. Their type is double unless suffixed. The suffix of f or F
indicates float; 1 or L indicates long double.
String constant: It is a sequence of characters which is written in pair of double quotes
(“ “). It is declared as array of characters. A string constant may consist of any combination
of digits, letters, escaped sequences and spaces. It also includes numbers but such numbers
cannot be used for mathematical calculations. Some examples of string constants are char
name = “Divyansh”, char age = “15”, etc.

New Gateway to Computer Science Book -10 257


Rules for Constructing String constants
 A string constant may consist of any combination of digits, letters, escaped sequences
and spaces enclosed in double quotes.
 Every string constant ends up with a NULL character which is automatically assigned
(before the closing double quotation mark) by the compiler.
Difference between single character constant and string constant

Single Character Constant String Constant


It is enclosed within single inverted A sequence of characters is enclosed in
commas. double quotes.
The maximum length of a character A string constant can be of any length.
constant can be one character.
A single character constant has an A single character string constant does not
equivalent integer value. have an equivalent integer value.
A single character constant occupies one A single string constant occupies two
byte. bytes.

Variables
A variable defines a location name where we can put value and we can use these values
whenever required in the program. Variable is a name or identifier which indicates some
physical address in the memory, where data will be stored in the form of the bits of string.
The value of a variable can be changed at different times of executions and it may be
chosen by the programmer.
Rules for naming variable:
 Variable name must begin with letter or underscore.
 Variables are case sensitive.
 Variables name can be constructed with digits, letters.
 Special symbols are not allowed other than underscore.
 C keywords are not allowed to use.

Statements
A statement is a command given to the computer that instructs the computer to take
a specific action, like display message on the console, performing the mathematical
operation and so on. In C program, collection of statements and each statement must be
terminated with a semicolon (;).

258 New Gateway to Computer Science Book -10


Operators
C language offers many types of operators. They are,
 Arithmetic operators
 Assignment operators
 Relational operators
 Logical operators
 Bit wise operators
 Conditional operators (ternary operators)
 Increment/decrement operators
 Special operators
Arithmetic Operators
C Arithmetic operators are used to perform mathematical calculations like addition,
subtraction, multiplication, division and modulus in C programs. Some of the arithmetic
operators with their examples are listed below in the table.
Arithmetic Operators/Operation Example
+ (Addition) A+B
– (Subtraction) A-B
* (multiplication) A*B
/ (Division) A/B
% (Modulus) A%B
Assignment Operators
These are used to assign the values for the variables in C programs. In C programs, values
for the variables are assigned using assignment operators. For example, if the value “10”
is to be assigned for the variable “sum”, it can be assigned as “sum = 10;” There are 2
categories of assignment operators in C language. They are, simple assignment operator
such as = (equals to) and compound assignment operators such as +=, - =, * =, / =, % =,
& =, ^ = .

Operators Example/Description Example


= Assignment x+y
+= Add to x+=y
-= Subtract from x-=y
*= Multiply by x*=y
/= Divide by x/=y
%= Modulo by x%=y

New Gateway to Computer Science Book -10 259


Relational Operators
These operators are used to compare the value of two variables. It is used to find the
relation between two variables. Some of the relational operators with their examples are
listed below in the table.

Operators Example/Description
> x > y (x is greater than y)

< x < y (x is less than y)

>= x >= y (x is greater than or equal to y)

<= x <= y (x is less than or equal to y)

== x == y (x is equal to y)

!= x != y (x is not equal to y)

Logical Operators
These operators are used to perform logical operations on the given two variables. There
are three logical operators in C language. They are, logical AND (&&), logical OR (||)
and logical NOT (!).

Operators Example/Description
&& (logical AND) (x>5)&&(y<5)
It returns true when both conditions are true.
|| (logical OR) (x>=10)||(y>=10)
It returns true when at-least one of the conditions is true.
! (logical NOT) !((x>5)&&(y<5))
It reverses the state of the operand “((x>5) && (y<5))”
If “((x>5) && (y<5))” is true, logical NOT operator makes it
false.
Bit wise Operators
These operators are used to perform bit operations. Decimal values are converted into
binary values which are the sequence of bits and bit wise operators work on these bits.
Bit wise operators in C language are & (bitwise AND), | (bitwise OR), ~ (bitwise NOT),

260 New Gateway to Computer Science Book -10


^ (XOR), << (left shift) and >> (right shift). Below are the bit-wise operators and their
name in c language.
 & : Bitwise AND  | : Bitwise OR
 ~ : Bitwise NOT  ^ : XOR
 << : Left Shift  >> : Right Shift
Conditional Operators (Ternary Operators)
Conditional operators return one value if condition is true and returns another value is
condition is false. This operator is also called as ternary operator. The (?) Question mark
and (:) colon are the ternary operators used in C programming.
Syntax: (Condition? true_value: false_value);
Increment / Decrement Operators
Increment operators are used to increase the value of the variable by one and decrement
operators are used to decrease the value of the variable by one in C programs. These
operators are also called as a Unary operator. Below are the unary operators used in C
programming.

Operators Description
It is an increment operator which increases the value of operand.
++
Such as num = x ++ , num = ++ x.
It is a decrement operator which decreases the value of operand.
--
Such as num = x -- , num = -- x.
Syntax:
Increment operator: ++var_name; (or) var_name++;
Decrement operator: – -var_name; (or) var_name – -;
Special Operators
Below are some of the special operators that the C programming language offers.

Operators Description
& This is used to get the address of the variable.

* This is used as a pointer to a variable.

Sizeof () This gives the size of the variable.

New Gateway to Computer Science Book -10 261


Data Types and Sizes

There are few basic data types in C. They are listed in the table below:

Data type Description Size Range


char It is used to store single character or 1 byte 0 - 255
alphabet.
int It is used to store numeric value without 4 bytes -2147483648 to
decimal portion. 2147483647
float It is used to store single precision floating 4 bytes 3.4E-38 to 3.4E+38
point number. Such number may contain
fraction & or an exponent.
double It is used to store double precision floating 8 bytes 1.7E-308 to
point number with decimal places. 1.7E+308
The list of data types can be increased by using the data type qualifiers such as - short,
long, and unsigned. For example, an integer quantity can be defined as long, short, signed
or unsigned integer. The memory requirement of an integer data varies depending on the
compilers used. The qualified basic data types and their sizes are shown in table below.

Data type Size Range


short int 2 bytes -32768 to 32767
long int 4 bytes -2147483648 to 2147483647
unsigned short int 2 bytes 0 to 65535
unsigned int 4 bytes 0 to 4294967295
unsigned long int 4 bytes 0 to 4294967295
long double (extended precision) 8 bytes 1.7E-308 to1.7E+308

Input and Output Functions used in C

C programming has various library functions for data input and output, such as getchar,
putchar, scanf, printf, gets and puts. All these built-in functions are present in C header
files. These functions enable the transfer of data between the C program and standard
input/output devices. Input function means to provide the program with some data to be
used in the program and output function means to display data on screen or write the data
to a printer or a file.

262 New Gateway to Computer Science Book -10


scanf ( ) function
The scanf function is used to read formatted input data. The format in which input data is
to be provided is specified by the scanf function itself as its first parameter. The syntax of
scanf function is given below.
Syntax: scanf(<control string>, &address1, &address2, . . . , &address n);
In the above syntax the first parameter <control string> contains a list of format specifiers
indicating the format and type of data to be read. The remaining parameters - &address1,
&address2, ..., &address n are addresses of the variables where the read data will be stored.
scanf reads the input data as per the format specifiers and stores them to the corresponding
addresses. In the above syntax & is pre-fixed to the variable name to denote its address.
There must be the same number of format specifiers and addresses as there are input data.
For instance, in the following example:
Example: scanf(“%d %f”,&x,&y);
In the above example, the first argument is a string that contains two format specifiers-
%d and %f, the first format specifier (%d) is for argument &x and the second one (%f) is
for the argument &y. So, two pieces of input data will be read - the first piece is treated
according to %d and the second one is treated according to %f. Format specifiers in the
<control string> are always specified for the remaining arguments, in order, from left to
right.
The format specifiers described in the table below apply to both scanf and printf functions.

Format Input Data (scanf) Output Data (printf)


Specifier
%c reads a single character single character
%d reads a numeric value as signed int. Treats signed decimal integer
the input data as a decimal number.
%i can read data value provided either as a print as a signed decimal
decimal int, hexadecimal int or octal int integer.
%o reads data value as an octal number prints data as an octal integer
without leading zero.
%x reads data value as a hexadecimal number prints data as a hexadecimal
integer without leading 0x.
%u reads data value as an unsigned integer prints as an unsigned integer.
%f reads data as a floating point value without prints as a floating point value
the exponent. (without exponent)

New Gateway to Computer Science Book -10 263


printf()

The printf function is used to output data onto the standard output device. In general, the
printf function is written as

Syntax: printf(<control string>, arg1, arg2, . . . , argn);

where the <control string> refers to a string containing required formatting information
as in scanf, and arg1, arg2, ..., argn are individual data variables whose values are to
be printed. However, unlike scanf, these data variable names are not preceded by the &
symbol. This is because printf is expected to only output the values of these variables and
not their addresses.

getchar()

This is a single character input function. getchar() reads a single character from the
standard input data stream. When you input a single character for the C program to read,
you must indicate end of data stream or end of input by pressing the return/enter key after
entering your response character.

putchar()

This is a single character output function. putchar() writes a single character to the standard
output data stream. The file associated with the standard output device, is normally the
console.

gets() and puts()

The standard library function gets accepts input in the form of a string. The character
string may even include white space characters. Each call to gets will read all the
characters from the input steam until an end of line character is encountered. The end of
line character is represented as \n and gets generated when you press the enter key. gets
assigns the read string to the variable that is passed as its parameters. gets assigns NULL
when an error occurs.

clrscr() function

The clrscr() function is used to clear the screen and move cursor to upper left hand corner
of screen. It can be used anywhere in the program. It is better to use before the declaration
part.

264 New Gateway to Computer Science Book -10


Understanding Header File

A header file is a file having an extension .h which contains C function declarations macro
definitions. It holds the definitions of various functions and their associated variables
that need to be imported into your C program with the help of pre-processor #include
statement. The default header file that comes with the C compiler is the stdio.h. Including
a header file means that using the content of header file in your source program. The basic
syntax of using these header files is given below.
Syntax: #include <file>
Some common header files included in C programming are listed below.
#include<stdio.h>: This standard input-output header file is used to perform input and
output operations in C such as scanf() and printf().
#include<string.h>: This string header file is used to perform string manipulation
operations like strlen and strcpy.
#include<conio.h>: The console input-output header file is used to perform console
input and console output operations like clrscr() to clear the screen and getch() to get the
character from the keyboard.
#include<stdlib.h>: The standard library header file is used to perform standard utility
functions like dynamic memory allocation, using functions such as malloc() and calloc().
#include<math.h>: The math header file is used to perform mathematical operations like
sqrt() and pow(). To obtain the square root and the power of a number respectively.
#include<ctype.h>: The character type header file is used to perform character type
functions like isaplha() and isdigit(). To find whether the given character is an alphabet
or a digit respectively.
#include<time.h>: The time header file is used to perform functions related to date
and time like setdate() and getdate(). To modify the system date and get the CPU time
respectively.
#include<graphics.h>: This header file provides access to a simple graphics library that
makes it possible to draw lines, rectangles, ovals, arcs, polygons, images, and strings on
a graphical window.

New Gateway to Computer Science Book -10 265


Program Writing

Example 1
Write a program to Display “ Shubharambha Publication Pvt. Ltd. “
#include <stdio.h>
int main()
{
printf(“Shubharambha Publication Pvt.Ltd”);
return 0;
}

Output
Shubharambha Publication Pvt.Ltd

 In the above program, the #include<stdio.h> is a pre-processor command. This


command tells the compiler to include the contents of stdio.h (standard input and output)
file in the program. The stdio.h file contains functions such as scanf() and print() to
take input and display output respectively. If you use printf() function without writing
#include <stdio.h>, the program will not be compiled.
 The execution of a C program starts from the main() function.
 The printf() is a library function to send formatted output to the screen. In this program,
the printf() displays Shubharambha Publication Pvt. Ltd text on the screen.
 The return 0; statement is the “Exit status” of the program. The program always ends
with this statement.

Example 2
Write a program to add any two integers.
#include <stdio.h>
int main()
{
int firstNumber, secondNumber, sum;
printf(“Enter two integers: “);
scanf(“%d %d”, &firstNumber, &secondNumber);

266 New Gateway to Computer Science Book -10


sum = firstNumber + secondNumber;
printf(“%d + %d = %d”, firstNumber, secondNumber, sum);
return 0;
}

Output
Enter two integers: 20 10
20 + 10 = 30

 In this program, the user is asked to enter two integers. Two integers entered by the user
is stored in variables firstNumber and secondNumber respectively. This is done using
scanf() function. Then, variables firstNumber and secondNumber are added using +
operator and the result is stored in sum.
 Finally, the sum is displayed on the screen using printf() function.

Example 3
Write a program to input temperature in Celsius and display the temperature in Fahrenheit.
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
printf(“Enter the temperature in celcius :”);
scanf(“%f”, &celsius);
fahrenheit = 9.0 / 5 * celsius + 32;
printf(“Temperature in fahrenheit : %0.2f”, fahrenheit); r
eturn 0;
}

Example 4
Write a program which accepts principle, rate and time from user and prints the simple
interest.
#include <stdio.h>
int main()
{

New Gateway to Computer Science Book -10 267


float principle, rate, time, si;
printf(“Enter the principle :”);
scanf(“%f”, &principle);
printf(“Enter the rate :”);
scanf(“%f”, &rate);
printf(“Enter the time :”);
scanf(“%f”, &time);
si = principle * rate * time / 100;
printf(“Simple interest is %0.2f”, si);
return 0;
}
Example 5
Write a program that asks the user to input the length of sides of the triangle and prints
the area.
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, s, area;
printf(“Enter the length of side 1 :”);
scanf(“%f”, &a);
printf(“Enter the length of side 2 :”);
scanf(“%f”, &b);
printf(“Enter the length of side 3 :”);
scanf(“%f”, &c);
s = (a + b + c) / 2;
area = sqrt(s*(s - a)*(s - b)*(s - c));
printf(“\nThe area of the triangle is %0.2f”, area);
return 0;
}
Example 6
Write a program that prompts the user to input the radius of a circle and outputs the area
and circumference of the circle.
#include <stdio.h>
int main()
{

268 New Gateway to Computer Science Book -10


float radius, area, circumference;
printf(“Enter the radius of the circle :”);
scanf(“%f”, &radius);
area = 3.14 * radius * radius;
circumference = 2 * 3.14 * radius;
printf(“\nThe area of the circle is %0.2f”, area);
printf(“\nThe circumference of the circle is %0.2f”, circumference);
return 0;
}

Control Statements in c
The statements that are used to control the flow of execution of statements are known
as conditional control statements. Control statements enable us to specify the flow of
program control. It is the order in which the instructions in a program must be executed.
They make it possible to make decisions, to perform tasks repeatedly or to jump from one
section of code to another.
if statement
This is a popular decision making statement and is used to control the flow of execution
of statements. It is basically a two way decision statement and is used in conjunction with
as expression .The syntax is given below.
If(test condition)
{
statements;
}
If-else statement
The if-else statement is used to carry out a logical test and then take one of two possible
actions depending on the outcome of the test (i.e., whether the outcome is true or false).
The syntax for if-else statement is given below.
if (condition)
{
statements
}
else
{
statements
}

New Gateway to Computer Science Book -10 269


Example 7
A program to checks whether the entered number is positive or negative.
#include<stdio.h>
int main( )
{
int a;
printf(“n Enter a number:”);
scanf(“%d”, &a);
if(a>0)
{
printf( “n The number %d is positive.”,a);
}
else
{
Nested else-if Statements
The else-if statement is useful when you need to check multiple conditions within the
program, nesting of if-else blocks can be avoided using else-if statement. The syntax of
this statement is given below.
if(condition1)
{
// statement(s);
}
else if(condition2)
{
//statement(s);
}
else if (conditionN)
{
//statement(s);
}
else
{
//statement(s);
}

270 New Gateway to Computer Science Book -10


Example 8
A program to find the greatest of three numbers.
#include<stdio.h>
int main( )
{
int a, b,c;
a=6,b= 5, c=10;
if(a>b)
{
if(b>c)
{
printf(“nGreatest is: “ , a);
}
else if(c>a)
{
printf(“nGreatest is: “, c);
}
}
else if(b>c) //outermost if-else block
{
printf(“nGreatest is: “ , b);
}
else
{
printf( “nGreatest is: “ , c);
}
return 0;
}

Looping Statements in c
When you need to execute a block of code several number of times then you need to use
looping statement in C. In C programming language there are three types of loops they
are while, for and do-while.
While loop
This loop checks the condition at first. Iif the condition is true then control goes inside
the loop body otherwise it goes outside the body. It repeats in clock wise direction. The
syntax is given below.

New Gateway to Computer Science Book -10 271


while(condition)
{
Statements;
......
Increment/decrements (++ or --);
}
Example 9
#include<stdio.h>
Output
#include<conio.h>
1
void main()
{ 2
int i; 3
clrscr(); 4
i=1;
while(i<5)
{
printf(“\n%d”,i);
i++;
}
getch();
}
For loop
A for loop is a repetition control structure which allows us to write a loop that is executed
a specific number of times. The loop enables us to perform n number of steps together in
one line. The syntax is given below.

for (initialization expr; test expr; update expr)


{
// body of the loop
// statements we want to execute
}
Example 10
#include<stdio.h>
#include<conio.h>
void main()
{

272 New Gateway to Computer Science Book -10


int i;
clrscr(); Output
for(i=1;i<5;i++) 1
{ 2
printf(“\n%d”,i); 3
} 4
getch();
}

Do loop
A do while loop is a control flow statement that executes a block of code at least once,
and then repeatedly executes the block, or not, depending on a given condition at the end
of the block (in while). The syntax is given below.
do
{
Statements;
........
Increment/decrement (++ or --)
} while();

Example 11
#include<stdio.h>
#include<conio.h>
void main()
{
int i; Output
clrscr(); 1
i=1; 2
do 3
{ 4
printf(“\n%d”,i);
i++;
}
while(i<5);
getch();
}

New Gateway to Computer Science Book -10 273


Practical Section in C Programming

Program 1
Write a program that allows the user to input two integers and displays the largest integer.
#include <stdio.h>
int main()
{
int num1, num2;
printf(“Enter two integers :”);
scanf(“%d%d”, &num1, &num2);
if (num1 > num2)
{
printf(“Largest number is %d.”, num1);
}
else
{
printf(“Largest number is %d.”, num2);
}
return 0;
}
Program 2
Write a program that prompts the user to input a number and displays if the number is
even or odd.
#include <stdio.h>
int main()
{
int num;
printf(“Enter a num:”);
scanf(“%d”, &num);
if(num % 2 == 0)
{
printf(“The number is even”);
}

274 New Gateway to Computer Science Book -10


else
{
printf(“The number is odd”);
}
return 0;
}
Program 3
Write a program that prompts the user to input a number and prints its factorial.
#include <stdio.h>
int main()
{
int i, n, fact = 1;
printf(“Enter a number :”);
scanf(“%d”, &n);
for (i = 1; i <= n; i++)
{
fact *= i;
}
printf(“The factorial of %d is %d.”, n, fact);
return 0;
}

Program 4
Write a program in C to read 10 numbers from keyboard and find their sum and average
by using for loop.
#include <stdio.h>
void main()
{
int i,n,sum=0;
float avg;
printf(“Input the 10 numbers : \n”);
for (i=1;i<=10;i++)
{

New Gateway to Computer Science Book -10 275


printf(“Number-%d :”,i);
scanf(“%d”,&n);
sum +=n;
}
avg=sum/10.0;
printf(“The sum of 10 no is : %d\nThe Average is : %f\n”,sum,avg);
}
Program 5
Write a program to print the numbers between 1 and 100 which are multiple of 3 using
the do while loop.
#include<stdio.h>
int main()
{
int i = 1;
do
{
if(i % 3 == 0)
{
printf(“%d “, i);
}
i++;
}while(i < 100);
return 0;
}

Program 6
Write a C program to print ODD numbers from 1 to N using while loop.
#include <stdio.h>
int main()
{
int number;
int n;
number=1;

276 New Gateway to Computer Science Book -10


printf(“Enter the value of N: “);
scanf(“%d”,&n);
printf(“Odd Numbers from 1 to %d:\n”,n);
while(number<=n)
{
if(number%2 != 0)
printf(“%d “,number);
number++;
}
return 0;
}
Program 7
Write a program to display a number if it is negative.
#include <stdio.h>
int main() {
int number;
printf(“Enter an integer: “);
scanf(“%d”, &number);
if (number < 0) {
printf(“You entered %d.\n”, number);
}
printf(“The if statement is easy.”);
return 0;
}
Program 8
Write a C program to check whether the entered number is prime or not.
#include <stdio.h>
int main() {
int n, i, flag = 0;
printf(“Enter a positive integer: “);
scanf(“%d”, &n);
for (i = 2; i <= n / 2; ++i) {
// condition for non-prime

New Gateway to Computer Science Book -10 277


if (n % i == 0) {
flag = 1;
break;
}
}
if (n == 1) {
printf(“1 is neither prime nor composite.”);
}
else {
if (flag == 0)
printf(“%d is a prime number.”, n);
else
printf(“%d is not a prime number.”, n);
}
return 0;
}

Program 9
Write a program to print all uppercase alphabets using while loop.
#include <stdio.h>
int main()
{
char alphabet;
alphabet=’A’;
printf(“Uppercase alphabets:\n”);
while(alphabet<=’Z’)
{
printf(“%c”,alphabet);
alphabet++;
}
return0;
}

278 New Gateway to Computer Science Book -10


Program 10
Write a program to print the numbers from 1 to 100 using while loop in C.
#include <stdio.h>
int main()
{
int number;
number=1;
printf(“Numbers from 1 to 100: \n”);
while(number<=100)
{
printf(“%d”,number);
number++;
}
return0;
}

Program 11
Write a program using while or do while loop to read any integer number and print its
multiplication table.
#include <stdio.h>
int main()
{
intnum;
int i;
printf(“Enter an integer number: “);
scanf(“%d”,&num);
i=1;
while(i<=10){
printf(“%d\n”,(num*i));
i++;/*Increase loop counter*/
}
return0;
}

New Gateway to Computer Science Book -10 279


Program 12
Write a program to print all upper case and lower case alphabets.
#include <stdio.h>
int main()
{
char i;
printf(“Capital (upper) case characters:\n”);
for(i=’A’; i<=’Z’; i++)
printf(“%c”,i);
printf(“\n\nLower case characters:\n”);
for(i=’a’; i<=’z’; i++)
printf(“%c”,i);
return0;
}

Program 13
Write a program to print the uppercase and lowercase alphabets from A to K.
#include <stdio.h>
int main()
{
char i;
printf(“Capital (upper) case characters:\n”);
for(i=’A’; i<=’K’; i++)
printf(“%c”,i);
printf(“\n\nLower case characters:\n”);
for(i=’a’; i<=’k’; i++)
printf(“%c”,i);
return0;
}

280 New Gateway to Computer Science Book -10


Program 14
Write a program to find sum of natural numbers in given range.
#include <stdio.h>
int main()
{
int i, start, end, sum=0;
printf(“Enter lower limit: “);
scanf(“%d”,&start);
printf(“Enter upper limit: “);
scanf(“%d”,&end);
for(i=start; i<=end; i++)
{
sum+= i;
}
printf(“Sum of natural numbers from %d to %d = %d”, start, end, sum);
return0;
}
Program 15
Write a program to count the total digits in a given integer using loop.
#include <stdio.h>
int main()
{
longlongnum;
int count = 0;
printf(“Enter any number: “);
scanf(“%lld”, &num);
while(num != 0)
{
count++;
num /= 10;
}
printf(“Total digits: %d”, count);
return0;
}

New Gateway to Computer Science Book -10 281


Innovative Task

 Make a list of 32 keywords used by C programming and make a list of at least 5


format specifier that are being used by C programming and submit to your teacher.

Assignment
1. Answer the following question.
a. What is C programming? Define it with its features.
b. Who was the inventor of C? When was it invented?
c. What are the advantages and disadvantages of C programming?
d. Define structure programming.
e. What are the elements of C programming?
f. Define C constant with its types.
g. What are the rules for naming variables?
h. Write differences between single character constant and string constant.
i. List out the operators used by C language.
j. Explain logical operators.
k. Define conditional operators with syntax.
l. What are the various data types used by C language?
m. List out some of the input and output functions used in C.
n. Write down the name of some format specifiers used by C.
o. Define header file with syntax.
p. What is control statement? Explain some control statements with syntax.
q. What is looping statement? Write down the types of looping statements with their
syntax.

282 New Gateway to Computer Science Book -10


2. Write a C program for the followings:
a. To input temperature in Celsius and display the temperature in Fahrenheit.
b. To input principle, rate and time from the user and print the simple interest.
c. To prompts the user to input the radius of a circle and outputs the area and
circumference of the circle.
d. To input two integers and displays the largest integer.
e. To input a number and displays if the number is even or odd.
f. To check whether the entered number is divisible by 3 and 5 or not.
g. To check whether the entered number is odd or even.
h. To display the area of four walls.
i. To display the first ten prime numbers.
j. To check whether the entered number is prime or not.
k. To display the greatest number among three different numbers.
l. To display the factorial of a given number.
m. To print the odd numbers from 1 to 100 using while loop, for loop and do loop.
n. To display the small letters from aa to mm.
o. To read any integer number and print its multiplication table.
p. To print the numbers between 1 and 100 which are multiple of 7 using the do
while loop.

New Gateway to Computer Science Book -10 283


List of Abbreviations

AC : Alternate Current
ADSL : Asymmetric Digital Signature Line
ANSI : American National Standard Institute
ARP : Address Resolution Protocol
ARPA : Advance Research Project Agency
ASCC : Automatic Sequence Controlled Calculator
ASCII : American Standard Code for Information Interchange
ATM : Automated Teller Machine
AVI : Audio-Video Interleaved
CAD : Computer Aided Design
CAE : Computer Aided Education
CAM : Computer Aided Manufacturing
CAN : Computer Association of Nepal
CBT : Computer Based Training
CDMA : Code Division Multiple Access
CMOS : Complementary Metallic Oxide Semiconductor
COBOL : Common Business Oriented Language
CREN : Council Research European Network
CRT : Cathode Ray Tube
CSMA/CD : Carrier Sense Multiple Access / Coliseum Detection
CVT : Constant Voltage Transformer
DARPA : Department of Advance Research Project Agency
DBMS : Database Management System
DHCP : Dynamic Host Configuration Protocol

284 New Gateway to Computer Science Book -10


DNS : Domain Name Server
DSP : Digital Signal Processor
DSS : Digital Satellite System
DVD : Digital Video Disk
EBCDIC : Extended Binary Coded Decimal Code
EDP : Electronic Data Processing
E-Mail : Electronic- Mail
FAQ : Frequently Asked Questions
FAT : File Allocation Table
FM : Frequency Modulation
FORTRAN : FORmula TRANslator
FTP : File Transfer Protocol
GIF : Graphic Interchange Format
GPRS : General Pocket Radio Service
GSM : Global System for Mobile communication
HTML : Hyper Text Make up Language
HTTP : Hyper Text Transfer Protocol
IAB : Internet Architecture Board
IBN : Interactive Broadband Network
IBT : Internet Based Training
ICT : Information Communication Technology
IETF : Internet Engineering Task Force
IFIP : International Federation of Information Processing
IP : Internet Protocol
IPX / SPX : Internetwork Packet Exchange / Sequenced Packet Exchange
IRC : Internet Relay Chat

New Gateway to Computer Science Book -10 285


IRTF : Internet Research Task Force
IS : Information Service
ISAPI : Internet Server Application Programming Interface
ISD : International Subscriber Dialling
ISDN : Integrated Service Digital Network
ISO : International Organization for Standardization
ISOC : Internet Society
ISP : Internet Service Provider
ITSP : Internet Telephony Service Provider
JPEG : Joint Photographic Expert Group
LAN : Local Area Network
LCD : Liquid Crystal Display
Mac OS : Macintosh Operating System
MAC : Media Access Control
MAN : Metro Area Network
MAP I : Messaging Application Programming Interface
MBPS : Mega Byte Per Second
MIDI : Musical Instrument Digital Interface
MMS : Multimedia Message Service
MODEM : Modulator and Demodulator
MPEG : Moving Pictures Experts Group
MPOA : Multi Protocol Over ATM
MPPP : Multilink Point-to-Point Protocol
MSAV : Microsoft Antivirus
MSB : Most Significant Bit
MSN : Microsoft Network

286 New Gateway to Computer Science Book -10


MUK : Multimedia Upgrade Kit
NetBEUI : Network Bios(Basic Input Output System) Enhance User Interface
NFS : Network File System
NIC : Network Interface Card
NITDC : National Information Technology Development Council
NOS : Network Operating System
OLE : Object Linking and Embedding
PCO : Public Call Office
PDF : Portable Document Format
POP : Post Office Protocol
PSTN : Public Switch Telephone Network
RARP : Reverse Address Resolution Protocol
RDBMS : Relational Database Management System
RIP : Routing Information Protocol
RJ-45 : Registered Jack - 45
RTF : Rich Text Format
RTP : Real Time Protocol.
SDSL : Symmetric Digital Subscriber Line
SGML : Standard Generalized Mark-up Language
SIM : Subscriber Identification Module
SMS : Short Message Service
SMTP : Simple Mail Transfer Protocol
SNA : System Network Architecture
SPX : Sequence Packet Exchange
SQL : Standard Query Language
STD : Standard Trunk Dialling

New Gateway to Computer Science Book -10 287


STP : Shielded Twisted Pair
TCP/IP : Transmission Control Protocol / Internet Protocol
UHF : Ultra High Frequency
UPS : Uninterruptible Power Supply
URL : Uniform Resource Locator
USB : Universal Serial Bus
USP : Universal Serial Port
UTP : Unshielded Twisted Pair
VCD : Video Cascade Recorder
VHF : Very High Frequency
VOIP : Voice Over Internet Protocol
VSAT : Very Small Aperture Terminal
W3C : World Wide Web Consortium
WAIS : Wide Area Information Server
WAN : Wide Area Network
WAP : Wireless Application Protocol
Wi Fi : Wireless Fidelity
WWW : World Wide Web

288 New Gateway to Computer Science Book -10

You might also like