0% found this document useful (0 votes)
6 views157 pages

A Complete Computer Science Note

Grade 10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views157 pages

A Complete Computer Science Note

Grade 10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

A complete Computer Science Note

Page |1

Contents
1. Introduction Technology Fundamentals.........................................................................................................................2
(1.1) Networking & Telecommunications.......................................................................................................................2
(1.2) Ethical and Social Issues in ICT.............................................................................................................................13
(1.3) Computer Security...............................................................................................................................................16
(1.4) E-Commerce.........................................................................................................................................................20
(1.5) Contemporary Technology..................................................................................................................................23
FULL FORMS.............................................................................................................................................................28
TECHNICAL TERMS...................................................................................................................................................31
2. Database Management System...................................................................................................................................33
(2.1) Introduction.........................................................................................................................................................33
3. Programming in QBASIC...............................................................................................................................................38
(3.1) Programming in QBASIC......................................................................................................................................38
Modular Programming Solutions.............................................................................................................................40
Output Solutions with Dry run.................................................................................................................................50
Debugging Solutions.................................................................................................................................................68
Analytical Questions Solutions.................................................................................................................................84
(3.2) File processing (file handling)..............................................................................................................................94
File Handling Programming Solutions......................................................................................................................96
4. C- Programming..........................................................................................................................................................106
1. Introduction to C-Language Programming.............................................................................................................106
C PROGRAMMING Solutions..................................................................................................................................110
Page |2
Page |3

[Link] Technology Fundamentals


(1.1) Networking & Telecommunications
Communication
The process of sending and receiving data and information between two or more than two people is known as
communication.

Telecommunication
The transmission of data and information from one place to another for the purpose of communication is known as
telecommunication. E.g. mobile phone, Internet phone, television, landline, radio, etc.

Data communication
Data communication is the process of transferring data and information between computers and other electronic
devices. E.g. E-Mail, Chat and phone calls

Components of Data Communication


The five basic components (data, sender, medium, receiver and protocol) are required to make data communication.

Data (message) : Data is to be communicated between sender and receiver.


Sender : Sender is a device used to transfer data.
Medium: Medium is a channel through which sender and receiver make communication.
Receiver: Receiver is a device used to receive data.
Protocol: Protocol is a set of rules followed by sender and receiver.

Data Transmission Mode


Data transmission mode is the way of transmission of data from one location to another.
There are three types of transmission mode:
i) Simplex mode
ii) Half duplex mode
iii) Full Duplex Mode

Simplex mode
Simplex mode is the transmission of data and information that takes place in only one direction. It is a
unidirectional mode of data transmission.
Radio, newspaper, television broadcasting, books etc. are examples of simplex mode.

Half duplex mode


Half-duplex is the transmission of data and information that flows in both directions but only one direction at a
time. Walky-talky and wireless handset are examples of half-duplex mode.

Full duplex mode


Full duplex mode is the transmission of data and information that flows in both direction simultaneously on the
transmission path.
Mobile and landline phones are examples of full duplex mode.

Communication Media / Transmission Media


A channel or path through which data and information are transmitted between connected devices in a network
environment is called communication media.
The two main types of communication media are:
1. Guided (Wired/bounded) communication media
2. Unguided (Wireless/unbounded) communication media

1. Guided (Wired/bounded) Communication Media


The media which uses cable or wire to transfer data and information among computers are called guided
communication media.
Page |4
Page |5

This is an easy, fast and secure way to transfer data and information from one computer to another.
The three types of wire or cable are:
a. Twisted pair Wire
b. Co-Axial Cable
c. Fiber Optic Cable

2. Unguided (Wireless/unbounded) Communication Media


Unguided communication is a communication channel in which data and information transferred between two devices
without using wire or cable.
It uses radio signal for receiving and transmitting electronic data.

The three types of wireless communication are:


 Radio Wave
 Micro Wave
 Satellite Communication

Twisted Pair Wire


Twisted pair wire is made of copper and a pair of wires are twisted together and insulated with plastic.
This is also widely used in landline telephone.
RJ-45 connector is the most popular connector used in twisted-pair wire.
Wires are twisted with each other so as to reduce crosstalk (A disturbance caused by electromagnetic interference,
along a circuit or a cable pair).

The two types of twisted pair wire are:


i. UTP (Unshielded Twisted Pair)
ii. STP (Shielded Twisted Pair)

Unshielded twisted pair (UTP)


Unshielded twisted pair is a popular type of cable that consists of two unshielded wires twisted around each other
which are used in telephone wiring and local area networks (LANs).
It is called unshielded because it has no additional foil wrap, or shield.
RJ-45 connector is commonly used with unshielded twisted pair.

Shielded twisted pair (STP)


Shielded twisted pair is a type of copper telephone wiring in which each of the two copper wires are twisted together
and coated with an insulating coating.
The extra covering in shielded twisted pair wiring protects the transmission line from electromagnetic interference.
D-shell connectors are used with shielded twisted pair.

Co-axial cable
Coaxial (or “coax”) cable is a common type of cable used for transmitting data over long distances.
They are most commonly used to transmit cable TV and Internet signals.
BNC and T connectors are the most popular connector used in co-axial cable.

Fiber optic cable


Fiber optics cable is one of the costlier cables used in data communication which uses light to carry a data signal
through the cable.
The connectors used in fiber optics are Screw Mounted Adaptors (SMA), Spring-loaded Twist (ST), SC and FC.

Radio wave transmission


The transmission making use of radio waves through air is called radio wave transmission.
It provides low bandwidth for data communication.
Radio, TV, cellular phones etc. uses radio transmission in one form or another.
The radio waves can travel through walls and through an entire building.
Depending upon the frequency, they can travel long distance or short distance.
It does not require line of sight for data transmission
Page |6
Page |7

Microwave transmission
Microwave is a line-of-sight wireless communication technology that uses high frequency beams of radio waves to
provide high speed wireless connections that can send and receive voice, video, and data information.
Microwaves do not pass through buildings. So, indoor receivers cannot be used effectively.
It provides higher bandwidth for data communication.
It requires line of sight for data transmission.

Infrared transmission
Infrared Transmission is the transmission of data or voice information over infrared (IR) light over short ranges.
It requires line-of-sight and is unable to break through walls.

Satellite Communication
Satellite communication is used to transfer information wirelessly worldwide after 1965.
It is an artificial satellite placed in outer space for the purpose of telecommunication, radio, television, Internet, etc.
Text, photo, video, etc. can be transferred worldwide using satellite communication.
It is like microwave relay stations in the space or sky.

Computer Network
Computer network is a group of two or more computers and devices connected to each other through wired or wireless
media to exchange data and information and share hardware, software and other resources.
It can share resources like scanner, printer, hard disk, operating system software, application software, etc. within the
networking computer.

Advantage of Computer Network


1. A network connected computers can share hardware devices such as scanner, printer, hard disk, etc.
2. It can communicate and share information all over the world through Internet.
3. Computer network supports centralized administration.
4. Networking also provides the facility of data and software backup system.

Disadvantage of Computer Network


1. Computer network can be route for computer virus and malware transmission.
2. Skilled manpower is required to manage and operate computer network.
3. The initial setup cost is very high to build computer network.
4. Cybercrimes are originated from computer network.

The services provided by computer network are


print service, message service, application service, file service, database service, etc.

"Computer network reduces the operation cost." Justify this statement.


Computer network reduces the operation cost as it allows to share software and hardware in the network, so extra
hardware or software copies is not needed to install for each and every computer in the network.
Basic Elements of the Network
 Physical parts and devices used to connect computers in the network environment are called
hardware components.
 The hardware components of computer network are computer set, modem, hub, NIC card, bridge, repeater, etc.
 The software elements are NOS, Protocol and Device Driver

1. NIC Card
NIC stands for Network Interface Card which connects all computers in network.
It provides a port on the back of system unit to connect a computer in network.
It controls flow of data to and from computers in network environment.

2. Connectors
Connectors are used to connect communication media with network devices.
It provides data communication through NIC card.
Page |8
Page |9

The different types of connectors are:


 RJ- 45 connector for UTP cable
 BNC connector for co-axial cable
 ST connector for fiber optics cable

3. Hub
Hub is a network connectivity device with multiple ports for connecting different computers on network.
It connects computers in star topology.
It broadcasts all network data across each connection.

4. Switch
Switch is a network connectivity device which joins multiple computers together to share information among them.
The selected computer can get information through switch.
It works faster than hub.

Hub Vs Switch
Hub Switch
It is cheaper than switch. It is more expensive than hub.
It transmits data slower than switch. It transmits data faster than hub.
It broadcasts the information packets to all computer It transfers packets to only those selected
connected network. computers connected in network.
It has 4 / 12 ports It has 24 to 48 ports

5. Bridge
Bridge is a network connectivity device that interconnects two computer networks having similar protocol.
It inspects incoming signals and decides whether to forward or discard it.
It connects similar networks.

6. Router
Router is a network connectivity device that joins multiple wired or wireless networks together.
Like a bridge, router also inspects and forwards data among different networks having similar protocol.
It is an intelligent device that has ability to determine the best possible path for data transmission.

7. Gateway
Gateway is a network connectivity device that interconnects two networks having dissimilar communication
protocols.
It is also called protocol converters.

8. Repeater
Repeater is a network connectivity device that accepts weak signals and regenerates them and after that sends the
message on their way.
It makes possible for long-distance data transfer. So it boosts the data signals that are received from network.

9. MODEM (Modulator and Demodulator)


MODEM is a device which connects computers to ISP (Internet Service Provider) by the help of telephone line or
router device.
The MODEM which is placed inside the CPU Casing is called internal modem. MODEM which is placed outside the
Casing is called an external modem.

Importance of MODEM
MODEM converts analog signal to digital signal and vice - versa. The MODEM converts the computer's digital
signals into analog signals which are then transmitted across the phone line which is called modulation phase and The
MODEM receives analog signals from phone line and converts into digital signals for the computer which is called
P a g e | 10

demodulation phase.
P a g e | 11

Modulation
The process of translating digital signals of a computer to analog signals, which are then transmitted across the
standard telephone lines, is known as modulation.

Demodulation
The process of translating analog signals from a phone line and converts then into digital signals for the computer is
known as demodulation.

Bandwidth
The amount of data that can be carried from one point to another in a given time period is called bandwidth.
We can measure bandwidth in digital devices by bits per second (bps) and in analogue devices by cycles per second
(cps) or Hertz (Hz).

Network Operating System (NOS)


Network operating system is an important software which controls and manages computer network.
Novell Netware is a popular NOS. Windows NT, Windows XP, Linux, Banyan Vinex, etc. are other example of NOS.

The main functions of NOS are:


 It helps to setup and install network.
 It allows administration to add or remove users from computer network.
 It enables users to have access to network resources.
 It manages and controls all the resources of computer network.

Protocol
A set of rules followed for interconnection and communication between computers in a network is called a protocol.
So it is rules followed while sending and receiving information using network software.
NCP (Network Control Protocol) was the first protocol.

Some common protocols are as follows:


 TCP/IP (Transmission Control Protocol/Internet Protocol) is used in Internet.
 HTTP (Hypertext Transfer Protocol) is used to transfer HTML documents in WWW.
 SMTP (Simple Mail Transfer Protocol) is used in sending e-mail.
 POP (Post Office Protocol) is used to retrieve e-mail from a mail server.
 FTP (File Transfer Protocol) is used to transmitting files between computers.

Device driver
Device driver is a program that controls the functionality of the hardware device.

Types of Network
Computer network can be classified according to its area covered.
The main three types of computer network on the basis of geographical location (area covered) are:
1. LAN (Local Area Network)
2. MAN (Metropolitan Area Network)
3. WAN (Wide Area Network)

1. LAN (Local Area Network)


Local Area Network is a network limited within a small area like a room, a building, school, college, etc. generally
connected through wire media.
It can cover up to one kilometre for transferring data and information between the computers.
It has high speed data transfer capacity than MAN and WAN.
Computer in LAN can be connected through wireless media and is referred to as WLAN (Wireless Local Area
Network).
Computer lab networking and cyber networking are examples of LAN.
P a g e | 12
P a g e | 13

Features of LAN (Local Area Network)


Coverage area is a generally small geographical area such as room, building and few kilometers.
 LAN runs the multiple devices to share a transmission medium.
 The different topology used mainly bus and ring in LAN
 The communication quality is better in LAN, the transmission error rate are low as compare to WAN
LAN supports a variety of communications transmission medium such as an Ethernet cable (thin cable, thick cable,
and twisted pair), fiber and wireless transmission.

2. MAN (Metropolitan Area Network)


Metropolitan Area Network (MAN) is a network within the area like valley, city, metropolitan, etc. connected through
wire or wireless technology or media.
It covers more area than LAN and less area than WAN.
It has high speed data transfer capacity than WAN and is slower than LAN.
It is used in medium size organization having various branches within city or valley.
Cable TV network and telephone networks providing high-speed DSL lines are examples of MAN.

Features of MAN (Metropolitan Area Network)


 Network size up to 50 km. It may be as small as a group of buildings in a campus to as large as covering the whole
city.
 It is normally owned by single or multiple organizations.
 It facilitates sharing of regional resources.
 They provide uplinks for connecting LANs to WANs and Internet.

3. WAN (Wide Area Network)


Wide Area Network is a network that is extended to a large area i.e. world in which computers are connected through
wireless technology or media as satellite communication. It is the largest computer network.
Internet, 4G Mobile Broadband Systems and satellite communication are the best examples of WAN.

Features of WAN (Wide Area Network)


 It covers the whole world and cannot be restricted to any geographical location. It uses satellite and microwave
communication.
 It is normally owned by multiple organizations.
 Communication links are provided by public carriers like telephone networks, satellites, network providers, cable
systems, etc.
 They have low data transfer rate and high propagation delay so they have low communication speed.

Network Architecture/Model
Network architecture defines how the computer communicates and interacts with each other on network.

The three types of network architecture are:


1. Peer to Peer Network
2. Client-Server Network
3. Centralized Network

1. Peer to Peer Network


Peer to peer is a type of network model where all nodes on the network have an equal relationship with each other.
It can share data, hardware and software with each other.
It is suitable for a small area such as small offices, small room, building, etc.
It uses many operating systems such as Windows 2000, Windows 8, Macintosh Operating System etc., have built-in
features to support peer to peer network.
Advantage of Peer to Peer Network

 All resources and contentions can be shared in this network.


 System administrator is not required and each user can control their shared resources.
P a g e | 14

 The failure of one computer doesn't affect the functioning of other peers.
P a g e | 15

Disadvantages of Peer to Peer Network


 It is difficult for administrator and control as resources are decentralized in this network.
 Security is very low in this system.
 Data recovery or backup is very difficult.

2. Client-Server Network
The network model where one or more powerful computers (servers) provide the different network services and all
other users of computer network (clients) access those services to perform user's tasks is known as client-server
network.
In such networks, there exists a central controller called server.
A server is a specialized computer that controls the network resource and provides services to other computers in the
network.
Novell Netware, Windows NT, Linux, etc. are the common examples of an operating system of client-server network.

Advantages of Client-Server Network


 Centralized back up is possible in client-server computer network.
 The use of dedicated servers also increases the speed of sharing resources.
 Security is better in this network as all the shared resources are centrally administered.

Disadvantages of Client-Server Network


 It requires specialized servers with large memory. This leads to an increase in the cost.
 The cost of network operating system that manages the various clients is also high.
 It requires network administrator.

3. Centralized Network
A centralized network is a network model in which a central host computer performs data processing and storage on
behalf of clients.
 The main computer is known as host or server computer.
 Workstation is just used for input/output operations, which has no processing capabilities and are connected
to server or host computer. Linux or UNIX operating system is used in centralized network.

Advantages of Centralized Network


 It saves cost of installation of network system.
 It secures all data and information on host computer which works on IPOS (input process output system).
 Host Computer gives facilities like Disk storage and software to workstation.

Disadvantages of Centralized Network


 The malfunctioning of host computer affects other workstation.
 It takes long time for data processing.
 It is difficult to add more workstation

Workstation
A computer on a network that uses resources of the network is called workstation.

Node
Each computer or device of network is called node.

Network Topology (LAN Topology)


Network topology is the cabling structure of interconnected pattern of computers in LAN.

The three main types of topology are:


1. Bus Topology
2. Ring Topology
3. Star Topology
P a g e | 16
P a g e | 17

1. Bus Topology
The type of topology in which all nodes and network devices are connected to single cable is called bus topology.
Terminators are attached at the cable's start and end points.
When it has exactly two end points, it is called linear bus topology.

Advantages of Bus Topology


 It is cost effective and cable required is least compared to other network topology.
 It is used in small networks and easy to understand.
 It is easy to expand networks.

Disadvantage of Bus Topology


 Break/Failure in main cable will make the whole network to malfunction.
 Heavy network traffic or increase in nodes will degrade performance of network.
 Terminators are necessary at both ends of the cable.

2. Ring/Loop Topology
The type of topology in which each computer is connected to another computer with the last one connected to the first
is called ring topology.
It uses fiber optic cable to transfer data.
Each and every computer has equal responsibilities.
Data is transferred in a sequential manner.

Advantages of Ring Topology


 In this topology all computers, in close loop, act as a client or server to transfer the information.
 Transmitting network is not affected by high traffic or by adding more nodes.
 It is cheap to install or setup and expand.

Disadvantages of Ring Topology


 It is difficult for troubleshooting.
 In ring topology, adding or deleting the computers disturbs the network activity.
 Failure of one computer disturbs the whole network in this topology.
P a g e | 18

3. Star Topology
The type of topology which connects all nodes to central device called hub/switch through a cable is called star
topology.
It is probably the most common topology.
Star topology can be used with twisted pair, optical fiber and coaxial cable.

Advantages of Star Topology


 It provides fast performance and low network traffic.
 It is easy to troubleshoot setup and modify.
 The failure of one node has not affected the rest of the nodes.

Disadvantages of Star Topology


 Hub and more wires are required, so the cost of installation is high.
 The whole network is stopped when the hub fails.
 The system crucially depends on control device switch/hub. If it fails, entire network fails.

Internet
The worldwide connection of computer networks that use TCP/IP protocols to communicate with one another using
wire or wireless media as well as network devices is called the Internet.
Internet is a network of networks.

History of Internet
Internet was originated in 1969 AD by ARPANET (Advanced Research Project Agency Network).
ARPANET provides communication among various bodies of government which was developed by United States
Department of Defense.
In 1992 AD, the Internet was openly used throughout the world.
In Nepal, Internet service was started by Mercantile Company in 1994 AD.

Advantages of internet
a) Internet has an endless knowledge supply which anyone can access that too free of cost.
b) Selling and buying has become so easy with the use of internet and it has helped millions to sell and buy
their goods online.
c) Internet has given us E-Mail which is fast, secure and reliable mode of communication.
d) It makes easy to transfer the file or information.

Disadvantages of internet
a) Increasing virus threats not only steals your sensitive data but also damages your computer.
b) People using too much of internet get disconnected from the real world.
c) Pornography that can get in the hands of young children too easily.
d) Addiction to online games affects health leading to obesity and serious health issues.

Extranet
P a g e | 19
P a g e | 11

An extranet is a private network that uses internet technology and the public telecommunication system to connect
more than one organization.
Intranet
An intranet is a private computer network that uses the internet protocol to securely share any part of information of
an organization.

Services of Internet
1. World Wide Web
2. E-mail
3. Telnet
4. FTP (File Transfer Protocol)
5. Search Engine
6. IRC (Internet Relay Chat)
7. Online Banking
8. E-commerce
1. World Wide Web
World Wide Web was developed by Tim-Berners-Lee in 1989 AD. It is also called the web.
The interlinked collection of hypertext documents and multimedia content available on internet is called WWW.

2. E-mail (Electronic Mail)


E-mail is the most widely used service on the Internet which sends and receives messages electronically through the
Internet. E.g. sarthak1@[Link]

Advantages of using E-mail


 It is the cheapest and fastest means of communication.
 It is more reliable than postal mail.
 E-mail can be accessed from any part of the world at any time.
 Information can be shared globally.
 We can send photos, songs, video clips and other file with e-mail attachments.
 A single mail can be sent to multiple people at a time.

Disadvantages of e-mail
 The recipient needs access to the internet to receive email.
 Viruses are easily spread through email attachments.
 Minor mistakes in e-mail address may deliver the mail to wrong address.
 Since it passes through a vast electronic network, it may be seized in between.

Any four sites that provide e-mail services are:


a) [Link]
b) [Link]
c) [Link]
d) [Link]

3. Telnet
Telnet is the facility of Internet that allows user to use a remote computer through Internet.

4. FTP (File Transfer Protocol)


File Transfer Protocol (FTP) is transmission of files between computers on the Internet.
File Transfer protocol helps to transfer (download or upload) files from one computer to another computer.

Uploading
Uploading refers to the process of sending or transferring data (files, documents, images, videos, etc.) from a local
device, such as a computer or smartphone, to a remote server or another device.

Downloading
P a g e | 12
P a g e | 13

Downloading is the process of receiving or retrieving data (files, documents, images, videos, etc.) from a remote
server or another device to a local device.

5. Search Engine
Search engine is the communication program that searches documents on the basis of specified keywords and returns
a list of the web links that matches the keywords.
Google, Ask, Alta Vista, Bing and Yahoo can search for files on WWW (World Wide Web).

6. IRC (Internet Relay Chat)


IRC allows people from all over the world to communicate in real-time. Real-time communication means
communicating with people in the immediate present time.

7. Online Banking
Online banking is also known as Internet banking or web banking which allows a user to conduct financial
transactions through Internet.
It offers customers almost every service traditionally available through a local branch including deposits, transfers,
and online bill payments.
Online banking is fast and efficient. Convenience is a major advantage of online banking.

8. E-commerce
E-commerce is also known as electronic commerce or Internet commerce which means buying and selling of goods,
products, or services through Internet.
Transaction of money, funds, and data are also considered as E-commerce.
Online stores like hamrobazar, alibaba, muncha, foodmandu, Amazon, Flipkart, Shopify, Myntra, Ebay, Quikr, Olx,
etc. are examples of E-commerce websites.

ISP (Internet Service Provider)


An Internet service provider (ISP) is an organization that provides services for accessing and using the Internet.
World Link, Mercantile, Classitech, Vianet etc are the ISPs of Nepal.

Web browser
Web browser is a computer program that access web pages and displays them on the user’s computer.
E.g., Mozilla Firefox, Google Chrome, Internet Explorer, opera etc.
P a g e | 14
P a g e | 15

(1.2) Ethical and Social Issues in ICT


Computer ethics
Computer ethics is a set of moral principles or code of conducts that regulate the use of computers systematically
without making harm to other users.
It gives awareness to the user regarding the immoral behaviour and activities in the computing field.

Commandments of computer ethics


 Do not use a computer to publish fake information.
 Do not search the file or record of other people.
 Do not destroy or delete the records of other people.
 Do not use a computer to steal someone's privacy.
 Do not snoop around in other people's files.
 Do not use other people's computer resources without authorization.

Digital citizenship
Digital citizenship refers to the responsible and ethical use of technology and the internet which involves
understanding, practicing, and promoting appropriate behavior when using digital tools and resources.

Elements of digital citizenship


Digital Access: The state of full electronic participation in society
 Digital Commerce: The act of promoting the purchase of goods through electronic means
 Digital Communication: Electronic exchange of information
 Digital literacy: Teaching and learning about teaching and technology
 Digital Security: Electronic precautions
Digital Health: The solution to health problems using digital technology
 Digital Law: Act, rules and regulations required for performing electrical work

Digital footprint
A digital footprint is the trail of data and information left behind by an individual's online activities which includes
social media posts, website visits, online purchases, and other digital engagements.

The following should be considered when managing Digital Footprint:


 Subscribed accounts and unused social media accounts which are no longer in use should be unsubscribed or
