A Complete Computer Science Note
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
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
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.
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
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.
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.
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
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.
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).
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.
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)
Network Architecture/Model
Network architecture defines how the computer communicates and interacts with each other on network.
The failure of one computer doesn't affect the functioning of other peers.
P a g e | 15
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.
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.
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.
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.
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.
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.
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.
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.
3. Telnet
Telnet is the facility of Internet that allows user to use a remote computer through Internet.
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).
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.
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
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.
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.
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..
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.
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.
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%
When was Electronic transaction act 2063 authenticated and published in Nepal?
December 8 2006 (22 Mangshir 2063)
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.
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.
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.
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.
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.
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.
(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.
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
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.
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.
Infrastructure as a Service (IaaS): Customer can use processing, storage, networking, and other computing
resources from cloud service providers to run their software system.
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.
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.
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.
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).
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.
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
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
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.
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.
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.
Data type
Data type is an attribute for a field that determines the type of data that can be stored in that 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.
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.
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.
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.
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.
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.
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.
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.
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.
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 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.
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).
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.
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.
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)]
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
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
[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
[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]]
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
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
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]
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
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]
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.
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
22. WAP to calculate area of rectangle using SUB...END SUB and arca of circle using
FUNCTION...END Function.
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]
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
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
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
0 0 < > 0 No
Loop Exits
Dry Run
A X=1 TO 6 PRINT A; IS A MOD 2=0 ? Yes (A=A/2) No(A=A*3+1)
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
Dry Run
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)
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
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
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
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
11. Write the output of the given program showing the dry table. [2]
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
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 .
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
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
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
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
20. Write down the output of the given program. \Show with dry run in table. (2)
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
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
111111 6 to 5 no [Loop
Exits]
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
23. Write down the output of the following along with dry run table. 2
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
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
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
26. Write down the output of the given program. Show with dry run in table: [2]
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
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
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
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
Debugged program.
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
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
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)
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
Debugged Program
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
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.
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
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
FUNCTION SUM(N)
WHILE N< > 0
R = N MOD 10
S= S + R
N = N \ 10
WEND
SUM=S
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
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
Debugged Program
DECLARE FUNCTION PAL$ (W$)
CLS
INPUT "Enter a word"; W$
PRINT PAL$
(W$) 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
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
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]
Debugged Program
DECLARE SUB rev (s$)
CLS
INPUT n$
CALL rev (n$)
END
Debugged Program
11. Read the following program and answer the given questions: [2]
SUB string(x$)
L=LEN(X$)
FOR A = L to 1 step -
2 PRINT MID$
(x$.A,1); NEXT A
END SUB
Questions:
12. Study the following program and answer the given questions.
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
18. Study the following program and answer the given questions: (2×1=2)
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.
23. Study the following program and answer the given questions. [2]
DECLARE SUB TEST(A$)
CLS
A$= “COMPUTER”
END
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:
25. Study the following program and answer the given questions:
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]
SUB EXAMSEE(A$)
FOR I= LEN (A$) TO 1 STEP-1
PRINT LEFT$(A$,1)
NEXT I
END SUB
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.
File number
The number assigned to a file in order to identify it during processing is called file number.
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.
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
CHDIR statement: It changes the current default directory for the specified drive.
FILES statement: The FILES statement displays the list of files residing on the specified disk.
INT ( ) : It rounds and returns the largest integer less than or equal to a numeric expression.
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.
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.
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.
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.
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)
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.
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 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.
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
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.
Control structures in C
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;
}
#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;
}
#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;
}
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;
}
#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;
}
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;
}
{
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;
}