deleted.
 Ensure the content posted protect your privacy.
 Not to forget that online posts are private.
 To note that parents, teachers and other people can view the content posted.
 Ensure the content posted does not damage yours or others reputation.

Cyber bullying
Cyberbullying refers to harassment or bullying that takes place through electronic devices and digital platforms, such
as the internet, social media, or messaging apps..

Examples of cyber bullying:


 Sending rude emails, texts or instant messages online or on the phone
 Posting hurtful things about someone on social media
 Taking an embarrassing photo or video and sharing it without permission
 Pretending to be another person by creating a fake online profile.
 Spreading rumours or gossip about someone online
 Offensive chat on online gaming.
P a g e | 16
P a g e | 17

Cyber law
The law which governs the legal issues in the cyber space regarding the internet or WWW for digital data processing
and transaction is called cyber law. The importance of cyber law is that it controls cyber-crime and misuse of
computer.

Aims of formulating cyber law in Nepal


- To legalize the transaction through electronic media to control various types of electronic frauds
- To punish a person who does criminal activities through electronic means especially on computers.

Cyber law was introduced in Nepal in 30th Bhadra, 2061 [15 September, 2004]

Cyberspace
Cyberspace is the virtual environment created by the Internet and devices and services related to the Internet.

Cyber crime
Cyber crime refers to criminal activities that are carried out using computers, networks and the internet.
E.g. Software piracy, hacking, cracking, pornography etc.
Computer hacking means stealing and destroying other data, information, files and program.

Digital signature
 Digital signature is a security mechanism system used on the internet for data and information transaction by
attaching a code at the end of the electronic message that confirms the authenticity of sent message.
 The importance of digital signature is that it provides legal framework to facilitate and safeguard electronic
transaction in the electronic media.

ICT (Information and Communication Technology)


A technology which collects stores and processes data into information and communication through computer system
is known as ICT.

Challenges of ICT
 Internet criminals enter into the system by creating fake identities and use the system for their benefits which is
difficult to recognize and control.
 Hacking or unauthorized access of system is increasing.
 Sharing unnecessary information of individual or group of people is the danger of ICT in this era.
 The Digital Divide is a social issue referring to the differing (conflicting) amount of information between those
who have access to the Internet (especially broadband access) and those who do not have access.

IT Policy 2072
 IT Policy launch in Nepal – 2000 AD (2057 BS)
 Most recent and the latest information technology policy– ICT Policy 2015 (2072 BS)
 Total laws in ICT policies 2015 (2072 BS) – 21 Policies
 Strategies in ICT policies 2015 (2072 BS) – 21 Strategies
 Percentage of the population will have digital skills by the end of 2020? – 75%
 Percentage of the population will be able to access the broadband services by 2020? – 90%
 Percentage of the population of Nepal will have internet access by 2020? – 100%
 Percent of government services will be provided online by 2020? – 80%

Objectives of IT Policy 2000


a) To establish knowledge based industry
b) To increase employment
c) To build knowledge based society

Vision of ICT Policy 2015


 To transform Nepal into information and knowledge based society and economy.
P a g e | 18
P a g e | 19

Mission of ICT Policy 2015


 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.

Goals of ICT policy


 At least 75 percent of the population will have digital literacy skills by the end of 2020.
 80% of all citizen facing government services would be offered on line by 2020
 By 2020, entire population of Nepal to have access to Internet.
 By 2020, 90 percent of the population to have access to broadband service

ETA (Electronic Transaction Act)


 ETA (Electronic Transaction Act) deals with issues related to cybercrime and also help in making and
implementing laws over cybercrime.
 Maintaining privacy in the cyberspace, creating strong passwords, updating the security software, updating
password are some of the techniques to keep secure him /her.
 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 imprisonment.

When was Electronic transaction act 2063 authenticated and published in Nepal?
December 8 2006 (22 Mangshir 2063)

Objectives of the Electronic Transaction Act 2063


a) To make legal provision for authentication and regulation of electronic data.
b) To make a reliable data generation, communication, and transmission.
c) To make a secured and authentic means of electronic communication.
d) To regulate all the relating matters of electronic transactions.
Scopes of the Electronic Transaction Act 2063
a) Creation and use of digital signature
b) Control cyber/computer-related crimes.
c) Protection of intellectual property.
d) Protection of confidentiality.
e) Social Media
f) Social Media is an online tool that helps us to stay connected with the whole world

Different platforms of Social media


Facebook Twitter Instagram LinkedIn Blogs Wikipedia

Opportunities of using social media


a) It creates awareness and innovate the way people live
b) Social media let us share anything with others around the world.
c) It keeps us informed about the world.
d) It creates brand exposure for business to the largest audience.

Threats of using social media


a) Personal data and privacy can be easily hacked and shared on the internet.
b) More chances of creating fake accounts.
c) Negative impact on the health.
d) Decrease the working efficiency of people.
e) Spreading false or unreliable information.
P a g e | 20
P a g e | 21

(1.3) Computer Security


Computer Security / Cyber Security
Computer security refers to protecting computer and its content from damage, theft or misuse and action to prevent
such incidents.
Computer security includes security of data and information strored and being transferred, computer programs and
applications and computer hardware.

Types of computer security


 Hardware security
 Software security.

Information Security (infosec)


Information security is the practice of preventing unauthorized access, use, disclosure, modification, recording or
destruction of information.

Key principles of Information Security


a) Confidentiality:- Only authorized users can access the data resources and information.
b) Integrity:- Only authorized users should be able to modify the data when needed.
c) Availability:- Data should be available to users when needed.

We can protect our data by


 by periodically checking the hard disk and replacing it if it shows failure symptoms
 by copying the data in another disk in the system to avoid accidentally erasing or erasing data by
unauthorized person.
 we can copy important data into online storage devices which is also called cloud storage like
Dropbox, Google Drive, iCloud, OneDrive etc.
 We can also, sometimes, send important files as an attachment to our own mail such as Gmail or Hotmail.
 Another issue of protecting data is preventing them from authorized access. Unauthorized users may access
our data store in our computer in the cloud storage. To prevent our data from unauthorized access we have
to protect the storage space, folder or file with password.

Security Threats
⚫ A risk which can potentially harm computer systems and organization.
⚫ The cause could be physical such as someone stealing a computer that contains vital data.
⚫ The cause could also be non-physical such as a virus attack.

Possible Security Threats


Phishing is the fake attempt to obtain sensitive information such as usernames, passwords and credit card details by
disguising oneself as a trustworthy entity in an electronic communication.

A botnet is a logical collection of Internet-connected devices such as computers, smartphones or internet of things
(IoT) devices whose security have been breached and control is given away to a third party.

A rootkit is a malicious code (kit) that hides in system area provides continued Administrator's (root) privileged access
to a computer while actively hiding its presence.

Keylogger is hardware or software for recording the keys pressed on a keyboard secretly so that person using the
keyboard does not know that their actions are being monitored.
A computer hacker is any skilled computer expert who uses his/her technical knowledge to overcome a problem.

Malicious code (Malware)


Malicious code is a kind of harmful computer code or web script that is planned to cause undesired effects to damage
a system.
P a g e | 22
P a g e | 23

Types of malware
a) A computer virus is a destructive program that copies itself and infects a PC, spreading from one file to
another, and then from one PC to another when the files are copied or shared.
Some viruses produce unnecessary messages on the screen, some virus hide files, some virus corrupt files
and programs, some virus reduce memory size, etc.
Computer viruses can spread from one computer to other computers through sharing of infected portable disk
like pendrive, opening a virus infected email, messages or attached files and downloading files and programs
form the websites which are not secure.
b) Computer worms use the network to send copies of themselves to other PCs, usually utilizing a security hole
to travel from one host to the next, often automatically without user intervention.
c) Trojan horses are applications that look like they are doing something harmless, but secretly have malicious
code that does something else.
d) Spyware is any software installed on user’s PC that collects your information without user’s knowledge
e) Adware is a software application used by companies for marketing purposes; advertising banners are
displayed while any program is running.

Security mechanisms
⚫ A mechanism that is designed to detect, prevent, or recover from a security attack.
⚫ It includes
⚫ Authentication Systems
⚫ Firewalls
⚫ Cryptography
⚫ Antivirus Software
⚫ Backup System

Authentication System
⚫ The process of identifying an individual usually based on a username and password is called an
authentication system.
⚫ Authentication system makes sure that right people enters the system and access the right information.
⚫ Types of Authentication
Password Biometric

Password
⚫ A password is a string of characters including letters, digits, or other symbols which confirms the identity of
a user.
⚫ Password secures the data by protecting the data from unauthorized access.
⚫ We have to keep the password secure and strong so that unauthorized users may not gain access to the
resource and misuse it with our identity.

Following are some of the tips to make password secure and strong:
 Never share your credentials online.
 Don't use easily guessable the name of a pet, child, family member, birthdays, birthplace, name of a favourite holiday.
 Don't use a sequence like abcd or 1234 which are, again, easily guessable.
 Mix characters, numbers and symbols. Also, mix small and capital letters.
 Avoid using the same password in all applications.
 Change password periodically

Biometric
 Biometrics are physical or behavioral human characteristics that can be used to digitally identify a person to
grant access to systems, devices or data.
 E.g., fingerprints, facial patterns and voice.

Firewall
A firewall is the network security systems that monitors and controls the traffic flow between the Internet and private
network on the basis of a set of user-defined rules.
Firewall blocks unwanted traffic as well as malicious software from infecting your computer.
P a g e | 24

Cryptography
⚫ Cryptography is the study of secure communications techniques that allow only the sender and intended
recipient of a message to view its contents.
⚫ Cryptography is used to secure and protect data during communication.

Types of Cryptograpy
Encryption
Decryption

Encryption
⚫ Encryption is the technology to encode file or message that is being stored or transferred online in
intelligible content which cannot be used by an unauthorized person.
⚫ Encryption is done by the person who is sending the data to the destination
Decryption
⚫ The conversion of encrypted data into its original form is decryption.
⚫ Decryption is done at the person who is receiving the data

Antivirus software
⚫ Antivirus software is software designed to detect and remove virus from computer system and ensures
virus free environment.
⚫ E.g. Kaspersky, NAV, MSAV, McAfee, NOD 32 etc.

Backup system
 Backup is the system of copying data and programs into another location or creating a duplicate copy of it in a
secured place.
 Backup is vital to computer security system in order to save the data from being lost or damaged due to accidental
or intentional harm. When data and software are lost or damaged, we can easily recover through backup.

Hardware Security
Hardware security is the protection given to the various hardware tools and equipment used in computer system from
the accidental or intentional harm.

Different hardware security measures are:


a) Regular Maintenance
b) Insurance
c) Dust free environment
d) Protection from Fire
e) Protection from Thief
f) Air condition system
g) Power Protection device (Volt guard, Spike guard, UPS)

Regular Maintenance
Computer system need regular maintenance to keep the computer hardware in good working condition and it also
helps to find out problems in hardware and correct the problems before they cause several damages.

Insurance
 A means of protection from financial loss.
 If a computer is damaged or stolen or any kind of harm done then we can claim for the insurance amount and
get the economic support.

Dust Free Environment


 Dust particles can cause the failure of hardware components.
 Computer room should be absolutely free from dust and air pollution.
P a g e | 25

Protection from Fire


 Due to faulty wiring, loose connection, smoking in the computer room and overload on power socket can
cause fire in a room.
 Using fire alarms, fire doors, fire detectors and fire extinguishers can minimize the damage of
hardware components and loss of information from fire.

Protection from Theft


The computer room should have physical security with proper locking system, controlled access of authorized persons
only by having human guard or biometric machine.

Air Condition System


A system for controlling the temperature and humidity (wetness) of the air
Maintains suitable temperature or humidity in the computer room.
Room Temperature should be maintained between 210C to 240C.

Power Protection Device


An electric device that controls electric voltage and provides enough backup to the computer system when there is
power failure.
Computer needs 220 volts to 240 volts constantly.
Some common power protection devices are:
a) UPS
b) Volt Guard
c) CVT (Constant Voltage Transformer)
d) Spike Guard
e) Surge Suppressor

Why Power Protection Device needed?


To protect computer system from damage, expensive data loss and unnecessary down time (is out of action or
unavailable for use).

Volt Guard
A power protection device that provides constant output voltage to the computer system in case of high input voltage
coming from the source.

UPS (Uninterruptible Power Supply)


 UPS is a battery supported power protection device which controls the electric voltage and supplies clean and
continuous power to the computer system even during power failures.
 The importance of UPS in computer security system is that it controls fluctuation of electric voltage and provides
enough backup electric power to the computer system when there is power failure.

Spike Guard
A device designed to protect electrical devices from voltage spikes.
Automatically maintains a constant voltage level.

Software security
The security given to the software and data from being lost or damaged due to accidental or intentional harm is called
software security.

Some of the software security measures


a) Backup
b) Scandisk
c) Password
d) Antivirus
Scan disk
Scan disk is a process which involves in maintaining the disk files and folders, bad sectors, lost clusters, lost chains
and other errors of the specific disk and it can fix them if it is possible.
P a g e | 26
P a g e | 27

(1.4) E-Commerce
 E-Commerce refers to electronic transactions such as buying, selling and exchanging of goods, services and
information over computer communication network such as the Internet.E.g. Amazon, Flipkart, eBay,
sastodeal, daraz etc.
 The main goal of e-commerce is to reduce cost, lower the product cycle time, faster customer response and
deliver the better quality service.
 Nepali online shopping sites are [Link], [Link], [Link],
[Link], [Link], [Link], muncha. com and many more.

Differences between E-commerce and Traditional Commerce are

Traditional Commerce E-commerce


Traditional commerce refers to the commercial E-commerce refers to the commercial transactions
transactions or exchange of information, buying or exchange of information, buying or selling
or selling product/services from person to person product/services electronically with the help of
without use of internet. internet.
In traditional commerce delivery of goods is In e-commerce delivery of goods takes time.
instant.
In traditional commerce customers can inspect In e-commerce customers can not inspect
products physically before purchase. products physically before purchase.
Its accessibility is for limited time in a day. Its accessibility is 24×7×365 means round the
clock.

Advantages of E-commerce
 Faster buying/selling procedure, as well as easy to find products.
 There are no geographical limitations, can deliver service globally.
 Low operational costs and better quality of services
 It makes buying/selling possible 24/7, faster, as well as easy to find products.

Disadvantages of E-commerce
 Lack of personal touch. We cannot touch the goods physically.
 We cannot do any transaction without Internet access device. So, it is heavily dependent on Internet technologies
 Easy to set up so anyone can start e-commerce site. We need to be careful about the quality of product and
service delivery.
 Not all goods can be purchased online

Types of Ecommerce Models


a) Business to Consumer (B2C):
The most common type of E-Commerce is Business-to-Consumer. B2C establishes the electronic business
relationships between a business organization (merchant) and final consumers.
(e.g. You buy a pair of shoes from an online retailer)
Amazon. com is a good example of B2C e-commerce.
b) Business to Business (B2B):
Business-to-Business (B2B) e-commerce is conducted between companies. Individual customer cannot buy
from this type of e-commerce. Producers and wholesalers typically operate with this type of electronic
commerce. (e.g. A business sells software-as-a-service for other businesses to use)
[Link] is a good example of B2B e-commerce.
c) Consumer to Consumer (C2C):
Consumer-to-Consumer (C2C) type of e-commerce is conducted between consumers.
These transactions are conducted through a third party, which provides the online platform where the transactions
are actually carried out.
(e.g. You sell your old furniture on hamrobazar to another consumer)
[Link] is a good example of C2C website in Nepal.
P a g e | 21

d) Consumer to Business (C2B):


When a consumer sells their own products or services to a business or organization
(e.g. An influencer offers exposure to their online audience in exchange for a fee, or a photographer licenses their
photo for a business to use).

M-Commerce / Mobile Commerce


M-Commerce refers to the process of buying and selling of goods and services through wireless handheld devices
such as smartphones, tablets or personal digital assistants (PDAs).
The term itself was coined in 1997 by Kevin Duffy.
Examples: Purchasing airlines tickets, purchasing movie tickets, Restaurant / Hotel booking and reservation, Fund
Transfer, Top – Up Charges Fund Transfer, Balance Enquiry, etc.

Advantages of M-Commerce
 It provides a very convenient and easy to use the system to conduct business transaction.
 It helps to get wider variety of products and services.
 It saves both the time and energy of the user.
 It reduces the costs of the business organizations.

Disadvantages of M-commerce
⚫ It has great start-up costs and many complications arise.
⚫ Without accessing the internet connections user will not be able to receive any data to purchase.
⚫ It has the issue of security of the customer’s private information.
⚫ Mobile payment options are not available in every geographic location.

Online Payment
Online payment refers to the payment for buying goods or services through the Internet using different online payment
gateway.
E.g. eSewa Nepal, iPay, Khalti, e-banking, etc.

Different modes of Electronic Payments


a) Credit Card
b) Debit Card
c) Smart Card
d) E-Money
e) Electronic Fund Transfer (EFT)
f) E-Cheque

Advantages of online payment


 Digital Payment can be done at any time, from any location around the globe.
 It makes huge money transactions easier and faster.
 It offers higher payment security.
 There’s no risk of your money getting stolen or lost when you pay online.

Disadvantages of online payment


 We need to pay third-party payment service charges.
 Not all shops are equipped with the facility of online payment..
 It might create privacy issues.
 Account can be hacked and money can be misused.

Likewise, different forms of e-payment in Nepal include


a) Credit Cards (introduced by Nabil Bank in 1990)
b) Debit Cards (all commercial banks)
c) Automated teller machines (introduced by Himalayan Bank Ltd. in 1995)
d) Electronic fund transfers at points of sale (EFTPOS)
e) Internet banking (introduced by Kumari Bank Ltd. in 2002)
P a g e | 22

f) Mobile banking; (introduced by Laxmi Bank Ltd. in 2004).


P a g e | 23

g) Digital Wallet such as e-sewa, Khalti etc.


h) Cash on Delivery (CoD) – if you don’t have any online payment system then you can pay cash when you
receive the product from delivery person.

E-commerce Vs M-commerce

E-commerce M-commerce
Any kind of commercial transaction that is M-commerce refers to the commercial
conducted, over the internet using activities which are transacted with the
electronic system is known as e- help of wireless computing devices such
commerce. as cell phone or laptops.

e-commerce activities are performed with M-commerce activities are performed with
the help of desktop computers and laptops. the help of mobile devices like
smartphones, tablets, PDA’s (Personal
Digital Assistant) etc.
E-commerce devices are not easy to carry M-commerce devices are easy to carry and
and portability point of view it is not so portability point of view it is good.
good.

E-commerce developed in 1970’s. M-commerce developed in 1990’s.


P a g e | 24
P a g e | 25

(1.5) Contemporary Technology


Cloud Computing
Cloud computing is a technology that allows users to access and use of computing resources, like servers and
software, over the internet.
Some of the cloud providers are Amazon AWS, Microsoft Azure, Google Cloud, IBM Cloud, VMware Cloud, Oracle
Cloud and Alibaba Cloud.

Examples of Cloud Computing


Drop box, Face book, Gmail, YouTube
Google Drive, Apple iCloud
Google Photos, Online Photoshop, Microsoft Office 365

Uses of Cloud Computing


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

Advantages of Cloud Computing


It allows to quickly and easily access, store information anywhere, anytime in the whole world, using an internet
connection.
It is easier to get back-up and restore the data.
It reduces both hardware and software maintenance costs for organizations.
Data is securely stored and handled.

Disadvantages of Cloud Computing


Storing sensitive data on remote servers raises privacy issues.
Uploading and downloading large volumes of data can be time-consuming.
Switching providers or platforms can be complex and costly.
Cloud services can experience outages, leading to disruptions in business operations.

Types of cloud computing services

Infrastructure as a Service (IaaS): Customer can use processing, storage, networking, and other computing
resources from cloud service providers to run their software system.

Software as a Service (SaaS): Customer subscribes the software services from a


vendor for an annual subscription fee or sometimes free and use it over Internet.
Services like Gmail, Google Drive, Office 365 are some of the examples of SaaS.

Platform as a Service (PaaS): Customer use infrastructure and programming tools and environment supported by the
vendors to develop their own applications.
IBM provides Bluemix for software development and testing on its cloud.

Types of Cloud
 Public cloud - Public cloud is cloud computing that’s delivered via the internet and shared across
organizations. Example: Services like Google Cloud, Microsoft Azure, or Amazon Web Services (AWS).
 Private cloud - A private cloud is a cloud computing environment dedicated to a single organization. Example: A
company might have its own private cloud for its specific needs.
 Hybrid cloud - A combination of both public and private cloud services, allowing organizations to
maintain sensitive data on-premises while using public cloud for less critical workloads.
Example: A company might keep some data and applications in its private cloud and use the public cloud for
others, creating a mix that suits its needs.
P a g e | 26
P a g e | 27

Artificial intelligence
AI is an emerging branch in computer science, which interprets the means and method of making computers think like
human beings.
John McCarthy coined the term Artificial Intelligence in the year 1955.

Some of the examples of AI are


speech recognition (like Siri, Microsoft Cortana, Amazon Echo, Google Home etc.),
spam email filter,
self-driving cars,
face recognition etc.

Advantages of AI
 AI reduces labor and operational costs by automating tasks.
 AI processes and analyzes data faster than humans, leading to quicker decision-making.
 AI can automate repetitive tasks, saving time and reducing errors.
 AI systems can work continuously (24/7) without rest.

Disadvantages of AI
 Automation by AI can lead to job losses in certain industries.
 Developing and maintaining AI systems can be costly for businesses.
 AI can analyze and collect personal data, raising privacy concerns.
 Understanding and managing AI systems can be complex and require specialized knowledge.

Applications of AI
 Robotics – AI is used in robotics to control robots and make them perform task autonomously.
 Gaming - The AI machines can play strategic games like chess, where the machine needs to think of a large
number of possible places.
 Natural Language Processing − It is possible to interact with the computer that understands natural
language spoken by humans.
 Security - AI is used in facial recognition, threat detection, and cybersecurity

Virtual Reality
Virtual Reality (VR) is the use of computer technology to create a simulated environment that doesn’t actually exist,
that can give a feel of near real world with all or some of senses experiencing the virtually simulated environment.
We can swim with whales in oceans, fight with aliens, fly aeroplanes, visit distance places without being there and
much more within the VR.

Advantages of Virtual Reality:


 Virtual reality creates a realistic world.
 It enables user to explore places.
 Through Virtual Reality user can experiment with an artificial environment.
 Virtual Reality make the education more easily and comfort.
Disadvantages of Virtual Reality
 The equipment used in virtual reality are very expensive.
 It consists of complex technology.
 In virtual reality environment we can’t move by our own like in the real world.
 Some individuals may become addicted to VR experiences.

Application areas of VR
 Gaming- VR Gaming allows players to immerse (dip) themselves in virtual world and interact with environment
and characters
 Education - VR can help students learn by making the content more engaging and memorable.
 Health care - VR can help people to learn how to manage their anxiety and stress.
 Architecture and Design - VR can be used to create 3D models of buildings and products.
P a g e | 28
P a g e | 29

E-Governance
 E-Governance is a set of services provided by the government to public via electronic media especially
using Internet.
 Examples of such services include paying their taxes online, requesting various services from government
though governmental websites, providing information to public via government’s websites.
 The basic purpose of e-governance is to simplify processes for all, i.e. government, citizens, businesses, etc. at
National, State and local levels.
 An ordinary citizen gets the government facility through the internet.

Models of E-Governance
 Government-to-Citizen(G2C)
 Government-to-business (G2B)
 Government-to-Government (G2G)
 Government-to-Employee (G2E)

Government-to-Citizen(G2C)
 G2C-is transaction between the government to citizens.
 It includes online registration of birth/ death/marriage certificates, filling of income taxes, electricity bills, license
renewals etc.

Government-to-business (G2B)
 G2B it is the transaction between government to business.
 It includes online application forms, renewing licenses, registration etc.

Government-to-Government (G2G)
 G2G it is the transaction between government to government.
 It provides safe and secure inter-relationship between domestic or foreign government.

Government-to-Employee (G2E)
 G2E it is the transaction between government to employee.
 G2E aims to bring employees together and improvise knowledge sharing.

Advantages of E-governance
 Citizens can access government services and information conveniently from anywhere.
 It reduces paperwork and manual tasks, which can lead to faster decision-making and service delivery.
 E-governance systems promote transparency by making government actions and decisions visible to the public.
 Cheaper, more effective, and speedy communications.
 Corruption will be reduced as there will be direct interaction with the system and public without any
intermediaries

Disadvantages of E-governance
 Collecting and storing citizen data online can raise privacy and security issues.
 Not all citizens may have the necessary technology skills to explore e-governance platforms.
 E-governance may exclude individuals without access to the internet or digital devices.
 In rural and remote areas, the internet may not work well, so people there can't easily use e-government services.

Mobile Computing
Mobile computing refers to a variety of devices that allow people to access data and information from wherever they
are via a mobile device.

Advantages of Mobile Computing


 It allows people to work and communicate from anywhere at any time.
 It keeps connected to the Internet, allowing to access information all the times.
 It increases the productivity of users reducing time and cost.
 It is one of the major handheld sources of entertainment for users at present.
P a g e | 210
P a g e | 211

Disadvantages of Mobile Computing


 Mobile devices have limited battery life, requiring frequent recharging.
 Excessive use of mobile devices can lead to health issues.
 Mobile devices can be vulnerable (weak) to cyberattacks and data theft. It can be expensive, with high costs
for devices, data plans, and accessories.
 Mobile devices may have limited storage space, which can be insufficient for storing large files and media.

The Internet of Things (IoT)


⚫ IoT is a system of interrelated computing device to exchange information over a network without human-to-
human or human to computer interaction.
⚫ The term "The Internet of Things" was coined by Kevin Ashton in a presentation to Proctor & Gamble in 1999.

Components of IoT
a) Sensors/Devices - Sensors/Devices collect data from their environment.
b) Connectivity to Cloud - The sensors/devices can be connected through Bluetooth, WiFi, Cellular
etc. Data
c) Processing - Software perform data processing on cloud data to get a analyzed or computed data.
d) User Interface - The analyzed or computed data is made useful to the end user via and alert(email, text,
notification).

Applications of Internet of Things (IoT)


 Smart Home - IoT devices can be used to automate and control home appliances, security systems and lighting
which make homes more comfortable, efficient and secure.
 Health care - Wearable devices such as smartwatches and fitness trackers can collect data about our health and
activity levels which track our progress, improve our health and even diagnose diseases.
 Smart city - IoT can be send to make cites more efficient and sustainable by improving traffic flow, optimize
energy use and reduce waste.
 Smart agriculture - It helps farmers monitors and manage crops, cattle and equipment through sensors, drones and
data analysis.
Advantages of Internet of Things (IoT)
 It reduces the human effort, so it saves a lot of time.
 Information is easily accessible from any place at any time on any device.
 It enhances security and offers personal protection.
 It enables convenient control of home appliances.

Disadvantages of Internet of Things (IoT)


 Hackers may gain access to the system and steal personal information.
 IoT systems require a stable internet connection to function.
 Setting up IoT infrastructure can be expensive.
 The setup and management of IoT devices can be challenging for non-technical users.

E-learning
E-learning is a new concept of delivering digital contents in learner oriented environment using information and
communication technology (ICT).

Advantages of E-learning
 There is no any geographical limitation for learning.
 It is quite favorable for learner as it can happen at any time and anywhere.
 It reduces or eliminates travel costs to attend learning events.
 It reduces or eliminates need for classroom/instructor infrastructure.

Disadvantages of E-learning
 Learners with low motivation or bad study habits may fall behind
 Students may feel isolated from the instructor and classmates
 Instructor may not always be available when students are studying or need help
 Slow Internet connections or older computers may make accessing course materials frustrating
P a g e | 212
P a g e | 213

E-Banking
E-banking refers to a digital banking system that enables customers to conduct financial transactions and manage
their accounts online through the internet or mobile apps without the need for a physical visit to a bank branch.

Internet Banking
⚫ a facility offered by banks and financial institutions that allow customers to use banking services over the
internet.
⚫ Customers need not visit their bank’s branch office to avail each and every small service.
⚫ Use PC or laptop and internet connection to use this facility.
⚫ Kumari Bank was the initiator of internet banking in Nepal. It started its e-banking services in 2002.

Features of Internet Banking


 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, DTH connections, etc.
Mobile Banking
 Mobile banking is the act of making financial transactions on a mobile device (cell phone, tablet, etc.).
 Download Mobile App or SMS system
 Inquiry based transactions such as balance inquiry, transaction history, and transaction
alert.
P a g e | 214

FULL FORMS
3D Third Dimension
4G - Fourth Generation
ADSL - Asymmetric Digital Subscriber Line
AI - Artificial Intelligence
AM - Amplitude Modulation
AMC - Annual Maintenance Contract
ANSI American National Standards Institute
ARPANET - Advanced Research Project Agency Network
ASCII - American Standard Code for Information Interchange
AVG - Anti-Virus Guard
B2B - Business to Business
B2C - Business to Customer
BASIC Beginner's All Purpose Symbolic Instruction Code
BBS Bulletin Board System
BCC Blind Carbon Copy
BCDIC Binary Coded Decimal Interchange Code
BIOS - Basic Input Output System
bits binary digit
BNC - Bayonet Neill–Concelman
bps - bits per second
C2B - Customer to Business
C2C - Customer to Customer
CAN Campus Area Network
CCTV Closed Circuit Television
CDMA Code Division Multiple Access
CoD - Cash on Delivery
CPAV Central point Antivirus
CPU – Central Processing Unit
CRBT Caller Ring Back Tone
CSMA/CD Carrier Sense Multiple Access with Collision Detection
CSU/DSU Channel Service Unit / Data Service Unit
CVT Constant Voltage Transformer
DARPA - Defense Advanced Research Projects Agency
DHCP Dynamic Host Configuration Protocol
DNS - Domain Name System
DoD Department Of Defense
DSL - Digital Subscriber Line
DTH Direct To Home
EBCDIC Extended Binary Coded Decimal Interchange Code
E-Commerce – Electronic Commerce
EDI - Electronic Data Interchange
EDP - Electronic Data Processing
E-fax – Electronic Fax
EFT - Electronic Fund Transfer
EFTPOS - Electronic fund transfers at points of sale
E-Governance – Electronic Governance
E-mail - Electronic Mail
EMI - Electromagnetic Interference
P a g e | 215

ETA - Electronic Transaction Act


ETDSA - Electronic Transaction and Digital Signature Act
OS – Operating System
FAQ Frequently Asked Questions
OTP - One Time Password
FC Ferrule Connector
PaaS - Platform as a Service
FM - Frequency Modulation
PAN Personal Area Network
FT – File Transfer
PC – Personal Computer
FTP - File Transfer Protocol
PDA - Personal Digital Assistant
FTTH Fiber To The Home
PDF Portable Document Format
G2C Government To Citizen
PIN - Personal Identification Number
G2G
PM -- Government
Phase to Government
Modulation
GPRS
PNG General
PortablePacket
Network Radio Service
Graphics
GPS
POP-- Global Positioning
Post Office Protocol System
GSM
POS- Point ofSystem
Global Sale for Mobile Communication
HoR
PSTN - - House Switched
Public of Representative
Telephone Network
HTML
PUK Hyper Text Markup
Personal Unlocking Key Language
HTTP
QBASIC - - Hypertext
Quick Transfer
Beginner's Protocol Symbolic Instruction Code
All-Purpose
HTTPS
QoS – Hypertext Transfer
Quality of Service Protocol Secure
IaaS
RDMBS- Infrastructure
Relational as a Service
Database Management System
ICT
RJ-45 – - Information
Registered Jackand Communication Technology
– 45
INTERNET
SaaS - International
Software as a Network
Service
IoT
SC - – Internet of
Subscriber Things
Connector
IP -
SDSL Symmetric Digital Subscriber line
Internet Protocol
SIM
IPX/SPX Subscriber
Internetwork Identification ModuleSequenced Packet Exchange
Packet Exchange/
SMA
IR - - Screw-Mounted
Infrared Radiation Adaptor
SMPS
IRC - - Switched ModeChat
Internet Relay Power Supply
ISDN --
SMS Short Message Service
Integrated Services Digital Network
ISP
SMTP- - InternetMail
Simple Service Provider
Transfer Protocol
IT - -
SQL InformationQuery
Structured technology
Language.
JPEG
ST connector - Joint Photographic
Straight Tip connector Experts Group
LAN
STP -- Local Area
Shielded Network
Twisted Pair
MAC
TCP Media Access Control Protocol
Transmission Control
Malware
TCP/IP -- Malicious Software
Transmission Control Protocol/Internet Protocol
MAN
Telnet- - Metropolitan
Teletype NetworkArea Network
Mbps
UPS -- Megabits per second
Uninterruptible Power Supply
M-Commerce
URL - - Mobile Commerce
Uniform Resource Locator
MMS
UTP - - Multimedia Messaging
Unshielded Twisted PairService
MODEM
Virus - - Modulator
Vital and Demodulator
Information Resources Under Seize
MS-
VLAN Access – Microsoft
Virtual Access
Local Area Network
MSAV
VOIP - Microsoft
Voice Over Anti VirusProtocol
Internet
NAS
VPN-.- NetworkPrivate
Virtual Attached Storage
Network
NAV
VR - - Norton Reality
Virtual AntiVirus
NCC
VRML- - NationalReality
Virtual Computer Center
Modeling Language
VSAT
NCP - Very SmallControl
Network Aperture Terminal
Protocol
WAN -
NetBEUI Wide Area
NetBIOS NetworkUser Interface
Extended
WAP -
NetBIOS Network
Wireless Basic Input Output
Application ProtocolSystem
Wi-Fi
NIC - - Wireless
Network Fidelity
Interface Card
WI-MAX
NOS - Worldwide Interoperability
Network Operating System for Microwave Access
WLAN - Wireless Local Area Network
WWW - World Wide Web
P a g e | 216

TECHNICAL TERMS
Give appropriate technical terms of the followings.
1. Data transmission in one direction only that is to send or receive only. Simplex Mode
2. The mode of data communication in which data can be transferred in both directions at a time. Full Duplex Mode
3. Device used to connect a PC with a telephone line. MODEM
4. Device to convert analog signal into digital signal and, vice versa. MODEM
5. A network limited with a room or building. LAN
6. The computer on which users run applications. Client
7. Cabling structure of LAN. Network Topology
8. The arrangement of connection patterns of computers or nodes and others resources. Network Topology
9. Each computer or device on a network . Node
10. A device that controls two dissimilar networks . Gateway
11. The amount of data that can be transmitted through communication channels in a fixed time period. Bandwidth
12. A server where incoming emails are collected in mailbox . Mail server
13. A computer that provides services to other computer . Server
14. A main computer of a computer network. Server
15. Operating system that can handle network . Network Operating System
16. Software which controls and manages computer network. NOS (Network Operating System)
17. A powerful program that controls and coordinates a computer’s hardware devices and runs software
and applications. Operating System
18. A cable that transmits light signals . Fiber Optic Cable.
19. Connection of two or more computers to share information . Computer Network
20. The network of networks . Internet
21. Sending and receiving messages electronically through the Internet . E-mail
22. Buying and selling of goods, products, or services over the Internet . E-commerce
23. The websites that search documents for specified keywords in WWW . Search engine
24. The communication program that searches documents on the basis of specified keywords and returns a list
of the web links that matches the keywords. Search engine
25. A port on the back of the system unit to connect a computer in network. NIC (Network Interface Card)
26. A set of rules that are followed by computer network. Protocol
27. Amplify the signal for long-distance communication in microwave. Repeater
28. Network connecting device that boosts the data signals. Repeater
29. A set of moral principles or code of conducts that regulate the use of computers . Computer ethics
30. A code of behaviour for using the Internet . Cyber ethics
31. The use of technology as a measure of behaviour responsible for digital society . Digital citizenship
32. The recording of interaction with the digital world. Digital Footprint
33. Digital marks created while using internet. Digital Footprint
34. The legal issues related to using of inter-networked information technology . Cyber law
35. The issues related to cybercrime and also help in making and implementing laws over cybercrime . Electronic Transaction Act
36. A process of performing a variety of tech-enabled activities via virtual communities and network. Social media
37. a collective online communications channels dedicated to community based input, interaction, content
sharing and collaboration. Social media
38. Combination of information technology and telecommunication technology. ICT (Information
and Communication Technology)
39. A bullying that takes place over digital devices like cell phones, computers, and tablets. Cyber bullying
40. The fake attempt to obtain sensitive information . Phishing
41. The hardware or software for recording the keys pressed on a keyboard. Keylogger
42. Law that governs the legal issues of cyberspace . Cyber law
43. The skilled computer expert who uses technical knowledge to overcome a problem. Hacker
44. The kind of harmful computer code or web script designed to create system vulnerabilities . Malicious codes
45. A malicious program of computer that damages data and Software. Malware
46. A small destructive program whose intention is harms computer software and data. Computer virus
47. The process of identifying an individual usually based on a username and password . Authentication system
48. A memorized secret used to confirm the identity of a user . Password
49. The uniquely identified by evaluating one or more distinguishing biological traits. Biometric
50. The network security systems that monitors and controls the traffic flow . Firewall
P a g e | 217

51. The technology to encode file or message. Encryption


52. The method by which information is converted into secret code that hides the information's true meaning. Encryption
53. It is the process of converting plain text to cipher text. Encryption
54. An intelligent device that has ability to determine the best possible path for data transmission. Router
55. A type of program designed to detect and remove viruses from computer system. Antivirus software
56. A program that can disinfect a file from virus. Antivirus software
57. A software application used by companies for marketing purposes. Adware
58. Any software installed on your PC that collects your information without your knowledge. Spyware
59. The conversion of encrypted data into its original form. Decryption
60. The study of secure communications techniques that allow only the sender and intended recipient of
a message to view its contents. Cryptography
61. Commercial transaction through mobile devices. M-Commerce
62. Paperless payment through Internet. Online payment
63. A system of interrelated computing device to exchange information over a network without human-to-human
or human to computer interaction. IoT (Internet of Things)
64. A variety of devices that allow people to access data and information from wherever they are. Mobile computing
65. A set of services provided by the government to public via electronic media especially using Internet. E-Governance
66. The use of computer technology to create a simulated environment. Virtual Reality
67. An emerging branch in computer science, which interprets the means and method of making computers
think like human beings.. AI (Artificial Intelligence)
68. The smallest unit to represent information on a quantum computer. Qubit (Quantum bit)
69. Crimes committed using electronic devices and cyber space. Cyber crime
70. Secret group of characters which helps to protect file from unauthorized person. Password
71. A type of network in which every computer works as both client and server. Peer to Peer Network
72. A system of copying data and information reading in computer into another location. Backup
73. A company which provides services of Internet. Internet Service Provider (ISP)
74. The internet service that enables to connect a remote or host computer. Telnet
75. Learning through the electronic media. E-learning
76. The process of repeatedly executing some code until condition satisfies. Looping
77. The protocol that makes the network communication possible. TCP/IP
78. The moral principle that controls cybercrime. Computer Ethics
79. Combination of Public and Private clouds. Hybrid Cloud
80. Hacking done with permission from the client. Ethical Hacking
81. A Private networks that allow organizations to share information and resources among the internal users. Intranet
82. The process of arranging the fragmented file in computer. Defragmentation
83. A unique numerical identifier for every device or network that connects to the internet. IP Address
84. The money that is exchanged electronically. Digital Currency
85. Software require for browsing and surfing content on the WWW. Web Browser
86. A concept of transferring data from your computer to server computer. Uploading
87. A concept of transferring data from server computer to your computer. Downloading
88. only numbers are allowed in the secret code. PIN (Personal Identification Number)
89. The combination of username and password that is used to access a resource. Credentials.
90. An applications that look like they are doing something harmless, but secretly have malicious code that
does something else. Trojan
91. A way to get the investment whole or part of it back in case the computer system is damaged. Insurance
92. The process of sending and receiving data and information between two or more than two people. Communication
93. The mode of data and information that flows in both directions but only one direction at a time. Half Duplex Mode
94. Connect communication media with network devices. Connectors
95. A network device which broadcasts the information packets to all computer connected network. Hub
96. A network model where one or more powerful computers provide the different network services and all
other users of computer network access those services to perform user's tasks. Client/Server Network
97. The network in which the main computer is known as host or server computer. Centralized network.
98. A collection of internet host systems that make services available on the Internet using the HTTP
(HyperText Transfer Protocol). WWW
99. Protecting our computer and its content from damage, theft or misuse and action to prevent such incidents.
Computer security
100. A logical collection of Internet-connected devices such as computers, smartphones or internet of
P a g e | 218

things (IoT) devices whose security have been breached and control is given away to a third party. Botnet
[Link] Management System
(2.1) Introduction
Data
Data are raw form of any facts, figures or entities which does not give any meaning.
For example, Aaradhya, 1000, account, balance etc. are raw data individually does not give any meaning.

Information
Information is the organized collection of inter-related data which has significant meaning.
For example, Aaradhya has 1000 balance in his bank account gives significant meaning.

Database
A collection of systematically organized inter-related data is called a database. The purpose of data base is to store,
organize and retrieve data. E.g. Dictionary, Marks Ledger, Telephone Directory, Attendance Register etc.

Database can be computerized and non-computerized (manual).


The database which is managed in file or ledger without using computer system is called manual database (non-
computerized).
The database which is managed by using computer system is called computerized database.

Difference between computerized and non-computerized database


Computerized Database Non-Computerized Database
It can store large volume of data. It is limited by physical storage available.
We can search data very easily. It can take a while to manually search through all
of the records.

DBMS (Database management system)


DBMS is a computerized system that stores data, processes them and provides information in an organized form.
E.g. MS-Access, Oracle, MySQL, Fox Pro etc.

Advantages of DBMS
a) It reduces data redundancy which means duplication of data.
b) It allows multiple users to access the same data simultaneously.
c) Large volume of data can be stored and updated easily.
d) It provides high security of data as well as maintains accurate database.

RDBMS (Relational Database Management System)


RDBMS is a type of DBMS that uses a relational model to organize and manage data, allowing users to easily retrieve
and manipulate it. E.g.: MySQL, Oracle, MS Access etc.

MS-Access
MS-Access is a relational database management system developed by Microsoft Corporation which is used to store
and manipulates large volume of data in multiple tables.

Features of MS-Access:
a) It provides the flexible ways to add, edit, delete and display the related data.
b) Queries help to view, change and analyse the data indifferent ways.
c) Forms are used for viewing and editing the information.
d) Reports are used for summarizing and printing the data.

Record (Tuple)
A record is a row in a table which contains information about single items in a database. Record is complete set of
information.

Field (Attributes)
P a g e | 219

A field is a column in a table which contains information about a certain type for all records. Field is a smallest
unit of information.
P a g e | 20

Value
A value is the each specific piece of information in a table.

Symbol_No Name Address Class


25612 Ram Thapa Kathmandu 10
25617 Shyam Shrestha Dhading 8
25635 Rita Dhungel Pokhara 10
Fields are : Symbol_No, Name, Address and Class
Records are : 25612, Ram Thapa, Kathmandu, 10 ; 25617, Shyam Shrestha, Dhading, 8 ; 25635, Rita Dhungel,
Pokhara, 10
Values are: 25612, 25617, 25635, Ram Thapa, Shyam Shrestha, Rita Dhungel, Kathmandu, Dhading, Pokhara, 10,
8, 10.

Data type
Data type is an attribute for a field that determines the type of data that can be stored in that field.

Data types of MS-Access:


Data Type Description Maximum Data / Default Field
Space Size
Text Used for text or combinations of text and Up to 255 Characters 255
numbers, as well as numbers those don't require
calculations, such as phone numbers
Memo Lengthy text or combinations of text and Up to 64,000 / 65535
numbers. Characters
Number Used for data to be included in mathematical 1,2,4 or 8 Bytes Long Integer
calculations.
Date/Time Used for dates and time data 8 Bytes
Currency Used for currency values. 8 Bytes
Auto Used for unique sequential (incrementing by 1). 4 Bytes
Number
Yes/No Used for data that can be only one of two 1 Bit
possible values, such as Yes/No (Boolean values)
OLE Object Used for OLE objects (such as MSWord Up to about 1 GB
documents, MS-Excel spread sheets, pictures,
sounds)
Hyperlink Used for hyperlinks Up to 2048 Characters
Attachments To attach any supported type of file Up to about 2 GB
Lookup Used to create a field that allows you to choose a Dependent on the data
Wizard value from another table type of the lookup
field

Field Properties
Field properties are settings or attributes that allow users to control various aspects of data entry, validation,
formatting, and behavior within the database.

Field Properties Description


Field Size Field size is a field property which is used to set the maximum size for data stored
in the field that is set to the Text or Number data type.
Caption Caption is a field property which gives alternative name given for any field.
The maximum size for this is 2048 characters.
Default Value Default Value is a field property that is displayed automatically for the field when
we add a new record to the table.
Format Format is a field property that allows to display data in a format different from the
way it is actually stored in a table.
P a g e | 21

Input Mask Input mask is a field property that controls the value of a record and sets in a
specific format.
Validation Rule Validation Rule is a field property which is used to limit the values that can be
entered into a field.
Validation Text Validation Text is a field property which displays an error message that appears if
the data entered is invalid according to the specified validation rule.
Required Required is a field property which is used to specify whether a value is required in a
field or not.
Indexed Indexed is a field property which speeds up searching and sorting of records based
on a field.

Objects of Ms Access
Table, Form, Query, Report, Pages, Macros, and Modules

Table
Tables are the primary building block of database which stores and manages large volume of data into rows and
column.

Importance of table
 Tables store and organize data efficiently, reducing data redundancy and inconsistencies.
 Tables enable the use of data validation rules to ensure data accuracy and completeness.
 Tables are essential for creating forms, queries, and reports that extract useful insights and information from data.
 Tables provide security features to restrict access to sensitive data and ensure data privacy.

Methods to create table


Design view
Datasheet view
Using wizard

Design View – Related with table structure. We can add, edit or delete field and its properties.
Datasheet View – Related with records. We can add, modify, search or delete records.

Form
Form is one of the MS-Access database objects which provides graphical interface to view, modify and add data in a
table or multiple linked tables.

Importance of form
 Forms provide an easy-to-use interface for data entry and manipulation, improving data accuracy and
completeness.
 Forms can include validation rules to ensure data quality and prevent errors.
 Forms enable users to customize the look and feel of data input screens.
 Forms can be linked to other objects, such as tables or queries, to simplify data management.

Methods to create form


Design view
Using wizard

Report
Report is one of the MS-Access database objects used to present information in an effective and organized format that
is ready for printing.

Importance of report
 Reports provide a formatted presentation of data that is easy to read and understand.
 Reports enable users to summarize, analyze, and visualize data in meaningful ways.
 Reports can be exported or printed for sharing with others.
P a g e | 22

 Reports can be based on tables, queries, or other reports, providing flexibility and ease of use.

Why is Report created?


Reports are created in MS Access to present data from one or more tables in a formatted and organized manner,
allowing users to easily view and analyze the information.

The data sources for report are table and query

Methods to create report


Design view
Using wizard

Query
Query is an object of database that is used to view, retrieve, change and analyze records from a table or multiple
linked tables based on specified condition.
Queries can be used to filter data, to perform calculations with data, and to summarize data.

Its types are select query and action query.


Select query is a type of query which is used to select and display the relevant data from the database.
Action query is a query that makes changes to or removes many records in just one operation.
Examples of action query are update query and delete query.
An update query is a type of query that makes entire changes to a record or group of records in one or more tables
A delete query is a type of query that deletes a record or group of records from one or more tables.
An append query is a type of action query used to add records from one or more tables or queries to another table,
based on specified criteria or selection rules.
A make-table query is a type of query used to create a new table based on the results of a select query.

Advantages of query
 Queries enable users to retrieve specific data from tables or other data sources, based on specified criteria.
 Queries allow users to filter, sort, and group data in meaningful ways.
 Queries enable users to perform calculations and aggregate functions on data to extract useful insights.
 Queries can be used to create reports and forms that extract meaningful information from data.

Methods to create query


Design view
Using wizard

Sorting
The process of arranging all the records in a table either ascending or descending order based on field or fields is
known as sorting. Sorted data is easier to handle than unsorted data.

The advantages of sorting are:


 Sorting helps to organize data and make it easier to find and retrieve specific information.
 Sorting can save time and improve efficiency by allowing users to quickly access the data they need.

Filtering
Filtering is the process of viewing required record of a table that matches the specifies criteria.

Primary key
A primary key is a field or combination of fields in a table that uniquely identifies each record, and is used to establish
relationships between tables and enforce data integrity.
The primary key does not accept duplicate value for a field and it does not allow a user to leave the field blank or null.

Importance of primary key


It sets the relationship between tables.
It reduces and controls duplication of record in a table
P a g e | 23

Foreign key
A foreign key in MS Access is a field that establishes a relationship between two tables by referencing the primary
key of another table.

Composite Key
Composite Key is the group of primary key that consists of two or more attributes.

Data Redundancy
 Data redundancy is the duplication of data within a database.
 Data redundancy can be controlled by normalizing the database, eliminating duplicate data and storing it in
separate tables, and using foreign keys to establish relationships between the tables.

Relationship
A relationship refers to the association or connection between two tables based on a common field or fields. Its types
are:
i) One to one relationship
ii) One to many relationship
iii) Many to many relationship
P a g e | 24

[Link] in QBASIC
(3.1) Programming in QBASIC
Modular programming
Modular programming is a technique used to divide our program into many small logical, manageable and functional
modules or blocks.

Advantages of modular programming


 Many programmers can write different program modules independently.
 The debugging of the program becomes easier and faster.
 The same procedure can be used in different places, which reduces the program codes.
 It improves the readability of a program.
 It is easy to design code.

Types of Procedure in Modular Programming


a) Sub-procedure
b) Function-procedure

Main Module - The main part of the program inside which several submodules are created.

Sub-Program - A group of statements written in a separate module to perform one or more tasks

Sub module / Procedure


Module is a block of statement that solves a particular problem.

SUB procedure
A sub-procedure is a small manageable and functional part of a program that performs specific tasks and does not
return any value to the calling module.
A CALL statement is used to call the sub procedure in a program.
SUB-procedure’s name does not accept data type symbol because it does not need to return a value.

Passing arguments by value (Call by value)


Call by value is a method of calling a procedure in which actual data are passed to the calling procedure module. It is
done by enclosing each parameter by a separate parenthesis ( ).

Passing arguments by reference (Call by Reference)


Call by reference is a method of calling a procedure in which the reference (address) of parameters are passed to the
calling procedure module instead of actual value. By default, the parameters are passed using call by reference
method.

Formal parameters
Formal parameters are variables which are used to specify or declare types of data to be passed to the procedures
either sub or function. A formal parameter is always variable(s).

Actual or Real parameters


Actual or Real parameters are arguments which are used to pass real value or data to the procedure.
Actual parameters may be variables or constant values or can also be in the form of expression.

Local variable
A variable which is defined in a module and is not accessible to any other modules is known as local variable
It is only accessible to the module where it is defined.
Value of local variable is destroyed when execution of module is over.
Global variable
A variable in main module which can be accessed from any module or procedure of a program is known as a global
variable.
Variable can be made global declaring them with DIM SHARED or COMMON SHARED or SHARED statement.
P a g e | 25

FUNCTION procedure
A function-procedure is a small manageable and functional part of a program that performs specific tasks and returns a
value to the calling module.
FUNCTION-procedure is called by statement and expression method.
FUNCTION-procedure’s name accepts data type symbols such as $, %, !, #, &, etc. and it depends on the type of
value to be returned. E.g.: FUNCTION REV$ returns string.

String function [SEE 2074 U]


String function is used with string it returns string value.

Numeric function [SEE 2074 U]


Numeric function is used with number it returns numeric value.

Library functions [SQE 2074K]


Library functions are built-in or readymade functions provided by QBASIC. E.g. MID$( ), LEN( ), SQR( ) etc.

User defined function


Function which is defined by the user according to the need is called user defined function.

CALL statement [SLC 2071] [PMT 2075K]


The function of CALL statement is to transfer control to another sub procedure from main module.

DECLARE statement
The function of DECLARE statement is to declare procedure such as FUNCTION or SUB in modular programming.

DIM SHARED / COMMON SHARED statement - to declare global variables in main module.

SHARED - to declare global variables in sub module


P a g e | 26

Modular Programming Solutions


1. Write a program in QBASIC that asks length, breadth and height of room and calculate its area and
volume. Create a user defined function to calculate area and sub-program to calculate volume. Hint:
[A=L×B], [V=L×B×H]

DECLARE FUNCTION AREA(L,B)


DECLARE SUB VOL(L,B,H)
CLS
INPUT “Enter Length”; L
INPUT “Enter Breadth”; B
INPUT “Enter Height”; H
PRINT “Area of room=”; AREA(L,B)
CALL VOL(L,B,H)
END

FUNCTION AREA(L,B)
AREA = L * B
END FUNCTION

SUB VOL(L,B,H)
V=L*B*H
PRINT “Volume of Room=”; V
END SUB

2. Write a program in QBASIC that allows the user to input length, breadth and height and then calculate the
area of 4 walls. Hint: [A = 2H(L+B)]

DECLARE FUNCTION AREA (L, B, H)


CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
INPUT “ENTER HEIGHT”; H
PRINT “AREA OF FOUR WALLS”; AREA(L, B,
H) END

FUNCTION AREA (L, B, H)


A = 2 * H * (L + B)
AREA = A
END FUNCTION

3. Write a program in QBASIC that allows user to enter radius of a circle. Create a user define function to find
the area of circle and sub procedure to find volume of a cylinder. Hint: [A= r2 v= r2h]
DECLARE FUNCTION AREA (R)
DECLARE SUB VOL(R, H)
CLS
INPUT “Enter Radius”; R
INPUT “Height”; H
PRINT “Area of Circle=”; AREA(R)
CALL VOL(R, H)
END

FUNCTION AREA(R)
AREA = 3.14 * R ^ 2
END FUNCTION
P a g e | 27

SUB VOL (R, H)


V = 3.14 * R ^ 2 * H
PRINT “Volume of Cylinder=”; V
END SUB

4. Write a program in QBASIC that ask the radius of circle. Write a program to calculate the area and
circumference of a circle. Create a user defined function first (r) to calculate area and sub procedure second
(r) to calculate circumference of a circle.
Ans:
DECLARE FUNCTION FIRST
(R) DECLARE SUB SECOND (R)
CLS
INPUT "ENTER RADIUS"; R
PRINT " AREA OF A CIRCLE="; FIRST (R)
CALL SECOND (R)
END

FUNCTION FIRST (R)


FIRST = 3.14 * R ^ 2
END FUNCTION

SUB SECOND (R)


C = 2 * 3.14 * R
PRINT " CIRCUMFERENCE OF CIRCLE =" ; C
END SUB

[Link] a program in QBASIC to ask a number and display sum of digits by using
FUNCTION..END FUNCTION. [4]
DECLARE FUNCTION SUM (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF DIGITS="; SUM(N)
END

FUNCTION SUM (N)


S=0
WHILE N < > 0
R = N MOD 10
S=S+R
N = N \ 10
WEND
SUM = S
END FUNCTION

[Link] a program in QBASIC that asks length, breadth of a room and calculate its area and
perimeter. Create a user defined function to calculate area and sub program to calculate perimeter.
[Hint: [Area=LxB], [p=2(L+B]]

DECLARE FUNCTION AREA (L,B)


DECLARE SUB PER(L,B)
CLS
INPUT “Enter Length”; L
INPUT “Enter Breadth”; B
PRINT “Area of rectangle=”; AREA(L,B)
P a g e | 28

CALL PER(L,B)
END

FUNCTION AREA(L,B)
AREA = L*B
END FUNCTION

SUB PER(L,B)
P=2*(L+B)
PRINT “Perimeter of rectangle=”; P
END SUB

7. Write a program in Q-Basic to find the perimeter of rectangle using Sub…END SUB procedure.
DECLARE SUB PER (L, B)
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
CALL PER (L, B)
END

SUB PER (L, B)


P = 2 * (L + B)
PRINT “PERIMETER OF RECTANGLE”; P
END SUB

8. Write a program in Q-Basic to find the largest among three number using FUNCTION procedure.
DECLARE FUNCTION GREAT (A, B, C)
INPUT “ENTER ANY THREE NUMBERS”; A, B, C
PRINT “THE GREATEST NUMBER IS”; GREAT (A, B,
C) END
FUNCTION GREAT (A, B,
C) IF A > B AND A > C
THEN
G=A
ELSEIF B > A AND B > C THEN
G=B
ELSE
G=C
END IF
GREAT = G
END FUNCTION

9. Write a program to ask a number and display odd or even using FUNCTION procedure.
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT “THE GIVEN NUMBER IS “; CHECK$
(N) END

FUNCTION CHECK$ (N)


IF N MOD 2 = 0 THEN
CHECK$ = “EVEN NUMBER”
ELSE
CHECK$ = “ODD NUMBER”
END IF
END FUNCTION
P a g e | 29
P a g e | 30

10. Write a program to calculate Area of circle using Function procedure and use SUB procedure to
calculate its circumference in Q-Basic.[Hint: [A=pr2], [C=2pr]

DECLARE FUNCTION AREA (R)


DECLARE SUB CIR(R)
CLS
INPUT “Enter Radius”; R
PRINT “Area of circle=”; AREA(R)
CALL CIR(R)
END

FUNCTION AREA(R)
AREA = 22/7*R^2
END FUNCTION
SUB CIR(L,B)
C=2*22/7*R
PRINT “Circumference of circle=”; C
END SUB
11. Write a program in QBASIC that will asks the user to input length, breadth and height of a room
then use SUB procedure calculate its volume and FUNCTION procedure to calculate its area of four
walls.
DECLARE SUB VOL(L,B,H)
DECLARE FUNCTION AREA(L,B,H)
CLS
INPUT “Enter length”; L
INPUT “Enter breadth”; B
INPUT ”Enter height”; H
CALL VOL(L, B, H)
PRINT “Area of four walls=”; AREA(L, B, H)
END
SUB VOL(L, B, H)
V=L*B*H
PRINT “Volume of room”;
V END SUB
FUNCTION AREA(L, B, H)
AREA=2*H*(L+B)
END
12. Write a program to check whether input number is negative, positive or zero using FUNCTION
procedure. [4]
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT “The given number is “; CHECK$(N)
END
FUNCTION CHECK$ (N)
IF N > 0 THEN
CHECK$ = “POSITIVE NUMBER”
ELSEIF N < 0 THEN
CHECK$ = “NEGATIVE NUMBER”
ELSE
CHECK$ = “ZERO”
END IF
END FUNCTION
P a g e | 31

13. Write a SUB program to print series: 1,1, 2, 3, 5, 8, ........... up to 10th terms. [4]
DECLARE SUB SERIES ()
CLS
CALL SERIES
END

SUB SERIES
A=1
B=1
FOR I = 1 TO 10
PRINT A;
C=A+B
A=B
B=C
NEXT I
END SUB

14. Write a program to calculate total surface area of a cylinder using function procedure and volume
using sub procedure. [Hint: Total surface area-2pr(h+r), Volume=pr2h] [4]
DECLARE FUNCTION AREA(R, H)
DECLARE SUB VOL(R,H)
Cls
INPUT "Enter radius"; R
INPUT "Enter height";
H PRINT AREA(R, H)
Call VOL(R, H)
END

FUNCTION AREA (R, H)


AREA = 2 * 3.14 * R * (R + H)
END FUNCTION
SUB VOL (R, H)
V = 3.14 * R ^ 2 * H
PRINT "Volume of cylinder"; V
END SUB
15. Write a program in QBASIC that asks principal, time and rate of interest and calculate simple interest and
amount. Create a user- defined function to calculate simple interest and sub-program to calculate amount. Hint:
[S1=P*T*R/1001, (A=P+SI)
DECLARE FUNCTION INTEREST(P,T,R)
DECLARE SUB AMOUNT(P,I)
CLS
INPUT "ENTER PRINCIAL"; P
INPUT "ENTER TIME"; T
INPUT "ENTER RATE"; R
PRINT "SIMPLE INTEREST="; INTEREST(P, T, R)
CALL AMOUNT(P, I)
END
FUNCTION INTEREST (P, T,
R) SHARED I
I = P * T * R / 100
INTEREST = I
END FUNCTION
SUB AMOUNT (P, I)
A=P+I
P a g e | 32

PRINT "AMOUNT="; A
END SUB

16. Write a program in QBASIC to display greater number using function procedure and smaller number
using sub procedure among three numbers.
DECLARE FUNCTION GREAT(A,B,C)
DECLARE SUB SMALL(A,B,C)
CLS
INPUT"ENTER FIRST NUMBER";A
INPUT"ENTER SECOND NUMBER";B
INPUT"ENTER THIRD NUMBER";C
PRINT"THE GREATEST NUMBER IS: ";GREAT(A,B,C)
CALL SMALL(A,B,C)
END

FUNCTION GREAT(A,B,C)
IF A>B AND A>C THEN
GREAT=A
ELSEIF B>A AND B>C THEN
GREAT=B
ELSE
GREAT=C
END IF
END FUNCTION
SUB SMALL(A,B,C)
IF A<B AND A<C THEN
PRINT"THE SMALLEST NUMBER IS ";A
ELSEIF B<A AND B<C THEN
PRINT"THE SMALLEST NUMBER IS ";B
ELSE
PRINT"THE SMALLEST NUMBER IS ";C
END IF
END SUB

17. Write a program in QBasic that ask the radius and height of a cylinder and calculate the volume
and curve surface area. Create a user-defined function to calculate volume and sub-procedure to calculate
curve surface area of a cylinder. [Hints: V=πr2h, CSA=2πrh]
Ans.
DECLARE FUNCTION VOL(R,H)
DECLARE SUB CSA(R,H)
CLS
INPUT “ENTER THE RADIUS”;R
INPUT “ENTER THE HEIGHT”;H
PRINT “THE VOLUME OF CYLINDER IS ”;VOL(R,H)
CALL CSA(R,H)
END

FUNCTION VOL(R,H)
VOL = 3.14*R*R*H
END FUNCTION
SUB CSA(R,H)
C = 2*3.14*R*H
PRINT “THE CURVE SURFACE AREA OF CYLINDER IS ”; C
END SUB
P a g e | 33
P a g e | 34

18. Write a QBASIC program that asks length, breadth, height and calculate Volume of Cuboid and
Total Surface Area. Create a USER DEFINED FINCTION to calculate Volume of Cuboid and SUB-
PROGRAM to calculate Total Suface of Area.
DECLARE FUNCTION VOL(L,B,H)
DECLARE SUB TSA(L,B,H)
CLS
INPUT”Enter length”;L
INPUT”Enter breadth”;B
INPUT”Enter height”;H
PRINT”Volume of cuboid=
“;VOL(L,B,H) CALL TSA(L,B,H)
END

FUNCTION VOL(L,B,H)
VOL=L*B*H
END FUNCTION

SUB TSA(L,B,H)
T=2*(L*B+B*H+L*H)
PRINT”Total surface area of cuboid=”;T
END SUB
19. Write a program in QBASIC to define a function procedure to display the area of sphere and sub
procedure to display the volume of sphere where user need to input radius in main module.
[Hint: Area = 4*3.14*R^2, Volume = 4/3*3.14*R^3]

DECLARE SUB AREA (R)


DECLARE FUNCTION VOL(R)
CLS
INPUT “Enter Radius”; R
CALL AREA(R)
PRINT “Volume of sphere=”; VOL(R)
END

SUB AREA(R)
A=4*3.14*R^2
PRINT “Area of sphere=”; A
END SUB

FUNCTION VOL(R)
VOL=4/3*3.14*R^3
END FUNCTION
20. Write a program in QBASIC that asks two numbers to find sum of squares of two
numbers using SUB....END SUB program and average of two numbers using FUNCTION...END
FUNCTION.

DECLARE SUB SQU(A, B)


DECLARE FUNCTION AVG(A, B)
CLS
INPUT “Enter first number”; A
INPUT “Enter Second number”; B
CALL SQU(A,B)
PRINT “Average of two numbers=”; AVG(A, B)
END
SUB SQU(A, B) S=A^2 + B^2
PRINT “Sum of squares of two numbers=”; S
P a g e | 35

END SUB

FUNCTION AVG(A, B)
AVG=(A+B)/2
END FUNCTION
21. Write a program in QBASIC that allows user to enter a number and check whether the given
number is prime or composite using sub procedure and check given number is even or odd using
function procedure

DECLARE SUB PRIME (N)


DECLARE FUNCTION CHECKPO$ (N)
CLS
INPUT “Enter any number”; N
CALL PRIME (N)
PRINT “The given number is”; CHECKPO$(N)
END

SUB PRIME (N)


C=0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN
PRINT "PRIME NUMBER"
ELSE
PRINT "COMPOSITE NUMBER"
END IF
END SUB

FUNCTION CHECKPO$ (N)


IF N MOD 2 = 0 THEN
CHECKPO$ = “EVEN NUMBER”
ELSE
CHECKPO$ = “ODD NUMBER”
END IF
END FUNCTION

22. WAP to calculate area of rectangle using SUB...END SUB and arca of circle using
FUNCTION...END Function.

DECLARE SUB AREA (L, B)


DECLARE FUNCTION ARE (R)
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
INPUT “ENTER RADIUS”; R
CALL AREA (L, B)
PRINT “AREA OF CIRCLE ”; ARE(R)
END

SUB AREA (L,


B) A = L * B
PRINT “AREA OF RECTANGLE=”;
A END SUB
P a g e | 36

FUNCTION ARE (L,


B) ARE = 3.14 * R ^ 2
END FUNCTION
P a g e | 37

23. Write a program in Q-BASIC that asks length, breadth and height of cuboid and calculate its
lateral surface area and Volume. Create a Function procedure to calculate lateral surface area and sub
procedure to calculate volume.) [Hint:- LSA = 2h (I+b) and V=lxbxh]

DECLARE FUNCTION LSA(L,B,H)


DECLARE SUB VOL(L,B,H)
CLS
INPUT “Enter Length”; L
INPUT “Enter Breadth”: B
INPUT “Enter Height”: H
PRINT “Lateral Surface Area of Cuboid=”; LSA(L, B, H)
CALL VOL(L, B, H)
END

FUNCTION LSA(L, B, H)
LSA=2*H*(L+B)
END FUNCTION

SUB VOL(L,B,H)
V=L*B*H
PRINT “Volume of Cuboid=”; V
END SUB

24. Write a program to define a sub procedure to display the reverse of string input by user. And define
function procedure to find out volume of cylinder where the necessary data has to be fed in main module.
[Hint volume of Cylinder=pR2H] [4]
DECLARE SUB REV(A$)
DECLARE FUNCTION VOL(R, H)
CLS
INPUT “Enter any string”; A$
INPUT “Enter radius”; R INPUT
“Enter Height”; H CALL
REV(A$)
PRINT “Volume of Cylinder=”; VOL(R, H)
END

SUB REV(A$)
FOR I=LEN(A$) TO 1 STEP-1
B$=MID$(A$, I, 1)
C$=C$+B$
NEXT I
PRINT “Reversed String is”; C$
END SUB

FUNCTION VOL(R, H)
VOL=22/7*R^2*H END
FUNCTION
P a g e | 38
P a g e | 39

25. Write a program in QBASIC that asks radius of a circle and calculate its curved surface area and volume of
hemisphere. Create a user - defined function to calculate volumeof hemisphere and sub procedure to calculate
curved surface area. [CSA=2pr2, Volume= ] 4

DECLARE FUNCTION VOL(R)


DECLARE SUB CSA(R)
CLS
INPUT “Enter Radius”; R
PRINT “Volume of hemisphere=”; VOL(R)
CALL SCA(R)
END

FUNCTION VOL(R)
VOL = 2/3*22/7*R^2
END FUNCTION

SUB CSA(R)
C=2*22/7*R^2
PRINT “Curved surface area=”; C
END SUB
P a g e | 40
Output Solutions with Dry run
1. Write the output of the given program: Show with dry run in table. [2]
DECLARE SUB SHOW(A)
CLS
N=87
CALL SHOW(N)
END

SUB SHOW(A)
DO
B=A MOD 6+3
IF B MOD 4=0 THEN GOTO AA
PRINT B;
AA:
A=A-10
LOOP WHILE
A>=50 END SUB

Dry run table


N A B=A MOD 6 + 3 IS B MOD 4=0 ? PRINT B A=A-10 WHILE
A>=50
87 87 87 MOD 6 + 3 6 MOD 4=0 ? 6 87-10=77 77>=50 YES
=3 + 3 = 6 2 = 0 No
77 77 MOD 6 + 3 8 MOD 4=0? 77-10=67 67>=50 YES
5+3=8 0=0 YES
67 67 MOD 6+3 4 MOD 4=0? 67-10=57 57>=50 YES
1+3=4 0=0 YES
57 57 MOD 6+3 6 MOD 4=0? 6 57-10=47 47>=50
3+3=6 2=0 NO NO Loop
Exits
47

The output of the program is:


6 6

2. Write the output of the given program: (Workout with dry run) [2]
DECLARE FUNCTION OUTPUT1(A)
CLS
N=135
CALL OUTPUT1(N)
END

SUB OUTPUT1(A)
DO WHILE A < >
0 R = A MOD 10
T=T+R
A=A\
10 LOOP
PRINT T
END SUB

Dry run Table


N A DO WHILE A < > 0 R=A MOD 10 T=T + R A=A\10 PRINT T
135 135 135 < > 0 Yes 135 MOD 10 = 0+5=5 135\10=13 9
5
13 13 < > 0 Yes 13 MOD 10=3 5+3=8 13\10=1

1 1 < > 0 Yes 1 MOD 10=1 8 + 1=9 1\10=0

0 0 < > 0 No
Loop Exits

The output of the program is:


9

3. Write down the output of the given programs. [2]


DECLARE SUB DISPLAY
(A) CLS
A= 3
CALL DISPLAY (A)
END
SUB DISPLAY (A)
FOR X = 1 TO 6
PRINT A;
IF A MOD 2 = 0 THEN
A=A/2
ELSE
A= (A*3)+1
END IF
NEXT X
END SUB

Dry Run
A X=1 TO 6 PRINT A; IS A MOD 2=0 ? Yes (A=A/2) No(A=A*3+1)

3 1 To 6 Yes 3 3 MOD 2=0 3*3+1=10


1=0 NO
10 2 To 6 Yes 10 10 MOD 2=0 10/2=5
0=0 YES
5 3 To 6 Yes 5 5 MOD 2=0 5*3+1=16
1=0 NO
16 4 To 6 Yes 16 16 MOD 2=0 16/2=8
0=0 YES
8 5 To 6 8 8 MOD 2=0 8/2=4
0=0 YES
4 6 To 6 4 4 MOD 2=0 4/2=2
0=0 YES
2 7 To 7 No Loop
terminates
The output of the program is:
3 10 5 16 8 4

4. Write down the output of the given program. Show with the dry run in table.
DECLARE SUB SERI ( )
CLS
CALL SERI
END
SUB SERI
A$ = "SCIENCE"
B = LEN (A$)
FOR I = 1 TO 4
PRINT TAB(I); MID$(A$, I,
B) B =B-2
NEXT I
END SUB
DRY RUN TABLE:
A$ B=LEN(A$) I=1 TO 4 PRINT TAB(I);MID$(A$, I, B) B=B-2
SCIENCE 7 1 SCIENCE 7-2=5
5 2 CIENC 5-2=3
3 3 IEN 3-2=1
1 4 E 1-2=-1
-1 5 LOOP EXITS

The output of the program is:


SCIENCE
CIENC
IEN
E

5. What will be output?


DECLARE FUNCTION FACT (N)
CLS
N=5
PRINT FACT
(N) END
FUNCTION FACT
(N) F=1
FOR I=1 TO N
F=F*I
NEXT I
FACT=F
END FUNCTION

Dry Run

N F FOR I=1 to 5 F=F*I PRINT FACT(N)


5 1 1 to 5Yes 1*1=1 120
1 2 to 5 Yes 1*2=2
2 3 to 5 Yes 2*3=6
6 4 to 5 Yes 6*4=24
24 5 to 5 Yes 24*5=120
120 6 to 5 No
LoopExits

The output of the program is:


120

6. Write the output of the given program: (Workout with a dry run). 2
DECLARE SUB
ABC(A) CLS
A=2
CALL ABC(A)
END
SUB ABC(A)
FOR J= 1 TO
5 PRINT A;
A=A+3;
NEXT J
END SUB

Dry run
A J=1 to 5 PRINT A A=A+3
2 1 to 5 Yes 2 2+3=5
5 2 to 5 Yes 5 5+3=8
8 3 to 5 Yes 8 8+3=11
11 4 to 5 Yes 11 11+3=14
14 5 to 5 Yes 14 14+3=17
17 6 to 5 No (loop
exits)

The output of the program is:


2 5 8 11 14

7. Write the output of the given program showing the dry run table.
DECLARE SUB result ( )
CLS
CALL result
END
SUB result ( )
FOR I = 9 to 1 step -2
Sum = sum + i^2
NEXT i

END SUB
Dry Run
I = 9 to 1 step -2 Sum = sum + i^2 PRINT sum
9 to 1 yes 0 + 81=81 165
7 to 1 yes 81 + 49 = 130
5 to 1 yes 130 + 25 = 155
3 to 1 yes 155 + 9 = 164
1 to 1 yes 164 + 1 = 165
-1 to 1 no
Loop Exits

The output of the program is:


165

8. Write down the output of the given program. Show with dry run in table. 2
DECLARE SUB Result(C$)
C$=”COMPUTER”
CALL Result(C$)
END
SUB Result(C$)
FOR C=1 TO LEN(C$) STEP 2 M$=MID$
(C$,C,1)
N$=N$+M$
NEXT C
END SUB
Dry run
C$ C=1 TO LEN(C$) M$=MID$(C$,C,1) N$ PRINT N$
STEP 2
COMPUTER 1TO 8 step 2 Yes C C CMUE
3 to 8 Yes M C + M =CM
5 to 8 Yes U CM + U =
CMU
7 to 8 Yes E CMU+ E =
CMUE
9 to 8 No
Loop Exits

The output of the program is:


CMUE

9. Write down the output of the given program:

DECLARE SUB Series(A)


CLS
A=20
CALL Series(A)
END
SUB Series(A)
FOR K=1 to 5
PRINT A;
A=A+10
NEXT K
END SUB

Dry run
A K=1 to 5 PRINT A A=A+10
20 1 to 5 yes 20 20+10=30
30 2 to 5 yes 30 30+10=40
40 3 to 5 yes 40 40+10=50
50 4 to 5 yes 50 50+10=60
60 5 to 5 yes 60 60+10=70
70 6 to 5 no
Loop exits

The output of the program is:

20 30 40 50 60

10. Write down the output of the given program. Show with dry run in table. [2]
DECLARE SUB Num ( )
CLS
CALL Num
END

SUB Num
N=2
A=5
C=1
WHILE C <= 9
PRINT N
N=N*3+A
A=A-1
C=C+2
WEND
END SUB

Dry Run
N A C C<=9 PRINT N N=N*3+A A=A-1 C=C+2
2 5 1 1 < = 9 Yes 2 2*3+5=11 5-1=4 1+2=3
11 4 3 3 < = 9 Yes 11 11*3+4=37 4-1=3 3+2=5
37 3 5 5 < = 9Yes 37 37*3+3=114 3-1=2 5+2=7
114 1 7 7 < = 9 Yes 114 114*3+2=343 2-1=1 7+2=9
343 0 9 9 < = 9 Yes 343 343*3+1=1029 1-1=0 9+2=11
1029 -1 11 11 < = 9 No
Loop Exits

The output of the program is:


2
11
37
114
343

11. Write the output of the given program showing the dry table. [2]

DECLARE SUB series()


CLS
CALL series
END

SUB series()
A=11111
C=5
WHILE C>=1
PRINT A; A=A\
10
C=C-1
WEND
END SUB

Dry Run
Variable Condition PRINT A; A=A\10 C=C-1
Check
A C>=1
11111 5>=1 Yes 11111 11111 \10=1111 5-1=4
1111 4>=1 Yes 1111 1111\10=111 4-1=3
111 3>=1 Yes 111 111\10=11 3-1=2
11 2>=1 Yes 11 11\10=1 2-1=1
1 1>=1 Yes 1 1\10=0 1-1=0
0 0>=1 No
Loop Exits
The output of the program is:
11111 1111 111 11 1

12. Write the output of the following program. Show dry run in table. [2]
DECLARE FUNCTION EXAM$(W$)
W$ = "COMPUTER"
PRINT EXAM$(W$)
FUNCTION EXAM$ (W$)
FOR P = 1 TO LEN(W$)
K$ = MID$(W$, P, 1)
IF P MOD 2 = 0 THEN
K$ = LCASE$(K$)
ELSE
K$ = UCASE$(K$)
END IF
S$ = S$ + K$
NEXT P
EXAM$ = S$
END FUNCTION
Dry Run
W$ P=1 to 8 K$= IS Yes No S$ = S$ + PRINT
MID$(W$ P MOD 2 = (K$ = (K$ = K$ EXAM$(W$
, P, 1) 0 LCASE$(K UCASE$(K )
$) $)
COMPUTE 1 to 8 Yes C 1 MOD 2=0 C C CoMpUtEr
R 1=0 No
2 to 8 Yes O 2 MOD 2 =0 o Co
0=0 Yes
3 to 8 Yes M 3 MOD 2=0 M CoM
1=0 No
4 to 8 Yes P 4 MOD 2 =0 p CoMp
0=0 Yes
5 to 8 Yes U 5 MOD 2=0 U CoMpU
1=0 No
6 to 8 Yes T 6 MOD 2 =0 t CoMpUt
0=0 Yes
7 to 8 Yes E 7 MOD 2=0 E CoMpUtE
1=0 No
8 to 8 Yes R 8 MOD 2 =0 r CoMpUtEr
0=0 Yes
9 to 8 No
Loop
Exits
The output of the program is:
CoMpUtEr
13. Write down the output of the given program. Show with dry run in table.
DECLARE SUB SERIES ()
CLS
CALL SERIES
END

SUB SERIES ( )
X=1
Y=2
FOR P 1 TO 10
PRINT X:
X=X+Y
Y=Y+1
NEXT P
END SUB
Dry run
X Y P=1 TO 10 PRINT X: X=X+Y Y=Y+1
1 2 1 TO 10 Yes 1 1+2=3 2+1=3
3 3 2 TO 10 Yes 3 3+3=6 3+1=4
6 4 3 TO 10 Yes 6 6+4=10 4+1=5
10 5 4 TO 10 Yes 10 10+5=15 5+1=6
15 6 5 TO 10 Yes 15 15+6=21 6+1=7
21 7 6 TO 10 Yes 21 21+7=28 7+1=8
28 8 7 TO 10 Yes 28 28+8=36 8+1=9
36 9 8 TO 10 Yes 36 36+9=45 9+1=10
45 10 9 TO 10 Yes 45 45+10=55 10+1=11
55 11 10 TO 10 Yes 55 55+11=66 11+1=12
66 12 11 TO 10 No
Loop Exits

The output of the program is:


1 3 6 10 15 21 28 26 45 55

14. Write down the output of the given program with dry run table. [2]
DECLARE SUB NUMBER ()
CLS
CALL NUMBER
END
SUB NUMBER
N=3:C=1
WHILE C<=5
PRINT N
N=N*10+3
C=C+1
WEND
END SUB
Dry Run
N C C<=5 PRINT N N=N*10+3 C=C+1
3 1 1<=5 yes 3 33 1+1=2
33 2 2<=5 yes 33 333 2+1=3
333 3 3<=5 yes 333 3333 3+1=4
3333 4 4<=5 yes 3333 33333 4+1=5
33333 5 5<=5 yes 33333 333333 5+1=6
6 6<=5 no (loop
exits)
The output of the program is:
3
33
333
3333
33333

15. Write down the output of the given program. Show with dry run in table .

DECLARE SUB SERI()


CLS
CALL SERI
END

SUB SERI
X# = 1
FOR I = 1 TO 5
PRINT X# * X#
X# = X# * 10 +1
NEXT I
END SUB

X# I = 1 TO 5 PRINT X# * X# X# = X# * 10 +1
1 1 to 5 ‘yes’ 1 1*10+1=11
11 2 to 5 ‘yes’ 121 11*10+1=111
111 3 to 5 ‘yes’ 12321 111*10+1=1111
1111 4 to 5 ‘yes’ 1234321 1111*10+1=11111
11111 5 to 5 ‘yes’ 123454321 11111*10+1=111111
111111 6 to 5 ‘no’
Loop exits

The output of the program is:


1
121
12321
1234321
123454321

16. Write down the output of the given program and show them in dry run table: [2]
DECLARE SUB CITY (K$)
CLS
CALL CITY ("KATHMANDU")
END
SUB CITY (K$)
FOR K = 1 TO LEN (K$)
C$ = MID$ (K$, K, 1)
IF K MOD 2 = 1 THEN
C$ = UCASE$ (C$)
ELSE
C$ = LCASE$ (C$)
END IF
X$ = X$ + C$
NEXT K
PRINT X$
END SUB
DRY RUN
K$ K=1 C$ = IS K Yes No X$ = X$ + PRINT X$
TO MID$ MOD C$ = C$ = LCASE$ C$
LEN (K$, 2=1 UCASE$ (C$)
(K$) K, 1) (C$)
KATHMANDU 1 to 9 K 1 MOD K K KaThMaNdU
‘yes’ 2=1 YES
2 to 9 A 2 MOD a Ka
yes 2=1 NO
3 to 9 T 3 MOD T KaT
yes 2=1 YES
4 to 9 H 4 MOD h KaTh
yes 2=1 NO
5 to 9 M 5 MOD M KaThM
yes 2=1 YES
6 to 9 A 6 MOD a KaThMa
yes 2=1 NO
7 to 9 N 7 MOD N KaThMaN
yes 2=1 YES
8 to 9 D 8 MOD d KaThMaNd
yes 2=1 NO
9 to 9 U 9MOD U KaThMaNdU
yes 2=1 YES
10 to 9
no
Loop
exits

OUTPUT
KaThMaNdU

17. FIND OUTPUT ALONG WITH DRY RUN

DECLARE SUB SERIES ( )


CLS
CALL SERIES
END
SUB SERIES
A$="NEPAL"
B=1
FOR I=1 TO LEN(A$) STEP
2 IF B < > 3 THEN
PRINT MID$(A$,B,I)
ELSE
PRINT MID$(A$,1,I)
END IF
B=B+1
NEXT I
END SUB
DRY RUN
A$ B 1 TO 5 STEP 2 B< > 3 PRINT MID$(A$,B,I)
NEPAL 1 1 TO 5 YES 1 < > 3 YES N
2 3 TO 5 YES 2 < > 3 YES EPA
3 5 TO 5 YES 3 < > 3 NO NEPAL
4 7 TO 5 NO
LOOP EXITS
OUTPUT
N
EPA
NEPAL

18. Write down the output of the given program. (2)

Show with dry run in table.

DECLARE SUB SERU ( )


CLS
CALL SERU
END
SUB SERU ()
X=2
C=1
WHILE C<=10
S=X^C
PRINT S;
C=C+1
WEND
END SUB

Dry Run
X WHILE C<=10 S=X^C PRINT S; C=C+1
2 1<=10 Yes 2^1=2 2 1+1=2
2<=10 Yes 2^2=4 4 2+1=3
3<=10 Yes 2^3=4 8 3+1=4
4<=10 Yes 2^4=4 16 4+1=5
5<=10 Yes 2^5=4 32 5+1=6
6<=10 Yes 2^6=4 64 6+1=7
7<=10 Yes 2^7=4 128 7+1=8
8<=10 Yes 2^8=4 256 8+1=9
9<=10 Yes 2^9=4 512 9+1=10
10<=10 Yes 2^10=4 1024 10+1=11
11<=10 No
Loop Exits

Output of the program is


2 4 8 16 32 64 128 256 512 1024

19. Write the output of the given program showing the dry run table. (2)
DECLARE FUNCTION PRO(N)

CLS
A=2
FOR J=1 TO 5
X= PRO(A)
PRINT X
NEXT J
END
FUNCTION PRO(N)
N=N+2
PRO=N
END FUNCTION
Dry Run
A J=1 to 5 X= PRO(A) N N=N+2 PRO=N PRINT X
2 1 to 5 yes X= PRO(2) 2 2+2=4 PRO=4 4
2 to 5 yes X= PRO(4) 4 4+2=6 PRO=6 6
3 to 5 yes X= PRO(6) 6 6+2=8 PRO=8 8
4 to 5 yes X= PRO(8) 8 8+2=10 PRO=10 10
5 to 5 yes X= PRO(10) 10 10+2=12 PRO=12 12
6 to 5 no
loop exits

Output of the program is


4
6
8
10
12

20. Write down the output of the given program. \Show with dry run in table. (2)

DECLARE SUB PATTERN(SS)

CLS
B$="PROGRAM"
CALL PATTERN(B$)
END

SUB PATTERN(S$)

H=LEN(S$)
I=10
FOR J=1 TO H STEP
2 H=H-2
PRINT TAB(I); MID$(S$,J,H)
I=I+1
NEXT J
END SUB

B$ S$ H=LEN(S$) I J=1 to 7 step 2 PRINT TAB(I);


MID$(S$,J,H)
PROGRAM PROGRAM 7 10 1 to 7 step 2 Yes MID$(S$,1,5)
PROGR
5 11 3 to 7 step 2 Yes MID$(S$,3,3)
OGR
3 12 5 to 7 step 2 Yes MID$(S$,5,1)
G
1 13 7 to 7 step 2 Yes MID$(S$,7,-1)
-
-1 14 9 to 7 step 2 No
[Loop Exits]

The output of the program is:


PROGR
OGR
G
21. Write the output of the given program. Show with dry run in table. [2]

DECLARE SUB SERIES ( )


CALL SERIES
END

SUB SERIES
A=1
FOR I = 1 TO 5
PRINT I * A
A = A+ (10 ^ I)
NEXT I
END SUB

Dry Run
A I=1 to 5 PRINT I * A A= A+ (10 ^ I)
1 1 to 5 yes 1*1 =1 1+(10^1)=11
11 2 to 5 yes 2*11=22 11+(10^2)=111

111 3 to 5 yes 3*111=333 111+(10^3)=1111

1111 4 to 5 yes 4*1111=4444 1111+(10^4)=11111


11111 5 to 5 yes 5*11111=55555 11111+(10^5)=111111

111111 6 to 5 no [Loop
Exits]

The output of the program is


1
22
333
4444
55555

22. Write down the output of the given program. [2]


DECLARE FUNCTION TEXT$(A$)
CLS
A$= “TECHNOLOGY”
Y$= TEXT$(A$)
PRINT Y$
END

FUNCTION TEXT$
(A$) B= LEN(A$)
FOR I = 1 TO B
IF I MOD 2 = 1 THEN
B$= B$+MID$(A$,I,1)
END IF
NEXT I
TEXT$= B$
END FUNCTION

Dry Run
A$ B I=1 to B IF I MOD 2 =1 B$=B$+MID$(A$,I,1) Y$ PRINT Y$
TECHNOLOGY 10 1 to 10 1 MOD 2=1 T TCNLG TCNLG
1=1 yes
2 to 10 2 MOD 2=1
0=1 no
3 to 10 3 MOD 2=1 T+C = TC
1=1 yes
4 to 10 4 MOD 2=1
0=1 no
5 to 10 5 MOD 2=1 TC+N=TCN
1=1 yes
6 to 10 6 MOD 2=1
0=1 no
7 to 10 7 MOD 2=1 TCN+L=TCNL
1=1 yes
8 to 10 8 MOD 2=1
0=1 no
9 to 10 9 MOD 2=1 TCNL+G
1=1 yes
10 to 10 10 MOD 2=1 TCNLG
0=1 no
11 to 10
Loop
Exit

The output of the program is


TCNLG

23. Write down the output of the following along with dry run table. 2

DECLARE SUB SENDUP(S$)


E$= “NPABSON"
CALL SENDUP(E$)
END

SUB SENDUP(S$)
FOR i = 1 to LEN(S$) STEP 1
IF i MOD 2<>0 THEN
EE$=EE$+LCASE$(MIDS(S$,I,1))
ELSE EE$=EE$+UCASE$
(MIDS(S$,I,1)) END IF
NEXT i
PRINT EE$
END SUB

Dry Run
E$ S$ i=1 to i Yes EE$=EE$+LCASE$ No EE$=EE$+UCASE$
LEN(S$ MO (MIDS(S$,I,1 (MIDS(S$,I,1
) D2 )) ))
<>0
NPABSO NPABSO 1 to 7 1 n n+P=nP
N N yes MO
D2
<>0
1<>0
Yes
2 to 7 2
yes MO
D2
<>0
0<>0
No
3 to 7 3 nP+a
yes MO nPa
D2
<>0
1<>0
Yes
4 to 7 4 nPa+B
yes MO nPaB
D2
<>0
0<>0
No
5 to 7 5 nPaB+s
yes MO nPaBs
D2
<>0
1<>0
Yes
6 to 7 6 nPaBs+O
yes MO nPaBsO
D2
<>0
0<>0
No
7 to 7 7 nPaBsO+n
yes MO nPaBsOn
D2
<>0
1<>0
Yes
8 to 7
loop
exits

The output of the program is :


nPaBsOn

24. Write down the output of the following program with dry run table.
DECLARE SUB REG(M,N$,T)
CLS
A=1
X$=”PABSON”
CALL
REG(A,X$,T) END
SUB REG(M,N$,T)
FOR I=LEN(N$) TO 1 STEP-
1 PRINT MID$(N$,I,M)
M=M+1
NEXT I
END SUB

Dry Run
A X$ M T I=LEN(N$) TO 1 STEP-1 PRINT MID$(N$,I,M) M=M+1
1 PABSON 1 0 6 TO 1 STEP-1 Yes MID$(PABSON,6,1) 1+1=2
N
2 5 TO 1 STEP -1 Yes MID$(PABSON,5,1) 2+1=3
ON
3 4 TO 1 STEP -1 Yes MID$(PABSON,4,1) 3+1=4
SON
4 3 TO 1 STEP -1 Yes MID$(PABSON,3,1) 4+1=5
BSON
5 2 TO 1 STEP -1 Yes MID$(PABSON,2,1) 5+1=6
ABSON
6 1 TO 1 STEP -1 Yes MID$(PABSON,1,1) 6+1=7
PABSON
7 0 TO 1 STEP -1 No
Loop Exits
The output of the program is :
N
ON
SON
BSON
ABSON
PABSON

25. Write down the output of the given program.

DECLARE SUB ptt()


CLS
CALL patt
END

SUB patt
X=1
FOR i=1 TO 5
PRINT X
X=(x*10)+i
NEXT i
END SUB

Dry Run
X I=1 to 5 PRINT X X=(x*10)+i
1 1 to 5 Yes 1 (1*10)+1
=11
2 to 5 Yes 11 (11*10)+2
=112
3 to 5 Yes 112 (112*10)+3
=1123
4 to 5 Yes 1123 (1123*10)+4
11234
5 to 5 Yes 11234 (11234*10)+5
112345
6 to 5 No
Loop Exits

The output of the program is :


1
11
112
1123
11234

26. Write down the output of the given program. Show with dry run in table: [2]

DECLARE SUB SERIES(X)


CLS
X=7
CALL SERIES(X)
END

SUB SERIES(X)
FOR M = 1 TO 10
PRINT X;
IF X MOD 2=0 THEN
X=X/2
ELSE
X=3*X+1
END IF
NEXT M
END SUB

Dry Run
X M=1 to 10 PRINT X; X MOD 2=0 X=3*X+1 (No) X=X/2 (Yes)
7 1 to 10 yes 7 7 MOD 2=0 X=3*X+1
1=0 No =3*7+1=22
22 2 to 10 yes 22 22 MOD 2=0 =22/2
0=0 Yes =11
11 3 to 10 yes 11 11 MOD 2=0 3*11+1=34
1=0 No
34 4 to 10 yes 34 34 MOD 2=0 34/2=17
0=0 yes
17 5 to 10 yes 17 17 MOD 2=0 3*17+1=52
1=0 no
52 6 to 10 yes 52 52 MOD 2=0 52/2=26
0=0 Yes
26 7 to 10 yes 26 26 MOD 2=0 26/2=13
0=0 Yes
13 8 to 10 yes 13 13 MOD 2=0 3*13+1=40
1=0 No
40 9 to 10 yes 40 40 MOD 2=0 40/2=20
0=0 Yes
20 10 to 10 yes 20 20 MOD 2=0 20/2=10
0=0 Yes
10 11 to 10 No
Loop Exits

The output of the program is:


7 22 11 34 17 52 26 13 40 20

27. Write the output of the given program. Show with dry run in table. 2
DECLARE SUB SERIES()
CLS
CALL SERIES
END

SUB SERIES( )
X#=11111
FOR I= 1 TO 5
PRINT X#^2
X# = (X# - 1) / 10
NEXT I
END SUB

Dry Run
X#=11111 I=1 to 5 PRINT X#^2 X#=(X#-1)/10
1 to 5 Yes 123454321 (11111-1)/10=1111
1111 2 to 5 Yes 1234321 (1111-1)/10=111
111 3 to 5 Yes 12321 (111-1)/10=11
11 4 to 5 Yes 121 (11-1)/10=1
1 5 to 5 Yes 1 (1-1)/10=0
0 6 to 5 No
Loop Exits

The output of the program is:


123454321
1234321
12321
121
1
Debugging Solutions
1. Re-write the given program after correcting the bugs: [2]
REM to add record in an existing file
CLS
OPEN “[Link]” FOR OUTPUT AS #1
AA:
INPUT “Enter Name, Class and Roll No.”; Nm$, Cl, Rn
INPUT #2, Nm$, Cl, Rn
INPUT “More records”; Y$
IF UCASE$(Y$)=”Y” THEN GOTO aa
CLOSE “[Link]”
END

Debugged program:
REM to add record in an existing file
CLS
OPEN “[Link]” FOR APPEND AS #1
AA:
INPUT “Enter Name, Class and Roll No.”; Nm$, Cl, Rn
WRITE #1, Nm$, Cl, Rn
INPUT “More records”; Y$
IF UCASE$(Y$)=”Y” THEN GOTO AA
CLOSE #1
END

2. Re-write the given program after correcting the bugs. [2]


REM to add more data in a sequential file.
OPEN “[Link]” FOR INPUT AS #2
DO
INPUT “ENTER NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “ENTER SALARY”; S$
WRITE #1, N$, A$, S
INPUT” Do you want to add more records.”; M$
LOOP WHILE UCASE(M$) = “Y”

END

Debugged Program
REM to add more data in a sequential file.
OPEN “[Link]” FOR APPEND AS
#2 DO
INPUT “ENTER NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “ENTER SALARY”; S
WRITE #2, N$, A$, S
INPUT” Do you want to add more records.”; M$
LOOP WHILE UCASE$(M$) = “Y”
CLOSE #2
END
3. Re-write the given program after correcting the bugs. [2]
REM to create a new file
CLS
OPEN “[Link]” FOR INPUT AS #1
DO
INPUT “Enter Name, Roll No & Total. “; N$, R, T
INPUT #1, N$, R, T
INPUT “Supply more records Y/N”; C$
LOOP WHILE UCASE(Y$)=”Y”
CLOSE #1
END

Debugged Program
REM to create a new file
CLS
OPEN “[Link]” FOR OUTPUT AS #1
DO
INPUT “Enter Name, Roll No & Total. “; N$, R, T
WRITE #1, N$, R, T
INPUT “Supply more records Y/N”; C$
LOOP WHILE UCASE$(C$)=”Y”
CLOSE #1
END

4. Debug the following program.

REM to store name, address in the file "[Link]"


CLS
OPEN "[Link]" FOR INPUT AS #1
DO
INPUT "Enter name"; name$
INPUT "Enter address"; address
WRITE name$, address$
INPUT "do you want to continue"; ans$
LOOP WHILE UCASE$(ans$)="Y"
CLOSE #2
END

Debugged program.

REM to store name, address in the file "[Link]"


CLS
OPEN "[Link]" FOR OUTPUT AS #1
DO
INPUT "Enter name"; name$
INPUT "Enter address"; address$
WRITE #1, name$, address$
INPUT "do you want to continue"; ans$
LOOP WHILE UCASE$(ans$)="Y"
CLOSE #1
END
5. Re-write the given program after correcting the bugs: [2]
REM to store record in data file

CLS
OPEN "[Link]" FOR INPUT AS #1
DO
INPUT "Enter Name, address and gender": NS, A. G
INPUT #1, NS, A. G
INPUT "Do you want to continue "; Y$
WHILE UCASE$(Y$) = "Y"
CLOSE "[Link]"
END

Debugged Program
CLS
OPEN "[Link]" FOR OUTPUT AS #1
DO
INPUT "Enter Name, address and gender": NS, A$, G$
WRITE #1, NS, A$, G$
INPUT "Do you want to continue "; Y$
LOOP WHILE UCASE$(Y$) = "Y"
CLOSE #1
END
[Link]-write the given program after correcting the bug. [2]
REM To store name and age in a sequential data file
[Link]
OPEN [Link] FOR OUT AS#1
CLS
INPUT "Enter
name";N INPUT
"Enter age";A WRITE
1,N$,A CLOSE #1
END

Debugged Program
REM To store name and age in a sequential data file
[Link]
OPEN “[Link]” FOR OUTPUT AS#1
CLS
INPUT”Enter name”;N$
INPUT”Enter age”;A
WRITE #1,N$,A
CLOSE #1
END

7. Rewrite the given program after correcting the bugs.


REM to create sequential data file "[Link]" to enter some records.
CLS OPEN "[Link]" FOR INPUT AS #1
UP:
INPUT "ENTER NAME";N$
INPUT "ENTER ADDRESS";A$
INPUT "ENTER PHONE NUMBER";PH
WRITE #2, N$,A$,PH
INPUT "Do you want to continue(y/n)?";an IF LCASE(an$)="y" THEN GOTO UP
CLOSE #1
END
Debugged program
REM to create sequential data file "[Link]" to enter some records.
CLS
OPEN "[Link]" FOR OUTPUT AS #1
UP:
INPUT "ENTER NAME";N$
INPUT "ENTER ADDRESS";A$
INPUT "ENTER PHONE NUMBER";PH
WRITE #1, N$,A$,PH
INPUT "Do you want to continue(y/n)?";an$
IF LCASE$(an$)="y" THEN GOTO UP
CLOSE #1
END

8. Re-write the given program after correcting the bugs: 2


REM to display records from existing file.
CLS
OPEN “[Link]” FOR APPEND AS #1
WHILE NOT EOF(#1)
WRITE #1, eN$, post$, salary
PRINT eN$, post$, salary
CLOSE#1
END

Debugged Program
REM to display records from existing file.
CLS
OPEN “[Link]” FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, eN$, post$, salary
PRINT eN$, post$, salary
WEND
CLOSE #1
END

9. Rewrite the given program after correcting bugs,


REM PROGRAM DISPLAY
RECORDS OPEN [Link] FOR
INPUT AS #1 CLS
WHILE NOTEOF(2)
INPUT #1, NAME$,AGE,SALARY
DISPLAY NAME$, AGE,
SALARY LOOP WEND
CLOSE #1
END

Debugged Program
REM PROGRAM DISPLAY
RECORDS OPEN “[Link]” FOR
INPUT AS #1 CLS
WHILE NOT EOF(1)
INPUT #1, NAME$,AGE,SALARY PRINT NAME$, AGE, SALARY WEND
CLOSE #1
END
10. Rewrite the given program
after correcting the bugs:
REM to display records from existing file.
OPEN "[Link]" FOR APPEND AS #1
WHILE NOT EOF (#1)
WRITE # 1, eN$, posts, salaryS
PRINT eN$, post$, salary
NEXT
CLOSE #1
END

Debugged Program
REM to display records from existing file.
OPEN "[Link]" FOR INPUT AS #1
WHILE NOT EOF (1)
INPUT # 1, eN$, posts, salary$
PRINT eN$, post$, salary
WEND
CLOSE #1
END

11. Re-write the given program after correcting the bugs: (2)

REM to store Name, post and salary


OPEN [Link] FOR OUT AS #1
INPUT "Enter name"; N
INPUT "Enter post"; PS
INPUT "Enter salary"; S
INPUT #2, NS, P$, S
CLOSE #1
STOP

Debugged Program
REM to store Name, post and salary
OPEN "[Link]" FOR OUTPUT AS #1
INPUT "Enter name"; N$
INPUT "Enter post "; P$
INPUT "Enter salary"; S
WRITE #1, N$, P$, S
CLOSE #1
END

12. Rem to add 5 records in data file [Link]


OPEN "[Link]" FOR INPUT AS
#5 FOR REP = 1 TO 5
INPUT "ENTER PATIENT NAME":PN$
INPUT "ENTER PATIENT
ADDRESS":AD$ INPUT "ENTER
PATIENT AGE": A% INPUT "ENTER
PATIENT GENDER":G$

STORE #5, PN$,AD$,A, G$


NEXT REP
CLOSE #1
END
Debugged Program

Rem to add 5 records in data file [Link]


OPEN "[Link]" FOR APPEND AS #5
FOR REP = 1 TO 5
INPUT "ENTER PATIENT NAME":PN$
INPUT "ENTER PATIENT
ADDRESS":AD$ INPUT "ENTER
PATIENT AGE": A% INPUT "ENTER
PATIENT GENDER":G$
WRITE #5, PN$,AD$,A%, G$
NEXT REP
CLOSE #1
END

13. Re-write the given program after correcting the bugs:

(2) REM to count total no. of passed student


WHILE NOT EOF()
OPEN "[Link]" FOR OUTPUT AS#1
INPU T#2,ID,M1,M2,M3
IF M1>=32, M2>=32, M3>=32 THEN
X=X+1
END IF
WEND
PRINT "TOTAL RECORD";X
END

Debugged Program

REM to count total no. of passed student


OPEN "[Link]" FOR INPUT AS #1
WHILE NOT EOF ( 1 )
INPUT #1, ID, M1, M2, M3
IF M1>=32 AND M2>=32 AND M3>=32 THEN
X=X+1
END IF
WEND
PRINT "TOTAL passed RECORD";X
CLOSE #1
END

14. Re-Write the given program after correcting the bug: 2

REM display records of students from Data file


OPEN "[Link]" FOR OUTPUT AS #1
PRINT "ROLL", NAME", "ADDRESS", "CLASS" , "SECTION"
DO WHILE NOT EOF
INPUT #1, RN. N$, AD$, CL, S$
PRINT RN, NS, ADS, CL, S$
NEXT
STOP #1
END
Debugged Program
REM display records of students from Data file
OPEN "[Link]" FOR INPUT AS #1
PRINT "ROLL", NAME", "ADDRESS", "CLASS" , "SECTION"
DO WHILE NOT EOF (1)
INPUT #1, RN. N$, AD$, CL, S$
PRINT RN, NS, ADS, CL, S$
WEND
CLOSE #1
END

15. Re-write the given program after correcting the bugs.

OPEN "[Link]" FOR OUTPUT AS #1


FOR I = 1 TO 5
INPUT "Enter Name, Class, Roll No. and Age"; N$, C, R, A
WRITE N$, C, R, A
CLOSE #1

Debugged Program:
OPEN "[Link]" FOR INPUT AS #1
FOR I = 1 TO 5
INPUT "Enter Name, Class, Roll No. and Age"; N$, C, R, A
WRITE #1, N$, C, R, A
NEXT I
CLOSE #1
END

16. Re-write the given program after correcting the bugs: 2


DECLARE SUB VOLUME (l,b,h)
CLS
INPUT "ENTER length, breadth & height";l, b, h
EXECUTE VOLUME
SUB VOLUME(l,b,h)
V=lxbxh
PRINT "The volumeis";V
END FUNCTION

Debugged Program
DECLARE SUB VOLUME (l,b,h)
CLS
INPUT "ENTER length, breadth & height";l, b, h
CALL VOLUME (l, b, h)
END

SUB VOLUME(l,b,h)
V=l*b*h
PRINT "The volume is";V
END SUB
17. Re-write the given program after correcting the bugs.

REM Program to generate 2, 2, 4, 6, 10 up to 10th term


DECLARE SUB FIBO ( )
CLS
EXECUTE FIBO
END

SUB FIBO
A=2
B=2
FOR ctr = 5 to 1
DISPLAY A; B;
A=A+B
B=A+B
NEXT ctr
END FUNCTION

Debugged Program

REM Program to generate 2, 2, 4, 6, 10 up to 10th term


DECLARE SUB FIBO ( )
CLS
CALL FIBO
END

SUB FIBO
A=2
B=2
FOR ctr = 5 to 1 STEP -1
PRINT A; B;
A=A+B
B=A+B
NEXT ctr
END SUB

18. Rewrite the following program after correcting the bugs. [2]
DECLARE FUNCTION SUM(N)
CLS
INPUT “ENTER A NUMBER”; N
SU= SUM(N)
PRINT “SUM =”; SUM(N)
END

FUNCTION SUM(N)
WHILE N< > 0
R = R MOD 10
S= S + R
N = N \ 10
WEND
S= SUM
END SUB
Debugged Program

DECLARE FUNCTION SUM(N)


CLS
INPUT “ENTER A NUMBER”; N
SU= SUM(N)
PRINT “SUM =”; SU
END

FUNCTION SUM(N)
WHILE N< > 0
R = N MOD 10
S= S + R
N = N \ 10
WEND
SUM=S
END FUNCTION

19. Re-Write the given program after correcting the bugs:

DECLARE FUNCTION RESULT$


(X,Y) CLS
INPUT “Enter marks in math:”, M R$=RESULT$
(X,N)
PRINT M$
END FUNCTION

FUNCTION RESULT$(X,Y)
IF X>=40 AND Y>=40 THEN
RESULT$ = "Pass"
ELSE
RESULT$ =
"Fail" END IF
END SUB

Debugged Program
DECLARE FUNCTION RESULT$
(X,Y) CLS
INPUT “Enter marks in math and science:”, M, N
R$=RESULT$(M,N)
PRINT R$
END

FUNCTION RESULT$(X,Y)
IF X>=40 AND Y>=40 THEN
RESULT$ = "Pass"
ELSE
RESULT$ =
"Fail" END IF
END FUNCTION
20. Re-write the given program after correcting the
bugs: CREATE FUNCTION SQUARE(N)
CLS
REM TO PRINT SQUARE OF A NUMBER
GET “ENTER ANY NUMBER”; N
CALL SQUARE(N)
END

FUNCTION SQUARE(N)
ANS=A^2
SQUARE = ANS
END SQUARE(N)

Debugged Program
DECLARE FUNCTION SQUARE(N)
CLS
REM TO PRINT SQUARE OF A NUMBER
INPUT “ENTER ANY NUMBER”; N
PRINT SQUARE(N)
END

FUNCTION SQUARE(N)
ANS=N^2
SQUARE = ANS
END FUNCTION

21. Re-write the given program after correcting the bugs: 2


REM To find the sum of even digits of multi digits number
DECLARE FUNCTION SUM (N)
CLS
ACCEPT “ENTER MULTI-DIGITS NUMBER ”; NUM
PRINT “SUM = ” ; SUM(N)
END
FUNCTION SUM(N)
WHILE N=0
R= N MOD 10
IF R MOD 2 = 0 THEN S=S+R
N = N \ 10
WEND
SUM (N)
=S
END FUNCTION

Debugged Program
REM To find the sum of even digits of multi digits number
DECLARE FUNCTION SUM (N)
CLS
INPUT “ENTER MULTI-DIGITS NUMBER ”; NUM
PRINT “SUM = ” ; SUM(NUM)
END
FUNCTION SUM(N)
WHILE N < > 0
R= N MOD 10
IF R MOD 2 = 0 THEN S=S+R
N = N \ 10
WEND
SUM =S
END FUNCTION
22. Rewrite the given program after correcting the
bugs. Rem to convert the given number in reverse order
DECLARE FUNCTION REV (A)
CLS
INPUT "ENTER A NUMBER"; A
CALL REV (A)
PRINT "REVERSE ="; RE
END
FUNCTION REV$ (A)
WHILE A<> 0
R= A MOD2
S = S * 10 + R
A = A - 10
WEND
REV = S
END SUB

CORRECTED PROGRAM
DECLARE FUNCTION REV (A)
CLS
INPUT "ENTER A NUMBER"; A
RE=REV(A)
PRINT "REVERSE ="; RE
END
FUNCTION REV (A)
WHILE A<> 0
R= A MOD
10 S = S * 10
+ R A = A \
10
WEND
REV = S
END FUNCTION

23. Re-write the given program after correcting the bugs: [2]
REM print the input integer in reverse order
DECLARE SUB REV (N)
CLS
INPUT "Enter an integer number"; NO
CALL REV (NO)
END
SUB REV
(N) A = N
WHILE A = 0
R = A MOD 10
S = S + 10 + R
A = A \ 10
NEXT
DISPLAY "Reverse"; S
END SUB

Debugged program
REM print the input integer in reverse order
DECLARE SUB REV(N)
CLS
INPUT “Enter an integer number”;NO
CALL REV(NO)
END
SUB REV(N)
A=N
WHILE A<>0
R=A MOD 10
S=S*10+R
A=A\10
WEND
PRINT”Reverse”; S
END SUB

24. Debug the following program.


DECLARE FUNCTION PAL$
(W$) CLS
INPUT "Enter a word"; W$
SHOW PAL$ (W$)
END
FUNCTION PAL$ (W$)
FOR I= LEN (W$) TO 1 STEP1
R$=R$+MID$ (W$, I, 1)
NECT I
IF R$-W$ THEM
P$="Palindrome"
ELSE
P$="Not palindrome"
ENDIF
P$=PAL$
END FUNCTION

Debugged Program
DECLARE FUNCTION PAL$ (W$)
CLS
INPUT "Enter a word"; W$
PRINT PAL$
(W$) END

FUNCTION PAL$ (W$)


FOR I= LEN (W$) TO 1 STEP-1
R$=R$+MID$ (W$, I, 1)
NEXT I
IF R$=W$ THEM
P$="Palindrome"
ELSE
P$="Not palindrome"
ENDIF
PAL$ =P$
END FUNCTION

25. Re-write the given program after correcting the bugs: 2


DECLARE SUB Series ( )
CLS
EXECUTE Series
END

SUB Series( )
REM Program to generate 1 1 2 3 5......upto the 20th terms
A=1
B=1
FOR ctr=10 to 1
DISPLAY A:B:
A=A+B
B=A+B
NEXT ctr
END Series ( )

Debugged Program
DECLARE SUB Series ( )
CLS
CALL Series
END

SUB Series( )
REM Program to generate 1 1 2 3 5......upto the 20th terms
A=1
B=1
FOR ctr=1 TO 10
PRINT A; B;
A=A+B
B=A+B
NEXT ctr
END SUB

26. Debug the following


program: DECLARE SUB SUM
(P, Q, R) CLS
INPUT “Enter the numbers”: P,Q,R
CALL SUM
END SUB

SUB Check(P,Q,R)
S=P+Q+R
PRINT “Sum of three numbers is”; SUM
END SUB

Debugged Program
DECLARE SUB SUM (P, Q,
R) CLS
INPUT “Enter the numbers”: P,Q,R
CALL SUM (P,Q,R)
END

SUB SUM(P,Q,R)
S=P+Q+R
PRINT “Sum of three numbers is”; S
END SUB

27. Re-Write the given program after correcting the bugs:


REM Program to make a word reverse
DECLARE FUNCTION Rev$(N$)
CLS
INPUT “Enter a word”: N$
DISPLAY “Reversed is”; Rev$
(N$) END
FUNCTION Rev$(N$)
FOR K=LEN$(N$) to 1 STEP-1 B$=B$+MID$
(N$,1,K)
NEXT K
B$=REV$
END FUNCTION

Debugged program
REM Program to make a word reverse
DECLARE FUNCTION Rev$(N$)
CLS
INPUT “Enter a word”: N$
PRINT “Reversed is”; Rev$(N$)
END
FUNCTION Rev$(N$)
FOR K=LEN(N$) to 1 STEP-1 B$=B$+MID$
(N$,K,1)
NEXT K
REV$ = B$
END FUNCTION
28. Re-Write the given program after correcting the bugs: [2]

REM to display the reverse of the supplied string


DECLARE SUB rev (s$)
CLS
INPUT n$
CALL rev$(n$)
END

SUB rev (n$)


FOR k=1 TO LEN(n$).
a$ = MID$(n$, 1, k)
p$ = p$ + n$
NEXT k
PRINT p$
END SUB

Debugged Program
DECLARE SUB rev (s$)
CLS
INPUT n$
CALL rev (n$)
END

SUB rev (n$)


FOR k= LEN(n$) TO 1 STEP-1
a$ = MID$(n$, k, 1)
p$ = p$ + a$
NEXT k
PRINT p$
END SUB
29. Debug

DECLARE FUNCTION vowel(S$)


w$=we love our country
v=vowel(w$)
PRINT "The total no. of vowel::"; v
END
FUNCTION vowel$(S$)
c=0
FOR K=1 TO length(S$)
B$=MID$(S$, K, 1)
B$=LCASE$(B$)
SELECT CASE B$
CASE "a", "e", "i", "o", "u"
c=c+1
END SELECT
NEXT K
C=vowel
END FUNCTION

Debugged Program

DECLARE FUNCTION vowel(S$)


w$="we love our country"
v=vowel(w$)
PRINT "The total no. of vowel::"; v
END
FUNCTION vowel(S$)
c=0
FOR K=1 TO LEN(S$)
B$=MID$(S$, K, 1)
B$=LCASE$(B$)
SELECT CASE B$
CASE "a", "e", "i", "o", "u"
c=c+1
END SELECT
NEXT K
vowel = c
END FUNCTION

30. Re-Write the given program after correcting the bugs:


REM program to make a word reverse
DECLARE FUNCTION Rev$(N$)
CLS
LNPUT “Enter a word”; N$
DISPLAY “Reversed is”; Rev$
(N$) END
EUNCTION Rev$(N$)
FOR K=LEN$(N$) To 1 STEP-1 B$=B$+MID$
(N$,1,K)
NEXT K
B$=Rev$
END FUNCTION
Debugged Program
REM program to make a word reverse
DECLARE FUNCTION Rev$(N$)
CLS
INPUT “Enter a word”; N$
PRINT “Reversed is”; Rev$(N$)
END
FUNCTION Rev$(N$)
FOR K=LEN (N$) To 1 STEP-1 B$=B$+MID$
(N$,K,1)
NEXT K
Rev$=B$
END FUNCTION
Analytical Questions Solutions
1. Study the following program and answer the given questions. [2×1=2]
OPEN “[Link]” FOR INPUT AS #1
OPEN “[Link]” FOR OUTPUT AS #2
INPUT “Enter name of the students”; S$
FOR I=1 TO 10
INPUT #1, Nm$, Cl$, A, B
IF S$< >Nm$ THEN
WRITE #2, Nm$, Cl$, A, B
END IF
NEXT I
CLOSE #1, #2
KILL “[Link]”
NAME “[Link]” AS “[Link]”
END
a. What is the main objective of the program given above?
The main objective of the program given above is to delete the record according to the entered name.
b. Do you get any problem in the above program if “Kill” statement is removed? Give reason.
Yes, the program will display the error message and it won’t delete the record.
2. Study the following program and answer the given questions. [2×1=2]
OPEN “[Link]” FOR INPUT AS
#1 DO
INPUT #1, N$, A$, S
IF UCASE$(A$)=”KATHMANDU” THEN
PRINT N$, A$, S
END IF
LOOP WHILE NOT EOF(1)
CLOSE #1
END
a. Write the use of statement “INPUT #1, N$, A$, S” in the above program.
The use of statement “INPUT #1, N$, A$, S” in the above program to read data from the data file
[Link].
b. What happens if you remove “UCASE$” from the above program?
If UCASE$ is removed then if Kathmandu is in small letters then it won’t be displayed on the screen.
3. Study the given program and answer the given questions. [2]
DECLARE FUNCTION test$ (A$)
CLS
INPUT “ENTER ANY WORD”; T$
PRINT test$(T$)
END
FUNCTION test$ (A$)
FOR M = LEN(A$) TO 1 STEP -1
C$= C$+ MID$(A$, M,1)
NEXT M
Test$ = C$
END FUNCTION
a) List the formal and actual parameters used in the program given above.
Formal parameter= A$ Actual parameter = T$
b) List the library function used in the above program.
The library function used in the above program is LEN( ) and MID$( ).
4. Study the following program and answer the given questions.
CLS
OPEN "[Link]" FOR INPUT AS #5
TOP:
INPUT "ENTER NAME"; N$
INPUT "ENTER ADDRESS";A$
INPUT "ENTER PHONE NUMBER";P
WRITE #5, N$, A$, P
INPUT "DO YOU WANT TO CONTINUE (Y/N)?"; AN$
IF UCASE$ (AN$) = "Y" THEN GOTO TOP
CLOSE #5
END
Questions:
a) List the variables used in above program.
Ans: variables used in above programs are: A$, P, N$, AN$.
b) What is the name of data file used in above program?
Ans: [Link] is the name of data file used in above
program.

5. Study the following program and answer the given questions:


DECLARE SUB PC$ (N)
CLS
INPUT "Enter a number"; N
CALL PC$ (N)
END
SUB PC$ (N)
FOR I=2 TO N-1
R=N MOD I
IF C=0 THEN
PRINT "Prime number"
ELSE
PRINT "Composite number"
ENDIF
END SUB
a. What is the name of sub procedure?
The name of the sub procedure is PC$(
)
b. List the local variable.
The local variable are N, I, R, C
6. Study the following program and answer the given questions. 2x1=2
DECLARE FUNCTION TEST(X)
X=100
Z=TEST(X)
PRINT Z
END
FUNCTION TEST(X)
FOR R=1 TO X
S=S+I
NEXT R
TEST=S
END FUNCTION
a) How many parameters are used in the above program?
Ans: The parameters used in the above program is one.
b) How many times does the statement S=S+I execute in the above program?
The statement S=S+I will execute 100 times in the above program
7. Read the following program and answer the given questions.
DECLARE FUNCTION FACT( N )
CLS
INPUT “Enter no”; N
PRINT “Factorial is”; FACT (N)
END
FUNCTION FACT
(N) F = 1
FOR X = 1 TO N
F=F*X
Next X
FACT = F
END FUNCTION
Questions:
a) What is the name of function procedure used in the above program?
The name of function procedure used in the above program is FACT ( ).
b) What is the main objective of the above program?
The main objective of the above program is to display the factorial of a given number.
8. Study the following program and answer the given questions. 2x1=2
DECLARE FUNCTION Prod(A,B)
CLS
INPUT “Enter first number”; A
INPUT “Enter second number”; B
PRINT “The product of the two number=”; prod(A,B)
END
FUNCTION Prod(A,B)
P=A*B
Prod=P
END FUNCTION
a) List all the numerical variables used in the program.
Ans: The numerical variables used in the program are A, B and P
b) List the local variable/s used in the above program.
The local variable/s used in the program are A, B and P.
9. Study the following program and answer the given questions.
DECLARE FUNCTION SUM(N)
CLS
INPUT”Enter any number”: N
X=SUM(N)
PRINT”The sum of individual digit is “; X
END
FUNCTION SUM(N)
WHILE N<>0
R=N MOD 10
S=S+R
N=INT(N/10)
WEND
SUM=S
END FUNCTION
a) Write the function of INT.
The int() function returns the numeric integer equivalent from a given expression.
b) How many times the WHILE…..WEND LOOP repeats if the value of N is 123?
The WHILE…..WEND LOOP repeats 3 times if the value of N is 123
10. Study the following program and answer the given questions: [2x1=2]

DECLARE FUNCTION count(bs)


INPUT a$
num=count (a$)
PRINT num
END

FUNCTION count (b$)


FOR K=1 to LEN (bs)
aS=MIDS(b$, K, 1)
IF UCASES(a$)="D" THEN
c=c+1
END IF
NEXT K
count = c
END FUNCTION

a) What is the name of FUNCTION procedure used in above program?


The name of FUNCTION procedure used in above program is count( ).

b) List out the formal and actual arguments from the


Formal parameter – b$, Actual parameter – a$

11. Read the following program and answer the given questions: [2]

DECLARE SUB string(x$)


CLS
X$=“COMPUTER"
CALL string(X$)
END

SUB string(x$)
L=LEN(X$)
FOR A = L to 1 step -
2 PRINT MID$
(x$.A,1); NEXT A
END SUB

Questions:

a) What is the value of L in the above program?


Ans: The value of L in the above program is 8.

b) List the numeric and string variable in the above program.


Ans: Numeric variable = L, A
String Variable = X$,

12. Study the following program and answer the given questions.

DECLARE FUNCTION ABC$(N$)


CLS
INPUT “ENTER ANY WORD”; W$
PRINT “THE RESULT STRING IS”; ABC(W$)
END

FUNCTION ABC$ (N$)


FOR I=1 TO LEN (N$)
P$=MID$ (N$,I,1)
R$=P$+R$
NEXT I
SHARED R$
ABC$=R$
END FUNCTION

a) List the arguments and parameters used in above program


Ans: The argument used in the above program is W$ and parameter is N$.

b) What is the use of SHARED in above program?


Ans: The SHARED keyword in QBASIC is used to declare global variables in sub module
13. Study the following program and answer the given questions: [2]

DECLARE FUNCTION text$(N$)


CLS
INPUT "Enter any string":X$
PRINT text$(X$)
END

FUNCTION text$(N$)
FOR i=len (N$) TO 1 STEP-1 W$=W$+MID$
(N$,i,1)
NEXT i
text$ = WS
NEXT Q

END FUNCTION

Questions:
a) What is the main objective of above program?
Ans: The main objective of above program is to reverse the string.
b) List all the parameters used in above program.
Ans: The parameters used in above program are X$ and N$

14. Study the following programs and answer the given questions. [2x1=2]
DECLARE SUB question (a, b, c)
CLS
x=10: y=20 : z=15
CALL question(x,y,z)
END
SUB question(a,b,c)
a = a +10
b=b+a
c=a+b
PRINT a,b,c
END SUB
a) What would be its output if x=1,y=2, z=3?
Ans: The output would be 11 13 24.
b) Write actual and formal parameters used in the
program. Ans: Actual parameters- x,y,z
Formal parameters-a,b,c
15. Study the following program and answer the given questions:
DECLARE FUNCTION TEST (A)
X = 10
Z = TEST
(X) PRINT Z
END
FUNCTION TEST (B)
FOR I = 1 TO B
S=S+I*I
NEXT I
TEST= S
END FUNCTION.
Questions:
a) How many parameters are used in the above program?
Ans. 1 parameter is used in the above program.
b) How many times does the statement S=S + I * I will be executed in the above program?
Ans. The statement S= S + I * I will be executed 10 times.
16. Study the following program and answer the given questions: [2x1 = 2]
DECLARE FUNCTION A
(X) CLS
X=5
Z =
A(X)
PRINT
Z END
FUNCTION A (X)
FOR I = 1 TO X
S=S+I
NEXT I
A=S
END FUNCTION
a. If the line S=S+I is changed to S=S+I^2, find the output of it.
Ans:The output will be 55.
b. How many times does the statement S=S+I execute in the above
program? Ans: The statement S=S+I executes 5 times.
17. Analytical Questions

OPEN “[Link]” FOR INPUT AS #1


OPEN “[Link]” FOR OUTPUT AS #2
CLS
DO UNTIL EOF(1)
INPUT #1, REGISTRATIONNUMBER, STUDENTNAME$, ENGLISH, NEPALI, MATHEMATICS
IF MATHEMATICS<20 THEN
MATHEMATICS=MATHEMATICS+10
END IF
WRITE #2, REGISTRATIONNUMBER, STUDENTNAME$, ENGLISH, NEPALI, MATHEMATICS
LOOP
CLOSE#1
CLOSE #2
KILL “[Link]”
NAME “[Link]” AS
“[Link]” END

a) What is the main objective of the program given above?


The main objective of the program given above is to increase marks of math by 10 whose marks in
math is less than 20.
b) Do you get any problem in above program if “Kill” statement is removed? Give reason.
Yes, there will be a problem in the above program if the "KILL" statement is removed. If the "KILL"
statement is removed, the program will not be able to delete the existing "[Link]" file.

18. Study the following program and answer the given questions: (2×1=2)

DECLARE FUNCTION COUNT (NS)


INPUT "Enter a word"; RS
C=COUNT(RS)
PRINT C
END

FUNCTION COUNT(NS)
FOR K=1 TO LEN(NS)
XS=MIDS(NS,K,1)
IF UCASES(XS)="A" THEN
X=X+1
END IF
NEXT K
COUNT=X
END FUNCTION
Questions:
a) List any two library functions used in above program.
Ans: Two library functions used in above program are UCASE$( ) and MID$( )

b) Write the use of variable "C" in line 3 [i.e. C=COUNT(RS)] given in the above
program. Ans: The use of variable "C" in line 3 [i.e. C=COUNT(RS)] is to store the value
returned by COUNT(RS) function.
19. Study the following program and answer the following questions: (2x 1=2)
DECLARE FUNCTION NUM(N)
INPUT N
S = NUM(N)
PRINT S
END
FUNCTION NUM(N)
X = INT(17/N)
Y =15 MOD N
NUM = X + Y
END FUNCTON
i. What is the name of function used in above program?
Ans: The name of function used in above program is NUM ( ).
ii. List the mathematical function used in above program.
Ans: The mathematical function used in above program is INT ( ).

20. Read the following program and answer the given questions.
DECLARE SUB AA (N$)
W$=CYBERCRIME"
CALL AA(W$)
END
SUB AA (N$)
R=LEN(N$) \ 2
E$=RIGHT$(N$,R) + LEFT$(N$,R)
PRINT E$
END SUB
Questions:
a) List the parameter(s) and argument(s) of the program.
Ans: The parameter used in above program is N$ and argument used in above program is W$.
b) List all the string library functions from the program.
Ans: The string library functions used from the program are LEN ( ), RIGHT$( ), LEFT$( ).
21. Study the following program and answer the given questions:
DECLARE SUB
FACTORS(N) N=10
CALL FACTORS(N)
END
SUB FACTORS(N)
FOR J=1 TO N
R=N MOD J
IF R=0 THEN PRINT
J;
NEXT J
END SUB
Questions:
a) Write down the use of MOD in the program.
Ans: The use of MOD in the program is to determine the remainder of a division operation.

b) How many time the loop executes in the above program?


Ans: The loop executes 10 times in the above program.
22. Study the following program and answer the given questions. [2×1=2]

DECLARE SUB TEST (A, B)


CLS
X= 7
Y=5
CALL TEST (X, Y)
END

SUB TEST (A, B)


FOR I = A to B STEP -1
A = A+ B
B=B+A
NEXT I
END SUB

a. List the formal parameter and


argument. Ans: Formal parameters are A
and B
Arguments are X and Y
b. Which loop is used in the above program?
Ans: FOR……NEXT loop is used in the above program.

23. Study the following program and answer the given questions. [2]
DECLARE SUB TEST(A$)
CLS
A$= “COMPUTER”
END

SUB TEST (A$)


L= LEN(A$)
FOR I = L TO 1 STEP -2
PRINT MID$(A$, I, 1)
NEXT I
END SUB

a) What statement should be added in the main module to execute the program?
Ans: CALL TEST(A$) statement should be added in the main module to execute the program.

b) List out the variables used in the above program with types.
Ans: the variables used in the above program are:
A$ - String Variable
L, I – Numeric Variable

24. Study the following program and answer the given questions:

DECLARE SUB TEST (B$)


CLS
INPUT W$
CALL TEST(W$)
END

SUB TEST (B$)


FOR I=1 To LEN (B$)
PRINT RIGHT$(B$,
i) NEXT I
END SUB
a. Write the names of two built in functions used in the above program
Ans: The names of two built in functions used in the above program are LEN ( ) and RIGHT$ ( )

b. List the real parameters of the above program


Ans: The real parameters of the above program is W$

25. Study the following program and answer the given questions:

DECLARE FUNCTION MATH$


(R) CLS
DIM SHARED P
INPUT "Enter first number:"; P
INPUT "Enter second number:"; C
Y$ = MATH$(C)
PRINT Y$
END

FUNCTION MATH$(R)
F=100 MOD R
IF 20 MOD P > 3 AND F < P THEN
MATH$=”True”
ELSE
MATH$=”False”
END IF
END FUNCTION
a) Variable P remained uncalled in the main module. Why?
Ans: Variable P remained uncalled in the main module because P is declared as global variable and its value can be
accessed by MATHS$ ( ) function without passing the value.

b) Find the output if the user supplies P=9 and c=4 running the program.
Ans: The output of the program if the user supplies P=9 and c=4 running the program is:
False

26. Study the following program and answer the given questions: [2]

DECLARE FUNCTION OUTPUTS(W$)


CLS
W$="CYBER CRIME"
PRINT OUTPUT$ (W$)
END

FUNCTION OUTPUT$ (W$)


FOR M= LEN(W$) TO 1 STEP-
2 M$=M$+MID$(W$, M, 1)
NEXT M
OUTPUT$=M$
END FUNCTION
a Why is $ sign is followed by function name?
Ans: The $ sign is followed by function name because the function returns string value.
b. List the library function used in the above program.
Ans: The library function used in the above program are LEN( ) and MID$( ).
27. Study the following program and answer the given questions: 2×1=2
DECLARE SUB EXAMSEE (A$)
INPUT "Enter any string", B$
CALL EXAMSEE (B$)
END

SUB EXAMSEE(A$)
FOR I= LEN (A$) TO 1 STEP-1
PRINT LEFT$(A$,1)
NEXT I
END SUB

a) Write the names of two built in functions used in the program.


Ans: The two built in functions used in the program are: LEN( ) and LEFT$( )
b) List the real parameter and formal parameter in the
program. Ans: The real parameter is B$ and formal parameter
is A$
(3.2) File processing (file handling)
File
The collection of different data or information or instructions, which is stored in secondary storage devices under a
unique file name, is known as file

File handling
File handling is a process to create a data file, write data to the data file and read data from the specified data file.

Data file
Data file is a collection of data such as name, address, class, etc. required for data processing.
The different types of data file are:
a) Sequential Access files - Sequential Access to a data files means that the computer system reads or writes
information to the file sequentially, starting from the beginning of the file and proceeding step by step.
b) Random access files - Random Access to a file means that the computer system can read or write information
anywhere in the data file.

Program File
The set of instruction written in a computer language for data processing under unique file name is known as program
file.

Mode of data file


Mode of data file means opening a sequential file for one of the three modes of operation like output mode, input
mode and append mode.

Modes of operation for opening a sequential file


a) Output Mode: It is used to create a new sequential data file and write data in it. If the file already exists its current
contents will be destroyed. It starts writing data always from the beginning of the file (BOF).
b) Input Mode: It is used to read / display data or information from the existing sequential data file.
c) Append Mode: It is used to add more records in the existing sequential file.. If the specified file does not exist
APPEND mode creates it. It starts adding of data always from the end of the file (EOF).

File number
The number assigned to a file in order to identify it during processing is called file number.

Write down the functions of:

OPEN statement: It opens a sequential file for one of the three possible operations (reading, writing, appending).

WRITE statement: It writes data to a sequential file. It inserts commas between the data items. It encloses strings in
double quotation marks.

PRINT#: It writes data to a sequential file It adds spaces between data items while storing data. It does not enclose
strings in double quotation marks.

CLOSE statement : It closes one or all open files.

INPUT# statement: It reads data items from a sequential file and assigns them to variables.

EOF( ) function: It is used to check whether the record pointer reaches at end of file or not.
LINE INPUT statement: It reads an entire line without delimiters from a sequential file to a string variable.

INPUT$ function: It returns a string of characters read from the specified file.

NAME statement : The NAME statement changes the name of a disk file or directory

KILL statement : The KILL statement deletes a file.


MKDIR statement : It creates a new directory..

CHDIR statement: It changes the current default directory for the specified drive.

RMDIR statement : It remove an existing empty directory.

FILES statement: The FILES statement displays the list of files residing on the specified disk.

SHELL: The SHELL statement executes a DOS command.

SYSTEM : This command is used to close QBASIC program window

INT ( ) : It rounds and returns the largest integer less than or equal to a numeric expression.

PRINT : Display result on screen.

MID$ ( ) : t is a string function that returns the specified number of characters from the specified location of string.

LEN ( ): Returns the number of characters in a string or the number of bytes required to store a variable.

SQR ( ) : Returns the square root of a numeric expression.


Qbasic Operators
Operators are special symbols that are meant for specific tasks or operators.
i) Arithmetic operators
ii) Relational operators
iii) Logical Operators
iv) String operator
Static variable
The variable which is declared by using the “STATIC” keyword is called static variable.
Comparing C and QBASIC language

QBASIC C
It is a high level language without feature of low It is a high level language with some features of
level language. low level language.
It is mostly used to design application software. It is mostly used to prepare system software.
It supports structure programming with sub and It is a structured programming language with
function procedure. function procedure.
It is not case sensitive It is case sensitive
IBM PC version of BASIC has around 159 It has only 32 keywords.
keywords.
File Handling Programming Solutions

1. Write a program to store Roll no., Name, Class and Address of any five students. [SEE 2074]
OPEN "[Link]" FOR OUTPUT AS #1
FOR I = 1 TO 5
INPUT "Enter Roll No."; r
INPUT "Enter Name"; n$
INPUT "Enter Class"; c
INPUT "Enter Address"; a$
WRITE #1, r, n$, c, a$
NEXT I
CLOSE #1
END

2. A sequential data file called “[Link]” contains same records under the field’s name, english, nepali
and computer. Write a program to add some more records in the same sequential data file. [SLC 2068]
OPEN “[Link]” FOR APPEND AS #1
DO
CLS
INPUT “ENTER NAME”; N$
INPUT “ENTER MARKS IN ENGLISH”; E
INPUT “ENTER MARKS IN NEPALI”; N
INPUT “ENTER MARKS IN COMPUTER”; C
WRITE #1, N$, E, N, C
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END
3. A sequential data file “[Link]” and store Name, Address and Salary of employees of an office.
WAP to add some more records in the data file “[Link]”. The program should terminate with user
choice. OPEN “[Link]” FOR APPEND AS #1
DO
CLS
INPUT “ENTER NAME”; N$
INPUT “ENTER MARKS IN ENGLISH”; E
INPUT “ENTER MARKS IN NEPALI”; N
INPUT “ENTER MARKS IN COMPUTER”; C
WRITE #1, N$, E, N, C
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END
4. Create a data file to store the records of few employees having Name, Address, Post, Gender and
Salary fields. [SEE 2073]
OPEN “[Link]” FOR OUTPUT AS #1
TOP:
CLS
INPUT “Enter Name”; N$
INPUT “Enter Address”; A$
INPUT “Enter Post”; P$
INPUT “Enter gender”; G$
INPUT “Enter Salary”; S
WRITE #1, N$, A$, P$, G$, S
INPUT “Do you want to continue”; CH$
IF UCASE$(CH$)=”Y” THEN GOTO TOP
CLOSE #1
END
5. Create a sequential data file ’[Link]’ to store item name, quantity and Rate also calculate
total amount(total=Quantity X Rate).Program should terminate according to the user’s choice.
OPEN “[Link]” FOR OUTPUT AS #1
TOP:
CLS
INPUT “Enter Item Name”; N$
INPUT “Enter Quantity”; Q
INPUT “Enter Rate”; R
T=Q*R
WRITE #1, N$, Q, R, T
INPUT “Do you want to continue”; CH$
IF CH$=”Y” OR CH$ = “y” THEN GOTO TOP
CLOSE #1
END

6. Create a sequential data file’[Link]’ to store name and marks of any three subjects also calculate total and
percentages only for 15 students.
OPEN "[Link]" FOR OUTPUT AS #1
FOR I = 1 TO 15
INPUT "Enter Name"; n$
INPUT "Enter marks in any three subjects”; A, B, C
T=A+B+C
P=T/3
WRITE #1, n$, A, B, C, T, P
NEXT I
CLOSE #1
END

7. Store SIDNO, name, address and Telephone number of five students and display the records on monitor
in sequential data file “STDINFO”
OPEN "[Link]" FOR OUTPUT AS #1
FOR I = 1 TO 5
CLS
INPUT "ENTER NAME"; N$
INPUT "ENTER ADDRESS"; A$
INPUT "ENTER TELEPHONE"; T#
WRITE #1, N$, A$, T#
NEXT I
CLOSE #1
OPEN "[Link]" FOR INPUT AS #1
CLS
FOR I = 1 TO 5
INPUT #1, N$, A$, T#
PRINT N$, A$, T#
NEXT I
CLOSE #1
END

8. A sequential data file “[Link]” contains serial no, name, address, telephone and email_id.WAP
to record as many records as the user wants. The serial number should be generated automatically like
5001,5003,5005.
OPEN " [Link] " FOR OUTPUT AS #1
DO
CLS
C = 5001
INPUT “ENTER NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “ENTER TELEPHONE”; T#
INPUT “ENTER EMAIL”; E$
WRITE #1, C, N$, A$, T$, E$
C=C+2
INPUT “DO YOU WANT TO CONTINUE (Y / N)”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END

9. A Sequential data file called "[Link]" has stored data under the field heading Symbol No., Name,
English, Nepali, and Computer. Write a program to display all the information of those students whose marks
in Computer is more than 80.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A, B$, C, D, E
IF E > 80 THEN PRINT A, B$, C, D, E
WEND
CLOSE #1
END

10. A sequential data file “[Link]” contains name and marks in three different subjects of some
students. Write a program to display only fail student’s records assuming pass marks 40.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, B$, C, D, E
IF C < 40 AND D <40 AND E <40 THEN PRINT B$, C, D, E
WEND
CLOSE #1
END
11. Write a program which reads records from the file ”[Link]” having the fields name, and marks
of three different subjects and display only those records whose percentage is greater than 60 and less than 80.
Also count the total number of records presenting in that data files.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, B$, C, D, E
A=A+1
T=C+D+E
P=T/3
IF P > 60 AND P < 80 THEN PRINT B$, C, D, E
WEND
PRINT “TOTAL NO. OF RECORDS=”; A
CLOSE #1
END

12. Write a program to read all the records from the data file “[Link]” and display all the
records where the fields name are unknown.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
LINE INPUT #1, A$
PRINT A$
WEND CLOSE #1 END
13. A data file "[Link]" contains the records composed of the fields like school, principal, address,
contact. Write a program in Qbasic to display records of the schools located in either Kathmandu or Palpa
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A$, B$, C$, D
IF UCASE$(C$) = “KATHMANDU” OR UCASE$(C$) = “PALPA” THEN PRINT A$, B$, C$, D
WEND
CLOSE #1
END

14. A data file “[Link]” has numerous records in it with name, address age, and telephone numbers in
it. Write a program to read all the records and print those with address “NEPAL” and age >15
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A$, B$, C, D
IF UCASE$(B$) = “NEPAL” AND C >15 THEN PRINT A$, B$, C, D
WEND
CLOSE #1
END

15. A sequential data file called '[Link]' contains NAME, AGE, CITY and TELEPHONE fields.
Write a program to display all the contents of that data file.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A$, B, C$, D
PRINT A$, B, C$, D
WEND
CLOSE #1
END

16. A data file “[Link]” 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.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A$, B$, C
D=D+1
WEND
PRINT “TOTAL NUMBER OF RECORDS=”; D
CLOSE #1
END
17. Write a program in QBASIC to open a sequential data file “[Link]”, which contains employees
records: Name, address and phone number and display all the records as well as total number of records
stored in the file.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, A$, B$, C
PRINT A$, B$, C
D=D+1
WEND
PRINT “TOTAL NUMBER OF RECORDS=”; D CLOSE #1 END

18. A sequential data file named “[Link]” 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 "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P, T, R
I=P*T*R/100
PRINT A$, B$, C, I
WEND
CLOSE #1
END

19. A sequential data file “[Link]” contains the information, Employee-Code, Employee-Name, Post,
Basic-Salary. Write a program to display those records whose Basic-salary is between 10000 to 15000 and Post
is ‘OFFICER’.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, E,, N$, P$, S
IF UCASE$(P$) = “OFFICER” AND S >= 10000 AND S>= 15000 THEN PRINT A$, B$, C, D
WEND
CLOSE #1
END

20. A data file name “[Link]”, contains number of records having fields name, post and salary. Write
a program to count total number of “Manager” in the data file. (hint: Manager is a post)
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S
IF UCASE$(P$) = “MANAGER” THEN PRINT C = C + 1
WEND
PRINT “TOTAL [Link] MANAGERS ARE”; C
CLOSE #1
END

21. A sequential data file “[Link]” contains name, post and salary fields of information about employees.
Write a program to display all the information of employees along with tax amount (also tax is 15% of
salary). OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S
T = 15 / 100 * S
PRINT N$, P$, S, T
WEND
CLOSE #1
END
22. A data file “[Link]” 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 15000 and less than
40000. OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S
IF S >= 15000 AND S <= 40000 THEN PRINT N$, P$, S
WEND
23. Write a program that reads the ”[Link]” file that has several record such as name, address, gender,
post, and salary .The program display those record whose sex is male and salary more than 10,000 and also
the program counts the total number of records in that file.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, A$, G$, P$, S
C=C+1
IF UCASE$(G$)=”M” AND S >= 10000 THEN PRINT N$, A$, G$, P$, S
WEND
PRINT “TOTAL NUMBER OF RECORDS=”; C
CLOSE #1
END

24. A sequential data file’[Link]’ has few records related to name, address, [Link] to display the
records whose address begins with ‘S’ or ‘D’
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, P$, S
A$ = UCASE$(LEFT$(N$,1))
IF A$ = “S” OR A$ = “D” THEN PRINT N$, P$, S
WEND
CLOSE #1
END

25. Write a program to open a data file “[Link]” that contains name, address, date of birth, email and
telephone number of some employees. Now display all those records whose date of birth is in current
month.

OPEN "[Link]" FOR INPUT AS #1


CLS
WHILE NOT EOF(1)
INPUT #1, n$, d$, a$
b$ = LEFT$(DATE$,
2)
c = VAL(b$)
e$ = LEFT$(d$, 2)
f = VAL(e$)
IF c = f THEN PRINT n$, d$, a$
WEND
CLOSE #1
END

26. A sequential data file “[Link]” has few records related to name, address, post and
DOB(mm/dd/yyyy). WAP to display the records of all those who were born between 1971 to 1999.

OPEN "[Link]" FOR INPUT AS #1


CLS
WHILE NOT EOF(1)
INPUT #1, n$, a$, p$, d$
d$ = RIGHT$(d$, 4)
c = VAL(b$)
IF c >= 1971 and c<=1999 THEN PRINT n$, d$, a$
WEND
CLOSE #1
END
27. Write a Qbasic program that read the "[Link]" file with Name, Address, Post and Salary columns
from E: drive that has 500 records of employees and displays only its last 50 records.
OPEN "E:\[Link]" FOR INPUT AS #1
CLS
FOR i = 1 TO 500
INPUT #1, n$, a$, p$, s
IF i >= 450 AND i <= 500 THEN PRINT n$, a$, p$, s
NEXT i
CLOSE #1
END

28. A sequential data file has 100 records having field name, class and roll number. Write a program to
display from 50th to 60th records.

OPEN "[Link]" FOR INPUT AS #1


CLS
WHILE NOT EOF
(1) INPUT #1, N$, C,
R D=D+1
IF D >= 50 AND D <= 60 THEN PRINT N$, C, R
WEND
CLOSE #1
END

29. Write a program to display the first 10 records from a file named “[Link]” having fields name,
phone and email.
OPEN "[Link]" FOR INPUT AS #1
CLS
FOR I = 1 TO 10
INPUT #1, N$, C, R
PRINT N$, C, R
NEXT I
CLOSE #1
END
30. A data file named “[Link]” contains some records with the fields Code, Name, Post and Salary. Write
a program to print odd position records of the data file.
OPEN "[Link]" FOR INPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, C, N$, P$, S
D=D+1
IF MOD 2 = 1 THEN PRINT C, N$, P$, S
WEND
CLOSE #1
END

31. A sequential data file named “[Link]” has several records having fields name, roll and class. Write
a program to copy all the records of class 10 into a newly created file [Link].
OPEN "[Link]" FOR INPUT AS #1
OPEN "[Link]" FOR OUTPUT AS #1
CLS
WHILE NOT EOF (1)
INPUT #1, N$, R, C
IF C = 10 THEN WRITE #2, N$, R, C
WEND
CLOSE #1, #2
END
32. A data file named “[Link]” contains name, age and salary for n number of persons. Write a program
to input a name to search data from a data file. If the data is not found, then display the message “Data not
found in the list”.
OPEN “[Link]” FOR INPUT AS #1
CLS
INPUT “Enter name to be searched”; S$
FLAG=0
WHILE NOT EOF(1)
INPUT #1, N$, A$, S
IF UCASE$(S$)=UCASE$(N$) THEN
PRINT N$, A$, S
FLAG=1
END IF
WEND
IF FLAG=0 THEN PRINT “Data not found”
CLOSE #1
END
33. A sequential data file '[Link]' contains registration number, student name, address and date of birth
of some students. Write a program that asks a user to input a registration number and displays the record of
the particular registration if present.
OPEN “[Link]” FOR INPUT AS
#1 CLS
INPUT “Enter registration no. to be searched”; S
FLAG=0
WHILE NOT EOF(1)
INPUT #1, R, N$, A$, D$
IF S = R THEN
PRINT R, N$, A$, D$
FLAG=1
END IF
WEND
IF FLAG=0 THEN PRINT “Data not found”
CLOSE #1
END

34. WAP that asks a post of the employee and displays his/her records from the sequential data
file “[Link]” having fields Name, Post, Dept and Salary.
OPEN “[Link]” 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
35. Delete some records from “[Link]” file where computer ask user to enter the record, which is to be
deleted. (Fields are name, address, and telephone number)

OPEN “[Link]” FOR INPUT AS #1


OPEN “[Link]” 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 “[Link]”
NAME “[Link]” AS “[Link]”
END

36. A sequential data file “[Link]” contains information such as student’s name, marks obtained in math,
science and computer. Write a program that increase the marks of computer by 10 of those student who
secured less than 40
OPEN "D:\[Link]" FOR INPUT AS #1
OPEN "d:\[Link]" FOR OUTPUT AS #2
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A, B, C
IF C > 40 THEN
WRITE #2, N$, A, B, C
ELSE
C = C + 10
WRITE #2, N$, A, B, C
END IF
WEND
CLOSE
KILL "D:\[Link]"
NAME "D:\[Link]" AS "D:\[Link]"
END

37. A sequential data file “[Link]” contains different records under fields: name rollno., name,
address and percentage. Write a program to edit a record and display both edited and unedited records on the
screen to compare them side by side.
OPEN "D:\RECORD" FOR INPUT AS #1
OPEN "d:\[Link]" FOR OUTPUT AS
#2 CLS
INPUT "ENTER ROLL NUMBER TO EDIT DATA"; E
FLAG = 0
WHILE NOT EOF(1)
INPUT #1, R, N$, A$, P
IF E <> R THEN
WRITE #2, R, N$, A$,
P ELSE
INPUT "ENTER ROLL NUMBER"; ER
INPUT "ENTER NAME"; EN$
INPUT "ENTER ADDRESS"; EA$
INPUT "ENTER PERCENTAGE"; EP
WRITE #2, ER, EN$, EA$, EP
FLAG = 1
END IF
WEND
IF FLAG = 0 THEN
PRINT "DATA NOT
FOUND" ELSE
PRINT "NON EDITED DATA"
PRINT "ROLL NUMBER= ";
R PRINT "NAME= "; N$
PRINT "ADDRESS= "; A$
PRINT "PERCENTAGE= ";
P PRINT " "
PRINT "EDITED DATA"
PRINT "ROLL NUMBER: ";
ER PRINT "NAME: "; EN$
PRINT "ADDRESS: "; EA$
PRINT "PERCENTAGE: "; EP
END IF
CLOSE
KILL "D:\[Link]"
NAME "D:\[Link]" AS "D:\[Link]"
END
4.C- Programming
1. Introduction to C-Language Programming
Structured programming
The programming that follows a top- down approach, on which developers separate the overall program structure into
different sub section, is called structured programming.

Advantages of structured programming


a) Reduces complexity and easy to code.
b) It takes less time to program and easy to debug.
c) Reuse of modules and flow of control is clear.

C language
C Language is a high-level structured programming language which is used to develop system software.
Dennis Ritchie at Bell telephone laboratory developed C-language in early 1970s.
C is called middle level language because it combines elements of high level language with some features of
assembler.
Data types used in C
Data type are means to identify the type data and associated operation of handling it.
Data types used in C language
a) char b) int c) float d) double e) void

Features of C language
a) C is a Structured Programming Language. which break down a program in several small modules and
makes the programmer easier to manage and debug the code.
b) C combines elements of a high level language with some features of assembler which helps to
manipulates memory address.
c) C is a case-sensitive programming language. It understands the capital alphabets and small alphabets
as different values.
d) C is many time faster and efficient than BASIC due to the variety of data type and a list of powerful
operators, programs written in C language.

Limitations of C language
a) There is no runtime checking. It has poor errors detection system.
b) It does not support object oriented programming.
c) C language has only 32 Keywords
d) There is no strict type checking int data type to float variables.

Application of C Language
a) Operating System
b) Language Compilers/Interface
c) Assemblers
d) Text Editors
e) DBMS
f) Utilities etc.

C Token
C tokens are the basic buildings blocks in C language which are constructed together to write a C program.
Each and every smallest individual unit in a C program are known as C tokens

C tokens are of six types.


a) Keywords (eg: int, while),
b) Identifiers (eg: main, total),
c) Constants (eg: 10, 20),
d) Strings (eg: “total”, “hello”),
e) Special symbols (eg: (), {}),
f) Operators (eg: +, /,-,*)
C keywords (reserved word)
Keyword is a set of special words which are already defined for some tasks.
C has only a set of 32 keywords, which have their predefined meaning and cannot be used as a variable name.
E.g. auto, double, int struct, break, else, long, switch, case, enum, register, typedef, char, extern, return, union,
continue, for, signed, void, do, if, static, while, default, goto, sizeof, volatile, const, float, short, unsigned

C Character set
Character Set is a group of valid characters and symbols supported by a programming language. Alphabets, Digits and
Special characters.

Identifiers
Identifiers are the names given to the entities such as variables, functions, arrays structures and unions.
E.g. int price; float total; Here, price and total are called identifiers.

Rules for naming Identifiers:


i) The Identifier must start with an alphabet or an under score (_).
ii) Identifier can be made from the combination of alphabets, digits and under score.
iii) No any C keyword can be used as an Identifier.
iv) Identifier must be unique and can be used for a single purpose only.

Format Specifier
The format specifier is used during input and output operation. It tells the compiler what type of data is stored in a
variable during the input and output operation such as taking data from keyboard and display data on the screen. Some
examples are %c, %d, %f, etc.
Data Type Format Specifier
short int %hd
unsigned short int %hu
unsigned int %u
int %d
long int %ld
unsigned long int %lu
char %c
float %f
double %lf

C Header Files
stdio.h - Used for standard input and output (I/O) operations. [printf( ), scanf( ), getchar( )]
conio.h - Contains declaration for console I/O functions. [clrscr( ), exit( )]
math.h - D e c l a r e s m a t h e m a t i c a l functions and macros. [pow(), squr(), cos(), tan(), sin(), log() ]
string.h - Used for manipulating strings. [strlen(), strcpy(), strcmp(), strcat(), strlwr(), strupr(), strrev() ]

Escape Sequence
Escape Sequence is a pair of character that is used with printf() function to display non-printing character or a special
character on the screen.
Some Examples of Escape Sequence:
\n - new line
\t - tab
\b - backspace
\o - null character
\? - question mark
\\ - slash
\' - single quote
\” - double quote
Format Identifier
We need to include format identifier to tell the data type in the area of format string of printf() function.
Variable Type Format Identifier
char %c
int %d
long int %ld
float %f

Variable
A variable is a location in the memory of a computer which holds data in a program and its value may change during
the execution of program.

Constant
Constant are the values that do not change during the execution of a program.

String Constant
String constant is a message to be displayed along with the other values stored in variables. It is enclosed within
double quotation (" ").

Output Function in C
Output function is used to show the calculated result or output on the screen.
In C language, printf() is one of the output function defined in header file.

printf() function
In C Language, printf() function is used to print the valued on the screen.
It is defined in header file. So, the header file must be added to use this function.

Input Function in C
Input function is used to ask data for processing.
In C language, scanf() is one of the input function defined in header file.

scanf() Function
scanf() is one of the most important functions of C Program.
This function is also defined in the header file and used to ask value from keyboard.

getch() function
getch() function is another input function of C language.
This function is defined in the header file .
This function is used to ask any one character from keyboard.
Arithmetic Calculations in C Program
There are basically four types of arithmetic operations:
i) Addition
ii) Subtraction
iii) Multiply
iv) Division

List of Arithmetic Operators in C


+ (Plus) - Addition
- (Minus) – Subtraction
* (Asterisk) – Multiplication
/ (Slash) – Division
% (Percentage Symbol) – Modulus Division
++ (Plus Plus) – Increment Operator
- - ( M i n u s M i n u s ) – Decrement Operator
Operator
Operators are special symbols that are meant for specific tasks or operators.
The different types of C operators are:- Arithmetic operators, Assignment operators, Unary operators, Relational
operators, Logical operators and Conditional operators.
Arithmetic operators are the operators that are used for manipulating arithmetic data and performs
arithmetic operation. The arithmetic operators are:- +, - , *, / and %
The operator that operate on one operand variable or constant is called urinary operator. E.g. ++, - -

C Expression
An expression consists of at least one operand with one or more operators. It is a legal combination of symbols that
represents a value.

Logical Calculation in C
The calculation that is done based on one or more conditions is called logical calculations.
Several relational or comparison operators are used to check the condition which gives True or False as a calculated
result.

Relational Operators in C
Relational Operator checks the relationship between two operands and returns either 1 (True) or 0 (False).
In C programming, relational operators can be used to take decisions and provide condition in looping statements.

List of Relational Operators in C


= = Equal to
> Greater than
< Less than
!= Not equal to
>= Greater than or equal to
<= Less than or equal to

Control structures in C

a) Sequence structure (straight line paths)


The statements are executed one after another sequentially from top to bottom without changing the flow of program.

b) Selection structure (one or many branches)


The control of the program is transferred from one part of the program to another on the basis of specified condition or
without condition.
If statement and switch statement are the examples of selection structure.

c) Loop structure (repetition of a set of activities)


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

Looping statements in C
C provides three kinds of loops: i) while loop ii) do loop iii) for loop
C PROGRAMMING Solutions
1. Write a C program to find the average of any two numbers given by the user.

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
float c;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
c=(a+b)/2;
printf("Average of two numbers= %.2f",c);
return 0;
}

2. Write a C program to calculate the average of three numbers.

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
float d;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
printf("Enter second number: ");
scanf("%d", &c);
d=(a+b+c)/3;
printf("Average of two numbers= %.2f",d);
return 0;
}
3. Write a C program to calculate the volume of a cylinder.
#include<stdio.h>
#include<conio.h>
int main()
{
float r, h, v;
printf("Enter radius and height: \n");
scanf("%f %f", &r, &h);
v=(22/7)*r*r*h;
printf("Volume of cylinder=
%.2f",v); return 0;
}

4. Write a C program to calculate distance travelled by a body.

#include<stdio.h>
#include<conio.h>
int main()
{
float u, a, s;
int t;
printf("Enter initial velocity: ");
scanf("%f", &u);
printf("Enter acceleration: ");
scanf("%f", &a);
printf("Enter time: ");
scanf("%d", &t); s=(u*t)+
(a*t*t)/2;
printf("Distance travelled by body= %.2f", s);

return 0;
}

5. Write a C program using to get radius of circle and then print its area.
#include<stdio.h>
#include<conio.h>
int main()
{
float r, a;
printf("Enter radius: ");
scanf("%f", &r);
a=(22/7)*r*r;
printf("Area of circle= %.2f", a);
return 0;
}

6. Write a C program to calculate and print the volume of a box.


#include<stdio.h>
#include<conio.h>
int main()
{
int l,b,h,v;
printf("Enter length: ");
scanf("%d", &l);
printf("Enter breadth: ");
scanf("%d", &b);
printf("Enter height: ");
scanf("%d", &h);
v=l*b*h;
printf("Volume of box= %d", v);
return 0;
}

7. Write a C program to get radius of a circle and then print its circumference.

#include<stdio.h>
#include<conio.h>
int main()
{
float r, c;
printf("Enter radius: ");
scanf("%f", &r);
c=2*(22/7)*r;
printf("Circumference of circle= %.2f", c);
return 0;
}
8. Write a C program to calculate the area of four walls.

#include<stdio.h>
#include<conio.h>
int main()
{
int l,b,h,a;
printf("Enter length: ");
scanf("%d", &l);
printf("Enter breadth: ");
scanf("%d", &b);
printf("Enter height: ");
scanf("%d", &h);
a=2*h*(l+b);
printf("Area of four walls= %d", a);
return 0;
}

9. Write a C program in QBASIC to find the total surface area of a box.

#include<stdio.h>
#include<conio.h>
int main()
{
int l,b,h,a;
printf("Enter length: ");
scanf("%d", &l);
printf("Enter breadth: ");
scanf("%d", &b);
printf("Enter height: ");
scanf("%d", &h);
a=2*((l*b)+(b*h)+(h*l));
printf("Total surface area of box= %d", a);
return 0;
}

10. Write a C program to calculate and print the simple interest.


#include<stdio.h>
#include<conio.h>
int main()
{
float p, t, r, i;
printf("Enter principal:
"); scanf("%f", &p);
printf("Enter time: ");
scanf("%f", &t);
printf("Enter rate: ");
scanf("%f", &r);
i = (p*t*r)/100;
printf("Simple Interest = %.2f", i);
return 0;
}
11. Write a C program to get temperature in celsius from the user and then print the temperature in
fahrenheit.
#include<stdio.h>
#include<conio.h>
int main()
{
float c, f;

printf("Enter temperature in Celsius: ");


scanf("%f", &c);
f = ((c * 9)/5) + 32;
printf("%.2f Celsius = %.2f Fahrenheit", c, f);
return 0;
}

12. Write a C program to find the area of triangle.


#include<stdio.h>
#include<conio.h>
int main()
{
int b,h;
float a;
printf("Enter base: ");
scanf("%d", &b);
printf("Enter height: ");
scanf("%d", &h);
a=(b*h)/2;
printf("Area of triangle= %.2f", a);
return 0;
}

13. Write a C program to get temperature in fahrenheit from the user and then print the temperature
in celcius.

#include <stdio.h>
#include<conio.h>
int main()
{
float c, f;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &f);
c = (f - 32) * 5 / 9;
printf("%.2f Fahrenheit = %.2f Celsius", f, c);
return 0;
}
14. Write a C program to convert USD(dollar) into NC (NEPALI currency).
#include<stdio.h>
#include<conio.h>
int main()
{
int d, n;
printf("Enter currency in dollar: ");
scanf("%d", &d);
n=d*100;
printf("$ %d = Rs. %d ", d, n);

return 0;
}
15. Write a C program to convert NC (NEPALI currency) into IC (Indian Currency)
#include<stdio.h>
#include<conio.h>
int main()
{
float i, n;
printf("Enter currency in Nepali Rupees: ");
scanf("%f", &n);
i=n/1.6;
printf("Nrs. Rs %.2f = IC Rs. %.2f ", n, i);

return 0;
}
16. WRITE A C PROGRAM to display whether the given number is positive, negative or zero.
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter any number: ");
scanf("%d", &n);
if(n>0)
printf("%d is positive number",n);
else if(n<0)
printf("%d is negative number",n);
else
printf("%d is zero number",n);
return 0;
}
17. Write a C program to test whether the given number is completely divisible by 13 or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter any number: ");
scanf("%d", &n); if(n
%2==0)
printf("%d is divisible by 13",n);
else
printf("%d is not divisible by 13",n);
return 0;
}
18. WRITE A C PROGRAM to check whether the given number is divisible by 3 and 5 or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter any number: ");
scanf("%d", &n);
if(n%3==0 && n%5==0)
printf("%d is divisible by 3 and 5",n);
else
printf("%d is not divisible by 3 and 5",n);
return 0;
}
19. WRITE A C PROGRAM to enter age and display whether a person can vote or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int a;
printf("Enter your age: ");
scanf("%d", &a);
if(a>=18)
printf("You can
vote"); else
printf("You cannot
vote"); return 0;
}
20. Write a C program to display the smaller among two numbers.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
printf("Enter any two numbers:\n ");
scanf("%d %d", &a, &b);
if(a<b)
printf("The smaller number is %d", a);
else
printf("The smaller number is %d", b);
return 0;
}
21. Write a C program to input three different and find the greatest number.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("Enter any three numbers:\n ");
scanf("%d %d %d" , &a, &b, &c);
if(a>b && a>c)
printf("The greatest number is %d", a);
else if(b>a && b>c)
printf("The greatest number is %d", b);
else
printf("The greatest number is %d", c);
return 0;
}
22. WRITE A C PROGRAM to display middle number among three different numbers.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("Enter any three numbers:\n ");
scanf("%d %d %d" , &a, &b, &c);
if((a>b && a<c) || (a<b && a>c))
printf("The middle number is %d", a);
else if((b>a && b<c) || (b<a && b>c))
printf("The middle number is %d", b);
else
printf("The middle number is %d", c);
return 0;
}
23. Write a C program to check whether the given number is odd or even.
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
printf("Enter any number: ");
scanf("%d", &n); if(n
%2==0)
printf("%d is even number", n);
else
printf("%d is odd number", n);
return 0;
}

24. WRITE A C PROGRAM to check whether the given year is leap year or not.

#include<stdio.h>
#include<conio.h>
int main()
{
int y;
printf("Enter the year: ");
scanf("%d", &y);
if((y%2==0) && (y%100 !=0) || (y%400==0))
printf("%d is leap year", y);
else
printf("%d is not leap year", y);
return 0;
}
25. WRITE A C PROGRAM to check whether the given number is perfect square or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int n, b;
float a;
printf("Enter any number: ");
scanf("%d", &n);
a=sqrt(n);
b=a;
if(a==b)
printf("%d is a perfect square number", n);
else
printf("%d is not a perfect square number", n);
return 0;
}

26. Write a C program to print the following series 9,7,5,…1.


#include<stdio.h>
#include<conio.h>
int main()

{
int i;
for(i=9;i>=1;i=i-2)
{
printf("%d \n", i);
}
return 0;
}
27. Write a C program to print the series 1,1,2,3,5,8… upto ten terms.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,i;
a=1;
b=1;
for(i=1;i<=10;i++)
{
printf("%d \n", a);
c=a+b;
a=b;
b=c;
}
return 0;
}
28. Write a C program to print natural numbers from 1 to 5.
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
i=1;
while(i<=5)
{
printf("%d \n", i);
i++;
}
return 0;
}
29. Write a C program to print the first ten odd numbers.
#include<stdio.h>
#include<conio.h>
int main()
{
int i, a;
i=1;
a=1;
while(i<=10)
{
printf("%d \n", a);
a=a+2;
i++;
}
return 0;
}

30. Write a C program to print the sum of digits of a given number.


#include<stdio.h>
#include<conio.h>
int main()
{
int n, s, r;
s=0;
printf("Enter any number:
"); scanf("%d", &n);
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("Sum of digits= %d",s);
return 0;
}
31. WRITE A C PROGRAM to display product of digits.
#include<stdio.h>
#include<conio.h>
int main()
{
int n, p, r;
p=1;
printf("Enter any number:
"); scanf("%d", &n);
while(n>0)
{
r=n%10;
p=p*r;
n=n/10;
}
printf("Product of digits= %d",p);
return 0;
}
32. WRITE A C PROGRAM to reverse the given digits.
#include<stdio.h>
#include<conio.h>
int main()
{
int n, s, r;
s=0;
printf("Enter any number:
"); scanf("%d", &n);
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
printf("Reverse digits= %d",s);
return 0;
}
33. Write a C program to print the multiplication table of any input number up to tenth terms.
#include<stdio.h>
#include<conio.h>
int main()
{
int n, i=1, c=0;
printf("Enter any number: ");
scanf("%d", &n);
for(i=1;i<=10;i++)
{
c=n*i;
printf("%d X %d = %d \n", n,i,c);
}
return 0;
}
34. WRITE A C PROGRAM to check whether the given number is prime or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int n, i=1, c=0;
printf("Enter any number: ");
scanf("%d", &n); for(i=2;i<=n;i+
+)
{
if(n%i==0)
c=c+1;
}
if(c==2)
printf("%d is prime number", n);
else
printf("%d is not prime number", n);
return 0;
}
35. WRITE A C PROGRAM to check whether the given number is palindrome or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int n, s, r, a;
s=0;
printf("Enter any number: ");
scanf("%d", &n);
a=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(a==s)
{
printf("%d is palindrome number", a);
}
else{
printf("%d is not palindrome number",a);
}
return 0;
}

You might also like