You are on page 1of 255

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

1
LESSON 1
BASIC CONCEPTS

1.1 INTRODUCTION
Let us begin with the word compute. It means to calculate. We all are familiar with calculations in
our day to day life. We apply mathematical operations like addition, subtraction, multiplication, etc.
and many other formulae for calculations. Simpler calculations take less time. But complex
calculations take much longer time. Another factor is accuracy in calculations. So man explored with
the idea to develop a machine which can perform this type of arithmetic calculation faster and with
full accuracy. This gave birth to a device or machine called computer.
The computer we see today is quite different from the one made in the beginning. The number of
applications of a computer has increased, the speed and accuracy of calculation has increased. You
must appreciate the impact of computers in our day to day life. Reservation of tickets in Air Lines and
Railways, payment of telephone and electricity bills, deposits and withdrawals of money from banks,
business data processing, medical diagnosis, weather forecasting, etc. are some of the areas where
computer has become extremely useful.
However, there is one limitation of the computer. Human beings do calculations on their own. But
computer is a dumb machine and it has to be given proper instructions to carry out its calculation.
This is why we should know how a computer works.

1.2 OBJECTIVES
After going through this lesson you will be in a position to
- define a computer
- identify characteristics of computer
- know the origin and evolution of computer
- identify capability of computer in terms of speed and accuracy
- distinguish computer from human beings and calculator
- identify the role of computer
- appreciate the evolution of computer through five generations


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

2
1.3 WHAT IS A COMPUTER?
Computer is an electronic device. As mentioned in the introduction it can do arithmetic calculations
faster. But as you will see later it does much more than that. It can be compared to a magic box, which
serves different purpose to different people. For a common man computer is simply a calculator,
which works automatic and quite fast. For a person who knows much about it, computer is a machine
capable of solving problems and manipulating data. It accepts data, processes the data by doing some
mathematical and logical operations and gives us the desired output.
Therefore, we may define computer as a device that transforms data. Data can be anything like marks
obtained by you in various subjects. It can also be name, age, sex, weight, height, etc. of all the
students in your class or income, savings, investments, etc., of a country. Computer can be defined in
terms of its functions. It can i) accept data ii) store data, iii) process data as desired, and iv) retrieve
the stored data as and when required and v) print the result in desired format. You will know more
about these functions as you go through the later lessons.
1.4 CHARACTERISTICS OF COMPUTER
Let us identify the major characteristics of computer. These can be discussed under the headings of
speed, accuracy, diligence, versatility and memory.

1.4.1 Speed
As you know computer can work very fast. It takes only few seconds for calculations that we take
hours to complete. Suppose you are asked to calculate the average monthly income of one thousand
persons in your neighborhood. For this you have to add income from all sources for all persons on a
day to day basis and find out the average for each one of them. How long will it take for you to do
this? One day, two days or one week? Do you know your small computer can finish this work in few
seconds? The weather forecasting that you see every day on TV is the results of compilation and
analysis of huge amount of data on temperature, humidity, pressure, etc. of various places on
computers. It takes few minutes for the computer to process this huge amount of data and give the
result.
You will be surprised to know that computer can perform millions (1,000,000) of instructions and
even more per second. Therefore, we determine the speed of computer in terms of microsecond (10
-6

part of a second) or nano-second (10
-9
part of a second). From this you can imagine how fast your
computer performs work.

1.4.2 Accuracy
Suppose some one calculates faster but commits a lot of errors in computing. Such result is useless.
There is another aspect. Suppose you want to divide 15 by 7. You may work out up to 2 decimal
places and say the dividend is 2.14. I may calculate up to 4 decimal places and say that the result is

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

3
2.1428. Some one else may go up to 9 decimal places and say the result is 2.142857143. Hence, in
addition to speed, the computer should have accuracy or correctness in computing.
The degree of accuracy of computer is very high and every calculation is performed with the same
accuracy. The accuracy level is determined on the basis of design of computer. The errors in computer
are due to human and inaccurate data.
1.4.3 Diligence
A computer is free from tiredness, lack of concentration, fatigue, etc. It can work for hours without
creating any error. If millions of calculations are to be performed, a computer will perform every
calculation with the same accuracy. Due to this capability it overpowers human being in routine type
of work.
1.4.4 Versatility
It means the capacity to perform completely different type of work. You may use your computer to
prepare payroll slips. Next moment you may use it for inventory management or to prepare electric
bills.
1.4.5 Power of Remembering
Computer has the power of storing any amount of information or data. Any information can be stored
and recalled as long as you require it, for any numbers of years. It depends entirely upon you how
much data you want to store in a computer and when to lose or retrieve these data.
1,4.6 No IQ
Computer is a dumb machine and it cannot do any work without instruction from the user. It performs
the instructions at tremendous speed and with accuracy. It is you to decide what you want to do and in
what sequence. So a computer cannot take its own decision as you can.
1.4. 7 No Feeling
It does not have feelings or emotion, taste, knowledge and experience. Thus it does not get tired even
after long hours of work. It does not distinguish between users.
1.4.8 Storage
The Computer has an in-built memory where it can store a large amount of data. You can also store
data in secondary storage devices such as floppies, which can be kept outside your computer and can
be carried to other computers.


IN-TEXT QUESTIONS 1
1. What is a computer? Why is it known as data processor?
2. What are the important characteristics of computer?



AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

4
1.5 HISTORY OF COMPUTER
History of computer could be traced back to the effort of man to count large numbers. This process of
counting of large numbers generated various systems of numeration like Babylonian system of
numeration, Greek system of numeration, Roman system of numeration and Indian system of
numeration. Out of these the Indian system of numeration has been accepted universally. It is the
basis of modern decimal system of numeration (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). Later you will know how
the computer solves all calculations based on decimal system. But you will be surprised to know that
the computer does not understand the decimal system and uses binary system of numeration for
processing.
We will briefly discuss some of the path-breaking inventions in the field of computing devices.
1.5 .1 Calculating Machines
It took over generations for early man to build mechanical devices for counting large numbers. The
first calculating device called ABACUS was developed by the Egyptian and Chinese people.
The word ABACUS means calculating board. It consisted of sticks in horizontal positions on which
were inserted sets of pebbles. A modern form of ABACUS is given in Fig. 1.2. It has a number of
horizontal bars each having ten beads. Horizontal bars represent units, tens, hundreds, etc.
1.5.2 Napiers bones
English mathematician John Napier built a mechanical device for the purpose of multiplication in
1617 A D. The device was known as Napiers bones.
1.5.3 Slide Rule
English mathematician Edmund Gunter developed the slide rule. This machine could perform
operations like addition, subtraction, multiplication, and division. It was widely used in Europe in 16
th

century.
1.5.4 Pascal's Adding and Subtractory Machine
You might have heard the name of Blaise Pascal. He developed a machine at the age of 19 that could
add and subtract. The machine consisted of wheels, gears and cylinders.
1.5.5 Leibnizs Multiplication and Dividing Machine
The German philosopher and mathematician Gottfried Leibniz built around 1673 a mechanical device
that could both multiply and divide.
1.5.6 Babbages Analytical Engine
It was in the year 1823 that a famous English man Charles Babbage built a mechanical machine to do
complex mathematical calculations. It was called difference engine. Later he developed a general-
purpose calculating machine called analytical engine. You should know that Charles Babbage is
called the father of computer.
1.5.7 Mechanical and Electrical Calculator

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

5
In the beginning of 19
th
century the mechanical calculator was developed to perform all sorts of
mathematical calculations. Up to the 1960s it was widely used. Later the rotating part of mechanical
calculator was replaced by electric motor. So it was called the electrical calculator.
1.5.8 Modern Electronic Calculator
The electronic calculator used in 1960 s was run with electron tubes, which was quite bulky. Later it
was replaced with transistors and as a result the size of calculators became too small.
The modern electronic calculator can compute all kinds of mathematical computations and
mathematical functions. It can also be used to store some data permanently. Some calculators have in-
built programs to perform some complicated calculations.
IN-TEXT QUESTIONS 2
1. What is the first mathematical device built and when was it built?
2. Who is called the father of Computer Technology.


1.6 COMPUTER GENERATIONS
You know that the evolution of computer started from 16th century and resulted in the form that we
see today. The present day computer, however, has also undergone rapid change during the last fifty
years. This period, during which the evolution of computer took place, can be divided into five
distinct phases known as Generations of Computers. Each phase is distinguished from others on the
basis of the type of switching circuits used.
1.6.1 First Generation Computers
First generation computers used Thermion valves. These computers were large in size and writing
programs on them was difficult. Some of the computers of this generation were:
ENIAC: It was the first electronic computer built in 1946 at University of Pennsylvania, USA by
John Eckert and John Mauchy. It was named Electronic Numerical Integrator and Calculator
(ENIAC). The ENIAC was 3050 feet long, weighed 30 tons, contained 18,000 vacuum tubes, 70,000
registers, 10,000 capacitors and required 150,000 watts of electricity. Today your favorite computer is
many times as powerful as ENIAC, still size is very small.
EDVAC: It stands for Electronic Discrete Variable Automatic Computer and was developed in 1950.
The concept of storing data and instructions inside the computer was introduced here. This allowed
much faster operation since the computer had rapid access to both data and instructions. The other
advantages of storing instruction was that computer could do logical decision internally.
Other Important Computers of First Generation
EDSAC: It stands for Electronic Delay Storage Automatic Computer and was developed by M.V.
Wilkes at Cambridge University in 1949.
UNIVAC-1: Ecker and Mauchly produced it in 1951 by Universal Accounting Computer setup.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

6
Limitations of First Generation Computer
Followings are the major drawbacks of First generation computers.
1. The operating speed was quite slow.
2. Power consumption was very high.
3. It required large space for installation.
4. The programming capability was quite low.

1.6.2 Second Generation Computers
Around 1955 a device called Transistor replaced the bulky electric tubes in the first generation
computer. Transistors are smaller than electric tubes and have higher operating speed. They have no
filament and require no heating. Manufacturing cost was also very low. Thus the size of the computer
got reduced considerably.
It is in the second generation that the concept of Central Processing Unit (CPU), memory,
programming language and input and output units were developed. The programming languages such
as COBOL, FORTRAN were developed during this period. Some of the computers of the Second
Generation were
1. IBM 1620: Its size was smaller as compared to First Generation computers and mostly used for
scientific purpose.
2. IBM 1401: Its size was small to medium and used for business applications.
3. CDC 3600: Its size was large and is used for scientific purposes.
1.6.3 Third Generation Computers
The third generation computers were introduced in 1964. They used Integrated Circuits (ICs). These
ICs are popularly known as Chips. A single IC has many transistors, registers and capacitors built on a
single thin slice of silicon. So it is quite obvious that the size of the computer got further reduced.
Some of the computers developed during this period were IBM-360, ICL-1900, IBM-370, and VAX-
750. Higher level language such as BASIC (Beginners All purpose Symbolic Instruction Code) was
developed during this period.
Computers of this generations were small in size, low cost, large memory and processing speed is
very high.
1.6.4 Fourth Generation Computers
The present day computers that you see today are the fourth generation computers that started around
1975. It uses large scale Integrated Circuits (LSIC) built on a single silicon chip called
microprocessors. Due to the development of microprocessor it is possible to place computers central
processing unit (CPU) on single chip. These computers are called microcomputers. Later very large
scale Integrated Circuits (VLSIC) replaced LSICs.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

7
Thus the computer which was occupying a very large room in earlier days can now be placed on a
table. The personal computer (PC) that you see in your school is a Fourth Generation Computer.
1.6.5 Fifth Generation Computer
The computers of 1990s are said to be Fifth Generation computers. The speed is extremely high in
fifth generation computer. Apart from this it can perform parallel processing. The concept of
Artificial intelligence has been introduced to allow the computer to take its own decision. It is still in a
developmental stage.
1.7 TYPES OF COMPUTERS
Now let us discuss the varieties of computers that we see today. Although they belong to the fifth
generation they can be divided into different categories depending upon the size, efficiency, memory
and number of users. Broadly they can be divided it to the following categories.
1. Microcomputer: Microcomputer is at the lowest end of the computer range in terms of speed and
storage capacity. Its CPU is a microprocessor. The first microcomputers were built of 8-bit
microprocessor chips. The most common application of personal computers (PC) is in this
category. The PC supports a number of input and output devices. An improvement of 8-bit chip is
16-bit and 32-bit chips. Examples of microcomputer are IBM PC, PC-AT .
2. Mini Computer: This is designed to support more than one user at a time. It possesses large
storage capacity and operates at a higher speed. The mini computer is used in multi-user system in
which various users can work at the same time. This type of computer is generally used for
processing large volume of data in an organisation. They are also used as servers in Local Area
Networks (LAN).
3. Mainframes: These types of computers are generally 32-bit microprocessors. They operate at
very high speed, have very large storage capacity and can handle the work load of many users. They
are generally used in centralised databases. They are also used as controlling nodes in Wide Area
Networks (WAN). Example of mainframes are DEC, ICL and IBM 3000 series.
4. Supercomputer: They are the fastest and most expensive machines. They have high processing
speed compared to other computers. They have also multiprocessing technique. One of the ways in
which supercomputers are built is by interconnecting hundreds of microprocessors. Supercomputers
are mainly being used for whether forecasting, biomedical research, remote sensing, aircraft design
and other areas of science and technology. Examples of supercomputers are CRAY YMP, CRAY2,
NEC SX-3, CRAY XMP and PARAM from India.
IN-TEXT QUESTIONS 3
1. Into how many generations the evolution of computer is divided?
2. What is VLSIC?
3. The personal computer that you see today is in which generation of computer?


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

8
1.8 WHAT YOU HAVE LEARNT
In this lesson we have discussed about the major characteristics of computer. The speed, accuracy,
memory and versatility are some of the features associated with a computer. But the computer that we
see today has not developed over night. It has taken centuries of human effort to see the computer in
its present form today. There are five generations of computer. Over these generations the physical
size of computer has decreased, but on the other hand the processing speed of computer has improved
tremendously. We also discussed about the varieties of computers available today.
1.9 TERMINAL QUESTIONS
1. Why is computer known as data processor?
2. Explain in brief the various generations in computer technology?
3. Write a short note on Fifth Generation of computer. What makes it different from Fourth
generation computer?
4. Why did the size of computer get reduced in third generation computer?
5. Give short notes on the following:
(a) Versatility (b) Storage (c) Slide Rule (d) Babbages Analytical Engine
6. Distinguish between Microcomputer and Mainframe computer.
1.10 FEEDBACK TO IN-TEXT QUESTIONS
IN-TEXT QUESTIONS 1
1. A computer is an electronic device, which is used to accept, store, retrieve and process the
data. It is called as data processor because it is mainly used for processing data for producing
meaningful information.
2. The characteristics of computer are speed, accuracy, diligence, versatility and storage.
IN-TEXT QUESTIONS 2
1. Analytical engine, 1823.
2. Charles Babbage
IN-TEXT qUESTIONS 3
1. Five generations
2. Very Large Scale Integrated Circuits
3. Fourth Generation
1.11 TERMINAL QUESTIONS
1. Explain various types of computers.
2. Explain in brief the various generations in computer technology.
3. Write a short note on Fifth Generation of computer. What makes it different from Fourth
Generation computer?
4. Why did the size of computer get reduced in Third Generation computer?
State True or False
1. (a) Word processor is Software Package that enables you to create, edit, print and save document .

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

9
(b) WordStar is a popular Word processor.
(c) Changing the size of the margins cannot reformat complete document or part of the text.
(d) Word has the facility of Macros.
(e) Word does not allow the user to mix the graphical pictures with text.
1.Choose the best answer.
(a) While working in Ms-Word you have to work with
(i) Mouse only
(ii) Keyboard only
(iii) Both mouse and keyboard
(b) In Ms- Word every command is available in
(i) Print
(ii) Letter
(iii) Icons
(c) You can go inside Ms-Word by the following way
(i) Take the mouse pointer to START button on the task bar and click the left mouse
button.
(ii) Take the mouse pointer to START button and click the right mouse button.
(iii) Move the mouse pointer on the screen.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

10
LESSON 2
COMPUTER ORGANISATION

2.1 INTRODUCTION
In the previous lesson we discussed about the evolution of computer. In this lesson we will provide
you with an overview of the basic design of a computer. You will know how different parts of a
computer are organised and how various operations are performed between different parts to do a
specific task. As you know from the previous lesson the internal architecture of computer may differ
from system to system, but the basic organisation remains the same for all computer systems.
2.2 OBJECTIVES
At the end of the lesson you will be able to:
- understand basic organisation of computer system
- understand the meaning of Arithmetic Logical Unit, Control Unit and Central Processing Unit
- differentiate between bit , byte and a word
- define computer memory
- differentiate between primary memory and secondary memory
- differentiate between primary storage and secondary storage units
- differentiate between input devices and output devices

2.3 BASIC COMPUTER OPERATIONS
A computer as shown in Fig. 2.1 performs basically five major operations or functions irrespective of
their size and make. These are 1) it accepts data or instructions by way of input, 2) it stores data, 3) it
can process data as required by the user, 4) it gives results in the form of output, and 5) it controls all
operations inside a computer. We discuss below each of these operations.
1. Input: This is the process of entering data and programs in to the computer system. You should
know that computer is an electronic machine like any other machine which takes as inputs raw data
and performs some processing giving out processed data. Therefore, the input unit takes data from us
to the computer in an organized manner for processing.
2. Storage: The process of saving data and instructions permanently is known as storage. Data has to
be fed into the system before the actual processing starts. It is because the processing speed of Central
Processing Unit (CPU) is so fast that the data has to be provided to CPU with the same speed.
Therefore the data is first stored in the storage unit for faster access and processing. This storage unit
or the primary storage of the computer system is designed to do the above functionality. It provides
space for storing data and instructions.
The storage unit performs the following major functions:
- All data and instructions are stored here before and after processing.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

11
- Intermediate results of processing are also stored here.
3. Processing: The task of performing operations like arithmetic and logical operations is called
processing. The Central Processing Unit (CPU) takes data and instructions from the storage unit and
makes all sorts of calculations based on the instructions given and the type of data provided. It is then
sent back to the storage unit.
4. Output: This is the process of producing results from the data for getting useful information.
Similarly the output produced by the computer after processing must also be kept somewhere inside
the computer before being given to you in human readable form. Again the output is also stored inside
the computer for further processing.
5. Control: The manner how instructions are executed and the above operations are performed.
Controlling of all operations like input, processing and output are performed by control unit. It takes
care of step by step processing of all operations in side the computer.

2.4 FUNCTIONAL UNITS
In order to carry out the operations mentioned in the previous section the computer allocates the task
between its various functional units. The computer system is divided into three separate units for its
operation. They are 1) arithmetic logical unit, 2) control unit, and 3) central processing unit.
2.4.1 Arithmetic Logical Unit (ALU)
After you enter data through the input device it is stored in the primary storage unit. The actual
processing of the data and instruction are performed by Arithmetic Logical Unit. The major
operations performed by the ALU are addition, subtraction, multiplication, division, logic and
comparison. Data is transferred to ALU from storage unit when required. After processing the output
is returned back to storage unit for further processing or getting stored.
2.4.2 Control Unit (CU)
The next component of computer is the Control Unit, which acts like the supervisor seeing that things
are done in proper fashion. The control unit determines the sequence in which computer programs and
instructions are executed. Things like processing of programs stored in the main memory,
interpretation of the instructions and issuing of signals for other units of the computer to execute
them. It also acts as a switch board operator when several users access the computer simultaneously.
Thereby it coordinates the activities of computers peripheral equipment as they perform the input and
output. Therefore it is the manager of all operations mentioned in the previous section..
2.4.3 Central Processing Unit (CPU)
The ALU and the CU of a computer system are jointly known as the central processing unit. You may
call CPU as the brain of any computer system. It is just like brain that takes all major decisions, makes
all sorts of calculations and directs different parts of the computer functions by activating and
controlling the operations.
Personal Computer Configuration

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

12
Now let us identify the physical components that make the computer work. These are
1. Central Processing Unit (CPU)
2. Computer Memory (RAM and ROM)
3. Data bus
4. Ports
5. Motherboard
6. Hard disk
7. Output Devices
8. Input Devices
All these components are inter-connected for the personal computer to work.
IN-TEXT QUESTIONS 1
1. What are the five basic operations performed by the computer?
2. Define ALU, CU and CPU.
3. Choose the correct answer:
(a) The task of performing arithmetic and logical operations is called
(i) ALU (ii) editing (iii) storage (iv) output
(b) The ALU and CU jointly known as
(i) RAM (ii) ROM (iii) CPU (iv) none of the above
(c) The process of producing results from the data for getting useful information

(i) output (ii)input (iii) processing (iv) storage


2.5 MEMORY SYSTEM IN A COMPUTER
There are two kinds of computer memory: primary and secondary. Primary memory is accessible
directly by the processing unit. RAM is an example of primary memory. As soon as the computer is
switched off the contents of the primary memory is lost. You can store and retrieve data much faster
with primary memory compared to secondary memory. Secondary memory such as floppy disks,
magnetic disk, etc., is located outside the computer. Primary memory is more expensive than
secondary memory. Because of this the size of primary memory is less than that of secondary
memory. We will discuss about secondary memory later on.
Computer memory is used to store two things: i) instructions to execute a program and ii) data. When
the computer is doing any job, the data that have to be processed are stored in the primary memory.
This data may come from an input device like keyboard or from a secondary storage device like a
floppy disk.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

13
As program or the set of instructions is kept in primary memory, the computer is able to follow in-
stantly the set of instructions. For example, when you book ticket from railway reservation counter,
the computer has to follow the same steps: take the request, check the availability of seats, calculate
fare, wait for money to be paid, store the reservation and get the ticket printed out. The programme
containing these steps is kept in memory of the computer and is followed for each request.

But inside the computer, the steps followed are quite different from what we see on the monitor or
screen. In computers memory both programs and data are stored in the binary form. You have
already been introduced with decimal number system, that is the numbers 1 to 9 and 0. The binary
system has only two values 0 and 1. These are called bits. As human beings we all understand decimal
system but the computer can only understand binary system. It is because a large number of integrated
circuits inside the computer can be considered as switches, which can be made ON, or OFF. If a
switch is ON it is considered 1 and if it is OFF it is 0. A number of switches in different states will
give you a message like this: 110101....10. So the computer takes input in the form of 0 and 1 and
gives output in the form 0 and 1 only. Is it not absurd if the computer gives outputs as 0s & 1s only?
But you do not have to worry about. Every number in binary system can be converted to decimal
system and vice versa; for example, 1010 meaning decimal 10. Therefore it is the computer that takes
information or data in decimal form from you, convert it in to binary form, process it producing
output in binary form and again convert the output to decimal form.

The primary memory as you know in the computer is in the form of ICs (Integrated Circuits). These
circuits are called Random Access Memory (RAM). Each of RAMs locations stores one byte of
information. (One byte is equal to 8 bits). A bit is an acronym for binary digit, which stands for one
binary piece of information. This can be either 0 or 1. You will know more about RAM later. The
Primary or internal storage section is made up of several small storage locations (ICs) called cells.
Each of these cells can store a fixed number of bits called word length.

Each cell has a unique number assigned to it called the address of the cell and it is used to identify the
cells. The address starts at 0 and goes up to (N-1). You should know that the memory is like a large
cabinet containing as many drawers as there are addresses on memory. Each drawer contains a word
and the address is written on outside of the drawer.

Capacity of Primary Memory
You know that each cell of memory contains one character or 1 byte of data. So the capacity is
defined in terms of byte or words. Thus 64 kilobyte (KB) memory is capable of storing 64 1024 =
32,768 bytes. (1 kilobyte is 1024 bytes). A memory size ranges from few kilobytes in small systems
to several thousand kilobytes in large mainframe and super computer. In your personal computer you

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

14
will find memory capacity in the range of 64 KB, 4 MB, 8 MB and even 16 MB (MB = Million
bytes).

The following terms related to memory of a computer are discussed below:
1. Random Access Memory (RAM): The primary storage is referred to as random access memory
(RAM) because it is possible to randomly select and use any location of the memory directly store
and retrieve data. It takes same time to any address of the memory as the first address. It is also
called read/write memory. The storage of data and instructions inside the primary storage is
temporary. It disappears from RAM as soon as the power to the computer is switched off. The
memories, which loose their content on failure of power supply, are known as volatile memories
.So now we can say that RAM is volatile memory.
2. Read Only Memory (ROM): There is another memory in computer, which is called Read Only
Memory (ROM). Again it is the ICs inside the PC that form the ROM. The storage of program
and data in the ROM is permanent. The ROM stores some standard processing programs supplied
by the manufacturers to operate the personal computer. The ROM can only be read by the CPU
but it cannot be changed. The basic input/output program is stored in the ROM that examines and
initializes various equipment attached to the PC when the switch is made ON. The memories,
which do not loose their content on failure of power supply, are known as non-volatile memories.
ROM is non-volatile memory.
3. PROM There is another type of primary memory in computer, which is called Programmable
Read Only Memory (PROM). You know that it is not possible to modify or erase programs stored
in ROM, but it is possible for you to store your program in PROM chip. Once the programmes are
written it cannot be changed and remain intact even if power is switched off. Therefore programs
or instructions written in PROM or ROM cannot be erased or changed.
4. EPROM: This stands for Erasable Programmable Read Only Memory, which over come the
problem of PROM & ROM. EPROM chip can be programmed time and again by erasing the
information stored earlier in it. Information stored in EPROM exposing the chip for some time
ultraviolet light and it erases chip is reprogrammed using a special programming facility. When
the EPROM is in use information can only be read.
5. Cache Memory: The speed of CPU is extremely high compared to the access time of main
memory. Therefore the performance of CPU decreases due to the slow speed of main memory. To
decrease the mismatch in operating speed, a small memory chip is attached between CPU and
Main memory whose access time is very close to the processing speed of CPU. It is called
CACHE memory. CACHE memories are accessed much faster than conventional RAM. It is used
to store programs or data currently being executed or temporary data frequently used by the CPU.
So each memory makes main memory to be faster and larger than it really is. It is also very
expensive to have bigger size of cache memory and its size is normally kept small.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

15
6. Registers: The CPU processes data and instructions with high speed, there is also movement of
data between various units of computer. It is necessary to transfer the processed data with high
speed. So the computer uses a number of special memory units called registers. They are not part
of the main memory but they store data or information temporarily and pass it on as directed by
the control unit.

IN-TEXT QUESTIONS 2
1. Distinguish between bit and byte.
2. Define volatile and non-volatile memory.
3. Write True or False:
(a) There are two kinds of computer memory primary and secondary.
(b) The computer takes inputs in the form of 0 and 1.
(c) The storage of program and data in the RAM is permanent.
(d) PROM is secondary memory.
(e) The memories which do not loose their content on failure of power supply are known as non-
volatile memories.



2.6 SECONDARY STORAGE
You are now clear that the operating speed of primary memory or main memory should be as
fast as possible to cope up with the CPU speed. These high-speed storage devices are very
expensive and hence the cost per bit of storage is also very high. Again the storage capacity of
the main memory is also very limited. Often it is necessary to store hundreds of millions of
bytes of data for the CPU to process. Therefore additional memory is required in all the
computer systems. This memory is called auxiliary memory or secondary storage.

In this type of memory the cost per bit of storage is low. However, the operating speed is
slower than that of the primary storage. Huge volume of data are stored here on permanent
basis and transferred to the primary storage as and when required. Most widely used
secondary storage devices are magnetic tapes and magnetic disk.

1. Magnetic Tape: Magnetic tapes are used for large computers like mainframe computers
where large volume of data is stored for a longer time. In PC also you can use tapes in the
form of cassettes. The cost of storing data in tapes is inexpensive. Tapes consist of magnetic
materials that store data permanently. It can be 12.5 mm to 25 mm wide plastic film-type and

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

16
500 meter to 1200 meter long which is coated with magnetic material. The deck is connected
to the central processor and information is fed into or read from the tape through the
processor. It similar to cassette tape recorder.

Advantages of Magnetic Tape:
- Compact: A 10-inch diameter reel of tape is 2400 feet long and is able to
hold 800, 1600 or 6250 characters in each inch of its length. The maximum capacity
of such tape is 180 million characters. Thus data are stored much more compactly on
tape.
- Economical: The cost of storing characters is very less as compared to other
storage devices.
- Fast: Copying of data is easier and fast.
- Long term Storage and Re-usability: Magnetic tapes can be used for long
term storage and a tape can be used repeatedly with out loss of data.

2. Magnetic Disk: You might have seen the gramophone record, which is circular like a disk
and coated with magnetic material. Magnetic disks used in computer are made on the same
principle. It rotates with very high speed inside the computer drive. Data is stored on both the
surface of the disk. Magnetic disks are most popular for direct access storage device. Each
disk consists of a number of invisible concentric circles called tracks. Information is recorded
on tracks of a disk surface in the form of tiny magnetic spots. The presence of a magnetic spot
represents one bit and its absence represents zero bit. The information stored in a disk can be
read many times without affecting the stored data. So the reading operation is non-destructive.
But if you want to write a new data, then the existing data is erased from the disk and new
data is recorded.

3. Floppy Disk: It is similar to magnetic disk discussed above. They are 5.25 inch or 3.5 inch in
diameter. They come in single or double density and recorded on one or both surface of the
diskette. The capacity of a 5.25-inch floppy is 1.2 mega bytes whereas for 3.5 inch floppy it is
1.44 mega bytes. It is cheaper than any other storage devices and is portable. The floppy is a
low cost device particularly suitable for personal computer system.

4. Optical Disk:
With every new application and software there is greater demand for memory capacity. It is
the necessity to store large volume of data that has led to the development of optical disk
storage medium. Optical disks can be divided into the following categories:

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

17
1. Compact Disk/ Read Only Memory (CD-ROM): CD-ROM disks are made of reflective
metals. CD-ROM is written during the process of manufacturing by high power laser
beam. Here the storage density is very high, storage cost is very low and access time is
relatively fast. Each disk is approximately 4 1/2 inches in diameter and can hold over 600
MB of data. As the CD-ROM can be read only we cannot write or make changes into the
data contained in it.
2. Write Once, Read Many (WORM): The inconvenience that we can not write any thing in
to a CD-ROM is avoided in WORM. A WORM allows the user to write data permanently
on to the disk. Once the data is written it can never be erased without physically
damaging the disk. Here data can be recorded from keyboard, video scanner, OCR
equipment and other devices. The advantage of WORM is that it can store vast amount of
data amounting to gigabytes (10
9
bytes). Any document in a WORM can be accessed very
fast, say less than 30 seconds.
3. Erasable Optical Disk: These are optical disks where data can be written, erased and re-
written. This also applies a laser beam to write and re-write the data. These disks may be
used as alternatives to traditional disks. Erasable optical disks are based on a technology
known as magnetic optical (MO). To write a data bit on to the erasable optical disk the
MO drive's laser beam heats a tiny, precisely defined point on the disk's surface and
magnetises it.

2.7 INPUT OUTPUT DEVICES
A computer is only useful when it is able to communicate with the external environment.
When you work with the computer you feed your data and instructions through some devices
to the computer. These devices are called Input devices. Similarly computer after processing,
gives output through other devices called output devices.

For a particular application one form of device is more desirable compared to others. We will
discuss various types of I/O devices that are used for different types of applications. They are
also known as peripheral devices because they surround the CPU and make a communication
between computer and the outer world.

2.7.1 Input Devices
Input devices are necessary to convert our information or data in to a form which can be understood
by the computer. A good input device should provide timely, accurate and useful data to the main
memory of the computer for processing followings are the most useful input devices.
1. Keyboard: - This is the standard input device attached to all computers. The layout of keyboard
is just like the traditional typewriter of the type QWERTY. It also contains some extra command

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

18
keys and function keys. It contains a total of 101 to 104 keys. A typical keyboard used in a
computer is shown in Fig. 2.6. You have to press correct combination of keys to input data. The
computer can recognise the electrical signals corresponding to the correct key combination and
processing is done accordingly.
2. Mouse: - Mouse is an input device shown in Fig. 2.7 that is used with your personal computer. It
rolls on a small ball and has two or three buttons on the top. When you roll the mouse across a flat
surface the screen censors the mouse in the direction of mouse movement. The cursor moves very
fast with mouse giving you more freedom to work in any direction. It is easier and faster to move
through a mouse.
3. Scanner: The keyboard can input only text through keys provided in it. If we want to input a
picture the keyboard cannot do that. Scanner is an optical device that can input any graphical
matter and display it back. The common optical scanner devices are Magnetic Ink Character
Recognition (MICR), Optical Mark Reader (OMR) and Optical Character Reader (OCR).

- Magnetic Ink Character Recognition (MICR): - This is widely used by banks to
process large volumes of cheques and drafts. Cheques are put inside the MICR. As they
enter the reading unit the cheques pass through the magnetic field which causes the read
head to recognise the character of the cheques.
- Optical Mark Reader (OMR): This technique is used when students have appeared in
objective type tests and they had to mark their answer by darkening a square or circular
space by pencil. These answer sheets are directly fed to a computer for grading where
OMR is used.
- Optical Character Recognition (OCR): - This technique unites the direct reading of any
printed character. Suppose you have a set of hand written characters on a piece of paper.
You put it inside the scanner of the computer. This pattern is compared with a site of
patterns stored inside the computer. Whichever pattern is matched is called a character
read. Patterns that cannot be identified are rejected. OCRs are expensive though better the
MICR.


2.7.2 Output Devices
1. Visual Display Unit: The most popular input/output device is the Visual Display Unit (VDU). It
is also called the monitor. A Keyboard is used to input data and Monitor is used to display the
input data and to receive massages from the computer. A monitor has its own box which is
separated from the main computer system and is connected to the computer by cable. In some
systems it is compact with the system unit. It can be color or monochrome.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

19
2. Terminals: It is a very popular interactive input-output unit. It can be divided into two types:
hard copy terminals and soft copy terminals. A hard copy terminal provides a printout on paper
whereas soft copy terminals provide visual copy on monitor. A terminal when connected to a
CPU sends instructions directly to the computer. Terminals are also classified as dumb terminals
or intelligent terminals depending upon the work situation.
3. Printer: It is an important output device which can be used to get a printed copy of the processed
text or result on paper. There are different types of printers that are designed for different types of
applications. Depending on their speed and approach of printing, printers are classified as impact
and non-impact printers. Impact printers use the familiar typewriter approach of hammering a
typeface against the paper and inked ribbon. Dot-matrix printers are of this type. Non-impact
printers do not hit or impact a ribbon to print. They use electro-static chemicals and ink-jet
technologies. Laser printers and Ink-jet printers are of this type. This type of printers can produce
color printing and elaborate graphics.
Fig. 2.8


IN-TEXT QUESTIONS 3
1. Distinguish between impact and non-impact printers.
2. Define soft copy and hard copy terminals.
3. Write True or False:
(a) Secondary memory is called Auxiliary memory.
(b) The magnetic tapes and magnetic disk are primary memories.
(c) A CD-ROM is read only memory.
(d) Mouse is an output device.
(e) Printer is an important output device.



2.8 WHAT YOU HAVE LEARNT
In this lesson we discussed five basic operations that a computer performs. These are input, storage,
processing, output and control. A computer accepts data as input, stores it, processes it as the user
requires and provides the output in a desired format. The storage unit of a computer is divided into
two parts: primary storage and secondary storage. We have discussed the devices used for these two
types of storage and their usefulness.



AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

20
2.9 TERMINAL QUESTIONS
1. What are the five basic operations performed by any computer system?
2. Draw a block diagram to illustrate the basic organization of computer system and explain the
function of various units.
3. What is input device? How does it differ from output device?
4. Differentiate between RAM and ROM. Also distinguish between PROM and EPROM.
5. What is cache memory? How is it different from primary memory?
6. Write short notes on (a) Control Unit (b) Random Access Memory (RAM)
2.10 FEEDBACK TO IN-TEXT QUESTIONS

IN-TEXT QUESTIONS 1
1. The five basic operations that a computer performs are input, storage, processing, output and
control.
2. ALU: Arithmetic Logic Unit
CU: Control Unit
CPU: Central Processing Unit
3. (a) i (b) iii (c) i

IN-TEXT QUESTIONS 2

1. A bit is an acronym for binary digit, which stands for one binary piece of information. This
can be either 0 or 1. A byte is equal to 8 bits.
2. The memories which are erased if there is a power failure are known as volatile memories.
RAM is an example of volatile memory. The memories, which do not loose their content on
failure of power supply, are known as non-volatile memories. ROM is non-volatile memory.
3. (a) T (b) T (c) F (d) F (e) T

IN-TEXT QUESTIONS 3
1. Impact printers use the familiar typewriter approach of hammering a typeface against the
paper and inked ribbon. Non-impact printers do not hit or impact a ribbon to print. They use
electro-static chemicals and ink-jet technologies.
2. A hard copy terminal provides a printout on paper whereas soft copy terminals provide visual
copy on monitor.
3. (a) T (b) F (c) T (d) F (e) T




AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

21

LESSON 3
LANGUAGE/SOFTWARE

3.1 INTRODUCTION
In the previous lesson we discussed about the different parts and configurations of computer. It has
been mentioned that programs or instructions have to be fed to the computer to do specific task. So it
is necessary to provide sequence of instructions so that your work can be done. We can divide the
computer components into two major areas, namely, hardware and software. Hardware is the
machine itself and its various individual equipment. It includes all mechanical, electronic and
magnetic devices such as monitor, printer, electronic circuit, floppy and hard disk. In this lesson we
will discuss about the other part, namely, software.

3.2 OBJECTIVES
After going through this lesson you will be able to
- explain the concept of software
- distinguish between different types of software
- differentiate application software from system software
- define a language
- differentiate between different types of language
- distinguish between compiler and interpreter

3.3 WHAT IS SOFTWARE?
As you know computer cannot do anything without instructions from the user. In order to do any
specific job you have to give a sequence of instructions to the computer. This set of instructions is
called a computer program. Software refers to the set of computer programs, procedures that describe
the programs, how they are to be used. We can say that it is the collection of programs, which
increase the capabilities of the hardware. Software guides the computer at every step where to start
and stop during a particular job. The process of software development is called programming.

You should keep in mind that software and hardware are complementary to each other. Both have to
work together to produce meaningful result. Another important point you should know that producing
software is difficult and expensive.




AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

22
3.4 SOFTWARE TYPES
Computer software is normally classified into two broad categories.
- Application Software
- System software

Application Software: Application Software is a set of programs to carry out operations for a
specific application. For example, payroll is an application software for an organization to produce
pay slips as an output. Application software is useful for word processing, billing system, accounting,
producing statistical report, analysis of numerous data in research, weather forecasting, etc. In later
modules you will learn about MS WORD, Lotus 1-2-3 and dBASE III Plus. All these are application
softwares.

Another example of application software is programming language. Among the programming
languages COBOL (Common Business Oriented Language) is more suitable for business application
whereas FORTRAN (Formula Translation) is useful for scientific application. We will discuss about
languages in next section.

System Software: You know that an instruction is a set of programs that has to be fed to the
computer for operation of computer system as a whole. When you switch on the computer the
programs written in ROM is executed which activates different units of your computer and makes it
ready for you to work on it. This set of program can be called system software. Therefore system
software may be defined as a set of one or more programs designed to control the operation of
computer system.

System software are general programs designed for performing tasks such as controlling all operations
required to move data into and out of the computer. It communicates with printers, card reader, disk,
tapes etc. monitor the use of various hardware like memory, CPU etc. Also system software are
essential for the development of applications software. System Software allows application packages
to be run on the computer with less time and effort. Remember that it is not possible to run
application software without system software.

Development of system software is a complex task and it requires extensive knowledge of computer
technology. Due to its complexity it is not developed in house. Computer manufactures build and
supply this system software with the computer system. DOS, UNIX and WINDOWS are some of the
widely used system software. Out of these UNIX is a multi-user operating system whereas DOS and
WINDOWS are PC-based. We will discuss in detail about DOS and WINDOWS in the next module.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

23
So without system software it is impossible to operate your computer. The following picture is shown
in Fig. 3.1 relation between hardware, software and you as a user of computer system.


IN-TEXT QUESTIONS 1
1. What are program, programming and software?
2. Differentiate between system software and application software.
3. Write True or False
(a) The set of instructions given to the computer is called programming.
(b) Application Software is a set of programs to carry out operations for a specific application.
(c) UNIX is a multi-user operating system.


3.5 WHAT IS LANGUAGE?
You are aware with the term language. It is a system of communication between you and me. Some of
the basic natural languages that we are familiar with are English, Hindi, Oriya etc. These are the
languages used to communicate among various categories of persons. But how you will communicate
with your computer. Your computer will not understand any of these natural languages for transfer of
data and instruction. So there are programming languages specially developed so that you could pass
your data and instructions to the computer to do specific job. You must have heard names like
FORTRAN, BASIC, COBOL etc. These are programming languages. So instructions or programs are
written in a particular language based on the type of job. As an example, for scientific application
FORTRAN and C languages are used. On the other hand COBOL is used for business applications.

3.5.1 Programming Languages
There are two major types of programming languages. These are Low Level Languages and High
Level Languages. Low Level languages are further divided in to Machine language and Assembly
language.

3.5.2 Low Level Languages
The term low level means closeness to the way in which the machine has been built. Low level
languages are machine oriented and require extensive knowledge of computer hardware and its
configuration.




AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

24
(a) Machine Language
Machine Language is the only language that is directly understood by the computer. It does not needs
any translator program. We also call it machine code and it is written as strings of 1's (one) and 0s
(zero). When this sequence of codes is fed to the computer, it recognizes the codes and converts it in
to electrical signals needed to run it. For example, a program instruction may look like this:

1011000111101

It is not an easy language for you to learn because of its difficult to understand. It is efficient for the
computer but very inefficient for programmers. It is considered to the first generation language. It is
also difficult to debug the program written in this language.

Advantage
The only advantage is that program of machine language run very fast because no translation
program is required for the CPU.

Disadvantages
1. It is very difficult to program in machine language. The programmer has to know details of
hardware to write program.
2. The programmer has to remember a lot of codes to write a program which results in program
errors.
3. It is difficult to debug the program.

(b) Assembly Language
It is the first step to improve the programming structure. You should know that computer can handle
numbers and letter. Therefore some combination of letters can be used to substitute for number of
machine codes.

The set of symbols and letters forms the Assembly Language and a translator program is required to
translate the Assembly Language to machine language. This translator program is called `Assembler'.
It is considered to be a second-generation language.

Advantages:
1. The symbolic programming of Assembly Language is easier to understand and saves a lot of time
and effort of the programmer.
2. It is easier to correct errors and modify program instructions.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

25
3. Assembly Language has the same efficiency of execution as the machine level language. Because
this is one-to-one translator between assembly language program and its corresponding machine
language program.

Disadvantages:
1. One of the major disadvantages is that assembly language is machine dependent. A program
written for one computer might not run in other computers with different hardware configuration.



IN-TEXT QUESTIONS 2
1. What is the difference between FORTRAN and COBOL?
2. Differentiate between machine language and Assembly language.
3. Write True or False
(a) Low level language and High level language are two major types of programming
languages.
(b) Machine language is the only language that is indirectly understood by the computer.
(c) Assembly language is second generation language.




3.6 HIGH LEVEL LANGUAGES
You know that assembly language and machine level language require deep knowledge of computer
hardware where as in higher language you have to know only the instructions in English words and
logic of the problem irrespective of the type of computer you are using.

Higher level languages are simple languages that use English and mathematical symbols like +, -, %, /
etc. for its program construction.
You should know that any higher level language has to be converted to machine language for the
computer to understand.
Higher level languages are problem-oriented languages because the instructions are suitable for
solving a particular problem. For example COBOL (Common Business Oriented Language) is mostly
suitable for business oriented language where there is very little processing and huge output. There
are mathematical oriented languages like FORTRAN (Formula Translation) and BASIC (Beginners
All-purpose Symbolic Instruction Code) where very large processing is required.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

26
Thus a problem oriented language designed in such a way that its instruction may be written more
like the language of the problem. For example, businessmen use business term and scientists use
scientific terms in their respective languages.
Advantages of High Level Languages
Higher level languages have a major advantage over machine and assembly languages that higher
level languages are easy to learn and use. It is because that they are similar to the languages used by
us in our day to day life.
3.6.1 Compiler
It is a program translator that translates the instruction of a higher level language to machine
language. It is called compiler because it compiles machine language instructions for every program
instructions of higher level language. Thus compiler is a program translator like assembler but more
sophisticated. It scans the entire program first and then translates it into machine code.

The programs written by the programmer in higher level language is called source program. After this
program is converted to machine languages by the compiler it is called object program.

Higher Level Language
---------------------------------- (Compile) Program Machine Language
Program


Fig. 3.2
A compiler can translate only those source programs, which have been written, in that language for
which the compiler is meant for. For example FORTRAN compiler will not compile source code
written in COBOL language.

Object program generated by compiler is machine dependent. It means programs compiled for one
type of machine will not run in another type. Therefore every type of machine must have its personal
compiler for a particular language. Machine independence is achieved by using one higher level
language in different machines.

3.6.2 Interpreter
An interpreter is another type of program translator used for translating higher level language into
machine language. It takes one statement of higher level languages, translate it into machine language
and immediately execute it. Translation and execution are carried out for each statement. It differs

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

27
from compiler, which translate the entire source program into machine code and does involve in its
execution.
.
The advantage of interpreter compared to compiler is its fast response to changes in source program.
It eliminates the need for a separate compilation after changes to each program. Interpreters are easy
to write and do not require large memory in computer. The disadvantage of interpreter is that it is time
consuming method because each time a statement in a program is executed then it is first translated.
Thus compiled machine language program runs much faster than an interpreted program.

IN-TEXT QUESTIONS 3
1. What is the difference between interpreter and compiler?
2. Give some examples of high level language.
3. Write True or False
(a) High level languages are problem-oriented language.
(b) Object program generated by compiler is machine independent.
(c) The disadvantage of interpreter is that it is time consuming.

3.7 WHAT YOU HAVE LEARNT
In this lesson we discussed about two types of software, namely, system software and application
software. System software controls the hardware part of the computer. It is designed for performing
tasks such as controlling all operations required to move data into and out of the computer. It
communicates with printer, card reader, disk, tapes, etc. and monitors the use of various components
like memory, CPU, etc. DOS, UNIX and WINDOWS are three important system softwares.
Application software is a set of programs written for specific purpose. Examples of application
softwares are MS WORD, Lotus 1-2-3, COBOL, BASIC and FORTRAN. We have discussed about
levels of computer language.

3.8 TERMINAL QUESTIONS
1. What is software and hardware?
2. What is computer Language?
3. Name the three different categories of computer languages.
4. What is machine language? Why is it required?
5. What are advantages and disadvantages of machine language .
6 What is assembly language? What are its advantages over machine languages?
7 What is the difference between source program and object program?
8 What is higher level languages? Why are higher level languages are easier to use.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

28
9 What is compiler? Why is it required?
10 What is interpreter? How does it differ from compiler?
3.9 FEEDBACK TO IN-TEXT QUESTIONS

IN-TEXT QUESTIONS 1
1. Program is a set of instructions given to the computer by the user. Software is a set of computer
programs and procedures that describe the programs. Programming is the process of software
development.
2. Application Software is a set of programs to carry out operations for a specific application.
System software is a set of programs written for performing tasks such as controlling all operations
required to move data into and out of the computer.
3. (a) False b) T rue (c) True
IN-TEXT QUESTIONS 2
1. FORTRAN is used for scientific applications whereas COBOL is used for business applications.
2. Machine Languages are the only language that is directly understood by the computer. It is
written in binary form that is 0 and 1. The set of symbols and letters forms the Assembly Language.
3. (a) True (b) False (c) True
IN-TEXT QUESTIONS 3
1. Both compiler and interpreter are program translators used for translating higher level language
into machine language. While compiler scans the entire program first and then translates it into
machine code, an Interpreter translates the program line by line.
2. FORTRAN (Formula Translation) and BASIC (Beginners All-purpose Symbolic Instruction
Code) are some of the high level languages.
3. (a) True (b) False (c) True

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

29
LESSON 4
COMMUNICATION AND COMPUTER NETWORK

4.1 INTRODUCTION
Today computer is available in many offices and homes and therefore there is a need to share data and
programs among various computers with the advancement of data communication facilities. The
communication between computers has increased and it thus it has extended the power of computer
beyond the computer room. Now a user sitting at one place can communicate computers of any
remote sites through communication channel. The aim of this chapter is to introduce you the various
aspects of computer network.
4.2 OBJECTIVES
After going through this lesson you will be in a position to:
- explain the concept of data communication
- understand the use of computer network
- identify different components of computer network
- identify different types of network
- explain communication protocols
- understand what is internet and email and its uses in modern communication
- appreciate the use of satellite communication.
4.3 DATA COMMUNICATION
We all are acquainted with some sorts of communication in our day to day life. For communication of
information and messages we use telephone and postal communication systems. Similarly data and
information from one computer system can be transmitted to other systems across geographical areas.
Thus data transmission is the movement of information using some standard methods. These methods
include electrical signals carried along a conductor, optical signals along an optical fibers and
electromagnetic areas.

Suppose a manager has to write several letters to various clients. First he has to use his PC and Word
Processing package to prepare his letter. If the PC is connected to all the client's PCs through
networking, he can send the letters to all the clients within minutes. Thus irrespective of geographical
areas, if PCs are connected through communication channel, the data and information, computer files
and any other program can be transmitted to other computer systems within seconds. The modern
form of communication like e-mail and Internet is possible only because of computer networking.

Basic Elements of a Communication System
The following are the basic requirements for working of a communication system.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

30
1. A sender (source) which creates the message to be transmitted.
2. A medium that carries the message.
3. A receiver (sink) which receives the message.

In data communication four basic terms are frequently used. They are
- Data: A collection of facts in raw forms that become information after processing.
- Signals: Electric or electromagnetic encoding of data.
- Signaling: Propagation of signals across a communication medium.
- Transmission: Communication of data achieved by the processing of signals.

4.3.1 Communication Protocols
You may be wondering how do the computers send and receive data across communication links. The
answer is data communication software. It is this software that enables us to communicate with other
systems. The data communication software instructs computer systems and devices as to how exactly
data is to be transferred from one place to another. The procedure of data transformation in the form
of software is commonly called protocol.

The data transmission software or protocols perform the following functions for the efficient and error
free transmission of data.
Data sequencing: A long message to be transmitted is broken into smaller packets of fixed size for
error free data transmission.
Data Routing: It is the process of finding the most efficient route between source and destination
before sending the data.
Flow control: All machines are not equally efficient in terms of speed. Hence the flow control
regulates the process of sending data between fast sender and slow receiver.
Error Control: Error detecting and recovering is the one of the main function of communication
software. It ensures that data are transmitted without any error.

4.3.2 Data Transmission Modes
There are three ways for transmitting data from one point to another
1. Simplex: In simplex mode the communication can take place in one direction. The receiver
receives the signal from the transmitting device. In this mode the flow of information is Uni.-
directional. Hence it is rarely used for data communication.
2. Half-duplex: In half-duplex mode the communication channel is used in both directions, but only
in one direction at a time. Thus a half-duplex line can alternately send and receive data.
3. Full-duplex: In full duplex the communication channel is used in both directions at the same

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

31
time. Use of full-duplex line improves the efficiency as the line turn-around time required in half-
duplex arrangement is eliminated. Example of this mode of transmission is the telephone line.
A B
Simplex A to B only
A B
Half-Duplex A to B or B to A

A B
Full-Duplex A to B and B to A

Fig. 4.1

4.3.3 Digital and Analog Transmission
Data is transmitted from one point to another point by means of electrical signals that may be in
digital and analog form. So one should know the fundamental difference between analog and digital
signals. In analog signal the transmission power varies over a continuous range with respect to sound,
light and radio waves. On the other hand a digital signal may assume only discrete set of values within
a given range. Examples are computer and computer related equipment. Analog signal is measured in
Volts and its frequency in Hertz (Hz). A digital signal is a sequence of voltage represented in binary
form. When digital data are to be sent over an analog form the digital signal must be converted to
analog form. So the technique by which a digital signal is converted to analog form is known as
modulation. And the reverse process, that is the conversion of analog signal to its digital form, is
known as demodulation. The device, which converts digital signal into analog, and the reverse, is
known as modem.






Time


Analog Signal
Digital Signal
Fig. 4.2

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

32
4.3.4 Asynchronous and Synchronous Transmission
Data transmission through a medium can be either asynchronous or synchronous. In asynchronous
transmission data is transmitted character by character as you go on typing on a keyboard. Hence
there is irregular gaps between characters. However, it is cheaper to implement, as you do not have to
save the data before sending. On the other hand, in the synchronous mode, the saved data is
transmitted block by block. Each block can contain many characters. Synchronous transmission is
well suited for remote communication between a computer and related devices like card reader and
printers.

Following are the major communication devices used to day.
Wire Pairs: Wire pairs are commonly used in local telephone communication and for short distance
digital data communication. They are usually made up of copper and the pair of wires is twisted
together. Data transmission speed is normally 9600 bits per second in a distance of 100 meter.

Coaxial Cables: Coaxial cable is groups of specially wrapped and insulted wires that are able to
transfer data at higher rate. They consist of a central copper wire surrounded by an insulation over
which copper mesh is placed. They are used for long distance telephone lines and local area
network for their noise immunity and faster data transfer.

Microwave: Microwave system uses very high frequency radio signals to transmit data through
space. The transmitter and receiver of a microwave system should be in line-of-sight because the
radio signal cannot bend. With microwave very long distance transmission is not possible. In
order to overcome the problem of line of sight and power amplification of weak signal, repeaters
are used at intervals of 25 to 30 kilometers between the transmitting and receiving end.

Communication Satellite: The problem of line-sight and repeaters are overcome by using satellites
which are the most widely used data transmission media in modern days. A communication
satellite is a microwave relay station placed in outer space. INSAT-1B is such a satellite that can
be accessible from anywhere in India. In satellite communication, microwave signal is transmitted
from a transmitter on earth to the satellite at space. The satellite amplifies the weak signal and
transmits it back to the receiver. The main advantage of satellite communication is that it is a
single microwave relay station visible from any point of a very large area. In microwave the data
transmission rate is 16 giga bits per second. They are mostly used to link big metropolitan cities.

IN-TEXT QUESTIONS 1
1. What is communication protocol?
2. What is the difference between asynchronous and synchronous transmission?

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

33
3. State whether True or False
(a) The basic requirements for working of a communication system are sender medium and
receiver.
(b) Electric or Electromagnetic encoding of data is called Transmission.
(c) In full duplex the communication channel is used in both directions at the same time.
(d) Analog signal is measured in Volts and its frequency in Hertz
(e) The technique by which a digital signal is converted to analog form is known as
modulation.

4.4 COMPUTER NETWORK
A computer network is an interconnection of various computer systems located at different places. In
computer network two or more computers are linked together with a medium and data communication
devices for the purpose of communicating data and sharing resources. The computer that provides
resources to other computers on a network is known as server. In the network the individual
computers, which access shared network resources, are known as workstations or nodes.
Computer Networks may be classified on the basis of geographical area in two broad categories.
1. Local Area Network (LAN)
2. Wide Area Network (WAN)
4.4.1 Local Area Network
Networks used to interconnect computers in a single room, rooms within a building or buildings on
one site are called Local Area Network (LAN). LAN transmits data with a speed of several megabits
per second (10
6
bits per second). The transmission medium is normally coaxial cables.
LAN links computers, i.e., software and hardware, in the same area for the purpose of sharing
information. Usually LAN links computers within a limited geographical area because they must be
connected by a cable, which is quite expensive. People working in LAN get more capabilities in data
processing, work processing and other information exchange compared to stand-alone computers.
Because of this information exchange most of the business and government organisations are using
LAN.

Major Characteristics of LAN
- every computer has the potential to communicate with any other computers of the network
- high degree of interconnection between computers
- easy physical connection of computers in a network
- inexpensive medium of data transmission
- high data transmission rate


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

34
Advantages
- The reliability of network is high because the failure of one computer in the network does not
effect the functioning for other computers.
- Addition of new computer to network is easy.
- High rate of data transmission is possible.
- Peripheral devices like magnetic disk and printer can be shared by other computers.
Disadvantages
If the communication line fails, the entire network system breaks down.

Use of LAN
Followings are the major areas where LAN is normally used

- File transfers and Access
- Word and text processing
- Electronic message handling
- Remote database access
- Personal computing
- Digital voice transmission and storage
4.4.2 Wide Area Network
The term Wide Area Network (WAN) is used to describe a computer network spanning a regional,
national or global area. For example, for a large company the head quarters might be at Delhi and
regional branches at Bombay, Madras, Bangalore and Calcutta. Here regional centers are connected to
head quarters through WAN. The distance between computers connected to WAN is larger. Therefore
the transmission medium used are normally telephone lines, microwaves and satellite links.
4.4.3 Characteristics of WAN
Followings are the major characteristics of WAN.
1. Communication Facility: For a big company spanning over different parts of the country the
employees can save long distance phone calls and it overcomes the time lag in overseas
communications. Computer conferencing is another use of WAN where users communicate with
each other through their computer system.
2. Remote Data Entry: Remote data entry is possible in WAN. It means sitting at any location you
can enter data, update data and query other information of any computer attached to the WAN but
located in other cities. For example, suppose you are sitting at Madras and want to see some data
of a computer located at Delhi, you can do it through WAN.
3. Centralised Information: In modern computerised environment you will find that big
organisations go for centralised data storage. This means if the organisation is spread over many

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

35
cities, they keep their important business data in a single place. As the data are generated at
different sites, WAN permits collection of this data from different sites and save at a single site.
4.4.4 Examples of WAN
1. Ethernet: Ethernet developed by Xerox Corporation is a famous example of WAN. This network
uses coaxial cables for data transmission. Special integrated circuit chips called controllers are
used to connect equipment to the cable.

2. Aparnet: The Aparnet is another example of WAN. It was developed at Advanced Research
Projects Agency of U. S. Department. This Network connects more than 40 universities and
institutions throughout USA and Europe.

Difference between LAN and WAN
- LAN is restricted to limited geographical area of few kilometers. But WAN covers great distance
and operate nationwide or even worldwide.

- In LAN, the computer terminals and peripheral devices are connected with wires and coaxial
cables. In WAN there is no physical connection. Communication is done through telephone lines
and satellite links.

- Cost of data transmission in LAN is less because the transmission medium is owned by a single
organisation. In case of WAN the cost of data transmission is very high because the transmission
medium used are hired, either telephone lines or satellite links.

- The speed of data transmission is much higher in LAN than in WAN. The transmission speed in
LAN varies from 0.1 to 100 megabits per second. In case of WAN the speed ranges from 1800 to
9600 bits per second (bps).

- Few data transmission errors occur in LAN compared to WAN. It is because in LAN the distance
covered is negligible.

4.5 NETWORK TOPOLOGY
The term topology in the context of communication network refers to the way the computers or
workstations in the network are linked together. According to the physical arrangements of
workstations and nature of work, there are three major types of network topology. They are star
topology, bus topology and ring topology.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

36
4.5.1 Star topology
In star topology a number of workstations (or nodes) are directly linked to a central node (see, Fig.
4.3). Any communication between stations on a star LAN must pass through the central node. There is
bi-directional communication between various nodes. The central node controls all the activities of
the nodes. The advantages of the star topology are:
- It offers flexibility of adding or deleting of workstations from the network.
- Breakdown of one station does not affect any other device on the network.
The major disadvantage of star topology is that failure of the central node disables communication
throughout the whole network.






Fig. 4.3: Star Topology


4.5.2 Bus Topology
In bus topology all workstations are connected to a single communication line called bus. In this type
of network topology there is no central node as in star topology. Transmission from any station travels
the length of the bus in both directions and can be received by all workstations. The advantage of the
bus topology is that
- It is quite easy to set up.
- If one station of the topology fails it does not affect the entire system.
The disadvantage of bus topology is that any break in the bus is difficult to identify.




- -




Fig. 4.4: Bus Topology

NODE CENTRAL
NODE
bus
nodes

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

37


4.5.3 Ring Topology
In ring topology each station is attached nearby stations on a point to point basis so that the entire
system is in the form of a ring. In this topology data is transmitted in one direction only. Thus the data
packets circulate along the ring in either clockwise or anti-clockwise direction. The advantage of this
topology is that any signal transmitted on the network passes through all the LAN stations. The
disadvantage of ring network is that the breakdown of any one station on the ring can disable the
entire system.







Fig. 4.5: Ring Topology

IN-TEXT QUESTIONS 2
1. Differentiate between LAN and WAN.
2. What are the different types of network topology?
3. State True or False
(a) Networks used to interconnect computers in a single room, rooms within a building or buildings
on one site are called Wide Area Network (WAN).
(b) The term Wide Area Network (WAN) is used to describe a computer network spanning a regional,
national or global area.
(c) The speed of data transmission is much higher in WAN than in LAN.
(d) In star topology a number of workstations (or nodes) are directly linked to a central node.
(e) The advantage of the bus topology is that, If one station of the topology fails it does not affect the
entire system.

4.6 INTERNET
The Internet is a network of networks. Millions of computers all over the world are connected through
the Internet. Computer users on the Internet can contact one another anywhere in the world. If your
computer is connected to the Internet, you can connect to millions of computers. You can gather
NODES

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

38
information and distribute your data. It is very much similar to the telephone connection where you
can talk with any person anywhere in the world.

In Internet a huge resource of information is accessible to people across the world. Information in
every field starting from education, science, health, medicine, history, and geography to business,
news, etc. can be retrieved through Internet. You can also download programs and software packages
from anywhere in the world. Due to the tremendous information resources the Internet can provide, it
is now indispensable to every organisation.

Origin of Internet
In 1969 Department of Defence (DOD) of USA started a network called ARPANET (Advanced
Research Projects Administration Network) with one computer at California and three at Utah. Later
on other universities and R & D institutions were allowed to connect to the Network. APARNET
quickly grew to encompass the entire American continent and became a huge success. Every
university in the country wanted to become a part of ARPANET. So the network was broken into two
smaller parts MILNET for managing military sites and ARPANET (smaller) for managing non-
military sites. Around 1980, NSFNET (National Science Foundation Network) was created. With the
advancement of modern communication facilities, other computers were also allowed to be linked up
with any computer of NSFNET. By 1990 many computers were looking up to NSFNET giving birth
to Internet.

How Internet functions
Internet is not a governmental organisation. The ultimate authority of the Internet is the Internet
Society. This is a voluntary membership organisation whose purpose is to promote global information
exchange. Internet has more than one million computers attached to it.

E-mail
E-mail stands for electronic mail. This is one of the most widely used features of Internet. Mails are
regularly used today where with the help of postage stamp we can transfer mails anywhere in the
world. With electronic mail the service is similar. But here data are transmitted through Internet and
therefore within minutes the message reaches the destination may it be anywhere in the world.
Therefore the mailing system is excessively fast and is being used widely for mail transfer.

IN-TEXT QUESTIONS 3
1. What is Internet?
2. What is e-mail?

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

39
3. How does Internet function?

4.7 WHAT YOU HAVE LEARNT
In this lesson we discussed the importance and modes of communication through computers.
Computers can communicate with one another through computer networking. There are two types of
computer network: LAN and WAN. We discussed about the physical arrangements of computer and
peripherals in network topology. There are three types of network topology: star topology, bus
topology and ring topology. Also we discussed about Internet and e-mail.

4.8 TERMINAL QUESTIONS
1. What is computer Network? What are its main objectives?
2. Differentiate between analog and digital transmission of data.
3. Explain in brief different communication media.
4. What is the difference between simplex and full-duplex transmission?

4.9 FEEDBACK TO IN-TEXT QUESTIONS
IN-TEXT QUESTIONS 1
1. The data communication software instructs computer systems and devices as to how exactly data
is to be transferred from one place to another. The procedure of data transformation in the form of
software is commonly called protocol.
2. In asynchronous transmission data is transmitted character by character as you go on typing on a
keyboard. On the other hand, in the synchronous mode, the saved data is transmitted block by
block.
3. (a) True (b) False (c) True (d) True (e) True

IN-TEXT QUESTIONS 2
1. LAN is restricted to limited geographical area whereas WAN covers great distance. In LAN the
computer terminals and peripheral devices are connected with wires and coaxial cables whereas in
WAN communication is done through telephone lines and satellite links. The speed of data
transmission is much higher in LAN than in WAN.
2. There are three major types of network topology. They are star topology, bus topology and ring
topology.
3. (a) False (b) True (c) False (d) True (e) True

IN-TEXT QUESTIONS 3
1. The Internet is a network of networks. Information in every field starting from education, science,

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

40
health, medicine, history, and geography to business, news, etc. can be retrieved through Internet.
2. E-mail stands for electronic mail. Through e-mail we can transfer data anywhere in the world
within seconds.
3. Internet is not a governmental organisation. The ultimate authority of the Internet is the Internet
Society. This is a voluntary membership organisation whose purpose is to promote global
information exchange.





AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

41
LESSON 24
ELEMENTS OF BASIC STRUCTURE

24.1 INTRODUCTION
In this lesson, you will be introduced to a programming language called BASIC. It is the most popular
conversational programming language. Various versions of BASIC have been developed by computer
manufacturers for their computers. This language is quite simple to understand and has been adopted
by most of the microcomputers. It is suitable for both mathematical and business problems. It has
been specially designed for use in `time-sharing' environment but can also be used as a standard
language in a `batch-processing' environment.

24.2 OBJECTIVES
At the end of this lesson, you should be able to
- know how to construct constants, variables in BASIC language and expression using
mathematical, relational and logical operators.
- learn the structure and essential elements of BASIC.
- use some elementary BASIC commands in small programs.

24.3 BASIC AS A PROGRAMMING LANGUAGE
Basic is quite simple language and easy to understand. It is becoming more popular as an interactive
language. Now we shall discuss various features of this language.
24.3.1 Why BASIC?
B in BASIC stands for Beginners. Obviously, it is meant for those who are about to start learning
programming. To qualify as a beginner's language, it has to be simple, easy and readily available.
BASIC has all the qualities. Although, it is the beginner's language, its use by no means is restricted to
basic computer education or elementary applications. The second alphabet A stands for all-purpose. It
means BASIC can be used for a variety of applications involving business, science, mathematics and
graphics. In fact, with new enhancements, BASIC has some of the powers of more advanced
languages. The all purposeness is also derived from the fact that very large segments of games and
computer courseware are written in BASIC. The other three letters i.e. SIC stand for Symbolic
Instruction Code -- means the instructions may not be exactly in English but expressed in symbols.

The advantages of BASIC can be summed up as follows:
- BASIC is easy to learn and fun to practice. It may be called a `People's language'.
- It is available almost in every computer from micro to mainframe. Therefore, a program
developed in a micro can run on bigger system with minor modifications.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

42
- Program development cycle is quick, debugging is simple, and
- Modification of programs is quite easy.

24.3.2 History of BASIC
Conceived by John Kemeny and Thomas Kurtz, BASIC was born at Dartmouth College, USA in
1964. It had a rather humble beginning. The classical languages like COBOL or FORTRAN were
already developed. COBOL, in fact, was already established as the major data processing language.
FORTRAN on the other hand, became the principal programming language for scientific applications.
Both these languages, however, were not very simple to learn. There were extensive rules on syntax
and structure of the programs. Because of its simplicity, BASIC gained immediate popularity. It
became a widely used language for small commercial and scientific applications. BASIC had the
same impact on the world of programming languages as the PC had on the larger computer systems.
BASIC's popularity and acceptance by the user community compelled all the major computer
manufacturers to come out with their individual version of BASIC. When the microcomputer or PCs
were introduced, BASIC found a most convenient vehicle for its proliferation. The ease and simplicity
of BASIC made it the standard programming language for the microcomputer world. Even your MS-
DOS operating system comes with a BASIC interpreter called BASICA. (MS-DOS 3.2 onwards, a
more enhanced BASIC version, i.e., GWBASIC forms the part of the operating system.) American
National Standards Institute (ANSI) in 1978 came out with a standardised version of BASIC
language. Most of the versions of the currently available BASIC include the features of the ANSI
standard.

24.4 STRUCTURE OF BASIC
The general structure of standard BASIC language is best understood by a practical program. The
following small program prints the words WELCOME TO NATIONAL OPEN SCHOOL on the
screen:
10 REM: This is my first program
20 PRINT "WELCOME TO NATIONAL OPEN SCHOOL"
30 END
Keeping this program in view, let us go over the rules on the structure of the language.
These are:
- Each statement of instruction must appear on a separate line.
- A statement cannot exceed 80 characters i.e. one line on the terminal.
- A statement must start with a statement number. It is a positive integer.
- No two statements can have the same numbers.
- The statement must be in the ascending order.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

43
- Each statement number is followed by a BASIC command or keyword.
- You may use blank space to increase the readability of the program.

There is no restriction on blank lines within a program. These are the rules, as applicable to standard
or "Dartmouth BASIC" as it is called. The Microsoft BASIC i.e. BASICA or GWBASIC, however,
has provision for more than one statement in the same line and the use of keywords also need not
follow a line number. But if you strictly follow the rules of standard BASIC, the program will still
remain valid in Microsoft or any other BASIC. Now let us learn about some of the keywords, you
came across in the program.

24.5 ELEMENTARY BASIC STATEMENTS
In the program, you came across their important BASIC commands or keywords. These are REM,
PRINT and END. We will briefly discuss REM and END here. The PRINT will be discussed in
greater details in subsequent lessons. Presently for the purpose of understanding, you may take
PRINT, as an output instruction. The output may be meant for the terminal (as in this case) or it may
be directed to a disk file. What is important, is to remember, that in BASIC, print does not necessarily
mean a print out on a paper; it may mean display on the terminal or write on a disk file also.

24.5.1 REM
The REM is the short form for REMARKS. At the time of execution, when the interpreter comes
across the first three alphabets, as the keyword, it knows that the content of the line following REM is
not meant for execution and is to be ignored. REM is used purely to enhance the documentation
aspect of a program. It is meant for the reader of the program to understand the contents, purpose,
logic and other such aspects. Whatever, information on the program, you want to convey to the reader
of the program, may be placed after REM. There is no limit on the number of REM statements in a
program. In fact, it is recommended that you get used to judicious and copious use of REM
statements. It may not only help the reader, but it may also help you in understanding your own
programs, particularly if those are old or lengthy. At times to enhance the presence of a REM
statement you may place a blank line above or below a statement. This makes it more visible in
lengthy programs. You can place a blank line by a PRINT statement. If we want to insert a blank line
after the REM statement of the program, we may write the program as:

10 REM : This is my first program
20 PRINT
30 PRINT "WELCOME TO NATIONAL OPEN SCHOOL"
40 END


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

44
24.5.2 END
The END statement was mandatory in the older BASIC version to indicate the end of a program. In
other BASIC like Microsoft BASIC, it is not compulsory. In such cases, the program terminates at the
last or highest line number. Whenever END is used, it must be the last line. Any statement after the
END is irrelevant to the interpreter. Having been familiarised with a small BASIC program, let us
now see the elements other than the keywords, comprising this language.

24.6 THE CHARACTER SET
BASIC has the character set consisting of the following elements:
(a) Alphabets: A, B, C, ----. Z
(b) Digits: 0,1,2, ----, 9 and
(c) Special characters: + - * / ( ) . , $ ; : = > < " ^
The symbol ^ (caret) is used to denote exponentiation operator, the symbol * (asterisk) is used to
denote multiplication and the other symbols have their usual meanings. In addition these, blank space
denoted by the symbol b is also regarded as a character.



24.7 CONSTANTS AND VARIABLES
A quantity in a computer program which does not change its value during the execution of the
program is called a constant and the quantity which may change its values during the execution of the
program is called a variable. BASIC allows the following constants:

- Numeric constant
- String constant

Numeric constant is one that is formed by a sequence of digits 0,1,2, ---, 9 and may include a decimal
point. A numeric constant known as number may be as integer or a real number. 383, + 57, 0, - 6.2
and 6.15E4 are valid numeric constants. The number 6.15E4, in fact, represent 6.15 10
4
. The
notation E is used to represent exponential form. The number after E is the exponent which can be
positive or negative. However, its length cannot exceed two digits.

It is also important to keep in mind that
- BASIC does not distinguish between an integer and a fraction.
- Commands are not allowed in a numeric constant

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

45
- The limit on the number of digits that can be used varies from computer to computer. Normally, a
numeric constant can have up to a maximum of eight digits.

A string constant consists of a sequence of characters. It must be enclosed by a quotation mark. This
may contain blank space as a character but it should not include the quotation mark. String constants
are used to represent non-numeric quantities such as names, addresses, etc. For example, "PANKAJ
GOEL", "SUM = Rs 75", "162" are a few valid string constants.
In BASIC, variables are also of two types. They are
- Numeric variable
- String variable

Numeric variable can assume numeric value and is represented by an alphabet or an alphabet followed
by another alphabet or a digit. For example A, C, A2, ABC, A6 etc, represent numeric variables. A
string variable is represented by an alphabet followed by dollar ($) sign. It should be kept in mind that
while constructing the string variable, dollar ($) should be the last character. For example, A1$,
PKG$, BOOK1$, etc., are valid string variables.




IN-TEXT QUESTION 1
1. The following numbers (constants) are not written correctly. Indicate the errors:
(a) 4,75,163,
(b) +-7567
(c) 3.64E 1.5
(d) 6.05E
(e) 6125 -

2. Which of the following BASIC strings are correct?
(a) January 26, 1997
(b) Sixty-two
(c) 5121942
(d) 100 - 40 =60
(e) SUM "10"

3. Write the following as ordinary numbers:

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

46
(a) 1.23E6
(b) 1.5E - 5
(c) - 3E + 2
(d) 5.865696 E + 6
(e) - 1.2 E -2


24.8 ARITHMETIC EXPRESSIONS
A BASIC system can handle arithmetic expressions involving the five arithmetic operators +
(addition), - (subtraction), *(multiplication), /(division) and ^ (exponentiation). The hierarchy of
operations is as follows:
(i) Exponentiation
(ii) Multiplication and division
(iii) Addition and subtraction

Thus, in a particular arithmetic expression, the order of execution is as per this hierarchy, i.e. all
exponentiation operations are performed first, then multiplication/division and the
addition/subtraction operations are the last to be carried out. Note that within a particular hierarchical
group, the operations are executed form left to right. Normal hierarchy of operations can be altered by
use of parentheses. The operations within the innermost parentheses are performed first and then the
second innermost and so on.

In addition to this hierarchy of operations, the following rules must be kept in mind in arithmetic
expression:
- Two operations must not appear together. For example, C+-D, A/-C, etc are not permitted.
- String constants and string variables should not be used in arithmetic expressions. For example,
P+P$ is wrong.
- When brackets are used, they must be used in pairs, i.e., every left bracket must be matched with a
right bracket.
- Denominator of an expression should not be zero.
- Within a given pair of parentheses, the natural hierarchy of operations will apply.

Let us take an example where we give BASIC equivalents of a few algebraic expressions

Algebraic Expression BASIC Equivalent
2A+B 2*A+B

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

47
A(B+C) A*(B+C)
B
2
-4AC B^2-4*A*C

24.9 RELATIONAL OR LOGICAL EXPRESSIONS
A relational expression is formed by using any of the following relational operators:
Relational Operator Meaning
= Equal to
> Greater than
< Less than
< = Less than or equal to
> = Greater than or equal to
< > Not equal to

In the execution of programs, it is sometimes desired to compare two numerical quantities (or
sometimes string quantities) and take decisions on achieving certain conditions. For example, we may
be interested to check the number of repetitive calculations performed or to find out whether the
denominator of an arithmetic expression has become zero or if a particular quantity is negative, and so
on. Expressions written to compare two quantities using certain relational operators are known as
relational expressions. These expressions take only one of the two values, namely, TRUE or FALSE,
For instance, the relational expression A > B will be true if A is greater than B, otherwise FALSE.
This test result is used to change the sequence of execution of statements in a program. The general
form of a relational expression is as follows:



Relational
operator


When expressions are used on either side of the relational operators, the expressions will be evaluated
first and then the results of expressions compared. This means that relational operators come last in
the hierarchy of operators.

) /( ) ....( .......... .......... .......... D C B A
D C
B A
+ +
+
+
Constant
or
Variable
or
Expression
Constant
or
Variable
or
Expression

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

48
Logical expressions are used in IF---THEN Statements to determine the course of action of a running
program.

24.10 LOGICAL OPERATORS
Like relational operators, BASIC, also supports logical operators to perform logical operation on
numerical values. Logical operators are used to connect two or more relations and return a TRUE or
FALSE value to be used in a decision.
The common logical operators are:
- AND Conjunction
- OR Disjunction
- NOT Logical Negation

For example, the expression A > 50 AND B > 150 is TRUE when A is more than 50 and at the same
time B is more than 150.

Logical operators return results as indicated in the following tables. T indicates a TRUE and F
indicates a FALSE. X and Y are relational expressions.


AND Operator
X Y X AND Y
T
T
F
F
T
F
T
F
T
F
F
F

OR Operator
X Y X OR Y
T
T
F
F
T
F
T
F
T
T
T
F

NOT Operator
X NOT X
T F

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

49
F T

24.11 LIBRARY FUNCTIONS IN BASIC
The word `library' stands for collection. In the context of computer languages, a library is essentially a
collection of useful programs. These programs are used by the programmers to simplify their task of
program development. These programs are often referred as subroutines. The programmer does not
have to know the details of the sub-routine. Most of the programming languages are offered with a
number of sub-routines called sub-routine library or library functions. These built-in library functions
are used to simplify some useful common functions like calculation of square root, log of a number or
cosine of an angle. BASIC's library is rich with mathematical functions. For example, suppose you
want to calculate the square root of a numeric variable A. In simple mathematics, square root of A,
i.e., can be written as A

. Thus in BASIC it can be written as:


10 LET B = A^0.5
The value of B will be the square root of A. Using a library function the operation can be performed
as
10 LET B = SQR(A)

Of course, from the example, it appears that there is hardly any benefit in using the library function.
But imagine, if problem is little more complicated like calculation of the sine value of an angle or
logarithm of a number. The programming algorithm to calculate these is not so simple. To find the
logarithm of X by using LOG function you write
10 LET Y = LOG (X),
The variable Y will store the LOG value of X.
From this example, we may deduce the rules, governing the use of a function.
(a) Each function is assessed by the function name (LOG, SQR, etc.) followed by the function
argument placed within the parenthesis.
(b) The function argument is the information you supply to the function to act upon it. For
mathematical factions, it has to be a numeric constant or variable. Listed below are some
examples of mathematical functions in BASIC.








AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

50


Function Name Purpose Example
SIN Sine Calculate the Sine SIN(X)
value of an SIN(44/7)
angle (in radians)
LOG LOG Calculate the natural LOG(X)
logarithm of a number LOG(100)
SQR Square root Calculate the square SQR(A)
root of a number SQR(100)

(c) The function name is to be written exactly as given. No deviation is permitted.
(d) You cannot have a blank space between function name (SIN, LOG etc.) and the beginning of the
opening parenthesis enclosing the argument.

It should be noted that a library function program would produce the result faster than a BASIC
program that has been written to perform the same task. For example, calculation of square root by the
SQR function will be faster than writing in the form of a program. This is due to the fact that library
functions are optimised for the particular BASIC interpreter provided by the supplier.


IN-TEXT QUESTION 2
1. Evaluate the following BASIC expressions:
(a) 3 * 4/2 ^ 3 + 1
(b) 2 * (3+4) / (5-3) * 7

2. Write the BASIC expression corresponding to each of the following algebraic expression:
(a) (x+y)
4

(b) 2x
2
+ 5x + 6
(c) x/y + y/z
(d) (x-y)
4
/ (x+y)
4






AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

51
24.12 WHAT YOU HAVE LEARNT
This lesson is an introductory chapter on BASIC language. The purpose is to prepare you with the
basic rules of the language. The knowledge of these is essential for writing programs. The rules
described here pertain to standard BASIC. The GWBASIC or BASICA, which is going to be your
practical vehicle for learning this language however, an enhanced version of standard BASIC,
incorporating many additional features to add power to the language. It must however, be emphasized
that even if you stick to the rules of standard BASIC, it still remains completely valid for GWBASIC
or BASICA and can be run without any problem.

1.13 TERMINAL QUESTIONS
1. Define BASIC language along with its features.
2. Describe briefly the structure of BASIC language.
3. Differentiate between
(a) Numeric and String constant
(b) Arithmetical and Relational Expression
4. Write down the hierarchy of operations in Arithmetic Expression.
5. Define history of BASIC language briefly.

1.14 FEEDBACK TO IN-TEXT QUESTIONS


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

52
IN-TEXT QUESTION 1
1. (a) Commas are not allowed
(b) Two arithmetic operators +, - for the sign cannot be used simultaneously
(c) Exponent cannot contain a decimal point
(d) E must the followed by some integer number
(e) Negative sign should not be in the last

2. (a) correct
(b) correct
(c) correct
(d) correct
(e) Incorrect because quotation marks are not allowed in strings.

3. (a) 1230000
(b) 0.000015
(c) -300
(d) 5865696
(e) - 0.012

IN-TEXT QUESTION 2
1. (a) 2.5
(b) 49

2. (a) (x+y) ^4
(b) 2*x ^ 2 + 5*x + 6
(c) (x/y) + (y/z)
(d) (x-y) ^4 / (x+y) ^4



AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

53
LESSON 25
FLOWCHARTING
25.1 INTRODUCTION
The flowchart is a means of visually presenting the flow of data through an information processing
systems, the operations performed within the system and the sequence in which they are performed. In
this lesson, we shall concern ourselves with the program flowchart, which describes what operations
(and in what sequence) are required to solve a given problem. The program flowchart can be likened
to the blueprint of a building. As we know a designer draws a blueprint before starting construction on
a building. Similarly, a programmer prefers to draw a flowchart prior to writing a computer program.
As in the case of the drawing of a blueprint, the flowchart is drawn according to defined rules and
using standard flowchart symbols prescribed by the American National Standard Institute, Inc.

25.2 OBJECTIVES
At the end of this lesson, you will be able to understand:
- the meaning of flowchart
- the basic parts of the flowchart such as flowchart symbols and the flow lines connecting
these symbols.
- the advantages and limitations of flowchart

25.3 MEANING OF A FLOWCHART
A flowchart is a diagrammatic representation that illustrates the sequence of operations to be
performed to get the solution of a problem. Flowcharts are generally drawn in the early stages of
formulating computer solutions. Flowcharts facilitate communication between programmers and
business people. These flowcharts play a vital role in the programming of a problem and are quite
helpful in understanding the logic of complicated and lengthy problems. Once the flowchart is drawn,
it becomes easy to write the program in any high level language. Often we see how flowcharts are
helpful in explaining the program to others. Hence, it is correct to say that a flowchart is a must for
the better documentation of a complex program.
25.4 GUIDELINES FOR DRAWING A FLOWCHART
Flowcharts are usually drawn using some standard symbols; however, some special symbols can also
be developed when required. Some standard symbols, which are frequently required for flowcharting
many computer programs are shown in Fig. 25.1
Start or end of the program

Computational steps or processing function of a program


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

54
Input or output operation

Decision making and branching

Connector or joining of two parts of program

Magnetic Tape

Magnetic Disk

Off-page connector

| + Flow line

Annotation

Display



Fig. 25.1 Flowchart Symbols

The following are some guidelines in flowcharting:
(a) In drawing a proper flowchart, all necessary requirements should be listed out in logical
order.
(b) The flowchart should be clear, neat and easy to follow. There should not be any room for
ambiguity in understanding the flowchart.
(c) The usual direction of the flow of a procedure or system is from left to right or top to
bottom.
(d) Only one flow line should come out from a process symbol.
+
or
+
(e) Only one flow line should enter a decision symbol, but two or three flow lines, one for
each possible answer, should leave the decision symbol.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

55

Yes < 0 > 0


No = 0


(f) Only one flow line is used in conjunction with terminal symbol.





(g) Write within standard symbols briefly. As necessary, you can use the annotation symbol
to describe data or computational steps more clearly.

This is top secret data

(h) If the flowchart becomes complex, it is better to use connector symbols to reduce the
number of flow lines. Avoid the intersection of flow lines if you want to make it more
effective and better way of communication.
(i) Ensure that the flowchart has a logical start and finish.
(j) It is useful to test the validity of the flowchart by passing through it with a simple test
data.

25.5 ADVANTAGES OF USING FLOWCHARTS
The benefits of flowcharts are as follows:
1. Communication: Flowcharts are better way of communicating the logic of a system to all
concerned.
2. Effective analysis: With the help of flowchart, problem can be analysed in more effective way.
3. Proper documentation: Program flowcharts serve as a good program documentation, which is
needed for various purposes.
4. Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and
program development phase.
5. Proper Debugging: The flowchart helps in debugging process.
6. Efficient Program Maintenance: The maintenance of operating program becomes easy with the
help of flowchart. It helps the programmer to put efforts more efficiently on that part

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

56
25.6 LIMITATIONS OF USING FLOWCHARTS
1. Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart
becomes complex and clumsy.
2. Alterations and Modifications: If alterations are required the flowchart may require re-drawing
completely.
3. Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a
problem.
4. The essentials of what is done can easily be lost in the technical details of how it is done.


IN-TEXT QUESTIONS 1

1. Fill in the blank.
(i) A program flowchart indicates the_________ to be per formed and the __________ in which they
occur.
(ii) A program flowchart is generally read from _____________ to ________________
(iii) Flowcharting symbols are connected together by means of ___________________
(iv) A decision symbol may be used in determining the ____________ or ___________ of two data
items.
(v) __________ are used to join remote portions of a flowchart
(vi) ____________ connectors are used when a flowchart ends on one page and begins again on other
page
(vii) A ________ symbol in used at the beginning and end of a flowchart.
(viii) The flowchart is one of the best ways of ________ a program..
(ix) To construct a flowchart, one must adhere to prescribed symbols provided by the __________ .
(x) The programmed uses a ____________ to aid him in drawing flowchart symbols.

25.7 FEW EXAMPLES ON FLOWCHARTING
Now we shall present few examples on flowcharting for proper understanding of this technique. This
will help in student in program development process at a later stage.
Example 1
Draw a flowchart to find the sum of first 50 natural numbers.
Answer: The required flowchart is given in Fig. 25.2.




AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

57












NO

YES





Fig. 25.2 Sum of first 50 natural numbers

Fig 2.2 Flowchart for computing the sum of first 50 natural numbers.
START
SUM = 0
N = 0
N = N + 1
SUM = SUM + N
IS N=50?
PRINT SUM
END

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

58
Example 2
Draw a flowchart to find the largest of three numbers A,B, and C.
Answer: The required flowchart is shown in Fig 25.3












YES NO YES YES

NO NO










Fig 25.3 Flowchart for finding out the largest of three numbers



START
READ A, B, C
IS
B>C?
IS
A>B?
IS
A>C?
PRINT B
PRINT C PRINT C PRINT A
END

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

59
Example 3
Draw a flowchart for computing factorial N (N!)
Where N! = 1 2 3 N .
The required flowchart has been shown in fig 25.4
Answer:















NO


YES





Fig 25.4 Flowchart for computing factorial N

START
READ N
M = 1
F = 1
F = F * M
IS
M=N?
PRINT F
END
M=M+1

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

60
Example 4
A companys salesmen are selling toothpaste and tooth powder. The company having 50 salesmen
gives 10% commission on the sale of toothpaste and 20% commission on tooth powder.
Draw a flowchart to compute and print the total sale and the total commission for each salesman.

Answer: The required flowchart is shown in Fig 25.5
Note:
S = Salesman number
P1 = Amount of sales of paste
P2 = Amount of sales of powder
K = Counter for the number of salesman
























Fig 25.5: Flowchart for Computing Commission on Different Items


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

61
Example 5
Modify the flowchart in Example 4 to print the following heading.
Salesman No Total Sale Total commission
Under these heading, write the values of these variables for the 50 salesmen. At the end, the totals of
the entire sale and the entire commission should also be printed out.

Answer: The required flowchart is shown in Fig 25.6

Note:
TS = Total sales
TC = Total commission



























AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

62

Fig: 25.6 Flowchart for writing proper heading and its contents


IN-TEXT QUESTION 2
1. What are name and the use of the following symbols?
(a) (b) (c) (d) (e)

2. Define Flowcharting.


25.8 WHAT YOU HAVE LEARNT
In this lesson, we have discussed the advantages and limitation of flowcharting. We have also shown
some examples of flowcharting. This will help the students in learning this technique easily.

25.9 TERMINAL QUESTIONS
1. Draw a flowchart to read a number N and print all its divisors.
2. Draw a flowchart for computing the sum of the digits of any given number
3. Draw a flowchart to find the sum of given N numbers.
4. Draw a flowchart to computer the sum of squares of integers from 1 to 50
5. Draw a flowchart to arrange the given data in an ascending order.

25.10 FEEDBACK TO IN-TEXT QUESTIONS
IN-TEXT QUESTIONS 1
1. ( i ) Operations, sequence
(ii) Top, down
(iii) Flow lines
(iv) Equality, inequality
(v) connectors
(vi) Off -page
(vii) Terminal
(viii) documenting
(ix) ANSI (American National Standards Institute)
(x) Flowcharting template

IN-TEXT QUESTIONS 2

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

63
1. Symbol Name Use
(a) input/output To represent input of data for processing
or output of processed information.
(b) Terminal To indicate start or end of a program

(c) Decision marking To make logical construction to check some
condition.
(d) Process To represent an operation or a set of operation

(e) Connector To link one part of flowchart to another

2. Flowcharting is a technique of showing logical flow of data in pictorial form and integration of
programming steps for solving a given problem.



AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

64
LESSON 26
INPUT/OUTPUT AND PROGRAM CONTROL STATEMENTS

26.1 INTRODUCTION
In the previous lesson, we studied about the constants, the variables and the arithmetic operation used
in the BASIC language. We also saw how these constants, variables and the arithmetic operations
may be combined to form expressions and statements. Now we shall learn how the complete program
in BASIC language can be written using the basic principles we have learnt so far.

For a computer program to be executed using a computer, we should give some values to the
computer. Once the computer, completes the required computation work, we should ask the computer
to produce the results in a proper format that can be understood by the common man. The
INPUT/OUTPUT statements of the BASIC language achieve these two important functions. Besides
these we shall also discuss the use of repetitive and branching statements used in BASIC language.

26.2 OBJECTIVES
At the end of this lesson, you should be able to:
- understand clearly the use of INPUT/OUTPUT statements such as LET, READ-DATA,
INPUT, PRINT, PRINT USING etc.
- learn the use of LOOPING and CONTROL statements.
- develop BASIC programs using the various basic commands offered by the language

26.3 INPUT-OUTPUT STATEMENTS
It should be always kept in mind that computer cannot do anything by itself. It will act according to
the instructions supplied to it by the user. To achieve the required output in the desired format, a user
has to provide correct data and a series of processing instructions in proper order. In this section, we
will discuss various input/output statements provided in BASIC language.

26.3.1 Getting Data into Memory
As stated earlier, one of the basic features of a programming language is the input/output facility
offered by it. BASIC offers three such kinds of input statements. They are LET, INPUT and READ-
DATA. These statements are basically used to assign values to various variables.

26.3.2 LET Statements
Syntax:
Line number LET (variable name)=(Constants or Variables or expression)

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

65
Example of LET statement

10 LET X =5.32 ---> This is numeric constant
20 LET A = 6+9/3.2--> This is an arithmetic expression
30 LET Y = X+A --> This is also an arithmetic expression
40 LET I = u
2
-->numeric constant
50 LET I =I+Y -->I and Y are variable names
60 LET A$ = "NEW DELHI--> String variable
70 LET F$ = "99983" -->String variable
80 LET A = B--> numeric variable


These are all valid LET statements. The value of the variable on the left hand side of the equal to sign
is assigned the value given in the right hand side of the equal to sign

EXAMPLE
15 LET A =10
25 LET B =5
35 LET A = A+B
The example shows A is the variable name, which is, assigned the value 10 and B is the variable name
assigned the value 5. In the memory the line number 15 gives an instruction by which A will be the
address or name of a cell/location where the value 10 will be stored. Similarly B will be name or
address of a cell/location where 5 will be stored. Line number 35 instructs that the values in the
address A and B be added and the resulting value be kept at the cell/location whose address is A.





Memory location Memory location
A B
Execution of line 15 10 Not known
Execution of line 25 10 5
Execution of line 35 15 5



AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

66
Note here that after execution of line 15 it has been shown Not known in location B, because in this
program we have not given any value to the variable name B on line number 15. It's value is given in
the next line number 25. Since variable A has been already given the value 10 that continue to stay in
A until we assign a different value to A which replaces the earlier value. So in the next line number
35, A+B the values of A and B given before are added and put in the location A Now the latest value
of A is 15 and that of B will remain as 5. Let us suppose that line 35 has been replaced as
35 LET C = A + B
Here computer will add the values of A and B, i.e. 15 and put it in a third location C.

Location A Location B Location C
Line number 15 10 Not known Not known
Line number 25 10 5 Not known
Line number 35 10 5 15

26.3.3 INPUT Statement
Syntax
Line number INPUT Variable,List...

EXAMPLE
12 INPUT A,B,X
16 INPUT A$,F$,N$
20 INPUT Y1,F$,C2,NB

Whenever computer reads a line with the keyword INPUT it displays a sign? on the VDU and waits
for the data. We have to give the values of the variable at this prompt through the keyboard.

26.3.4 READ-DATA Statement
The LET and INPUT statement have certain limitations. By a LET statement we can assign one value
for each variable and if we have to get 10 values for 10 variables we have to use 10 statements with
LET. Also if a value is assigned through a LET statement its value can be changed only by replacing
that assignment statement by another assignment statement. In case of an input statement, the data is
provided at the prompt at execution time. If there is a large amount of data to be processed, it is
inconvenient to key in the entire data during the execution of the program. In such cases READ
statements are found useful. READ statement will always have a DATA statement along with it.
Syntax
Line number READ Variable, List....

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

67
Line number DATA Constant, List....
Example of a READ....DATA Statement

1 REM PROGRAM EXPLAINING READ....DATA STATEMENT
5 READ X2,Y,Z1,K
9 READ A,B3, C4, L
22 DATA 8,9,13,15,16,51,30,92
30 END

When the machine encounters the line number 5 with the READ statement followed by the variables
X2,Y,Z1,K it will collect from the DATA statements the values for these variables in the same order.
A one-to-one correspondence exists in READ-DATA statement, i.e. X2=8, Y=9, Z1=13, K=15.
In the next READ statement in line number 9 we have four more variables A,B3,C4,L.
These values will follow in the same order and one-to-one correspondence after the earlier READ
variables values, i.e., after 8,9,13,15, i.e., A=16, B3=51, C4=30, L=92.

Since all the values in the DATA here are exhausted, another i.e. third, READ statement cannot be
used until another DATA statement is included or more DATA is included in the above DATA list in
line number 22. A DATA statement can be anywhere in the program but must be before the END
statement. It is a normal practice to keep all DATA statements together at the end of the program
before END statement, so that in case you want to alter any data at the end it will be easy.

26.3.5 DATA BLOCK
The BASIC organises the contents of all the DATA statements into a data block. When the READ
statement are executed a pointer moves along with data block starting from the first element:
EXAMPLE
1 READ X1, Y1, Z1
7 READ N, M, L, K
12 READ A
19 READ X,Y
24 DATA 122
26 DATA-35,49, -101
28 DATA -691,81
30 DATA 8,10.-5,5
40 END

DATA BLOCK

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

68
Value Pointer Variable
122 <--- X1
-35 <--- Y1
49 <--- Z1
-101 <--- N
-691 <--- M
81 <--- L
8 <--- K
10 <--- A
-5 <--- X
5 <--- Y


Now look at the following some examples where all the programs do exactly the same work.

(a) 10 DATA "RAMA","DELHI",100,200,300
20 READ A$,B$,A, B, C
30 - - - - -
40 - - - - -
- - - - - - - - - - - - - -
80 END

(b) 10 READ A$,B$
20 READ A,B,C
30 - - - - - -
40 - - - - - -
60 DATA "RAMA","DELHI"
70 DATA 100,200,300
100 END

(c) 10 DATA "RAMA","DELHI"
20 DATA 100
30 DATA 200
40 DATA 300
50 READ A$,B$
60 READ A,B,C

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

69
- - - - - - - - - - - - -
100 END

(d) 10 READ A$
20 READ B$,A,B,C
30 DATA "RAMA"
40 DATA "DELHI"
50 DATA 100,200,300
- - - - - - - - - - - - -
100 END
In all these cases A$ is assigned the value RAMA and B$ the value DELHI.All the numeric variables
A,B,C are assigned the values 100,200,300 respectively.

So we note that for READ....DATA statement we should follow the following

- There could be any number of READ and DATA statements.
- As many variables are read by READ statement, at least the same number of values should be
there in the DATA statement. It may be more. If the number of values in DATA is less, then
there will be an error message OUT OF DATA given by the computer.
- The type of variables (i.e., numeric, string) in the READ statements containing many
variables.
- Although normally we keep all the DATA statements at the end of the program just before
END statement, DATA statement can occur anywhere in the program but before END
statement.

26.3.6 Restore Statement
The RESTORE statement beings the pointer to the first value of the DATA statement regardless of
the current position of the pointer.
Syntax
Line number RESTORE
For example,
10 RESTORE
The RESTORE statements may be used anywhere in the program, of course, before the END
statement.
The following example will clearly illustrates the use of RESTORE statement
10 READ X,Y

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

70
20 DATA 10,12,-7,,3.2, "PANKAJ"
30 RESTORE
40 READ A,B,C,D,N$
50 END
When the statement number 10 is executed, the variables X and Y are assigned the values of 10 and
12, the position of the pointer at this stage is shown below:


10 12 -7 3.2 "PANKAJ"
| (Pointer)
(Position of pointer before execution of RESTORE statement)

When the statement 30 RESTORE is executed, the pointer is brought back to the first data value of
data statement as shown below:

10 12 -7 3.2 "PANKAJ"
| ( Pointer)

Now, the execution of the statement number 40 against the value to A,B,C,D and N$ will be as
shown below:
A 10
B 12
C -7
D 3.2
N$ PANKAJ

The RESTORE statement can be used in the following forms also:

Statement number RESTORE *
and
Statement number RESTORE $

If the key word RESTORE is followed by asterisk (*), then only numeric pointer is reset as shown in
the previous example. However, if the key word RESTORE is followed by a dollar sign ($), then only
string pointer is reset to the first string data. The simultaneous use of both asterisk (*) and dollar sign
($) is not allowed.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

71
For example, if a BASIC program contains the following statements,

10 READ A,B,N$,M$
20 - - - - - - -
30 - - - - - - -
40 RESTORE *
50 READ P,Q,A$,B$
60 - - - - - - -
70 - - - - - - -
80 DATA 5,8,"DINESH",UPMA",10,12,"RAJESH","SANJU"
90 END

When the statement 10 is executed, A,B are assigned values 5 and 8 whereas the variables N$ and M$
are assigned the values DINESH and UPMA respectively. The execution of statement 40, restores the
numeric pointer to the first numeric value in the DATA statement i.e. to the value 5. The execution of
the statement 50, assigns the value 5,8, RAJESH and SANJU respectively to the variable P,Q,A$ and
B$. The values DINESH and UPMA are being ignored. Similarly, the execution of RESTORE$ can
also shown by taking similar example.

Consider another example
10 READ A,B,N$,M$
20 RESTORE $
30 READ P,Q,A$,B$
40 DATA 5,8, "DINESH", "UPMA", 10,12,"RAJESH",SANJU"
50 END
Here the statement RESTORE$ is used. The values assigned to the variable A,B,N$ and M$ are same
as in the previous example. However, when statement 20 is executed, the string pointer is reset to the
first string data namely DINESH. The execution of the statement 30 would assign the values 10 and
12 to the variables P and Q and then the pointer moves back-ward to assign the values DINESH and
UPMA to the variables A$ and B$

26.4 PRINT STATEMENT
The PRINT statement of BASIC provides limited methods of controlling the alignment and spacing of
printout in terminals. The general from of the PRINT statement is

Line number PRINT (Variable) separator (variable) separator or item......


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

72
The separation may be comma (,) or semicolon (;)

26.4.1 The Semicolon (;) Control
Program
10 LET S =1175.50
20 PRINT "TOTAL SALARY =";S; " RUPEES"
30 END

The output of the program 1 will be as
T O T A L S A L A R Y = 1 1 7 5 . 5 0 R U P E E S

Using semicolon in a print statement, the items are close to each other, and as a result more items can
be printed in one line,
26.4.2 The Comma (,) Control
100 PRINT "NUM","TEMP","SIZE", REMARK"
110 PRINT 65,-15.56,36,34
These two lines will be printed as follows
1 17 33 49 65 85
Zone 1 Zone 2 Zone 3 Zone 4 Zone 5
NUM
65
TEMP
-15.56
SIZE
36
REMARK
34

The number of columns in each zone may be checked from the literature of manual for the given
computer.

26.4.3 Print Using Statement
The PRINT USING statement is included in most versions of microcomputer BASIC. It allows
printed output to be formatted, giving the appearance of each data item. This PRINT USING
statement can specify both string and numeric data.

There are several different ways to format. The most commonly used are given below:
100 PRINT USING "##. ##"; A,B,C,
Line number PRINT USING Format String Numeric Variables
The format string "##. ##", which a numeric field containing a decimal point with not more than two
digits on each side.
What will be the output of the following program?

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

73
10 LET A =17.32
20 LET B = -5.38
30 LET C =40
40 PRINT USING "##. ##",A,B,C,
50 END
OUTPUT
17.32 -5.38 40.00

If string values are used instead of numeric values, the format string for PRINT USING will be as
follows:
100 PRINT USING "!!!!!!" ; N$
If N$ ="UNITED"
Then the above PRINT USING statement will give output as:
UNITED
Observe, there are six alphabets and we have used six exclamation sign (!). Each exclamation sign (!)
is used to represent each character of a string.
Note: Some computers use # for presenting a character.
Example
If N$ = "FROG" then
(a) 100 PRINT USING "!!!!";N$ gives output as bbFROG
(b) 100 PRINT USING ">!!!!!!";N$ gives output as
(> character is used for the right justification of a string.)
Since "!!!!!!" has six character representations and FROG has only four characters,">" sign gives
characters b b in the left side as the PRINT USING with > gives right justified. Space characters (b b
) are used to fill left space.
With the same explanation
100 PRINT USING <!!!!!!; N$ gives output FROG b b
(< is for left justified), Left justified space filled to right.
Note: b is used as space character.
26.4.4 TAB FUNCTION
The TAB (abbreviation of TABULATION) function is a very important function because it enables
the user to exercise exact control over the print positions. The use of a COMMA and a SEMICOLON
to space out the output is not so flexible as the TAB function.

TAB (n) moves the printer head to the n
th
column and printout of any data starts from that column.

Syntax:

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

74
Line number PRINT TAB (N); X

Where N is a positive number, a variable or an expression having positive value and X shows output
data
The execution of TAB function is explained below:-
(a) If N is an integer, the printer head moves to the Nth column and printing of the value of X starts
from that column
(b) In case N is a variable, not having the internal value, it is rounded and the printer head moves
according to this value.
For example, 5 X = 12
10 K = 5.3
20 PRINT TAB(k) ; X


(c) On the other hand, if N is an expression then first of all, the expression is evaluated and rounded, if
necessary. The printer head move based on the value of this expression.
The backward movement of the printer head is not allowed.
For example, consider the statement
10 PRINT TAB (25); "DINESH"; TAB(20); "RAJESH"
Here TAB (25) instructs the computer to start printing DINESH from column number 25 onwards.
Then TAB (20) instructs the computer to write RAJESH from column 20. Since the printer head is
already beyond the column 20 and backward movement is not allowed, so TAB (20) is ignored and
the output is same as if TAB (20) was not present. The above statement is equivalent to
10 PRINT TAB (25); "DINESH"; "RAJESH"
Consider another example, where TAB function is ignored
20 PRINT "10.3", TAB (10); "15.6"
The comma preceding the function TAB (10) Positions the printer head to the column 16 so that the
function TAB (10) becomes redundant as printer head cannot move backward and hence it is ignored.
The value 15.6 will be printer from column 16 onwards.
The use of TAB function is an elegant method to prepare patterns, producing tables and to plot graphs
etc.

26.5 PROGRAM CONTROL STATEMENTS # # THEIR SYNTAX AND USE
We have already seen a few BASIC statement like REM, (in Lesson 1),and
LET,INPUT,READ,DATA etc in this Lesson itself. The other few BASIC statements and their
explanations are given in this section. We will discuss them in details using different program.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

75
26.5.1 Unconditional Go To Statement
GOTO statement is used to transfer control from a statement, say S1 to another statement, say S2,
generally, S2 does not follow S1 immediately in sequence.
Syntax: Line number GO TO n
n is the line number of the statement where control will be transferred.



Program 1
10 READ A,B,X,Y
20 GO TO 60
30 LET X = X*X+A
40 LET =Y*Y +B
50 PRINT X, Y
60 LET X =A*X
70 LET Y =B*Y
80 PRINT X,Y
90 DATA 6,3,4,5
100 END

This shows after reading the values of A,B,X,Y, in line number 10, the control jumps to line number
60 and calculate X =A*X, Y =B*Y then prints X,Y in line number 80 and ends the program. Line
number 30,40,50 are never executed. If we want to execute 30,40,50 then our program will add few
more jump statements, i.e. few more GO TO statements.
Consider the following program 2.
Program 2
10 READ A,B,X,Y
20 GO TO 60
30 LET X =X*X+A
40 LET Y =Y*Y+B
50 PRINT X,Y
55 GO TO 100
60 LET X =A*X
70 LET Y =B*Y
80 PRINT X,Y
85 GO TO 30
90 DATA 6,3,4,5

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

76
100 END

Thus by introducing line number 55 and 85 all the statements are executed. So line number 30 and 40
prints X =X*X +A (value), Y =Y*Y+B (value) and line number 80 prints X = A*X and Y =B*Y



IN-TEXT QUESTION1

1. Fill in the blanks

(a) In the LET statement, the value of a variable on the ......... hand side of the equal to sign is
assigned to the variable given in the .......... hand side of the equal to sign.
(b) READ statement cannot be used without a ........... statement.
(c) DATA statement can occur anywhere in the program, but must be before the ........... statement.
2. State the difference between READ and INPUT statement?
3. What is the use of PRINT USING statement?
4. What is the use of RESTORE statement?
5. Define briefly the use of TAB function.


26.5.2 The Branching Statement IF... THEN
The IF...THEN is a decision making statement, depending upon the decision, it can change the order
of execution.
It helps the computer to check whether a relation is TRUE or FALSE.
Syntax: Line number IF (relational expression) THEN n where n is a line number or an instruction
itself.
If the relation expression is true then n will be executed otherwise the statement following this
IF...THEN statement will be executed.

EXAMPLE 2
Evaluate the expression Y =X
2
for X =1,2,3...
Program 1
10 LET X = 1
20 LET Y = X*X
30 PRINT Y

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

77
40 LET X = X+1
50 GO TO 20
60 END

In this process we see each time the line number 50 is executed the control is transferred to line
number 20 unconditionally. Thus we have an infinite loop which is never ending.
Computer goes round and round and never reaches END

To stop the infinite loop we can add a condition, i.e. say if X is greater than or equal to 31 (X >=31)
then the program ends otherwise it keeps on printing the value of expression Y = X
2
for X =1,2,3....30.

Program 2
10 LET X = 1
20 LET Y = X*X
30 PRINT Y
40 LET X = X+1
50 IF X> = 31 THEN 70
60 GO TO 20
70 END

Thus we see that IF-THEN is one of the powerful statements which can stop or get the computer out
of an infinite loop.

EXAMPLE 3
Problem 1
Write a program to find out the auto fare depending on the Kilometers traveled. The minimum fare
charged is Rs. 3.00. This minimum fare remains for 2 kms or less of travel. After 2 kms, the charges
are 75 rp per kilometer.
Program 1

10 INPUT "KILOMETER", K
20 IF K < = 2 THEN PRINT "RS.3 : END
30 LET CHARGE =3+ (K-2) *.75
40 PRINT CHARGE
50 END

Here in line number 20, if K is less than or equal to 2 (i.e., K<=2) then it will print Rs. 3 and (: END)

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

78
means END, in continuation to the line number 20 next statement is END.
Otherwise if K is not less than or equal to 2 then line number 30,40 then 50 will be executed.
26.5.3 The Branching Statement IF...THEN...ELSE
Another important statement is IF ...THEN...ELSE.
Syntax:
Line number IF (condition or relational expression)
THEN (line number or Instruction)
ELSE (line number or Instruction)
The IF...THEN...ELSE statement is a decision making statement as it decides the path of the program.
It helps in making comparisons and testing whether a condition is true or not.
IF is always followed by a valid BASIC condition or expression. If the condition is found true then
the line number or Instruction after THEN is performed otherwise line number or instruction after
ELSE is performed.

EXAMPLE 4
Problem 1

Ages of different students appearing in the Board examination are taken. If the age is below 17 the
student is not eligible, otherwise he can appear in the Board examination. We are asked to write a
program for this problem.

Program 1
10 INPUT AGE; A
20 IF A>= 17 THEN 30 ELSE 50
30 PRINT WELCOME FOR BOARD EXAMINATION
40 GO TO 60
50 PRINT YOU ARE NOT ELIGIBLE FOR BOARD EXAM.
60 INPUT WANT TO INPUT AGAIN (Y/N); Y$
70 IF Y$ = Y THEN 10
80 END

The line number 10 will cause the message in screen AGE? We input the age through the keyboard,
say 18. Line number 20 tests whether A>17 or not. Since A=18>17 line number 30 is executed.
Line number 30 prints WELCOME FOR BOARD
Line number 40 causes the control to pass to line number 60.
Line number 60 causes the message WANT TO INPUT AGAIN (Y/N)? We input either Y or N.
In line number 70 if input is Y then control goes to line number 10. Otherwise if input is N then

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

79
control goes to the line number 80 i.e. END.
Now if in line number 70 we input Y then control will pass again line number 10, we give another
age, say 13
In line number 20 value of A (i.e. 13) is not greater than 17, therefore ELSE part will be executed and
control will go to line number 50. Line number 50 will print YOU ARE NOT ELIGIBLE FOR
BOARD EXAM. Then line number 60 as before will be executed. In this way a large number of
students age can be tested. When we want to stop we should input N in line 60 for Y$.

Problem 2

10 INPUT A,B,C
20 IF A>B AND A>C THEN 50 ELSE 30
30 IF B>A AND B>C THEN 60 ELSE 40
40 IF C>A AND C>B THEN 70
50 PRINT "A IS THE LARGEST NUMBER": GO TO 80
60 PRINT "B IS THE LARGEST NUMBER": GO TO 80
70 PRINT "C IS THE LARGEST NUMBER"
80 INPUT "WANT TO INPUT AGAIN (Y/N)" ; Y$
90 IF Y$ = "Y" THEN 10
100 END

In line number 20,30,40 comparisons are made among the values of A,B, and C.
AND is a logical operator which combines A>B and A>C. If both the relational expression preceding
and following AND are true then the line number following THEN will be executed otherwise if one
of the relational expression, A>B or A>C is true then the line number following ELSE will be
executed. Same procedure follows for the next two IF statements also.

If expression at 20 is found true, the line number 50 will print A is THE LARGEST VALUE and then
GO TO 80 will be executed as the next statement to line number 50. If it is found false the control
passes to statement 30 and the expression at that statement is checked. This part of the program can
also be written as follows:

50 PRINT "A IS THE LARGEST NUMBER"
55 GO TO 80
60 PRINT "B IS THE LARGEST NUMBER"
65 GO TO 80


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

80
Thus line number 50 and 60 in earlier program of problem 2 is equivalent to line numbers 50,55,60,65
in the above program statement.
Syntax: For IF...THEN...ELSE with AND is given as;

IF (Condition 1 or Relational expression) AND (Condition 2 or Relational expression) THEN
(Instruction 1) ELSE (Instruction 2)

Like AND another logical operator is OR.
Syntax: for IF. THEN...ELSE with OR is:
IF (Condition 1 or Relational expression) OR (condition 2 or Relational expression)
THEN (Instruction 1) ELSE (Instruction 2)
This means if either of the conditions (or relational expression) followed or preceded by OR is true
then the instruction 1 is executed. If neither of them is true then instruction 2 is executed.
26.5.4 The Looping Statement FOR-TO...NEXT
We have already seen that a loop can be built in BASIC by using the IF-THEN and GOTO
statements.
When it is known in advance how many times the loop must be repeated the statement FOR-
TO...NEXT is the most effective statement.

A loop is built up by FOR-TO and ended by NEXT.
Syntax:
Line number FOR I = M TO N STEP J
Loop - - - - - -
- - - - - -
Line number NEXT I

The numeric variable name following FOR is called the control variable or loop variable.
M and N are numeric constants where M gives the initial or starting value of the loop and N gives the
final value, J followed by keyboard STEP gives the increment in M till N is reached. The increment
can be negative also.

M,N,J can be numeric variable names. In such cases their numeric values should be assigned before
the starting of the loop, i.e. before coming to FOR-TO statement.

They key word NEXT should have the same control variable I followed by it. Thus one loop can be
started with FOR-TO and ended with NEXT.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

81
Inside one FOR-TO ...NEXT loop there can be more FOR-TO...NEXT loop. But once a FOR-
TO...NEXT is inside another FOR-TO...NEXT, it should remain completely inside the former loop.
Such FOR-TO...NEXT loops are called Nested loops. In the absence of the STEP clause, the
increment is assumed to be 1.

EXAMPLE 5
Problem 1
Suppose we want to print the output in the following format:
* * * * *
* * * *
* * *
* *
*

Program 1

10 FOR S=5 TO 1 STEP-1
20 FOR X=1 TO S
30 PRINT "*" ;
40 NEXT X
50 PRINT
60 NEXT S
70 END

This program contains two loops: the outer loop is from the line number 10 to 60 and inner loop from
line numbers 20 to 40. In line number 10, initially S is assigned a value 5. Since the value of S is
greater than 1, control is transferred to line number 20, which causes the inner loop to execute 5 times
resulting into printing of 5 stars (*) in one row. The statement at line number 50 will transfer the
printer control to the beginning of the next line. When line 60 is encountered, the control goes back to
line number 10. Now the value of S becomes 4 and once again the inner loop is executed 4 times
resulting in printing of 4 (*) stars in second row. This process will continue till the value of S
becomes 1. After that it will come to end.

Problem 2

Suppose we want to sum to following series:
1,2,3,4_ _ _ _ 100.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

82

Program 2
10 LET S=0
20 FOR I=1 TO 100
30 LET S=S+I
40 NEXT I
50 PRINT " SUM OF SERIES =" ; S
60 END

26.5.5 The Multiple Branching Statement ON... GOTO

The GOTO statement allows only one transfer point, IF...THEN allows two transfer points, the
ON...GOTO can have more than two transfer points, thus providing multiple branching facility.
Syntax: line number ON (Numeric variable or expression) GOTO n1,.n2,n3,..
The expression is a valid BASIC expression and n1,n2,n3,.... are the statement numbers or line
number where the control will be transferred.

If ON is followed by numeric variable name and if the value of numeric variable is 1 control is
transferred to n1, if 2 then n2, if 3 then n3 and so on.

If ON is followed by an expression by an expression then it is evaluated and truncated to an integer
value. Control is transferred in the same manner as discussed above.
If the integer value is less than or more than number of line numbers present in the list then an "OUT
OF RANGE" error message will be given by the computer.

EXAMPLE 6

Problem
Write a program to add, subtract, divide and multiply two numbers A and B.
Program

5 INPUT A,B
10 INPUT " 1-ADD, 2-SUB, 3-MUL, 4-DIV"; N
20 ON N GOTO 30,40,50,60
30 PRINT A+B : END
40 PRINT A-B : END
50 PRINT A*B : END

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

83
60 PRINT A/B : END

When line 5 is executed, there will be question mark (?) then you have to input the values of A and B
through keyboard. Line number 10 will cause a message on the screen 1-ADD, 2-SUB, 3-MUL, 4-
DIV and then display of question mark (?) for N.
If we input through keyboard 1 then N takes the value 1.If we enter 2 or 3 or 4,N will take 2 or 3 or 4
accordingly. If the value of N is

1 control is transferred to 30,
2 control is transferred to 40,
3 control is transferred to 50,
4 control is transferred to 60

On execution of line number 30 addition of A and B will be displayed on the screen and program will
come to an end. Similarly, in line number 40,50,60 printing of the result of subtraction, multiplication
and division will be displayed respectively.



IN-TEXT QUESTIONS 2
1. Write a LET statement for each of the following:
(a) To assign the value 5.2 to the variable A
(b) To assign the string PENTIUM-SYSTEM TO the variable B$
(c) To assign the value of the variable C to the variable D
(d) To increase the value of the variable E by 1
(e) To assign the value equal to three times the value of the variable P to the variable Q

2. In the following FOR statements, write the values taken by the control variable
(a) 10 FOR L = 3 TO 12 STEP 2
(b) 20 FOR M = 1 TO 50 STEP 10
(c) 30 FOR N = 100 TO 0 STEP -20
(d) 40 FOR K = 5 TO 5
(e) 50 FOR I = 10 TO 6 STEP -1

3. Give the output of the following short program
10 PRINT "PANKAJ" , "GOEL"
20 PRINT "PANKAJ" ; "GOEL"

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

84
30 PRINT "PANKAJ",, "GOEL"

4. Give the output of the following short program
10 LET A = 40
20 LET B = 50
30 LET C = 60
40 LET D = A+B+C
50 PRINT A= A; A B = B; B C=; C, D=; D
60 END

26.6 WHAT YOU HAVE LEARNT
This lesson gives us the introductory features of BASIC language, which are very essential for writing
small programs in BASIC. Some additional statements and functions of BASIC will be discussed in
Lesson 4. The example programs given in this lesson should be run on a computer so that the concept
is clear before going to the next lesson.
26.7 TERMINAL QUESTION
1. What does an unconditional GOTO statement do?
2. What is the difference between an IF... THEN statement and an IF... THEN... ELSE statement?
3. How is the multiple branching facility provided in BASIC?
4. Write a program in BASIC using For-Next loop to get the following output:
1 * * * *
2 * * * * * * * * * *
3 * * * * *
4 * *
5 * * * * * * *
5. Write a program in BASIC to print out the largest number out of 10 given numbers.
26.8 FEEDBACK TO IN-TEXT QUESTION

IN-TEXT QUESTIONS 1
1. (a) Right, Left
(b) DATA
(c) END
2. In case of an INPUT statement, data is read from the keyboard at the time of execution of the
program. In READ statement, data is provided in the program itself through a DATA statement.
3. Print using statement allows printed output to be formatted corresponding to the given
specification.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

85
4. The restore statement brings the pointer to the first value of the DATA statement, regardless of
the current position of the pointer.
5. TAB function enables the user to exercise exact control over the print positions.

IN-TEXT QUESTIONS 2
1. (a) 10 LET A = 5.2
(b) 20 LET B$="PENTIUM-SYSTEM"
(c) 30 LET D = C
(d) 40 LET E = E+1
(f) 50 LET Q =3*P

3 (a) Values taken by L are : 3,5,7,9,11
(b) Values taken by M are : 1,11,21,31,41,
(c) Values taken by N are : 100,80, 60,40,20,0
(d) Value taken by K is : 5
(e) Values taken by I are : 10,9,8,7,6,

4. PANKAJ GOEL
PANKAJ GOEL
PANKAJ GOEL

5. A= 40 B= 50 C= 60 D =150

LESSON 27
HANDLING OF ARRAYS, FUNCTIONS AND SUB-ROUTINE

27.1 INTRODUCTION
In the previous lesson, you have gone through the programming technique and various
INPUT/OUTPUT and control statements in BASIC. But the features that make this programming
language more useful are use of subscripted variables, subroutine and various functions provided to
help the programmer. We shall be discussing all these features in this lesson. We have also included
various sample programs, which will help you further in writing more complex programs in BASIC
language.

27.2 OBJECTIVES
This lesson will explain you about handling of lists, tables, subroutine, sub-programs and some of the
functions of BASIC. At the end of this lesson, you should be able to:

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

86
- use functions and subroutines in BASIC language
- write complex programs in BASIC language
- learn how to set up and use arrays in BASIC programs

27.3 HANDLING LISTS AND TABLES (ARRAYS) IN BASIC
In all our programs so far, a single variable (one storage location in internal memory) has been
associated with each variable name. In this lesson, we will discuss the concept of an array: a
collection of variables, all of which are referenced by the same name. We will discuss one-
dimensional arrays (lists) and two-dimensional arrays (tables), concentrating on the former. Each item
of data in an array does not have a unique variable name, on the other hand, a group of similar data is
given one name. The smallest component of an array is called an element of the array.
Example 1: suppose we want to represent five numbers (10,12,42,91,7,) which represent the marks of
five students
Solution:
We can use an array name M(I) which is also called the subscripted variable and I is the subscript
which varies from 1 to 5. M is the name of array and M(1) is an element of the array M.

In the memory it is stored as,
M(I) Cells Quantities

M(1) 10
M(2) 12
M(3) 42
M(4) 91
M(5) 7
Problem1: Write a program to read the above data into the memory.
Program 1
10 DIM M(5)
20 FOR I = 1 TO 5
30 READ M(I)
40 NEXT I
50 DATA 10,12,42,91,7
60 END

Let us go back to the above example.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

87
M is an array of 5 numbers 10,12,42,91,7, where under the array name M the five different elements
M(1),M(2), M(3), M(4), M(5), are given one subscript I. This M(I), with a single subscript I, is an
example of a one-dimensional array. Let us study a practical example of one-dimensional array.

Example 2: We have an item biscuit in a shop. We have prices for 10 different biscuits as 60, 45.5,
32.6, 19.5, 52, 49,53.75, 29, 43, 38.6. We write a program to print these different values or we want to
know the price of any type of the above biscuits. We will do it by using an array.
Solution
Since they are similar items, we give them a single name BISCUIT or in short BIS. Since we know
only one specification i.e. price we have a single subscript, say I. So the array is now BIS(I). Since
there are 10 prices for 10 types of biscuits I varies from 1 to 10 i.e. BIS(1), BIS(2).BIS(10).

If we want to know the price for the biscuit of type 4, we will print BIS(4) which will give us the
required price.

Program 2
10 DIM BIS(10)
20 REM PRICES FOR 10 TYPES OF BISCUITS ARE TO BE READ
30 REM THE 10 PRICES HAS TO BE PRINTED ALSO
\40 FOR I = 1 TO 10
50 READ BIS(I)
60 NEXT I
70 PRINT THE PRICES OF TEN DIFFERENT BISCUITS
80 FOR I =1 TO10
90 PRINT BIS(I)
100 NEXT I
110 DATA 60,45.5, 32.6, 19.5, 52,49,53.75
120 DATA 29,43,38.6
130 END

OUTPUT
Line number 70 will print
THE PRICES OF TEN DIFFERENT BISCUITS
Line number 90 due to line number 80 and 100 will print
60
45.5
32.6

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

88
19.5
52
49
53.75
29
43
38.6
The line number 10 DIM BIS(10) is compulsory. This informs the machine that we are giving an
array with single subscript having 10 elements. So, 10 cells in the memory location will be kept for
the variable name BIS.
If we want an array of strings instead of numeric value, see the following example:

Example 3
To store the names of six motor cars in any array (table) such as:

FORD MARUTI AMBASSADOR FIAT STANDARD VAUXHAL L

We can write a program as follows:

Program 3
10 REM DECLARE THE NAME AND SIZE OF THE TABLE
20 DIM C$(6)
30 REM USE THE READ/DATA TECHNIQUE
40 REM TO STORE STRINGS
50 FOR J = 1TO 6
60 READ C$(J)
70 NEXT J
80 REM.. NOTE THE STRINGS USED AS DATA ARE
90 REM.. ENCLOSED BETWEEN QUOTATION MARKS
100 REM.. ARRAY NAME TO STORE STRINGS IS
110 REM.. GIVEN AN STRING VARIABLE NAME C$
120 DATA FORD, MARUTI, AMBASSADOR
130 DATA FIAT, STANDARD, VAUXHALL
140 END

The REM (i.e. remarks) given in the line number 30,40,80,90,100,110, explains the program.
Though DATA is given in two lines 120 to 130, the data should be in the order they are placed.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

89
C$(1) = FORD
C$(2) = MARUTI
C$(3) = AMBASSADOR
C$(4) = FIAT
C$(5) = STANDARD
C$(6) = VAUXHAULL

Example 4
Let the 10 data values are given as 4, -6, 7, 2.3, - 6.1, 5. 3
-1, 0, - 2.7,9
WE give this set of values the name, say VAR (I) where I is the subscript.
If I = 1, then VAR (1) has the value 4
I = 5, then VAR (5) has the value -6.1
I = 8 then VAR (8) has the value 0, and so on.

The program for adding all the 10 numbers.

Program 4
10 REM ADDING 10 NUMBERS IN A ONE DIMENSIONAL TABLE
12 DIM VAR (10)
15 LET SUM = 0
20 FOR I = 1 TO 10
30 READ VAR (I)
40 LET SUM = SUM +VAR (I)
50 NEXT I
60 DATA 4, -6,7, 2.3, -6.1, 5.3, -1, 0, -2.7,9
70 PRINT SUM
80 END
27.3.1 The DIM Statement
When subscripted variables are used in a program, certain information about them must be supplied to
the computer before it is used. These are:
(a) Which variables are subscripted?
(b) What is the maximum size for each subscript?

DIM is the short form of DIMENSION.
By using this statement in line number 10 of the program 1 above, the array whose name is M has
been allotted 5 cells in the memory location. Syntax for the DIM statement is

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

90
Line number DIM array name (unsigned integer)
The unsigned integer specifies the size of the array variable.
If we write 10 DIM A(100), X(10), then 100 locations are reserved for the array name A and 10
locations for the array name X.
DIM should be the first statement in the program barring REM statement.

Problem 5
Suppose we want to read the roll number of a student and his marks obtained in five subjects in the
board examination. Now print the roll number and average marks secured by him.

Program 5
10 DIM M(5)
20 INPUT ROLLNO
25 LET TOT = 0
30 FOR I = 1 TO 5
40 READ M(I)
50 LET TOT = TOT + M(I)
60 NEXT I
70 LET AVERAGE = TOT/5
80 PRINT ROLLNO, AVERAGE
90 DATA 60,52,49,80,72
100 END

On the execution of line number 30, initially the control variable I becomes 1 and line number 40
reads M(I), i.e. the first mark from line number 90, that is 60 and adds to the variable TOT which is
initially zero. So for I = 1 line 50 gives TOT = 0 +60 = 60, control then goes to line number 60 and
back to 30. Now I becomes 2 and line number 40 reads M(2), i.e. 2nd marks from DATA, i.e. 52. In
line number 50 TOT = 60 + M(2), i.e. TOT = 60+52 = 112 and so on. So line number 30 to 60 is
executed five times. Thus finally in the variable name TOT we have TOT = 60+52+49+80+72=313.

So, when line number 70 is executed AVERAGE = 313/5 =62.6. Line number 80 will print the
ROLLNO which is entered in line number 20 and the average AVERAGE as 62.6.

If we want to do this process for a large number of students say 10 we have to give more data in
DATA statement, i.e. 45 more data values and put another loop to repeat the process for ten students.

Program 5(a)

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

91
10 DIM M (5)
15 FOR J = 1 TO 10
20 INPUT ROLLNO
25 LET TOT =0
30 FOR I = 1 TO 5
40 READ M (I)
50 LET TOT = TOT + M(I)
60 NEXT I
70 LET AVERAGE = TOT/5
80 PRINT ROLLNO, AVERAGE
85 NEXT J
90 DATA 60,52,49,80,72,98,69,72,80,75
100 DATA 88,61,54,48,60,52,92,86,81,65
110 DATA _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
120 DATA _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
130 DATA _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
140 END










IN-TEXT QUESTIONS 1
1. Given the following code:
10 LET S =0
20 FOR I = 1 TO N STEP 2
30 LET S = S+2*I-1
40 NEXT I
50 END
You are required to complete each statement.
(a) The accumulator is the variable ___________
(b) The control variable is _______________

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

92
(c) After execution, S contains the sum of the first N _________ Integers.

2. Correct the errors in each of the following program segments:

(a) 10 FOR K = 1 TO 5
20 FOR J = 1 TO K
30 PRINT K + J
40 NEXT K
50 NEXT J

(b) 10 LET S = 0
20 FOR I = 1 TO 10
30 LET S = S + I
40 PRINT S
50 NEXT K

3. What is the output of each of the following program segments?
(a) 10 FOR I = 7 TO 10 STEP 2
20 PRINT I;
30 NEXT I
40 PRINT I
50 END

(b) 10 FOR I = 1TO 10
20 IF I = 5 THEN 40
30 PRINT I + 1
40 NEXT I
50 END
27.3.2 Double-Subscripts or two-dimensional arrays
A subscripted variable name in BASIC can have up to three subscripts. The use of two subscripts has
very wide applications, especially manipulation of tables or any such things, which has rows and
columns both in it.
Example: Represent subscripted variable or two-dimensional array having name TABLE(I.,J) where I
indicates row and J indicates column.
Where, TABLE (I,J) = 2 4 8 10
1 3 5 7

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

93
3 7 13 17

Thus we see TABLE (I,J) has 3 rows, i.e. I = 1 TO 3 and 4 columns, i.e. J = 1 TO 4.

Problem 6
We want to read and print the values of TABLE (I,J) as given above

Program 6
10 DIM TABLE (3,4)
15 FOR I = 1 TO 3
20 FOR J = 1 TO 4
30 READ TABLE (I,J)
35 PRINT TABLE (I,J)
40 NEXT J
50 NEXT I
70 DATA 2,4,8,10,1,3,5,7,3,7,13,17,
80 END
See how it reads the data


TABLE(1,1) TABLE(1,2) TABLE(1,3) TABLE(1,4)
2 ---------> 4 --------> 8 ----------> 10
TABLE(2,1) TABLE(2,2) TABLE(2,3) TABLE(2,4)
1 ---------> 3 --------> 5 ----------> 7
TABLE(3,1) TABLE(3,2) TABLE(3,3) TABLE(3,4)
3 ---------> 7 --------> 13 ----------> 17


As the subscript J corresponding to the column is in the inner FOR loop, the table is read row-wise. J
being in the inner loop changes more frequently from 1 to 4 for every value of I, which is in the outer
loop. If we want to read the data column-wise program will be as follows.

Program 7
10 DIM TABLE (3,4)
20 FOR J =1 TO 4
30 FOR I =1 TO 3

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

94
40 READ TABLE (I, J)
50 NEXT I
60 NEXT J
70 DATA 2, 1, 3, 4, 3, 7, 8, 5, 13, 10, 7, 17
80 END

More applications relating to subscripted variables will be shown in the last section.
We have shown you to store numeric data in a table (array) with row and column subscripts.
Now, You will see how string data is stored in a two-dimensional array.

Example
The following are data values (names), which are to be stored in the table form with rows and
columns.




HARIOM DINESH RAJESH PANKAJ
BIMLA UPMA SANJU ANAMIKA

The program is as follows:

Program 7
10 REM DECLARE THE NAME AND SIZE OF THE TABLE
20 DIM N$ (2,4)
30 REM SET UP AN OUTER LOOP TO CONTROL THE ROW SUBSCRIPT
40 FOR M = 1 TO 2
50 REM..SET UP AN INNER LOOP TO CONTROL THE COLUMN SUBSCRIPT
60 FOR P = 1 TO 4
70 REM .. USE A READ/DATA STATEMENT TO STORE DATA AS
80 REM .. SHOWN IN DIAGRAM
90 READ N$ (M, P)
100 NEXT P
110 NEXT M
120 DATA "HARIOM", "DINESH" "RAJESH"
130 DATA "PANKAJ", "BIMLA"

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

95
140 DATA "UPMA", "SANJU", "ANAMIKA"
150 END



IN-TEXT QUESTIONS 2

1. Determine whether each of the following statements is true or false.
(a) Array of string data and array of numeric data can be declared in the same DIM statement.
(b) All elements of an array must be of either string type or numeric type.
(c) One and two-dimensional arrays cannot be declared in the same DIM statement.

2. A two-dimensional array FAX has two rows and four columns
5 10 15 20
25 30 35 40
(a) What are the values of FAX (1,3) and FAX (2,1) ?
(b) Which elements of FAX contain the numbers 30 and 20 ?

3. What is displayed when the following program segment is executed?
10 DIM A (2,3)
20 FOR I = 1 TO 2
30 FOR J = 1TO3
40 LET A(I,J) = I+J+1
50 NEXT J
60 NEXT I
70 PRINT A(1,2); A(2,1); A(2,2)
80 END

4 Write a BASIC program that determines and prints the smallest and largest elements of a two-
dimensional array X (assuming that it; has been already inputted) with four rows and five
columns.

5. Write a BASIC program to arrange the following numbers in an ascending order:
-71, -20, 14, 0, 5



AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

96
27.4 FUNCTION AND SUBROUTINE
27.4.1 Defining a function---the DEF statement
To avoid repeated programming of the same set of calculations, the programmer would like to write
his or her own functions, which are similar to the Library functions. It may so happen that a particular
calculation or a set of calculations occurs more than once in the program. If the calculation can be
defined by a single statement then we use the function statement DEF FN.
Syntax: line number DEF FNV (a) = expression
Where V is the one-letter name of the function and "a" is the argument, which appears as a variable
in the expression on the right.

Problem 1
Suppose we want to write a program to calculate y for various values of x, say for x = 1,2,3,4,5, for
the expression y(x) =ax
2
+ bx + c

Program 1
10 DEF FNY (X) = A*X*X + B*X + C
20 INPUT A, B, C
30 FOR X = 1 TO 5
40 PRINT X, FNY(X)
50 NEXT X
60 END

On execution of the program line number 30 TO 50 will give the value of y(1) through y(5) for the
respective value of x, calculated at line number 10. The value of x is supplied in line number 30 and
values of A, B and C are input at line 20.

Problem 2
Let us consider the program to calculate
y = 1.5x + 3 for x<= 2
y = 2x + 5 for x>2

Program 2
100 DEF FNY(X)
105 INPUT X
110 IF X < = 2 THEN 140
120 LET FNY = 2*X + 5
130 GO TO 150

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

97
140 LET FNY = 1.5*X + 3
150 FNEND
170 PRINT X, FNY(X)
180 END

Here DEF FNY (X) statement in line number 100 is used without being equated to expression. The
FNEND statement in line number 150 indicates the end of the function. The line numbers 160 to 180
consist the main program. On execution of line 170 a call to the function FNY(X) is made causing the
execution of line number 100 to 150 with the input value of X.
The DEF statement must have DEF FN and variable name with one character and arguments included
in the parenthesis. Arguments can be more than one also. The argument is a variable, which must
appear in the right side after the equal to (=) sign, in case of DEF FN statement is equated to an
expression. (For example, see problem 1)

Example 1
Evaluate the algebraic formula z =(u/v + x/y)/2 for different set of values of u, v, x, y.

Solution
10 DEF FNZ(U,V,X,Y) =(U/V + X/Y)/2
20 INPUT U,V,X,Y
30 PRINT FNZ(U,V,X,Y)
40 END

This is for one set of values for U,V,X,Y. Now the program given below will evaluate the formula for
different set of values for U,V,X,Y
10 DEF FNZ (U,V,X,Y) = (U/V + X/Y)/2
20 INPUT U,V,X,Y
30 PRINT FNZ(U,V,X,Y)
35 IF U = O THEN 50
40 GO TO 20
50 END

Line number 40 sends the control back to INPUT. Now, you can enter another set of values for
U,V,X,Y. When you want to stop, you enter O for U. Then line number 35 will bring the program to
END.

Example 2

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

98
Define a function for subprogram for the algebraic formula
p = log(t
2
-a) for t
2
> a
log(t
2
) for t
2
= < a

Solution
30 DEF FNP(T,A)
40 INPUT T,A
50 IF T * T < = A THEN 80
60 LET FNP =LOG (T ^ 2 -A)
70 GO TO 90
80 LET FNP = LOG (T ^ 2)
90 FNEND
100 PRINT T, A FNP (T,A)
110 END

In line number 40, the values of T,A can be input by READ/DATA or by using LET statements twice.
Note: Please consult the machine manual for DEFFN statement before running the programs in the
machine.

27.4.2 Defining a subroutine -The GOSUB and RETURN statements
A subroutine is a collection of statements belonging to a process, which requires to be repeated very
frequently in the program. A subroutine consists of set of program statements that may be used
repeatedly at different places throughout the main program. In the main program the subroutines are
called at different places using GOSUB statement.

GOSUB Statement
Syntax: line number GOSUB n
Where n is the line number of the 1st statement in the subroutine.
Subroutines are placed at the end of the main programs in order to repeat a process. The program
control has to exit from the main program to enter a subroutine and after the process is completed it
comes back to the main program using RETURN statement.

RETURN statement
Syntax: line number RETURN
The RETURN statement in the subroutine transfers the control back to the main program to the line
immediately following the corresponding GOSUB statement. RETURN is the last statement in the
subroutine.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

99
GOSUB and RETURN are always used together in the program not independently.

Properties of GOSUB
- One subroutine can follow another subroutine but each subroutine should be complete within
itself.
- GOSUB unconditionally transfers the program from the main to the subroutine.
- GOSUB can also transfer the program conditionally by using it with IF-THEN ELSE
Syntax: Line number IF (Logical expression) THEN COSUB (line number) ELSE GOSUB (line
number)
- A subroutine can be called by the main program a number of times. But the returning point will
be different in each time.
- GOSUB takes the control from the main program to the subroutine and return brings back the
control from the subroutine to the main program.

Problem 1
Write a program to add, subtract, multiply and divide any two numbers.
10 INPUT A, B
20 INPUT "CHOICE", C$
30 IF C$ = "ADD" THEN GOSUB 80 : GOTO 65
40 IF C$ = "SUB" THEN GOSUB 120 : GOTO 65
50 IF C$ = "MUL" THEN GOSUB 170 : GOTO 65
60 IF C$ = "DIV" THEN GOSUB 210
65 PRINT C
70 END
80 REM "SUBROUTINE FOR ADDITION"
90 LET C = A + B
91 RETURN
120 REM "SUBROUTINE FOR SUBTRACTION"
130 LET C =A-B
150 RETURN
170 REM "SUBROUTINE FOR MULTIPLICATION"
180 LET C = A*B
200 RETURN
210 REM "SUBROUTINE FOR DIVISION"
220 LET C = A/B
240 RETURN

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

100

Short form of Problem 1 for addition
10 INPUT A, B
20 INPUT "CHOICE" C$
30 IF C$ = "ADD" THEN GOSUB 50
40 END
50 PRINT A+B
60 RETURN

So whatever will be the input of C$ in line number 20, GOSUB will go to these subroutines as it is
written for C$ = "ADD" similar subroutines will follow for "SUB", "MUL", "DIV" ON GOSUB
statement is similar to ON GOTO.
Syntax is given as:




Line no ON Numeric variable GOSUB
Or
Numeric expression
(Line number of sub-routine
1, sub. 2, sub .3.)


Program 2
10 INPUT A,B
20 INPUT "1-ADD, 2-SUB, 3-MUL, 4-DIV"; N
30 ON N GOSUB 50, 60, 70, 80
40 END (To make the program repeat we should add GOTO 10)
50 PRINT A+B : RETURN
60 PRINT A-B : RETURN
70 PRINT A*B : RETURN
80 PRINT A/B : RETURN
Note: To make the program repeat, we should add GOTO 10 at line 35


IN-TEXT QUESTIONS 3

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

101

1. (a) What is a subscripted variable?
(b) What is the function of a DIM statement?
(c) Define a subroutine?
(d) What does a RETURN statement do?

2. What is displayed when each of the following program segments is run?
(a) 10 GOSUB 400
20 GOSUB 500
30 PRINT "ONE"
40 END
400 PRINT "TWO"
410 RETURN
500 PRINT "THREE"
510 RETURN

(b) 10 DEF FNA (W) = 2*W+1
20 PRINT FNA (2)
30 LET x = 3
40 PRINT SQR (FNA (x+1))
50 END


27.5 EXAMPLES AND PROGRAMS SHOWING USAGE OF SOME BASIC FUNCTIONS:
INT, MOD, RND, LOCATE, LEN, VAL, STR$, RIGHT$, MID$

27.5.1 INT Functions
It takes a numeric value as its argument and returns its value after truncating the decimal part. The
value returned is always smaller than the number provided as the argument. For example,
10 Y= INT(13.2)
20 X= 15.6
30 Y= INT(X)

Statement 10 will return Y = 13 and
Statement 30 will return Y = 15.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

102
Example 1
Two numbers A and B are given. To find the higher number between them:

Program 1
10 INPUT "HIGHER NO"; A
20 INPUT "SMALLER NO ";B
30 LET C = A/B
40 IF INT(C)= C THEN PRINT HIGHER NUMBER=; A
50 END
This shows the use of the INT function.

Example 2
Write a program to find whether any year of the current century is a leap year or not.

Program 2
10 REM ** PROGRAM TO FIND WHETHER THE YEAR IS A LEAP YEAR OR
15 REM NOT **
20 PRINT "ENTER THE YEAR"
30 PRINT
50 INPUT YEAR
60 LET Y1 =INT(YEAR/4)
70 LET Y2 =YEAR/4
80 IF Y1 =Y2 THEN 110
90 PRINT YEAR "IS NOT A LEAP YEAR"
100 GO TO 120
110 PRINT YEAR; "IS A LEAP YEAR"
120 END

(A) Suppose we input year as 1988, then line number 60, we compute Y1 as 497 and also line number
70 gives Y2 as 497. Thus line number 80 gives Y1=Y2 and so the control is transferred to 110.

(B) Suppose we input year as 1989. The line number 60, we compute Y1 as 497. In line number
70, we get Y2 as 497.25. Thus in line number 80 Y1 is not equal to Y2, therefore control passes to 90.
27.5.2 MOD FUNCTION
Program 3
10 INPUT C, D
20 LET X= C MOD D

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

103
30 PRINT X
40 END

The MOD function determines the remainder on dividing a number by another. For example, 9 MOD
2 will give 1.

27.5.3 THE RND, LOCATE function
RND generates random numbers between 0 and 1.

Program 4
10 LET C= INT (RND*80)+1
20 LET R= INT( RND*25)+1
30 LOCATE R, C : PRINT "*"
40 GO TO 10
50 END

RND*80 and RND*25 generates random numbers between 0 to80 and 0 to25 respectively. Thus, in
line number 10,20 C is assigned the integer value of RND*80 plus 1 and R is assigned the value
RND*25 plus I respectively. The LOCATE clause followed by R,C followed by PRINT "*", prints a
"*'in the Rth row an Cth column.

27.5.4 THE LEN, VAL, STR$ function
LEN is used to count the number of character in a string. It takes a string as an argument and counts
every character including a blank.

Example
10 LET C$ = "BEAUTIFUL"
20 LET C = LEN (C$)
30 PRINT C
40 END
Output is 9 (as there are 9 characters in the word BEAUTIFUL. Note that the function LEN returns a
numeric constant.
VAL(X$) function returns a numeric constant equivalent to the value of the number represented by
the string X$. This string X$ should consist of all digits.

Example
10 LET X$= "12345"

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

104
20 LET Y = VAL(X$)
30 PRINT Y
40 END

Output of this program, on execution, will be 12345.
STR$(Y)
This is the reverse operation of VAL. The value of Y here is converted into a string literal. Y can be a
numeric constant, variable or expression.

Example
10 LET Y =7384
20 LET X$=STR$(Y)
30 PRINT X$
40 END
The output will be 7384. The numeric value of Y is converted to string in line number 20, i.e. X$ =
7384
27.5.5 String Processing in BASIC
Following are the few functions, which operate on string variables and help in string processing.

Left String
LEFT$ (X$,Y) Returns the left most Y characters from the string X$

Example 1
10 LET X$ = "MATHEMATICS"
20 PRINT LEFT$ (X$, 4)
30 END
The output will be MATH

Example 2
10 LET C$ ="INFORMATICS"
20 LET D$ = LEFTS(C$,6)
30 PRINT D$
40 END
Output will be INFORM.

Right string
RIGHT$(Y$,X) returns the rightmost X characters from the string Y$

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

105

Example 3
10 LET X$ = "PORTBLANK"
20 PRINT RIGHT$(X$,5)
30 END
Output will be BLANK.

Example 4
10 LET A$ = "MANAGED"
20 LET B$ = RIGHT$ (A$,4)
30 PRINT B$
40 END
Output will be AGED.

Middle String
MID$(X$,X,Y) Returns a sub string of X$ starting at the character position X from the left and
containing Y characters.

Example 5
10 LET X$ = "MANHATTAN"
20 PRINT MID$(X$,4,3)
30 END
Output will be HAT.

IN-TEXT QUESTIONS 4
1. (a) What is the use of an INT function?
(b) What would be the value of X in the following program segments?
(i) C$ = "AVAILABLE"
X = LEN(C$)

(ii) C$ = "899"
X = VAL(C$)

2. If A$ = "TO ERR IS HUMAN" B$ = "TO FORGIVE DIVINE", find the values of following
functions:
(a) LEFT$(A$,2)
(b) MID$(A$, 2, 3)

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

106
(c) RIGHT$ (B$, 4)

(d) A$ +" " +B$
(e) MID$ (A$,4, 3) + MID$ (B$,5,2)


27.6 EXAMPLE PROGRAMS

Problem 1
Write a program to invert TAERG to GREAT.

Program 1
5 LET L$ =
10 LET C$ = "TAERG"
15 L = LEN(C$)
20 FOR X = L TO 1 STEP -1
30 LET L$ = L$ +MID$(C$,X,1)
40 NEXT X
50 PRINT L$
60 END
Output GREAT

Problem 2
Write a program to give the word GRAPEFRUIT and FRUITGRAPE when GRAPE and are
separately. Given

Program 2
10 LET F$ = "GRAPE"
20 LET B$ = "FRUIT"
30 LET C$ = F$ +B$
40 PRINT C$
50 LET A$ = B$ +F$
60 PRINT A$
70 END
Line 40 prints GRAPEFRUIT
Line 60 prints FRUITGRAPE

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

107

Problem 3
The prices of different articles are stored in a one-dimensional table, there product code is also given
as:


Price in Rs. 20 15 16 18 14
Product Code 1 2 3 4 5

Let us assume that product code and quantity sold for an article is inputted through keyboard. Write a
program to calculate and print the cost of sale along with product code and quantity sold. Terminate
the procedure when the product code is out of range.

Program 3
10 DIM P (5)
20 FOR C = 1 TO 5
30 READ P(C)
40 NEXT C
50 DATA 20,15,16,18,14
60 INPUT "PRODUCT CODE"; C
70 IF C<1 OR C>5 THEN END
80 INPUT "QUANTITY SOLD"; Q
90 LET S = Q*P(C)
100 PRINT "PRODUCT CODE"; C ; "QUANTITY SOLD "; Q; COST OF SALE" ; S
110 GO TO 60
Line number 70 contains END.

Problem 4
A set of given numbers are there. Write a program to arrange them in descending order.

Program 4
10 REM PROGRAM TO ARRANGE THE GIVEN NUMBERS IN DESCENDING
ORDER
15 DIM X (25)
20 INPUT "HOW MANY NUMBERS ARE THERE",N
50 FOR I = 1 TO N

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

108
60 READ X (I)
65 NEXT I
70 PRINT "ORIGINAL ORDER IS:"
80 FOR I = 1 TO N
90 PRINT X(I) ;
100 NEXT I
110 PRINT "NUMBERS IN DECREASING ORDER"
120 FOR I = 1 TO N-1
130 FOR J= 1 TO N-1
140 IF A (J)>=A (J+1) THEN 180
150 TEMP= A (J)
160 A (J)= A (J+1)
170 A (J+1) =TEMP
180 NEXT J
190 NEXT I
200 FOR I = 1 TO N
210 PRINT A (I);
220 NEXT I
230 END

Problem 5
From the word "MAIDAMS" write the message "MADAM IS MAD"

Program 5
10 LET A$ = "MAIDAMS'
20 PRINT LEFT$(A$, 2)+MID$(A$,4,3); MID$(A$,3,1)+
RIGHT$(A$, 1);LEFT$(A$,2)+MID$(A$,4,1)
30 END
Line number 20 can be put in two consecutive PRINT statement also.

Problem 6
Write a program to print the Prime Numbers between any two numbers A (say 1) and B (say 100).

Program 6
10 INPUT TWO NUMBERS; A,B
20 FOR N= A TO B STEP 1
30 IF N MOD 2= 0 OR N<= 1 THEN GO TO 80

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

109
40 FOR X=3 TO SQR(N) STEP 2
50 IF N MOD X =0 THEN 80
60 NEXT X
70 PRINT N; IS THE PRIME NO
80 NEXT N
90 END

Explanation
In the line number 30, N MOD 2 is same as MOD(N,2) it gives the remainder of N/2, similarly in line
number 50,N MOD X means remainder of N/X.

27.7 WHAT YOU HAVE LEARNT
In this lesson we have discussed various statements relating to decision making, looping and
branching. Use of subroutine, sub-programs and arrays has been explained clearly by taking number
of examples. These commands play very important role in writing programs. The illustrations given in
this lesson will help you for a better grasp of BASIC programming. Usage of some BASIC functions
has been clearly defined for the benefit of the students.

27.8 TERMINAL QUESTIONS
1. Write a BASIC program to run up the following series
(a) 1,3,5,7, 9 100
(b) 2,4,6,8,10100
(c) 1,4,9,16,25100
(d) 1,8,27,64,1251000
2. What will be the output of the following programs?
(a) 10 FOR I = 1 TO 3
20 FOR J = 1 TO 5
30 PRINT I, J, I+J
40 IF J = 3 THEN 100
50 PRINT I, J , I*J
60 PRINT I+J, I-J
70 PRINT
100 NEXT J
110 NEXT I
120 END

(b) 10 FOR I = 1 TO 5

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

110
20 READ K
30 PRINT I ;
40 FOR J = 1 TO K
50 PRINT -;
60 NEXT J
70 PRINT
80 NEXT I
90 DATA 5,9,3,2,6
100 END
3. Write a program to invert LOOHCS to SCHOOL.
4. Write a program to write
PANKAJ KUMAR GOEL as P.K. GOEL.
5. Write a program to write your own address 10 times on the screen.

27.9 FEEDBACK TO IN-TEXT QUESTIONS

IN-TEXT QUESTIONS 1
1. (a) S
(b) I
(c) Positive odd
2. (a) 40 NEXT J
50 NEXT K
(b ) 50 NEXT I

3. (a) 7 9 11

(b) 2
3
4
5
7
8
9
10
11

IN-TEXT QUESTIONS 2

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

111
1. (a) True
(b) True
(c) False

2. (a) FAX(1,3,) = 15, FAX(2,1) = 25
(b) FAX(2,2) = 30, FAX(1,4) = 20

3. 4 4 5

4. 10 LET SMALL = X(1,1)
20 LET LARGE = X(1,1)
30 FOR I = 1 TO 4
40 FOR J = 1 TO 5
50 IF X(I,J) < SMALL THEN LET SMALL = X(I,J)
60 IF X(I,J) > LARGE THEN LET LARGE = X(I,J)
70 NEXT J
80 NEXT I
90 PRINT "SMALLEST VALUE ="; SMALL
100 PRINT "LARGEST VALUE ="; LARGE
110 END

5 10 DIM A(5)
20 REM READ NUMBER OF DATA VALUE
30 READ N
40 REM READ DATA VALUE INTO ARRAY A
50 FOR I =1 TO N
60 READ A(I)
70 NEXT I
80 REM NOW SORTING STARTS
90 FOR M = 1 TO N-1
120 IF A (M+1) > = A(M) THEN 18 0
130 REM INTERCHANGE OF DATA VALUES
140 LET P = A(M)
150 LET A (M) = A (M+1)
160 LET A(M+1) = P
180 NEXT M
190 REM PRINT THE SORTED ARRAY

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

112
200 FOR K = 1 TO N
210 PRINT A (K);
220 NEXT K
230 DATA 5, -71, -20, 14, 0, 5
240 END

IN-TEXT QUESTIONS 3
1. (a) A list of quantities can be given one variable name using a subscript. Such
a variable is called a subscripted variable.
(b) It defines the number of memory locations required for the array name.
(c) It is a collection of statements, which requires to be repeated very frequently
in a program. It is placed at the end of the program and may be referred to at
different places in the main program using GOSUB statement.
(d) RETURN transfers the control back to the main program, to the statement
immediately following the subroutine call.(i.e. GOSUB statement)
2. (a) TWO
THREE
ONE
(b) 5
3

IN-TEXT QUESTIONS 4
1 (a) It takes numeric value as its argument and returns its value after truncating its
decimal part.
(b) (i) 9
(ii) 899 (As numeric value)

2 (a) TO
(b) O E
(c) TO ERR IS HUMAN TO FORGIVE DIVINE
(e) ERROR



LESSON 28
PROCESSING FILES IN BASIC


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

113
28.1 INTRODUCTION
We have so far discussed programs where data is supplied either through READ...DATA statements
or through INPUT statements. But it is difficult to handle large volume of data with the help of these
statements. Moreover, data stored in one program cannot be shared by other programs. The above
limitations can be overcome by placing the data into a separate storage area called a data file.

A date file forms an essential framework of a data processing system. It is a collection of data
organised in a specific format and for a specific purpose, which is kept somewhere in external
memory. A file can be described as a collection of records where a record consists of number of data
values, which are either produced by a computer as per the instructions of a program or given to the
computer as a data. A typical data processing system many consist of many files. Many records in a
file contain detailed information about some aspect of the system. For example, a "pay file" may
contain one record for each employee containing all the particulars such as Employee Code, Name,
Address, Basic pay, HRA, DA, CCA, Designation, Sex, etc. Each partition is a data item and is
referred to as a field. A number of BASIC Programs can use this file as input.

File handling methods differ widely from system to system. In this lesson, we will discuss the
methods that are currently used in most of the IBM compatible systems.

28.2 OBJECTIVES
On completion of this lesson, you should be able to:
- understand various types of files
- know how to handle sequential files
- know how to handle random access files
- discuss various examples/ programs relating to these two type of files.


28.3 TYPES OF FILES
Depending on the way in which the data is stored and accessed, files are categorised as:
- Sequential access files
- Direct (Random) access files

Sequential Access Files
These files may be created on a magnetic tape or disk. Data from these files is read sequentially, item
after item, starting at the beginning. Though sequential access file is easy to handle, yet it has a
serious disadvantage. In the sequential file we cannot change the existing entry or insert a new entry.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

114
To do this, we should copy the entire content to another file making the changes on the way and then
copy the correct data back in to the original file. Another disadvantage is that we cannot simply locate
or go back to read a particular data item.

Fig. 28.1 and 28.2 show how data is stored on magnetic tapes and disk respectively. A disk consists
of a number of concentric circles known as tracks. The data items are stored on these tracks
sequentially.















Fig. 28.1 Sequential File on a Tape
Consider an inventory file shown in Table 28.1

Part name Part number Price Quantity
AAAA 101 8.00 100
BBBB 102 10.00 200
CCCC 103 12.00 300


Table 28.1 Inventory file





AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

115
















Fig. 28.2 Sequential File on a Disk

Details of each part are stored in one record. When we complete all the parts, the data file would look
like a long column of values as shown below:

AAAA
101
8.00
100
BBBB
102
10.00
200
CCCC
103
12.00
300
Programs are written to read these data values one after another.

Random Access Files

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

116
Random access files are created on disks to allow us to read or write from the files in random order.
Random access files allow more flexible access than the sequential files. You can read or write any
record directly in a random file without searching through all the records that precede it. Thus,
reading and writing of data is faster.

28.4 HANDLING OF SEQUENTIAL FILES
Using data files would require the incorporation of statements in your program to perform the
following functions:
- Giving a name to the file
- Opening the file
- Writing to or reading from the file
- Closing the file

28.4.1 Naming a file
A file is identified by its file specifications. It is of the form:

Device name: File name

The device name tells the system which device to look for the file and the file name tells which file to
look for on that device. The device name should be followed by a colon as indicated. Examples are:
A: MEAN
B: STUDENT. MKS
The device names A and B indicate the disk drive one and two respectively
File names can have a maximum of eight characters. However, the files stored on disks may have a
file name extension in the following form.
NAME.EXT
The extension consists of a period and followed by three letters. When you use longer file name, one
of the following conditions may occur.

File Name Result
1. Extension is longer than three characters. Extra characters are truncated.
2. Name is longer than eight characters. A period is inserted after the eighth character and
extra characters (up to three) are used as the
extension.
3. Name is longer than eight characters and
extension is included.
Gives an error.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

117

For example,
SURENDERKUMAR becomes SURENDER.KUM.
PROGRAM.PENSION becomes PROGRAM.PEN.
PAYROLLCALUCTION.BAS gives an error.

28.4.2 Opening a file
It is necessary to establish a line of communication between a program and a file that is to be used
before data can be read from or written to that file. This is achieved by using the OPEN command as
shown below:
OPEN ["Mode", #file number, "file name"]
Mode is a string constant and takes one of the following three forms
- O for sequential output file
- I for sequential input file
- R for random input/output file
It should be noted that the mode is enclosed in quotation marks.
File number is an integer number and can be any number between 1 and 15. It is a unique number
associated with the actual physical file. A file number may be a number, variable, or expression.
File name specifies the particular file to be used. This should conform to the specifications of the file
when it was created. File names must be enclosed in quotations.
Examples of opening sequential files for input and output operations are:
10 OPEN "I" # 1, " PANKAJ.DTA"
20 OPEN "O", # 3, "TEMP"

These can also be written as
10 OPEN" PANKAJ.DTA" FOR INPUT AS# 1
20 OPEN" TEMP" FOR OUTPUT AS #3

If a file opened for input operation does not exist, a "FILE NOT FOUND" error will be shown on the
screen. If a file, which does not exist, is opened, in that case file will be created. It is important to note
that opening a file for output destroys the existing data in that file.

28.4.3 Closing a File
A previously opened file can be closed using the CLOSE statement as follows

CLOSE [# file number, #file number, ......]

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

118

The file number is the number used in the OPEN statement. For example, the statement.
100 CLOSE #1, # 3
causes the files with file numbers 1 and 3 to be closed. The CLOSE statement is used when you have
finished processing data from a file.
A CLOSE statement with no file numbers specified causes all files that have been opened to be
closed.

You should also note that execution of END and RUN statements also causes all open sequential files
to be automatically closed. However, STOP does not close any files.

28.4.4 Writing Data to a File
We may write data to a sequential file using either of the following two statements.
PRINT [# file number, list of variables]

WRITE [ #file number, list of variables ]
File number refers to the file designator used when the file was opened for output. List of variables
specifies the data that is to be written to the file.

The difference between PRINT # and WRITE # Statements is that WRITE # inserts commas between
the data items and quotation marks for strings while PRINT # causes data to be written without any
delimiters (commas, etc.). For example consider the statement
40 PRINT #1 N $, AMT
In case N $ = " PANKAJ" and AMT = 2000, the
statement would write the following image to the file 1:
PANKAJ 2000

The statement
40 WRITE # 1, N $, AMT
would write the following image to the file 1:
"PANKAJ", 2000
The delimiters are useful when we try to read the data with an INPUT # statement.
Let us take an example for proper understanding the use of "WRITE" and "PRINT" statement.
Example 1
Program
10 REM *** PROGRAM INVENTI ***

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

119
20 REM -- PNM$ PART NAME
30 REM -- PN PART NUMBER
40 REM -- P PRICE
50 REM -- QTY QUANTITY
60 OPEN "O", # 1, "INVENT. DTA"
70 FOR I =1 TO 3
80 INPUT "NAME" ; PNM$
90 INPUT "NUMBER" PN
100 INPUT "PRICE" P
110 INPUT "QUANTITY" ; QTY
120 WRITE # 1, PNM$, PN, P, QTY
130 PRINT
140 NEXT I
150 CLOSE #1
160 END

Output
NAME? AAAA
NUMBER? 101
PRICE? 8
QUANTITY? 100

NAME? BBBB
NUMBER? 102
PRICE? 10
QUANTITY? 200

NAME? CCCC
NUMBER? 103
PRICE? 12
QUANTITY? 300

28.4.5 Reading Data from a File
Data can be read from a sequential file using the INPUT # statement. It takes the form

INPUT [ # file number, list of variables ]


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

120
The following INPUT # statement can be used to read data from the file INVENT. DTA:
200 INPUT #1, PNM$, PN, P, QTY

The type of data in the file must match the type specified in the list. Unlike INPUT, no question mark
is displayed with INPUT #
The following example will illustrate clearly the use of INPUT # statement.

Example 2
Write a program to read inventory data stored in the file INVENT. DTA inventory and print the table
with the value of each product.

Program
10 REM ** PROGRAM INVENT 2 **
20 OPEN I",#1, "INVENT. DTA"
25 PRINT "PART", "PART", " PRICE", "QUANTITY", " VALUE "
30 PRINT "NAME","NUMBER"
40 PRINT
50 INPUT #1 PNM$, PN, P, QTY
60 LET V= P* QTY
70 PRINT PNM$, PN, P, QTY, V
80 GOTO 50
90 CLOSE
100 END

Output
PART PART PRICE QUANTITY VALUE
NAME NUMBER
AAAA 101 8 100 800
BBBB 102 10 200 2000
CCCC 103 12 300 3600
Input past end in 50

The program in Example 2 reads sequentially, every item in the file. When all the data have been
read, line 50 causes an "Input past end" error. This can be avoided by using the EOF function. This
function tests for end of file and the control is directed appropriately. The end of the file is indicated
by a special character in the file.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

121
The program INVENT2 is modified as follows:

10 REM ** PROGRAM INVENT 2**
20 OPEN "I", #1 "INVENT. DTA"
25 PRINT "PART", "PART","PRICE, "QUANTITY" "VALUE"
30 PRINT "NAME", "NUMBER"
40 PRINT
50 IF EOF (1) THEN 100
60 INPUT #1, PNM$, PN, P, QTY
70 LET V = P*QTY
80 PRINT PNM$, PN, P, QTY, V
90 GOTO 50
100 CLOSE
110 END

28.4.6 Reading lines from a File
The LINE INPUT # statement may be used to read an entire line, ignoring delimiters, from a
sequential file and assign to a string variable. It is of the form
LINE INPUT [ #file number, string variable ]

File number is the number under which the file was opened and string variable is used to store a line
of string constant.

LINE INPUT # reads all characters in the sequential file up to a carriage return which was inserted by
the PRINT # statement. The next LINE INPUT # reads all characters up to the next carriage return.
Example 3 illustrates the use of LINE INPUT #statement.

Example 3
Write a program to input employee addresses from the keyboard, store them in a file named
ADDRESS, and read back to produce a list.


Program
10 REM ** PROGRAM EMPLOYEE **
20 REM ** INPUT EMPLOYEE ADDRESS THROUGH KEYBOARD **
30 OPEN "O ", #1 "ADDRESS"

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

122
40 FOR I = 1TO 3
50 LINE INPUT "TYPE IN ADDRESS" ADDR$
60 PRINT # 1 ADDR$
70 NEXT I
80 CLOSE 1
85 PRINT
90 OPEN : "I" # 1, "ADDRRESS"
100 FOR I= 1 TO 3
110 LINE INPUT # 1, ADDR$
120 PRINT ADDR$
130 NEXT I
140 CLOSE 1
150 END

Output
TYPE IN ADDRESSES? PANKAJ KUMAR GOEL, PITAMPURA, DELHI -34
TYPE IN ADDRESSES? RAJESH KUMAR, AUDIT OFFICE, GWALIOR
TYPE IN ADDRESSES? DR. SANJU, MEDICAL COLLEGE, JODHPUR
PANKAJ KUMAR GOEL, PITAMPURA, DELHI-34
RAJESH KUMAR, AUDIT OFFICE, GWALIOR
DR. SANJU, MEDICAL COLLEGE, JODHPUR

28.4.7 Adding Data to a Sequential File
To add any data to a sequential file that is already residing on a disk, you cannot just open the file and
write data to it. You must note that when a sequential file is opened for output, its current contents
are lost. In such cases, you should open the file with APPEND. For example, the statements
10 FILE = " A: TEMP"
20 OPEN FILE FOR APPEND AS #1

will open the file named TEMP on the disk in drive A and position the file pointers at the existing
data. Now we can add records to the file, which has been numbered as 1.
Following example will illustrate the use a of Append

Example 4
Write a program to add two more products to the file "INVENT. DTA" created earlier in Example 1.
DDDD 104 20.0 200
EEEE 105 30.0 300

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

123

Program
10 FILES = "INVENT. DTA"
20 OPEN FILES FOR APPEND AS #1
30 FOR I=1 TO 2
40 INPUT PNM$, PN, P, QTY
50 WRITE #1, PNM$, PN, P, QTY
60 NEXT I
70 CLOSE # 1
80 REM ** DATA INPUT FROM FILES **
90 OPEN "I", #1, "INVENT. DTA
100 PRINT
110 IF EOF (1) THEN 160
120 INPUT #1, PNM$, PN, P, QTY
130 PRINT PNM$, PN, P, QTY
140 GOTO 110
150 CLOSE # 1
160 END

Output
? DDDD, 104, 20, 200
? EEEE, 105, 30, 300

AAAA 101 8 100
BBBB 102 10 200
CCCC 103 12 300
DDDD 104 20 200
EEEE 105 30 300


28.5 HANDLING OF RANDOM ACCESS FILES
Unlike sequential files, random files cannot be created so easily. Random files require more
programming steps and skills. However, since random access files effectively retrieve or write
individual data items anywhere in the file they are often preferred.

28.5.1 Creating a Random File
Following are the steps required to create a random file:

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

124
- Open the file
- Allocate space in the random buffer for variables that will be written to the file
- Move the data into the random buffer
- Write the data from the buffer to the disk
Step1: Like sequential files, we may open random files using the OPEN Statement
.
OPEN ["R", #File number,"File name",Record length]

The character R indicates that the file to be opened is a random access file. Record length is a number
that specifies the length of records. The length may range from 1 to 32767, The default record length
is 128 bytes. For examples,

100 OPEN "R", #2, "PANKAJ',100
200 OPEN "R",#3, "CHAP5",120
These statements can also be written as
100 OPEN "PANKAJ" AS#2LEN =100
200 OPEN "CHAPS," AS #3 LEN = 120
Step2: Space in the random buffer is allocated by the FIELD statement in the form
FIELD [#file number, w
1
AS u
1,
w
2
AS u
2
...]

File number is the number of the concerned file just opened, w
1
specifies the number of character
positions to be allocated to the string variable and so on.
A FIELD statement defines variables that are used to put data into or get data out of a random buffer.
For example, the statement
50 FIELD #2, 20 AS A$ 10 AS B$
defines two string variables A$ and B$ and allocates first 20 bytes to the variable A$ and next bytes to
B$. Note that FIELD is a declaration statement and does not actually place data into the random
buffer.
Unlike sequential files, random files cannot be created so easily. Random files require more
programming steps and skills. However, since random access files effectively retrieve or write
individual data items anywhere in the life, they are often preferred.

The total number of bytes allocated in a FIELD statement must not exceed the record length specified
in the OPEN statement. For instance, the statements
10 OPEN "R",#2 "CHAP1",40
20 FIELD #2,20 AS A$, 5 AS B$, 10 AS C$, 10 AS D$

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

125
open a file named CHAP1 as a random file and allocates character positions as follows:

First 20 bytes to A$
Next 5 bytes to B$
Next 10 bytes to C$
Next 10 bytes to D$

Note that the total number of bytes allocated is 45, which is more than 40, the record length as defined
in the OPEN statement in line 10. In this case, a "Field overflow" error will appear on the screen.
Step 3: Placing data into the random file buffer is done by the LSET and RSET statements. They take
the form:
LSET u$ = x $
RSET u$ = x $

Where u$ is the name of a string variable that is defined in a FIELD statement and x$ is a string
variable representing the data to be placed into the field identified by u$ Examples of these statements
are:

30 LSET A$ = F1$
40 RSET B$ = F2$

LSET statement left-justifies the string in the field, and RSET statement right justifies the string. Let
us suppose F1$ represents CONNECTING-PROD and F2$ represents 5000. If the character positions
allocated to A$ is 18 andB$ is 5, then the field represented by A$ and B$ in the random buffer are
filled like this:

C O N N E C T I N G - P R O D 5 0 0 0
|--------------------------------------A$------------------------------------------|---------------|

Since all the fields in a random buffer are defined as string fields, any number value that is to be
placed in a random file buffer must be converted to string value before it is LSET or RSET. This can
be done using the following `convert' functions.

MKI$ converts an integer to a 2-byte string.
MKS$ converts a single-precision number to a 4-byte string.
MKD$ converts a double-precision number to an 8-byte string.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

126

LSET A$ MKI$ ( integer variable)
or
RSET A$ MKD$ (double-precision variable)

Where A$ is the string variable defined in the FIELD statement.

For example LSET A$ - MKI$(RN)
RSET B$- MKS$ (PAY)

Step 4: Moving of data from a random buffer to a random file is done by the PUT statement.
Each time a PUT statement is executed, a record is written to the file.
PUT {# file number, record number]

File number refers to the number under which the file was opened. Record number is the number of
the record to be written and expressed as an integer constant or variable. If record number is omitted,
the record will have the next available number. For example, the statement
100 PUT #2, 1
will write the information contained in the buffer to the first record of the random file numbered 2. It
can also be written as
100 PUT #2,K
where K is an integer variable. The value of K must be defined before using the PUT statement.
Each time a PUT statement is executed, a record is written to the file.
Let us take an example to clarify various statements discussed for creating a random file.

Example 5
Write a program to open a random and record salary file statement of employees with the following
details:
1 Name
2 Basic Pay
3 D.A.
4 H.R.A.
5 C.C.A.
Assume the following data:

Name Basic Pay D.A. H.R.A. C.C.A.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

127

UPMA 25,000 5000 8000 2000
SANJU 20,000 4000 7000 1500
ANAMIKA 15,000 3000 6000 1000

Program
10 REM ** CREATION OF RANDOM FILE **
20 OPEN " R",#1,"SALARY" 60
30 FIELD #1,20 AS N$, 10 AS B$ 10 AS D$, 10 AS H$, 10 AS C$
40 INPUT "RECORD NUMBER"; I
50 IF I=0 THEN 150
60 INPUT "NAME "; A$
70 INPUT "BASIC PAY"; P
80 INPUT " DEARNESS ALLOWANCE"; Q
82 INPUT "HOUSE RENT ALLOWANCE"; R
85 INPUT " COMPENSATORY CITY ALLOWANCE"; S
100 LSET N$ = A$
110 LSET B$ = MKS$ (P)
120 LSET D$ = MKS$ (Q)
122 LSET H$= MKS$ (R)
125 LSET C$ = MKS$ (S)
130 PUT # 1, I
140 GOTO 40
150 CLOSE # 1
160 END

Output
Record Number? 1
Name? UPMA
Basic pay? 25000
Dearness Allowance? 5000
House Rent Allowance? 8000
Compensatory city Allowance ? 2000
Record Number? 10
Name? SANJU
Basic pay? 20000

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

128
DA? 4000
HRA 7000
CCA? 1500
RECORD NUMBER? 40
Name? Anamika
Basic Day? 15000
DA? 3000
HRA? 6000
CCA? 1000
Record Number 0

28.5.2 Accessing a Random File
Like creation, accessing a random file includes the following points:
- Open the file for random access
- Allocate space in the random buffer for variable using the FIELD statement that will be read from
the file.(Remember that if a program performs both the input and output on the same random file,
you may use only one OPEN statement and one FIELD statement)
- Bringing data from the file to the buffer for processing
- Access and use data in the program

Step 1: Follow the procedure of step 1 in creating a file. (see Section 5.4.1)
Step 2: Follow the procedure of step 2 in creating a file. (see section 5.4.1)
Step 3: Bringing data from the file to the buffer is done by the GET statement. This is similar to the
PUT statement.
GET [#file number, record, number]

Record number is optional and, if it is omitted, the next record (after the last GET ) is read into the
buffer. For example,
200 GET #2, 10
will transfer the content of the record number 10 from the file number 2 to the buffer.
Step 4: After a GET statement, the data available in the buffer can be used by the program for further
manipulation and printing outputs. Remember that the numeric values are recorded as string values in
the buffer and therefore all numeric values must be converted back to numbers for performing any
arithmetic operations on them: This is done using following "convert" functions:
CVI converts a two-byte string to an integer.
CVS converts a 4-byte string to a single-precision number.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

129
CVD converrts an 8-byte string to a double-precision number.

These functions are written in the form:
x = CVI (u$)
x = CVS (u$)
x = CVD (u$)


u$ is the name of a string variable containing numeric values in the buffer and x is a numeric variable
representing the data to be used in the program.
The following program segment illustrates the use of GET and convert functions:
40 FIELD #2, 10 AS A$, 6 AS B$, 3 AS C$
50 GET #2
55 LET N$ = A$
60 LET M1 = CVS (B$)
70 LET R1 = CVI (C$)
80 PRINT N$, M1, R1

This program uses a random file numbered 2, which has fields as defined in line 40. Line 50 reads a
record from the file. Line 60 converts the contents of to a single-precision numeric value and assigns
it to the variable MI. Similarly, line 70 converts the contents of to an integer number and assigns the
value to the variable R1. Line 80 writes the vales of N, MI and R1 on the screen.

In this case, N$, M1 and R1 may represent student names, marks and class rank. Note the conversion
functions do not change the actual data. They only change the way the data is interpreted.

Remember that B$ and C$ were originally numbers which would have been written to the file using
the MKS$ and MKI$ functions. Example 6 will help us in understanding the technique of accessing
data stored in random life.


Example 6
Write a program to access the random file "SALARY" that was created in example 5.
You are required to print the data contained in any desired record along with the total salary.
Program
10 REM ** ACCESSING A RANDOM FILE **

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

130
20 OPEN "R" # 1, " SALARY", 60
30 FIELD # 1, 20 AS N$, 10 AS B$, 10 AS D$, 10 AS H$, 10 AS C$
40 INPUT "RECORD NUMBER' K
50 IF K=0 THEN 130
60 GET # 1, K
70 LET P = CVS (B$)
75 LET Q =CVS (D$ )
80 LET R =CVS (H$)
85 LET S = CVS (C$)
90 LET T = P+Q+R+S
100 PRINT "Record" K, N$, .P, .Q, .R, .S, .T
110 PRINT
120 GOTO 40
130 CLOSE
140 END

Output
RECORD NUMBER? 40
RECORD 40 ANAMIKA 15000 3000 6000 1000 25000
RECORD NUMBER? 1
RECORD 1 UPMA 25000 5000 8000 2000 40000
RECORD NUMBER? 10
RECORD 10 SANJU 20000 4000 7000 1500 32500
RECORD NUMBER? 0





IN-TEXT QUESTIONS 1

1. Determine whether the following statement to true or false
(a) A file can store a program's output for future use
(b) A file cannot be used by more than one program.
(c) When a file is opened for INPUT, data can be written from the program to the file.
(d) If a sequential file is created and then read in the same program, it must be closed and reopened
between these operations.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

131

2. Correct the syntax errors in each statement.
(a) 10 OPEN "FILE 1" AS # 2 FOR OUTPUT
(b) 20 WRITE # 2 A, B, C, D,
(c) 30 KILL FILE 2

3 Following program segment is supposed to create and display (on the screen) in file containing the
integers from 1 to 100, but it does not run properly. Correct the errors.

10 OPEN "FILE1" FOR INPUT AS # 1
20 FOR I = 1 TO 100
30 PRINT # 1, I
40 NEXT I
50 FOR I= 1 TO 100
60 INPUT # 1, I
70 PRINT # 2, I
80 NEXT I
90 CLOSE # 1
100 END
4. Write a program in BASIC to create a file called "STUDENT' containing the following data:
(a) Name of the student
(b) Roll Number
(c) Marks in LOTUS
(d) Marks in dBASE
(e) Marks in BASIC
5. Write a program to retrieve data from the "STUDENT' file created in question 4 above and copy
the same in a file named "STUDENT"1.

28.6 WHAT YOU HAVE LEARNT
In this lesson, we have discussed about processing of both sequential and random files. Although,
now-a-days advance programming languages are used to process files, file handling through BASIC is
quite simple and useful. Even today, BASIC files are quite popular in business data processing. It is
hoped that the fundamentals and the examples presents in this lesson will be helpful in understanding
the various steps involved in file processing and also to develop your own programs.

28.7 FEEDBACK TO IN-TEXT QUESTION

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

132
IN-TEXT QUESTIONS 1
1. (a) True
(b) False
(c) False
(d) True

2 (a) 10 OPEN "FILE1" FOR OUTPUT AS # 2
(b) 20 WRITE # 2, A, B, C, D
(c) 30 KILL "FILE 2"

3. CHANGE: 10 OPEN "FILE1" FOR OUTPUT AS # 1
70 PRINT I
INSERT: 45 CLOSE # 1
47 OPEN "FILE1" FOR INPUT AS # 1

4. 10 REM PROGRAM TO CREATE " STUDEN" FILE
20 OPEN "STUDENT" FOR OUTPUT AS # 1
30 PRINT "NAME, ROLLNO, LOTUS-MARKS, DBASE-MARKS, BASIC- MARKS"
40 PRINT "Type AAA, 0,0,0,0 TO MAKE AN END"
50 INPUT N$, R, L, D, B
60 IF N = "AAA" THEN 90
70 WRITE # 1, N$, R, L, D, B
80 GO TO 50
90 CLOSE # A
100 END

5. 10 REM PROGRAM TO COPY "STUDENT" FILE
20 OPEN "STUDENT" FOR INPUT AS # 1
30 OPEN "STUDENT1 FOR OUTPUT AS # 2
40 IF EOF (1) THEN 80
50 INPUT # 1, N$, R, L, D, B
60 WRITE # 2, N$, R, L, D, B
70 GO TO 40
80 CLOSE # 1
90 CLOSE # 2
100 END
28.8 TERMINAL QUESTIONS

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

133
1. Find the syntax errors in the following statements:
10 OPEN "FILES" AS #5 FOR OUTPUT
20 PRINT #6 A; ","; B$; ";"; PAY
30 INPUT #2, A: B: C
40 OPEN #2 LEN = 128
50 FIELD #1, A$ AS 10

2. The following program segment is supposed to create and display a file of numbers. Correct the
errors in it.
10 OPEN "NUMFL" FOR INPUT AS #1
20 FOR I = 1 TO 10
30 READ N
40 PRINT #3, N
50 NEXT K
60 FOR K = 1 TO 10
70 WRITE #1, N
80 PRINT N
90 NEXT I
100 CLOSE #1
110 DATA 5, 7, 9, 10, 12, 15, 17, 19, 20, 22
120 END

3. Suppose that a file named COMPUTE.DTA exists with 20 records of the form:
NM$ COST$


Correct the following program so that it displays the fifth record in this file on the screen:
10 OPEN "COMPUTER.DTA" A$ #1 LEN = 24
20 FIELD #1, 4 AS COST $, 20 AS NM$
30 GET #2, 5
40 LET NM$ = N$
50 LET COST$ = COST
60 PRINT #1, NM$, COST

4. Write a program segment that performs the following operations:
(a) Display the number of record of records in EMPLOYEE.DAT.
(b) Delete the fourth record from the file.
20 bytes 4 bytes

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

134
(c) Change the pay in the sixth record from Rs. 1500 to Rs. 2500.

5. Assume that a file PAYROLL exists with records with form Employee number (NUM), Name
(NM$), Rate of pay (RATE), and a sentinel record of 0, "AAA", 0. Write a program segment that
(a) Renames this file as PAY.
(b) Deletes a record with employee number 50.
(c) Adds the records 135, "SANJU", 12
(d) Change the rate of pay of employee number 140 from 15 to 20.
LESSON 20
INTRODUCTION TO DATABASE

20.1 INTRODUCTION
All of us are familiar with the term data. In fact, unknowingly we come across data in our day to day
life everyday. The age of a person, price of potato, number of students in a school, pin code of a city,
etc. are some examples of data. In our life we have to remember so much of data. But it is easier for
us to remember all information for a few individuals. For example, you may be in a position to tell
accurately the age, height, complexion, income, educational qualification, residential address, etc. of
your close friends. But it is too difficult for you to memorise all these information for a large number
of individuals. Let us consider the example of National Open School (NOS). Every year about one
lakh students take admission in NOS. If you are asked to memorise records of date of birth, subjects
offered and postal address of all these students, it will not be possible for you.

To deal with such problems we construct a database. We arrange all information about students in a
tabular form. We keep all the records so that if I am asked, How many students are there in
Economics? I am in a position to answer.

20.2 OBJECTIVES
After going through this lesson you will be in a position to
- explain the concept of database
- appreciate the features of database management system (DBMS)
- learn about the software packages available in the market to deal with database
- Invoke the dBASE III + programmes
- explain the advantages of dBASE III +
- work in dBASE III +.

20.3 WHAT IS A DATABASE?

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

135
Let us begin with the concept database and its management. Database is a collection of information
in a structured way. We can say that it is a collection of a group of facts. Your personal address book
is a database of names you like to keep track of, such as personal friends and members of your family.

Let us look into our earlier example of information on students in NOS. A sample of 5 students is
presented in the table below (see, Fig. 20.1). We have given 6 items of information on every student,
namely, Roll No, Name, Date of birth, Sex, Postal address and Subjects offered by the student.

Fig. 20.1 contains required details about each student. There are six pieces of information on each
student. They are Roll No, Name, Date of birth, Sex, Address and Subjects. Each piece of information
in database is called a Field. We can define field as the smallest unit in a database. Each field
represents one and only one characteristic of an event or item. Thus there are six fields in this
database.


ROLL NO


NAME

DATE OF
BIRTH

SEX

ADDRESS

SUBJECTS

9721001

Subrat Das

21.05.1980

M

C36, Sector 2,
Bhubaneswar
Orissa

Pol Sc, Eco,
History, Eng,
Hindi
9721002 Aditya Bhoi 12.06.1981 M At/Po. Burla,
Sambal Pur
Phy, Chem,
Biology, Eng,
Hindi
9732012


Madhu Jain 03.01.1979 F A31, Pilani,
Rajasthan
Pol Sc, Eco,
History, Eng,
Hindi
9724004


Ahmad Ali 23.11.1979 M 12A, Sheikh
Sarai-I, New Delhi
Phy, Chem,
Biology, Eng,
Hindi
9715023


C. Suresh 07.09.1980 M 96, Malviya
Nagar, Bhopal
Pol Sc, Eco,
History, Eng,
Hindi

Fig. 20.1


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

136
If you take a close look at all these fields, they are not of the same type. Date of birth is date type
whereas Name is character type. In database there can be five categories of fields. They are:
- Numeric
- Character
- Logic
- Memo
- Date
We will discuss about each type of field in detail later on in this lesson. First let us be familiar with
another concept that we will use frequently.

All the related fields for a particular event is called a Record. In the example above, all six fields
taken together for a particular student is called a record of that student. Hence, since there are six
students there are six records. Thus, we can define record as a collection of logically related fields.

Now we are in a position to define database in a formal manner. We can say that it is a collection of
logically related records. In other words a database is a collection of database files, and each database
file is a collection of records.

The task before us is creation of a database and its management. Data management involves creating,
modifying, deleting and adding data in files, and using this data to generate reports or answer queries.
The software that allows us to perform these functions easily is called a Data Base Management
System (DBMS). Using a DBMS files can be retrieved easily and effectively. There are many DBMS
packages available in the market. Some of them are:
- dBASE III Plus
- FoxBASE Plus
- SoftBASE
- Clipper
- Paradox

There are some WINDOWS based database packages available in the market such as MS ACCESS
(part of MS OFFICE). In this lesson we will discuss about the package dBASE III + which is a DOS
based package. It provides many choices to work with the program. This means you can work through
both assist screen and dot prompt. It allows you to work with both financial figures and text.

20.4 HOW TO START dBASE III PLUS?

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

137
You can invoke dBASE III + either from Hard disk or from floppy drives. In these days more and
more people are using the Hard disk to run the program. The computer systems with two floppy
drives and no Hard disk are obsolete now. However, we will discuss the procedures to invoke dBASE
III + in both Hard disk and floppy drives systems.

Let us begin with the procedure of loading dBASE III + into systems with Hard disk. The steps that
you should follow are

1. Start the computer in the DOS mode. The C prompt will appear on the screen. It will look
like C:\>.
2. You have to change the directory to come into dBASE III +. Type CD\DBASE and press
ENTER key. You can type either lower case or upper case alphabets. The computer does
not distinguish between the two.
3. On the screen you will see C:\DBASE>.
4. Type DBASE and press ENTER key. The computer will take a few seconds to show the
copyright and logo of dBASE III + on the screen.
5. Press ENTER key again. The dBASE III + logo will disappear from the screen and main
menu of dBASE III Plus will appear. Now you are inside the dBASE III + program.

Now let us discuss how to load dBASE III + from floppy drives. Suppose your system does not have a
hard disk and there are two floppy drives. Note that dBASE III + comes in two diskettes: system disk
# 1 and system disk # 2. You have to obtain both the diskettes before loading the dBASE III + in your
computer. The steps that you have to follow are:

1. As you start the computer on the DOS mode you see C:\> on the top left corner of the
monitor. Insert system disk # 1 in drive A.
2. Type A: The prompt will change to A:\>
3. Type dBASE and press ENTER key.
4. After a few seconds the screen will display details of the dBASE III + package like name,
version, etc. The bottom of the screen will contain the message,
INSERT SYSTEM DISK # 2 AND PRESS ENTER KEY.
5. Remove the system disk # 1 from drive A and insert system disk # 2.
6. Press ENTER key. After a few seconds main menu of dBASE will appear on screen.

As the computer displays the main menu of dBASE III + your monitor will look somewhat like Fig.
20.2.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

138

Fig. 20.2
(given at the end)



IN-TEXT QUESTIONS 1

1. Define field, record, file, and database briefly.
2. Name three DBMS packages.
3. Write True or False
(a) In database there can be six categories of fields.
(b) A database is a collection of logically related records.
(c) Date of birth is character type field.
(d) You can invoke dBASE III + either from Hard disk or from floppy drives.
(e) Paradox is a DBMS package.

20.5 HOW TO CREATE A DATABASE?

20.5.1 Creating a Database
When you want to create a database you have to take care of the following steps: You have to specify
the database file structure such as
- File name
- Field names
- Field types
- Field widths
- Decimal places (for numeric fields only)
1. Saving the database structure
2. Entering data into the file as records

20.5.2 File Name
- File name can be up to eight characters with additional three characters extension. For
example, you can give a file name NAMELIST.DBF to your database file.
- It must begin with an alphabet
- Can include numbers, and the underscore character ( _)
- It cannot contain blank space.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

139
20.5.3 Field names
- Can be up to 10 characters long
- Can start only with an alphabet
- Can contain digits in between
- Cannot contain any special character except the underscore ( _ ).

20.5.3 Field Types and Widths
In the beginning we had mentioned that there are five types of fields. Let us discuss them in detail.
1. Character: This type of field contains textual matter. For example, name, address, special
symbols, numbers and blank spaces. Character field can contain up to 256 characters or bytes. In
Fig. 20.1 the fields Name, Address, Sex and Subjects are character types.
2. Numeric: This type of field contains integers or decimal numbers, either positive or negative. The
maximum length of numeric field is up to 19 digits long.
3. Date: Date fields are 8 characters long. It is in the form of MM/DD/YY where MM is the month,
DD is the day of the month and YY is the year. In Fig. 20.1 the field Date of Birth is of date type.
4. Logical: It contains either a 'true' or 'false' (YES or NO) value. Its length is one character or one
byte.
5. Memo: Memo fields are used to store large block of text or tabular information. During data entry
it is activated by pressing CTRL+HOME and completed by pressing CTRL+END. The field
width of memo field is upto 5000 characters or bytes.

In order to create a new database you have to give the CREATE command at the dot prompt (see, Fig.
20.2). Let us create a new database file NOS. You have to type
. CREATE
and press ENTER.
On the screen you will find the following message:
Enter the name of the new file:

You have to type a file name, say, NOS and press ENTER. Remember that file name should not be
more than eight characters in length. When you enter the file name you will see a screen as in Fig.
20.3. Here you have to specify the structure of your database. Remember you can type commands
either in lower case or in upper case; dBASE III Plus does not distinguish between the two. Another
point to remember is that in dBASE III Plus you can write the first four alphabets of a command
instead of writing the whole command. For example, in place of CREATE if you can write CREA.

Bytes remaining: 4000

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

140

CURSOR

Char:
Word: Home End
Pan: ^ ^


INSERT
Char: Ins
Field: ^N
Help: F1


DELETE
Char: Del
Word: ^Y
Field: ^U


Up a Field: |
Down a Field: +
Exit/Save: ^End
Abort: Esc


Filed Name Type Width Dec Filed Name Type Width Dec
1. . . Character . . . .




CREATE <C:> NOS Field: 1/1 |
Enter the Field Name.
Field names begin with a letter and may contain letters, digits and under scores

Fig. 20.3

Suppose the name of the first field is ROLLNO. Hence you have to type in ROLLNO against the
highlighted space below field name and press ENTER. The cursor will jump automatically to the
column Type. Here by default the Field type is 'Character'. You can change it to other field types by
typing the first alphabet of the field type you want. For example:
C for character, N for numeric, D for date, L for logic and M for memo. For ROLLNO the field type
is Numeric. Hence you type in N. The cursor automatically moves in to the column Width. Here you
have to specify the number of digits the field ROLLNO has and press the RIGHT ARROW key.
Cursor will move to the last column Dec asking you to specify the number of decimal places the field
contains. Since ROLLNO does not contain any decimal number you have to press ENTER only. The
cursor will move automatically to the second record. Your screen will look like Fig. 20.4.

Here you have to give specifications for the second record and go on till all records are specified.

Bytes remaining: 4000


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

141
CURSOR

Char:
Word: Home End
Pan: ^ ^

INSERT
Char: Ins
Field: ^N
Help: F1

DELETE
Char: Del
Word: ^Y
Field: ^U

Up a Field: |
Down a Field: +
Exit/Save:
^End
Abort:
Esc


Filed Name Type Width Dec Filed Name Type Width Dec
1. .ROLLNO . Numeric .5 . . .

2. . . Character . . . .



CREATE <C:> NOS Field: 2/2
Enter the Field Name.
Field names begin with a letter and may contain letters, digits and under scores

Fig. 20.4

Once you have created a structure you want to use, you can save it in your disk.

Then you have to save the structure by pressing CTRL+W or CTRL+END

At this point the computer will prompt you
Press ENTER to confirm. Any other key to resume.
Once you press the ENTER key you will find another message:
Input data records now? (Y/N)
If you want to type in data then press Y. The computer screen will look like Fig. 20.5.



Bytes remaining: 4000

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

142

CURSOR

Char:
Word: Home End
Pan: ^ ^


INSERT
Char: Ins
Field: ^N
Help: F1


DELETE
Char: Del
Word: ^Y
Field: ^U


Up a Field: |
Down a Field: +
Exit/Save: ^End
Abort: Esc


ROLLNO: . .
NAME: . .
BIRTH DATE: . .
SUBJECTS: . .





CREATE <C:> NOS REC:NONE

Fig. 20.5

Now you can enter data on the screen. As you know, data on a particular student is a record. Thus you
have to enter as many records as you want. After completion of data entry you have to save it by
pressing CTRL and END keys together (CTRL+END). Another method of saving a database is by
pressing CTRL and W keys together (CTRL+W). If you want to quit dBASE without saving then you
have to press ESC or CTRL+Q. At this point dBASE asks you if you really want to Abort Editing?
(Y/N). You have to type Y for yes and N for no. If you type Y you will return to dBASE dot prompt
and if you type N you can continue editing of your file.

20.6 OPENING AN EXISTING FILE
Just as you open a book in order to read it, a database file, existing on a floppy or a hard disk, also has
to be opened. The USE command opens an existing database file so that it can be used for querying,
reporting or editing.
Suppose you want to open the earlier created file BIODATA for further modification. You give the
command:
.USE NOS

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

143

Note that when you save a database file in dBASE the computer gives an extension .DBF along with
the file name. While opening a file, dBASEIII+ assumes it to be a .DBF file.
The USE command assumes that the file is to be loaded from the default or active drive, i.e. the drive
from which dBASE was invoked. If the file is on a floppy, you have to instruct dBASE III+ to make
the A drive as the active work drive, rather than the C drive. This can be done by the following
command:
. SET DEFAULT TO A:

On selecting a work drive, all subsequent commands will apply to that drive.

20.6.1 Viewing the Contents of the File
After opening the file BIODATA you may like to see its content. This you can do by the LIST
command.
.List
The screen will look like Fig. 20.6.

. list
No database is in USE. Enter file name: biodata
Record# NAME SEX AGE
1 Anant m 25
2 Babloo m 13
3 Manju f 30
4 Sibu m 12
5 Soma f 8
.
Command Line <C:>BIODATA Rec: EOF/5
Type a command (or ASSIST) and press the ENTER key.
Enter a dBASE III PLUS command.

Fig. 20.6
Since there are 5 records only in the database we are dealing with all the records are visible on a
single screen. When all the records cannot come on a single screen the records scroll down and you
cannot see the records in the beginning. In order to overcome this problem you have to use the
DISPLAY ALL command.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

144
The .Display All command displays a screen full of records and pauses, until the user presses a key to
continue.

Press the F1 key for HELP.
. use biodata
. display
Record# NAME SEX AGE
1 Anant m 25



.
Command Line |<C:>|BIODATA |Rec: 1/5 | |
Type a command (or ASSIST) and press the ENTER key.
Enter a dBASE III PLUS command.

Fig. 20.7

20.7 ADDING RECORDS
Suppose some new students have taken admission in National Open School. You want to add these
student records to the existing file BIODATA. In order to do so you have to use the APPEND
command. The APPEND command displays a blank record for data entry. Once the data has been
entered, it presents another blank record. This process continues till the user presses CTRL+END






CURSOR

Char:
Word: Home End
Pan: ^ ^


INSERT
Char: Ins
Field: ^N
Help: F1


DELETE
Char: Del
Word: ^Y
Field: ^U


Up a Field: |
Down a Field: +
Exit/Save: ^End
Abort: Esc



AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

145
NAME . .
SEX . .
AGE . .

.
APPEND <C:> BIODATA Rec: EOF/5 |

Fig. 20.8










IN-TEXT QUESTIONS 2

1. What are the different types of fields in dBASEIII+.
2. What is the usefulness of the following commands: APPEND, LIST, CREATE.
3. Write True or False
(a) The field name can be a maximum of 10 characters.
(b) The maximum width for a character type field is 250.
(c) The width of a logical field is 2 digits.
(d) Character field is used for mathematical calculation.
(e) A field name should always start with an alphabet.

20.8 WHAT YOU HAVE LEARNT
In this lesson we discussed the concept of database and the software available to manage it. The
different methods to invoke dBASE III Plus are discussed. We have also explained the different types
of fields in a database. Now you should be in a position to create a new database, add records to an
existing database and see the contents of a database.

20.9 TERMINAL QUESTIONS

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

146
1. What are the different methods to start dBASEIII+ ?
1. Explain in brief the following field types:
Character field, Date field, Numeric field and Memo field.
2. What are the advantages of dBASEIII+?
3. How do you add records a database?

20.10 FEEDBACK TO IN-TEXT QUESTIONS
IN-TEXT QUESTIONS 1
1. Each piece of information in database is called a Field. Field is the smallest unit in a database. All
the related fields for a particular event is called a Record.
2. FoxBASE, dBASE, Clipper
3. (a) False (b) True (c) False (d) True (e) True


IN-TEXT QUESTIONS 2
1. There are five types of fields in database. They are Character, Numeric, Date, Logic and Memo.
2. Create command creates a new database. List command displays all the records in a database. The
Append command displays a blank record for data entry.
4. (a) True (b) False (c) False (d) False (e) True


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

147

dBASE III + version 1.0 IBM/MSDOS
Copyright Ashton-Tate 1984, 1985, 1986. All Rights Reserved.
dBASE, dBASE III, dBASE III +, and Ashton-Tate
are trademarks of Ashton-Tate

You may use the dBASE III + software and printed materials in the dBASE III
+ software package under the terms of the dBASE III + Software License
Agreement. In summary, Ashton-Tate grants you a paid-up, non-transferable,
personal license to use dBASE III + on one microcomputer or workstation. You
do not become the owner of the package, nor do you have the right to copy or
alter the software or printed materials. You are legally accountable for any
violation of the License Agreement or of copyright, trademark, or trade secret
laws.
Press the F1 key for HELP


-
Command Line |<C:>|

Type a command (or ASSIST) and press the ENTER key.
Enter a dBASE III + command.


Fig. 20.2





Dot
prompt

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

148
LESSON 20
INTRODUCTION TO DATABASE

1.1 INTRODUCTION
20.1 OBJECTIVES
20.2 HOW TO START dBASE III PLUS?

LESSON 21
ARRANGING RECORDS OF A DATABASE

21. 1 INTRODUCTION
Organizing a database means arranging individual records so that they appear in a sequence that
makes a proper sense and helps you to work with database efficiently. The concept can be appreciated
by taking an example of telephone directory. Imagine a situation where names in the directory are not
arranged alphabetically. This will create a mess and take much longer time to find a particular name in
the directory.

21. 2 OBJECTIVES
At the end of this lesson you would be able to
- use the SORT and INDEX commands to organise records of a database
- differentiate between FIND and SEEK commands
- count the number of records in a database
- modify a database
- DELETE records in a database
- RECALL and REPLACE records in a database

21. 3 DATABASE ORGANISATION
Information must be organized before you can make much sense of it. The elements of a database
structure - field name, type, and size are all intended to organise within each record. There are two
ways to organize records in database. One is INDEXING and the other is SORTING. Before sorting
a database you make sure that the database you want to sort is current:

21. 3. 1 SORT Command
The SORT command gives us the ability to copy the record and structure of a database to another
database. Files can be arranged in either ascending order or descending order by using SORT
command. Sort command can be used in multiple fields for data arrangement.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

149

This SORT command creates a new database file. But the new file contains records of the original
database file only the order is different. The following examples show the forms of the SORT
command. Let us consider a database file BIODATA, whose structure is shown in Fig. 21. 1

RECORD
NO.
NAME SEX AGE


1 Anant M 25
2 Babloo M 13
3 Manju F 30
4 Sibu M 12
5 Soma F 28

Fig. 21.1

Suppose you want to sort the records in this file in increasing order of the AGE field. You have to
give the command at the dot prompt:
.USE BIODATA and press ENTER
. SORT ON fieldname TO new filename. Thus you have to give the command
. SORT ON AGE TO BIO and press ENTER

Here field name is AGE and the sorted file name is BIO.DBF
To see the contents of the sorted file give the following commands:
. USE BIO.DBF
. LIST
The sorted file BIO. DBF looks like as shown in Fig. 21.2.










AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

150



. use biodata
. sort on age to bio
100% sorted 5 records sorted
. use bio
. list
Record# NAME SEX AGE
4 Sibu m 12
2 Babloo m 13
1 Anant m 25
5 Soma f 28
3 Manju f 30

Fig. 21.2

Here you notice one thing that BIO.DBF is a new file. In this new file, the record numbers given by
database is in a new order. But Age field is in sequence, because you have sorted the BIODATA.DBF
to increasing order of the AGE field. Suppose you want to sort the file in descending order of the
AGE field. Then you have to give the command SORT ON AGE/D TO TEMP.DBF. The new file
TEMP looks like as shown in Fig. 21.3
. use biodata
. sort on age/d to temp
100% sorted 5 Records sorted
. use temp
. list
Record# NAME SEX AGE
1 Manju f 30
2 Soma f 28
3 Anant m 25
4 Babloo m 13
5 Sibu m 12

Fig. 21.3


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

151
21. 3. 2 INDEX command
Index command can also be used to organise a data file. When you index a database, you ask dBASE
to create a separate and smaller file based upon designated fields in the database. The index command
does not create a new database file. It creates an index file for the database with a default extension
(.NDX). Unlike SORT command however INDEX does not permit the user to arrange the data in
descending order. It can also be used to arrange the records in multiple fields. The command structure
for index command is
.USE BIODATA
. INDEX ON field name TO file name
For example, if we index the file biodata.dbf according to field age to the file bioage then the records
in the file biodata.dbf are arranged in ascending order as given in Fig. 21.4

. use biodata
. index on age to bioage
100% indexed 5 Records indexed
. list
Record# NAME SEX AGE
4 Sibu m 12
2 Babloo m 13
1 Anant m 25
5 Soma f 28
3 Manju f 30
Fig 21.4

DIFFERENCE BETWEEN SORT AND INDEX COMMAND










Sort Command Index command

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

152
- Creates a new database file
Does not create a new file
- Arranges the records in ascending and
descending order
Arranges the records only in ascending order
- File extension is .DBF
File extension is .NDX
- Slower than index command
Faster than sort command
- Renumbers records
Does not renumber records

21.3.3 FIND and SEEK Commands
The FIND and SEEK commands both are used in indexed database. FIND operates with character
strings, while SEEK operates with either character string or numeric values. If SEEK operates with a
character string the string must be enclosed in a single or double quotes or square bracket Let us take
some examples
. USE BIODATA
. INDEX ON AGE TO BIOAGE
. USE BIODATA INDEX BIOAGE
. FIND 30
. DISPLAY
The screen will look like this

. use biodata
. index on age to bioage
. use biodata index bioage
. find 30
. display
Record# NAME SEX AGE
3 Manju f 30
Fig 21.5
The FIND command will move the record pointer to the first record which matches with find query
and the DISPLAY command will display it on the screen.

The SEEK command like FIND command also works only with an index file. When you SEEK
command with strings, you must use quotes. Consider the previous example, to SEEK the NAME
Manju, you must give the command
. USE BIODATA
. INDEX ON AGE TO BIOAGE
. USE BIODATA INDEX BIOAGE

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

153
. SEEK 30

. DISPLAY

The screen will look like this

.use biodata
. index on age to bioage
. use biodata index bioage
. seek 30
. display
Record# NAME SEX AGE
3 Manju f 30
Fig 21.6

The main difference between SEEK and FIND commands is that SEEK command will not work with
macros but FIND command is used in macros.

21.3.4 Counting Command
The COUNT command helps in finding the number of records in the active database that meet a
given condition.

. USE BIODATA
. COUNT FOR AGE> 13
The screen will appear as follows:

. use biodata
. count for age >13
3 records
. count
5 records

Fig 21.7

The COUNT command, without any condition, gives the total number of records in the active
database file.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

154
. COUNT
The computer prompts
5 RECORDS

21.3.5 LOCATE Command
The LOCATE command is used to find the records in a database which satisfy certain conditions. The
general form of LOCATE command is

. LOCATE [scope] FOR [condition]

Suppose you give the command
. USE BIODATA
. LOCATE FOR AGE =25
The computer will prompt
RECORD =1
Your screen will appear like this

. use biodata
. locate for age=25
Record = 1

Fig 21.8

For displaying that particular record in a database give the command DISPLAY and if you want to
continue the search give the command CONTINUE along with LOCATE command. Your screen will
appear like this






. use biodata
. locate for age=30
Record = 3
. continue

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

155
End of LOCATE scope
Command Line <C:>BIODATA Rec: EOF/5

Enter a dBASE III PLUS command.
Fig. 21.9



IN-TEXT QUESTIONS 1

1. What is the difference between SORT and INDEX command?
2. What is the usefulness of FIND and SEEK commands?
3. Define the following command with a suitable example
(a) COUNT (b) LOCATE


21. 4 MODIFYING A DATABASE
Modifying a database is almost as easy as creating a database. You begin with an existing structure
and want to modify the database by
- Inserting a new field
- Deleting an existing field
- Inserting a new record
- Deleting a record permanently

Let us explain the steps by taking our previous file BIODATA. Begin with opening the file.
. USE BIODATA
. EDIT 5


CURSOR
Char:
Word: Home End
Pan: ^ ^


INSERT
Char: Ins
Field: ^N
Help: F1


DELETE
Char: Del
Word: ^Y
Field: ^U


Up a Field: |
Down a Field: +
Exit/Save: ^End
Abort: Esc


NAME Soma

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

156
SEX f
AGE 28

EDIT <C:>BIODATA Rec: 5/5


Fig. 21.10

After making the desired changes, pressing Ctrl+W saves the changes and exits to the prompt.

21 .4. 1 The Record Pointer
How did the EDIT command display only the 5th record? This can be explained by the concept of a
record pointer that is maintained for each file opened by dBASEIII+. When the file is open the
pointer points to the first record in the file and moves to the other records after a command has been
given. For example, with the LIST command, the record pointer moves to the end of the file, since it
moves successively from the first record to the last record. The current record (i.e., the record on
which the pointer is positioned currently) can be displayed by giving the command. DISPLAY. This
command is used to position a particular record, which is to be displayed.

. DISPLAY
DISPLAY [ALL!RECORD<recordno. >]
[<expr_list>] [FOR<expl.>] [TO PRINT]

where:
<expr_list> is a list fields or expressions.
<expl.> is a condition.
.USE BIODATA
.DISPLAY
dBASE will display only the first record along with header which we have discussed earlier.
Let us consider the following example
dBASE will display the 4
th
record in the file along with header.

. use biodata
. goto 4
. display
Record# NAME SEX AGE

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

157
4 Sibu m 12
.
Fig 21.11

The GOTO command followed by the record number moves the record pointer to a specified record.

. GOTO 5
This command will position the pointer on the 5
th
record.
. GOTO<expN>

where <expN> is the record number.






. use biodata
. goto 5
. display
Record# NAME SEX AGE
5 Soma f 28
.

Fig 21.12

21. 4. 2 EDIT Command
Similarly, on giving the command EDIT 5, the record pointer moves to the 5
th
record and displays it
for modification.
To summarise, the steps involved in modifying a database, using the EDIT command are:
- Open the file by the command USE File Name
- Access the record(s) to be modified.
- Make the required changes in the records.
- Save the changes by pressing <Ctrl>+<W>.

This command positions the record pointer at the required record and displays it for modification

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

158

EDIT [ALL![RECORD]<record no. >]

[FIELDS<fieldlist>] [FOR<expl>]
Where:
<fieldlist> is a list of fields to be edited
<expL. > is a condition.
Now we open BIODATA by the command USE
.USE BIODATA
. EDIT
The screen looks like this



CURSOR
Char:
Word: Home End
Pan: ^ ^


INSERT
Char: Ins
Field: ^N
Help: F1


DELETE
Char: Del
Word: ^Y
Field: ^U


Up a Field: |
Down a Field: +
Exit/Save: ^End
Abort: Esc

NAME Soma
SEX f
AGE 28
EDIT <C:>BIODATA Rec: 5/5

Fig. 21.13

21. 4. 3 REPLACE command
The REPLACE command is used to REPLACE the contents of one or more specified field either the
current record or all record, depending on the form of the command.

. REPLACE ALL
Syntax:

REPLACE [ALL] <field> WITH <expr>
[FOR<expl>]


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

159
Where:

<field> is the field to be replaced
<expr> is the expression to replace the field
<expl> is a condition.

21. 4. 4 BROWSE Command
BROWSE command gives an option of adding new records. The BROWSE command also provides
the option of displaying and modifying selective fields. Once you make changes through BROWSE
command you can save the changes and exit to the dot prompt by pressing Ctrl + W. Consider the
following example:
. USE BIODATA
. BROWSE
Immediately dBASE will display a screenful of records as shown in Fig. 21.14
The difference between BROWSE and EDIT Command is that several records are viewed
simultaneously using BROWSE, while one record is displayed at a time when EDIT is used.


CURSOR
Char:
Word: Home End
Pan: ^ ^


INSERT
Char: Ins
Field: ^N
Help: F1


DELETE
Char: Del
Word: ^Y
Field: ^U


Up a Field: |
Down a Field: +
Exit/Save: ^End
Abort: Esc

NAME SEX AGE
Anant m 25
Babloo m 13
Manju f 30
Sibu m 12
Soma f 28

BROWSE <C:>BIODATA Rec: 1/5
View and edit fields.
Fig. 21.14

21. 5 MODIFY STRUCTURE

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

160
The MODIFY STRUCTURE command helps to change the structure of an active database file. The
command:

. MODIFY STRUCTURE
displays the structure of the database file as shown in figure 21.15 . After adding the field to the file
save the modified structure by pressing <Ctrl>+<W>. The MODIFY STRUCTURE command also
allows deleting fields or changing the field types and widths. You should keep in mind that if the field
widths are reduced, the data in that field may be lost. Hence changes to existing fields must be made
with proper care.

Let us consider the following example.
Bytes remaining: 3987

CURSOR
Char:
Word: Home End
Pan: ^ ^


INSERT
Char: Ins
Field: ^N
Help: F1


DELETE
Char: Del
Word: ^Y
Field: ^U


Up a Field: |
Down a Field: +
Exit/Save: ^End
Abort: Esc

Filed Name Type Width Dec Filed Name Type Width Dec
1 NAME Character 10
2 SEX Character 1
3 AGE Numeric 2 0

MODIFY STRUCTURE |<C:>|BIODATA |Field: 1/3 | |
Enter the field name.
Field names begin with a letter and may contain letters, digits and underscores
Fig. 21.15

21. 6 MORE ON QUERIES
Instead of giving the List to Print command with each and every query, the printer can be activated to
print the command as well as the output of the command. The command that can be given to activate
the printer is as follows:

. SET PRINT ON
. LIST

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

161

To deactivate the printer the command is:

. SET PRINT OFF

21.6.1 Deleting Records
The delete command marks the current record for deletion. When the records are marked for deletion
they are not transferred during copy and sort operation. Now we will discuss how delete command is
used in different ways.

. DELETE RECORD 5 <marks record 5 for deletion>.

1 records deleted

The DELETE command also provides the following options:

OPTION DESCRIPTION

DELETE ALL Mark all records for deletion
DELETE FOR Mark selective records for deletion
DELETE FILE ABC.FRM Delete file ABC.FRM on logged disk.
DELETE NEXT 4 Mark next 4 records for deletion.


Now delete all the records in the active database file BIODATA. You will find an asterisk (*) against
the records marked for deletion.

. use biodata
. delete all
5 records deleted
. list
Record# NAME SEX AGE
1 *Anant m 25
2 *Babloo m 13
3 *Manju f 30
4 *Sibu m 12

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

162
5 *Soma f 28
.
Command Line <C:>BIODATA Rec: EOF/5
Type a command (or ASSIST) and press the ENTER key ( -+).
Enter a dBASE III PLUS command.
Fig. 21.16

In this example we delete the next four records from the active database file.

. use biodata
. delete next 4
4 records deleted
. list
Record# NAME SEX AGE
1 *Anant m 25
2 *Babloo m 13
3 *Manju f 30
4 *Sibu m 12
5 Soma f 28

Command Line <C:>BIODATA Rec: EOF/5
Type a command (or ASSIST) and press the ENTER key ( -+).
Enter a dBASE III PLUS command.
Fig. 21.17

21.6.2 PACK Command
This command removes records permanently from the database file. Once packed a record cannot be
recovered. Deleting records in dBASEIII+ is a two step process. The records are first marked for
deletion with the DELETE command, and then removed permanently from the file by PACK
command

Let us take the following example

. USE BIODATA
. DELETE 3
. PACK

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

163

Next if you give LIST command then you will not find record 3 in database.

21.6.3 RECALL Command
The RECALL command is used to unmark those records that were marked for deletion with DELETE
command. Like DELETE command, RECALL has several forms.

OPTION DESCRIPTION

. RECALL RECORD 4 Unmark record 4 for deletion
. RECALL NEXT 3 Unmark the next 3 records for deletion
. RECALL ALL Unmark all records within the database for deletion.


Now we recall all the records marked for deletion in the active database file BIODATA. Notice that
the RECALL command unmarks the records, which were marked for deletion earlier.

. use biodata
. recall all
5 records recalled
. list
Record# NAME SEX AGE
1 Anant m 25
2 Babloo m 13
3 Manju f 30
4 Sibu m 12
5 Soma f 28
.
Command Line <C:>BIODATA Rec: EOF/5
Type a command (or ASSIST) and press the ENTER key ( -+).
Enter a dBASE III PLUS command.
Fig. 21.18

21. 7 CLOSING AN OPEN DATABASE FILE
The USE commands without file name closes an open database file. Open database can also be closed
with the QUIT, CLEAR ALL, CLOSE DATABASE and CLOSE ALL commands.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

164






IN -TEXT QUESTIONS 2
1. Differentiate between EDIT and BROWSE commands.
2. Bring out the uses of the following commands
DELETE
PACK
RECALL
REPLACE
USE

3. Choose the correct answer
(a) Delete command
(i) marks the record for deletion
(ii) append the record
(iii) change the number
(iv) none of the above
(b) To add record at the end of the database, you would use
(i) continue
(ii) list
(iii) append
(iv) use
(c) Which of the following command physically remove the records
(i) change
(ii) modify
(iii) pack
(iv) none of the above
(d) Which of the following command is used to close a database file.
(i) stop
(ii) use
(iii) start
(iv) none of the above
(e) The modify structure command helps

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

165
(i) to change the structure of an active database file.
(ii) to remove the structure
(iii) to name the structure
(iv) none of the above

21.8 WHAT YOU HAVE LEARNT
In this lesson we discussed the procedures of organising a database. In this process we distinguished
between SORT and INDEX commands, FIND and SEEK commands, DELETE and PACK
commands, BROWSE and EDIT commands. Now you should be in a position to count the number of
records in a database and modify structure of a database.

21.9 TERMINAL QUESTIONS
1. What are the different methods of data organisation.? Explain briefly.
2. Write short notes on SEEK, FIND, GOTO, EDIT, RECALL and PACK commands.
3. Define SORT and INDEX command with suitable example.
4. What are the different steps involved in modifying a database, while using EDIT command?
5. Define COUNT command with example.


21.10 FEEDBACK TO IN-TEXT QUESTIONS
IN-TEXT QUESTIONS 1
1. Files can be arranged in either ascending order or descending order by using SORT command.
But incase of INDEX command you can arrange the file only ascending order. Index command
does not create a new database file. But SORT command creates a new database file.
2. FIND operates with character strings, while SEEK operates with either character string or
numeric values.
3. (a) The COUNT command helps in finding the number of records in the active database that
meet a given condition. Example:
. USE NAME
. COUNT FOR AGE> 11

(b) The LOCATE command is used to find the records in a database which satisfy certain conditions.
Example:
. USE BIODATA
. LOCATE FOR AGE=18


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

166
IN-TEXT QUESTIONS 2
1. EDIT command displays one a particular record that is the record at the cursor position. But
BROWSE command displays all the records in the database file.
2. DELETE: marks the record for deletion.
PACK: Permanently deletes the records from the database file, which were earlier marked for
deletion by DELETE command.
RECALL: Unmarks the record marked earlier.
REPLACE: used to REPLACE the contents of one or more specified field
USE: Closes the active database file.
3. (a) i
(b) iii
(c) iii
(d) ii
(e) i
LESSON 22
HANDLING MULTIPLE FILES

22.1 INTRODUCTION
Many times we have to combine data from more than one file. In such situations we have to handle
multiple databases. Another point is that the data contained in a database file is not suitable for
presentation. It has to be put in a presentable format. This aspect of dBASE III Plus is possible
through the report form facilities of a database.

22.2 OBJECTIVES
After going through this lesson you should be in a position to
- explain the concept of multiple database
- understand work area
- relate more than two databases
- create a report file from a database
- print a report file

22.3 MULTIPLE FILE HANDLING
In the previous two lessons we have discussed about the commands to manipulate and retrieve data
from a single database file. But at times we may need to combine data from different database files for
purpose of manipulation and reporting. dBASE provides scope for handling up to 10 database files
open at the same time and access data from them. This is called Multiple File Handling.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

167

22.3.1 Characteristics of Multiple Files
Before we discuss the procedure of handling more than one-database files let us look into the
characteristics of multiple database files. Let us start with two files (dB1 and dB2). We may come
across the following situations.

Situation 1: The number of records in both database files dB1 and dB2 is the same. The number of
fields and the type of fields are the same.
Situation 2: The number of records in both dB1 and dB2 is same. The number of fields is same but
type of fields is different.
Situation 3: The number of records is different. But number of fields and type of fields is the same.
Situation 4: The number of records and number of fields are different. But there is at least one field
which is common to both dB1 and dB2. This common field is called the Key Field.

22.3.2 Types of Operations in Multiple File Handling
Let us look in to the type of work that we may require while handling two database files:
- We want to access data from both dB1 and dB2 at the same time.
- We want to create a database file dB3 by combining i) all the fields in the records of dB1 and
dB2, ii) selected fields from the records of dB1 and dB2.
- We may require updating of one or more fields in a file called the master file taking the data from
another file called the transaction file. Let us take dB1 as the master file and dB2 as the
transaction file. So we take data from dB2 to update dB1.

22.3.3 Selecting Work Areas for Different Files
When a database file is opened by the USE command, dBASE allots a work area for that file. When
we use only one file, we do not need to give any reference to the work area. But when we use multiple
files (up to 10 files), we have to specify the areas in which the different files will work. The SELECT
command is used to allot work areas for different files in dBASE. dBASE assigns numbers 1 to 10 or
characters A to J to these work areas. The general form of the SELECT command is
.SELECT workarea
.USE filename

Suppose we have two database files, dB1 and dB2. For allotting the work areas A and B for the two
files, we give the commands as follows:
. SELECT A
. USE dB1

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

168
. SELECT B
. USE dB2
On the other hand we may allot numbers to the work areas. For allotting the work areas 1 and 2 to the
files dB1 and dB2, we give the commands as follows:
. SELECT 1
. USE dB1
. SELECT 2
. USE dB2
In the example we have taken two database files but you can take any number (up to 10) of database
files. In place of dB1 and dB2 you can give any other file name.

22.4 ACTIVE AND NON-ACTIVE FILES
When several files are in use by the SELECT command, the file that is selected last is called the
active file and other files are called non-active files. When we allot work area to multiple files the file
selected last becomes the active file. In the last example, the file dB2 is selected last and so it is the
active file. Suppose you have a field by name AGE in dB2. This can be referenced simply as AGE
(note that AGE is a field in the active file.). Suppose you have a field by name STDNAME in the file
dB1. Then this field is referenced by writing as A-> STDNAME (note that when we refer to a field in
the non-active file we prefix it with the work area allotted to the no-active file). The symbol (->) 'a
minus sign followed by a greater than symbol' is used to establish the relation between the non-active
database file name and its field name.

22.4.1 How to Switch the File Status from Active to Non-Active?
You can make any non-active file, active by giving the command
.SELECT non-active-file-name.
Suppose in the example considered earlier if we give the command
.SELECT A
The file dB1 in the work area 1 becomes active and the file dB2 becomes non-active.

In this case the file in the work area 1 is made active currently. One must not give the USE command
for making a file active. The USE command opens a file and a file that is once opened must not be
again opened, since it is a syntax error. The SELECT Command does not open a file but simply
switches between the work areas. Thus we see that the SELECT command enables us to access fields
or data from as many as 10 database files.




AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

169
22.4.2 ALIAS Names for Database Files
dBASE has got a facility to give an alternate or an ALIAS name to a database file dB1. The SELECT
command is written as follows:
.SELECT A
.USE dB1 ALIAS biofile
If at any time you want to make the file dB1 active you can give the command
.SELECT biofile
The above command automatically puts the file dB1 in the work area A and makes it active. Without
making a file active, you can display any particular field from a non-active database can by giving
command as follows:
. DISPLAY alias name ->field-name (if you have given an alias name)
or
. DISPLAY work area name -> field-name (if you have not given an alias name)

You already know that the symbol (->) is used to establish the relation between the database name (or
its alias name) and its field names. For the field STDNAME in the active file dB1, we can display the
field by the command
. DISPLAY stdname
If no alias names are given by the user, dBASE will assume the filename itself as the alias name.
Suppose you give the following commands:
. CLOSE ALL (This command closes all files)
. SELECT B (This will select work area B)
. USE dB2 (This will assign work area B to file dB2)
. SELECT A (This will select work area A)
. USE dB1 (This will assign work area A to file dB1)
. DISPLAY STATUS
On the monitor you will see the status as follows:

Currently Selected Database
Select Area : A, Database in Use: A : dB1.dbf alias : dB1
Select Area : B, Database in Use: A : dB2.dbf alias : dB2

Fig 22.1

22.4.3 The SET RELATION TO Command

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

170
This command is used to link two database files with or without a common field between them.
Suppose you have to link two database files dB1 and dB2. The contents of these two are as shown in
the Fig. 22.2 and Fig. 22.3 respectively.
. USE dB1
. LIST

Record# CITY STATE SALARY
1 Cuttack Orissa 2500
2 Delhi Delhi 1350
3 Madras Tamilnadu 3000
4 Bombay Maharastra 1280
5 Chandigarh Punjab 8000
.
Command Line ||<C:>|| dB1 || Rec: EOF/5 || ||
Type a command (or ASSIST) and press the ENTER key (.).
Enter a dBASE III PLUS command.

Fig. 22.2

. USE dB2
. LIST

Record# NAME AGE
1 Anant 25
2 Babloo 23
3 Manju 30
4 Sibu 22
5 Soma 28
.
Command Line <C:>dB2 Rec: EOF/5
Type a command (or ASSIST) and press the ENTER key (.).
Enter a dBASE III PLUS command.

Fig. 22.3


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

171
In this example the two files have the same number of records but completely different field types.
The only relation which we see between these two files is that there is one to one correspondence
between the record number of the two files. We will now link the two files using this common feature
between them. The commands are given as follows:
.SELECT B
. USE dB2
. SELECT A
. USE dB1
. SET RELATION TO RECNO( ) INTO dB2
. LIST CITY, STATE, SALARY, B->NAME, B->AGE

The listing of the combined file looks as shown in the Fig. 22.4. In the above case all the fields and all
the records are listed.


Record# CITY STATE SALARY NAME AGE
1 Cuttack Orissa 2500 Anant 25
2 Delhi Delhi 1350 Babloo 23
3 Madras Tamilnadu 3000 Manju 30
4 Bombay Maharastra 280 Sibu 22
5 Chandigarh Punjab 8000 Soma 28
.
Command Line <C:>dB1 Rec: EOF/5
Type a command (or ASSIST) and press the ENTER key (.).
Enter a dBASE III PLUS command.

Fig. 22.4

IN-TEXT QUESTIONS 1

1. How many databases can be used simultaneously in dBASE III+?
2. Give the name of the first work area used in dBASE III+.
3. Which command is used to select a work area in dBASE III+?
4. Differentiate between active and non-active files.
5. Choose the correct answer:
(a) What is the maximum number of work areas that can be used in dBASE

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

172
(i) 20 (ii) 10 (iii) 5 (iv) 9
(b) The first work area in dBASE is referred as
(i) W -area (ii) A (iii) A-J (iv) none of the above

22.5 REPORT FORM
So far we have covered listing and modification of raw data. We also know how to link two files. But
in all the cases discussed so far the result we get is not formatted in a presentable manner. We cannot
take a print out and submit it straight away. The result we generate has to be presented in a suitable
form, as we will see below. Such a task is possible through the report form.

Report form files are created and modified with the CREATE or MODIFY REPORT command.
Before the command is used, a database file must be in use. The field characteristics within the
selected database file are used to help you design your report form.

Both .DBF and .VUE files are used with the CREATE or MODIFY REPORT command. Once
designed, the REPORT FORM filename command is used to reproduce the report on your screen. If
you add the TO PRINT clause to the REPORT FORM command, the report is printed as it is
displayed on your screen.

The default extension given a report form file is .FRM. However, you can assign a different extension
upon creation, or you can use the RENAME command rename the file extension.

22.6 HOW TO GENERATE THE REPORT FORM?
Open the file BIODATA and give the CREATE REPORT command. Instead of the word CREATE
you can use the word MODIFY also.
. USE BIODATA
. CREATE REPORT
dBASE responds to the above command by displaying the following message:
Enter Report File Name:
You have to type the filename BIO and press ENTER key. dBASE displays a menu screen with five
items in the main menu as follows (see, Fig. 22.5).
- Options
- Groups
- Columns
- Locate
- Exit

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

173
By default the menu item OPTIONS is highlighted. In the menu item OPTIONS there are 9 sub-items
as shown in Fig 22.5. By default the sub-item PAGE TITLE is highlighted. We will discuss about
each of these in detail.
22.6.1 OPTIONS
There are nine sub-items under the menu item OPTIONS. They are discussed below.

Options Groups Columns Locate Exit 01:43:57 pm


Page title .
Page width (positions) 80
Left margin 8
Right margin 0
Lines per page 58
Double space report No
Page eject before printing Yes
Page eject after printing No
Plain page No



CURSOR
Char:
Word: Home End
Pan: ^ ^


INSERT
Char: Ins
Field: ^N
Help: F1


DELETE
Char: Del
Word: ^Y
Field: ^U


Up a Field: |
Down a Field: +
Exit/Save:
^End
Abort:
Esc


CREATE REPORT |<C:> | BIO.FRM | Opt: 1/9 | |
Position selection bar - | + . Select - . . Leave menu - .
Enter up to four lines of text to be displayed at the top of each report page.


Fig. 22.5


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

174
1. Page Title: By default the cursor is over the page title item. On pressing the control key CTRL a
window opens up by the side of the option menu box where you want to enter titles of further
report. The titles can be up to lines of text, each line can be up to 60 characters.
2. Page width: This is used to specify the number of characters to be printed on each line of the
report. The default is 80 characters.
3. Left margin: In this option you can specify the number of characters required as left margin. The
default is 8 characters.
4. Right margin: Used to specify the number of characters required for right margin. The default is
0.
5. Number of Lines/Page: Used to specify the number of lines on every page of the report. The
default is 58 lines.

6. Double Space Report (Y/N): Used to specify double spacing in the report. Default is single
space.
7. Page Eject before Printing (Y/N): Used to skip to a new page before printing. By default a page
is skipped before a report is printed.
8. Page Eject after Printing (Y/N): Used to skip a page after the report is printed. By default it
does not skip a page after a report is printed.
9. Plain page (Y/N): Used to suppress/display page number and date. The default is NO which
suggests that page number, page title and date are displayed on each page. By typing Y (for Yes)
you will get the page title only on the first page. But the page number and date will not be printed.

22.6.2 GROUPS
After setting the above options now let us take the cursor to the second menu item GROUPS by the
right arrow key. The contents of the screen will change as shown in Fig. 22.6. There are six sub-items
under the menu item GROUPS. Each of them is described below.
1. Group on expression: This sub-item is highlighted by default (see Fig. 22.6). This item groups
the records having a common value in a key field. New groups are started when a new value is
encountered. The key field is selected in the COLUMNS menu selection.
2. Group heading: This let you enter a report heading that is displayed as each new group is
encountered and displayed.
3. Summary report only: The default option under this item is NO. This includes all records in the
report. If you change it to YES detail information is not provided and only subtotals are provided.
4. Page Eject after group: YES, This causes a form feed after each group is printed. The option NO
prints the groups together.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

175
5. Sub-group on expression: This selection lets you specify a secondary level of grouping for sub-
groups within groups. Like the main group, sub-groups should also be indexed or sorted.
6. Sub-group heading: Lets you enter a report heading that is displayed as each new sub-group is
encountered and displayed.

Options Groups Columns Locate Exit 02:02:46 pm


Group on expression .
Group heading
Summary report only No
Page eject after group Yes
Sub-group on expression
Sub-group heading

.
CREATE REPORT <C:> BIO.FRM Opt: 1/6
Position selection bar - | + . Select - . . Leave menu - .
Enter a field or expression on which to break for the first level of subtotals.

Fig. 22.6

22.6.3 COLUMNS
Now let us discuss the menu item COLUMNS. You can select this item by the right arrow key. The
screen will be displayed like Fig. 22.7. There are five sub-items under COLUMNS. Each of them is
discussed below.
1. Contents: Enter the field name for each column. You can press ENTER or F10 key to display a
field list. Select and return to the Column menu with the Right or Left Arrow key.
2. Heading : Lets you enter up to four 59-character lines as column headings.
3. Width: The column widths default to the field width or heading width, whichever is larger. You
can modify the width by typing a new field.
4. Decimal places: Uses the file structure value. If you enter a smaller number, the displayed result
is rounded. Only applies to numeric fields.
5. Total this column: The default is to print the total at the bottom of the report. Type NO to
suppress printing.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

176
Note that the column specifications must be given for each column. As you fill the items for the
column details, you will find that a REPORT FORMAT box is opened at the lower end in the position
of the cursor control menu. This shows the column heading and the column formats. The following
symbols are used to represent the structure of the report as you enter it.

Options Groups Columns Locate Exit 02:19:26 pm


Contents .
Heading
Width 0
Decimal places
Total this column

________Report Format_______________________________________________________
>>>>>>>







CREATE REPORT <C:> BIO.FRM Column: 1
Position selection bar - | + . Select - . . Prev/Next column - Pg Up/Pg Dn.
Enter a field or expression to display in the indicated report column.
Fig. 22.7
22.6.4 LOCATE
The locate menu is provided to help with column definition. This menu item lists the selection that
you made using COLUMNS menu. If you do not define the columns earlier the screen will display
like Fig. 22.8.

Options Groups Columns Locate Exit 06:25:04 pm

No columns defined


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

177


________Report Format_______________________________________________________
>>>>>>>







CREATE REPORT <C:> BIO.FRM | Opt: 1/1
Position selection bar - | + . Select - . . Leave menu - .
Step to any column immediately by selecting the column expression.
Fig. 22.8

22.6.5 EXIT MENU
The Exit Menu box has two items as shown in the Fig. 22.9. When SAVE is highlighted, press the
CTRL key. The Report File BIO.FRM is now saved and can be used for printing the report. The
option ABANDON does not save the report file.

Options Groups Columns Locate Exit 03:06:53 pm

Save
Abandon

________Report Format_______________________________________________________
>>>>>>>







CREATE REPORT <C:> BIO.FRM Opt: 1/2

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

178
Position selection bar - | + . Select - . . Leave menu -
Exit and save changes.
Fig. 22.9
22.7 PRINTING THE REPORT
To print the Report for selected records a FOR clause or a WHILE clause can be added to the
REPORT command. For saving the Report in a .TXT file, you give a TO filename clause to the
REPORT commands as shown below:
.REPORT FORM BIO TO REPO.TXT
The bio report is now stored in the REPO.TXT file. This is an ASCII file and you can see by giving
the TYPE command from DOS prompt.









IN-TEXT QUESTIONS 2

1. Which command is used for report creation?
2. What are the sub-menus of COLUMNS menu?
3. Choose the correct answer
(a) The extension name for Report file is
(i) .NDX (ii) .DBF (iii) .FRM (iv) .PRG
(b) How many items dBASE displays in the main menu of Report generation?
(i) 2 (ii) 7 (iii) 5 (iv) none of the above

22.8 WHAT YOU HAVE LEARNT
In this lesson we covered the basic commands and techniques for displaying data in a formatted
report. The first part of this lesson discusses the multiple database concepts like file handling, work
areas and the commands related to multiple database. The second part covers report generation from a
database file.

22.9 TERMINAL QUESTIONS

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

179
1. What are the characteristics of multiple files?
2 How do you switch the File Status from Active to Non-Active form?
3 What is the usefulness of SET RELATION TO command? Explain with example.
4 What are five items or menus while creating a report? Explain in brief.

22.10 FEEDBACK TO IN-TEXT QUESTIONS
IN-TEXT QUESTIONS 1
1. 10 databases
2. The first work area in database is A.
3. SELECT command
4. The file that is selected last is called the active file and other files are called non-active files.
5. (a) ii (b) ii

IN-TEXT QUESTIONS 2
1. CREATE or MODIFY commands are used in report creation.
2. Contents, Heading, Width, Decimal places, Total This Column are five sub menus of COLUMNS
menu.
3. (a) iii (b) iii
LESSON 23
PROGRAMMING CONCEPT


23.1 INTRODUCTION
By now we are familiar with various dBASE commands and how they are used. Let us consider
another use of dBASE namely in the area of programming. In this lesson we will discuss some
programming constructions in general sense. We will also point out the situations in which they are
used.
We had given a brief idea about the concept of programming while dealing with the lesson on
'Software' in the module 'Computer Fundamentals'. Here we will discuss programming in the context
of dBASE III Plus.

23.2 OBJECTIVES
After going through this lesson you should be in a position to
- understand the need of writing programs
- identify the important programming commands in dBASE III +
- write programs in dBASE III +

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

180
- identify the types of files created by dBASE III +

23.3 WHAT IS THE NEED OF PROGRAMS?
In the previous three lessons you have learnt so many commands in dBASE. These commands are
given to the computer step by step. We give a second command only after the first command is
executed. But many times the user has to give a set of instructions repeatedly to solve a particular
problem. In such situations writing the same set of instructions every time is time consuming. Another
factor is the chance of committing mistakes while keying in the commands. Hence we need to develop
computer programs and store it in a file.
As you know program is a set of instructions given by the user to the computer for solving a problem.
In the programming mode it is possible to write any number of commands together in single file.
When we give a single dBASE command to execute the file all the dBASE commands contained in
the file are executed.

Now let us discuss some of the important commands that are used in programming. They can be
broadly categorised into three areas: Control Commands, Input Commands and Output Commands.
Within these categories we see a number of commands. We will discuss the important ones only in
this lesson.
23.4 CONTROL COMMANDS
The important commands under this heading are
- Do While
- Exit
- If ElseEndif
- Loop
- EOF( )
- Do case, Endcase, Otherwise
We will now consider the general forms of these commands.

23.4.1 DO WHILE COMMAND
This command is used when a particular segment of commands have to be executed repeatedly. Thus
it is a looping command that sustains operation while some condition is true. The loop command is
used to return control directly back to the DO WHILE command. The first line of the DO WHILE
statements has the form:
DO WHILE logical expression
Continuous operation is sustained as long as the expression is true, or until an ENDDO or EXIT
command is encountered. The complete DO WHILE statement has the form:

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

181

DO WHILE expression


(Command lines)


ENDDO

Now let us consider an example using the do while command. Suppose you have to fine the sum of
natural numbers 1 to 100. (That is 1+2+3+4+..+100). In order to do this we take two variables
S and N. S is the sum of the numbers. N stands for natural number which takes value from 1 to 100.

S=0
N=1
DO WHILE N<101
S=S+N
N=N+1
ENDDO


In the above example we assume that S=0 and N=1. Let us interpret the command line N=N+1. This
shows that natural numbers increase by 1 at a time. The command line S=S+N shows the sum of
numbers.
When N=1, obviously the sum of numbers will be S=S+N = 0+1= 1.
When N=2, S= 1+2=3.
When N=3, S=3+3=6

and so on.
Here the role of the DO WHILE command is that, it repeats the summation process till N<101. Every
time a sum is obtained by the statement S=S+N, N takes the next value N=N+1. Thus a loop is
formed. The process is repeated till the expression N<101 is true. The process stops at the ENDDO
command.

23.4.2 EXIT COMMAND

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

182
The exit command transfers control from the DO WHILE loop to the command line following the
ENDDO statement, which is always the last line in a DO WHILE statement. Let us consider the
following example:











Do while N < 51
S = S + N
If N = 10
Exit
Endif
Enddo


The exit statement completely exits the control from the loop when the value of N = 10 and
immediately it stops execution following the ENDDO statement.

23.4.3 The IFELSEENDIF Commands
The IFELSEENDIF clauses allows a program to make decesions while it is running. The IF
command means the same thing that it does in English: IF this is the case THEN do this ELSE do not
instead.

IF <condition>
<commands>
[ELSE]
<commands>
ENDIF


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

183

Where <condition> is a valid dBASE logical expression, ELSE is an optional branch to alternative
commands, and ENDIF is the command required to close the IF clause. (If you forgot to include the
ENDIF command, dBASE will not give you any error message. Instead, your program will just
behave in a strange and unpredictable manner.)

23.4.4 LOOP COMMAND
When the loop command is executed the control passes back to the command line following the DO
WHILE command. Sometimes it may be required to stop executing some of the statements at the
lower end of the loop body and transfer the control to the beginning of the loop. In that case the loop
statement is used as shown below:


Do while logical-expression
. (command lines)
..
If condition
Loop
Endif
.. (command lines)
..
Enddo

23.4.5 EOF( ) Command
The EOF statement, which stands for end of file, is used with several commands including DO
WHILE, DO CASE, and IF (We will discuss these commands later). When an end-of-file condition
exists EOF( ) returns a true value. Otherwise it shows a false value. Going to the bottom of a file with
GO BOTTOM does not position the record pointer to the end of the file. Let us consider the following
example

.USE FILENAME
.GO BOTTOM
. ? EOF( )
.F

You can also go to the end of the file with the COUNT command.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

184

23.4.6 DO CASE , ENDCASE, AND OTHERWISE COMMANDS
The DO CASE Command is used when only one option out of several alternatives (That is several
CASEs) is to be selected. The CASE statement is used to check for a specific condition. Each CASE
statement is followed by one or more command lines. If a CASE statement is true, dBASE performs
all commands between that CASE statement and the next CASE statement. If a CASE statement is
false the command lines are ignored and the control passes to the next CASE statement. This process
continues till a true CASE is found or the ENDCASE statement is reached.

DO CASE
CASE X = 1

. (command lines)
CASE X = 2
..
.. (command lines)
CASE.
ENDCASE

Let us consider the following example.

X = 5
DO CASE
CASE X < 10
? "X is less than ten"
CASE X = 5
? "X is equal to five"
ENDCASE

However, the output from this routine is simply X is less than ten. Although it is true that X is equal to
five, the second CASE statement is never evaluated. In a DO CASE clause, only the first alternative
that evaluates to true is processed; all remaining commands and CASE statements up to the
ENDCASE command are ignored completely. In other words, the alternatives in the DO CASE clause
are mutually exclusive.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

185
OTHWERWISE: It is an alternative statement, which is used when none of the CASE statements are
true.

IN-TEXT QUESTIONS 1
1. Give three examples of control commands.
2. What is the usefulness of EXIT command?
3. When do you use the DO CASE command?


23.5 DATA INPUT COMMANDS IN dBASE
Now we will discuss some input commands, which are used to get data into a dBASE program.

23.5.1 ACCEPT Command
The ACCEPT command presents a prompt on the screen and waits for the user to respond by typing
some text and pressing ENTER key. Whatever you type is stored in a memory variable.
The syntax for the ACCEPT command is:
ACCEPT [<prompt>] TO <memory variable>
Where <prompt> is optional and <memory variable> is the name of the character memory variable
that will store the user's entry.

The data stored in the memory variable can be from 1 to 254 characters in length. If the user presses
the ENTER key without typing any character, the stored memory variable has an ASCII value of zero
and a length of zero.

PROGRAMMING THE PROMPT
The optional prompt can be surrounded by quotation marks, apostrophes, or brackets. The examples
below are equivalent:
ACCEPT "Enter your name" TO Name
ACCEPT 'Enter your name' TO Name
ACCEPT [Enter your name] TO Name

To embed an apostrophe or other character in the prompt, just use different characters for the outside
delimiters:
ACCEPT "What's your name" TO Name
The prompt itself can be stored in a memory variable.
Characteristics of ACCEPT Command

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

186
1. Any data entered via the ACCEPT command can be used for macro substitution.
2. ACCEPT will work with character strings of any length up to 254 characters.
3. To restrict the size of the memory variable character string, use the @.READ command.
4. To convert the character data entered via the ACCEPT command to numeric or date data, use the
VAL or CTOD functions.

23.5.2 INPUT COMMANDS
INPUT command is usually used to enter numeric data from the user. The optional prompt can be
enclosed in double quotation marks, apostrophes, or brackets.
The syntax for the INPUT command is:
INPUT [< prompt >] TO < memory variable >
Where <prompt> is an optional character string enclosed in double or single quotation marks or
brackets and <memory variable> is any valid memory variable name.
INPUT Enter your age TO Age
INPUT Enter your age TO Age
INPUT [Enter your age] TO Age
INPUT [Enter your age] TO Age
Let us consider another example to get data into the program through INPUT command.
INPUT Enter value for the principal TO principal
The computer will display the prompt on the screen and will wait until you enter the value for the
principal variable.

23.5.3 WAIT COMMAND
The WAIT command suspends processing of a program and waits for the user to press any key. It
accepts only a single keystroke and does not require the ENTER key to be pressed.

23. 5.4 @ ROW, COLUMN COMMAND
The symbol @ followed by row and column position used to position text at a specific row and
column location on the screen. The row-column notation starts at 0,0 which is the first row and first
column on the screen. Therefore, rows are 0-24 for a 25 line screen and columns are 0-79 for a 80
column screen. You can think of @ row,col as at row number, column number. The SAY and GET
statements are used individually or in combination with @ row,col. Let us consider the following
example:

1 @ 7,10 SAY What is your name?
2 @ 7,40 GET name

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

187
3 @11,10 SAY PIN number?
4 @11,40 GET PIN number
5 READ
In this example, line 1 displays the question What is your name? at row 7, column 10 on the screen.
Line 2 allows data entry from the keyboard into name field of the database in use. Line 3 and line 4
are similar to lines 1 and 2. Line 5 contains READ command which reads your typed response to the
GET statement into the specified field of the database in use.

23.6 OUTPUT COMMANDS
These are some of the important commands used in dBASE in the programming mode in addition to
all dot prompt commands we have used earlier. Examples are APPEND, BROWSE, EDIT, LIST, etc.

23.7 dBASE COMMANDS AND FUNCTIONS
Several different types of files are created and used by dBASE III Plus. Let us discuss some important
files and their extensions. They are:

Backup files .BAK
Catalog files .CAT
dBASE configuration file CONFIG.DB
System configuration file CONFIG.SYS
Database files .DBF
Database memo field file .FRM
Report form files .FRM
Label form files .LBL
Memory variable files .MEM
Database index files .NDX
Command files .PRG
Query files .QRY
Screen files .SCR
Standard data (or text) files .TXT
View files .VUE

When the files are created by dBASE, they are assigned different three-character extensions, like
CUSTOMER.DBF. Other files, like text files and report form files are created by dBASE. We give a
description for each file type listed above.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

188
1. Backup (.BAK): Backup files are automatically created as a safety measure when an edited
version of a text file is saved. For example, if you use the MODIFY COMMAND FILENAME
statement to change a file, the previous version of the modified file is kept with a .BAK extension.
This happens when you press CTRL-W to save (write) your modified version.

2. Catalog (.CAT): A catalog of filenames, including databases, index Files, etc. is created as files
are created or put into use. The catalog file is established with SET CATALOG TO filename
before file creation activity is started.

3. dBASE Config (CONFIG.DB): This file is used by dBASE when it is started. It contains one or
more commands that control dBASE operation. Normal defaults, including function key values
and SET functions, are controlled by this file. It can also contain a command line that causes
automatic execution of a command file.

4. System Config (CONFIG.SYS): This file is used by DOS when you turn on your computer. It lets
you have 20 files open at the same time, including 15 within dBASE III applications. It also creates
15 buffers, which speeds up dBASE III operation by letting it work in memory buffers rather than
having to read and write information to your disk during sorting and listing.
5. Database (.DBF): A standard database file is created and saved using te CREATE command.

6. Memo file (.DBT): When a database file contains memo (text) fields, an auxiliary file having the
extension .DBT is created to contain the memo fields . Databases can contain as many as 128
memo fields. Each memo field can contain up to 5,000 characters. Although memo fields use a
minimum of 512 bytes in the .DBT file, they only occupy 10 bytes in a database file. Memo files
are accessed when a database is being edited with APPEND, BROWSE, CHANGE, or EDIT by
pressing Ctrl-Home at the begining typing text into a memo field, press Ctrl-End to return to the
data entry mask.

7. Report form (.FRM): The CREATE/MODIFY REPORT command helps you to create and save
report format files that control the display and printing of data. The REPORT commands are
described in lesson 22.

8. Label from (.LBL): The CREATE/MODIFY LABEL command helps you create and save label
formats files that control the display and printing of data.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

189
9. Memory Varible (.MEM ) Memory files are created when memory variables are written to disk
using the SAVE command. The resulting file has the extension .MEM which allows you to save
memory variables to disk, and then clear memory to make room for more memory variables.
10. Index (.NDX) An index file is created from an existing database file. The records within an index
file are sorted (rearranged alphabetically or numerically) on one or more specified fields, which
are refereed to as "key" fields. Records retain their original record number. Changes to the
contents of index files change the database file.

11. Procedure (or command file) (.PRG) A procedure or command file is created and saved using
the dBASE full-screen editor or some other text editor; These are pure ASCII files and are
transferable (transportable) between different computer and operating systems. Command files are
created by the dBASE MODIFY COMMAND.

12. Query (.QRY): A query file establishes a filter that restricts display to specific records that meet
some established condition. The CREATE/MODIFY QUERY command is used.

13. Screen (.SCR): A screen file is used to create or edit screen format files. The CREATE/MODIFY
SCREEN command is used.

14. Standard Data (.TXT): A standard data or text file is created by copying a database file with
COPY TO filename SDF or DELIMITED. .TXT file is created when information is displayed
when the SET ALTERNATE TO filename and SET ALTERNATE ON commands are in effect.
The resulting file may be used by other programs, such as WordStars Mail Merge.

15. View (.VUE): Contains the name of related database files and related index and format files,
which list selected field names and relations. Used to call all related files with a single command.
The CREATE/MODIFY VIEW command is used for this purpose.


IN-TEXT QUESTIONS 2
1. What is the difference between INPUT and ACCEPT commands.
2. Give the extension of the following database files:
Program File
Memo File
View File
Back up File

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

190

23.8 WHAT YOU HAVE LEARNT
In this lesson we discussed the need for programming in dBASE. In this context we discussed three
types of programming commands. These are control commands, input commands and output
commands. The important commands available and their syntax for use in practice are discussed. We
have provided examples so that you can develop programs in dBASE yourself.



23.9 TERMINAL QUESTIONS
1. Write a program for simple and compound interest using DO-WHILE command.
2. Write a program for finding the sum of natural numbers between 1 to 10.
3. Write a program for printing Pay -slips using INPUT and ACCEPT commands.
4. Write a program for finding prime numbers between 1 to 100.

23.10 FEEDBACK TO IN-TEXT QUESTIONS

IN-TEXT QUESTIONS 1
1. Do While, Exit, If ElseEndif
2. The exit command transfers control from the DO WHILE loop to the command line.
3. The DO CASE Command is used when only one option out of several alternatives (That is several
CASEs) is to be selected.
.
IN-TEXT QUESTIONS 2
1. INPUT command is usually used to enter numeric string whereas ACCEPT command is used in
character string.
2. .PRG
.MEM
.VUE
.BAK








AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

191









Disk Operating System (DOS)

5.1 INTRODUCTION

When the computer starts, it starts the operating system that takes the control of the machine. An
Operating System is a set of programs that help in controlling and managing the Hardware and the
Software resources of a computer system. A good operating system should have the following
features;

1. Help in the loading of programs and data from external sources into the internal memory before
they are executed.

2. Help programs to perform input/output operations, such as;

- Print or display the result of a program on the printer or the screen.

- Store the output data or programs written on the computer in storage device.

- Communicate the message from the system to the user through the VDU.

- Accept input from the user through the keyboard or mouse.

5.2 OBJECTIVES

At the end of this lesson, you would be able to;

- explain the concept operating system

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

192
- discuss the functions of operating system
- understand the procedures of loading operating system into the memory
- use file management features of operating system
- create separate locations for logically related files
- copy files from one computer to another
- use Windows for File Management

5.3 DISK OPERATING SYSTEM

As the name suggests, the operating System is used for operating the system or the computer. It is a
set of computer programs and also known as DOS (Disk Operating System). The main functions of
DOS are to manage disk files, allocate system resources according to the requirement. DOS provides
features essential to control hardware devices such as Keyboard, Screen, Disk Devices, Printers,
Modems and programs.

Basically, DOS is the medium through which the user and external devices attached to the system
communicate with the system. DOS translate the command issued by the user in the format that is
understandable by the computer and instruct computer to work accordingly. It also translates the result
and any error message in the format for the user to understand.




(a) Loading of DOS

The BOOT Record into the computer memory loads DOS. BOOT Record in turn is triggered by ROM
program already there in the computer.

The system start-up routine of ROM runs a reliability test called Power On Self Test (POST) which
initializes the chips and the standard equipment attached to the PC, and check whether peripherals
connected to the computer are working or not. Then it tests the RAM memory. Once this process is
over, the ROM bootstrap loader attempts to read the Boot record and if successful, passes the control
on to it. The instructions/programs in the boot record then load the rest of the program. After the
ROM boot strap loader turns the control over to boot record, the boot tries to load the DOS into
the memory by reading the two hidden files IBMBIO.COM and IBMDOS.COM. If these two are
found, they are loaded along with the DOS command interpreter COMMAND.COM.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

193
COMMAND.COM contains routines that interpret what is typed in through the keyboard in the DOS
command mode. By comparing the input with the list of command, it acts by executing the required
routines/commands or by searching for the required routine utility and loads it into the memory.

5.4 COMPUTER FILES IN DOS

A file may contain a program or any other kind of information. Generally, a file must be given a
name that can be used to identify it. DOS permits the user to assign a name consisting of two parts
to a file - primary and secondary names. Primary name can be of a maximum of eight characters
consisting of Characters, Alphabets, Number and Hyphen), and the Secondary name should
consist of three characters, which is optional. The primary name and the secondary (or extension)
name, if any, are to be separated by a dot (.).

Primary name can be linked to proper name, whereas extensions are like surnames of people. Using
an extension with the file name is preferable, though optional. However, once the extension is
specified, using the complete name (primary name and extension, with the period separating them can
only refer the file). Using extensions can be an excellent way of naming a file so that it can be
identified easily.

Examples:

Filename Primary Name Separator Secondary Name
Employee Employee
Employee.Exe Employee . Exe
Employee.Dbf Employee . Dbf

DOS has a way of showing which disk drive is currently active. The floppy disk drives are assigned
alphabets A and B, whereas the hard disk drive is assigned the alphabet C. If your PC has a single
floppy drive, the drive would be A and if it has two, they would be termed as A and B. If your PC
includes a hard disk, besides a FDD (Floppy Disk Drive), the drive names would be A and C. If
the prompt is A, then it implies that the first floppy disk drive is active. Where as the DOS prompt
would be C, if the hard disk is active. Data as well as instructions reside in a file stored in a disk.


5.5 DIRECTORY STRUCTURE IN DOS


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

194
The files in the computer come from various sources. Some files come with DOS, while other come
with publications such as a word processor. These files contain codes and other information that is
necessary to make the computer application operational. Before long, there will be hundreds or
even thousands of files in the computer, which can make it difficult to locate specific files.

The names of all the files created in a disk are stored in its directory. Directory is just like a file
folder, which contain all the logically related files. DOS files are organized in a hierarchical or an
inverted tree-like structure. The general analogy is with a file cabinet containing a number of drawers,
which in turn may contain folders. The content of these folders is the needed information.

The file cabinet here is the ROOT DIRECTORY, the drawer is INDIVIDUAL DIRECTORY, the
folders are SUBDIRECTORY and the information in these folders may in turn be classified as
FILES.

Otherwise, the large number of files that get created for various purposes in a disk can make the
directory huge and difficult to view and manage. Therefore, DOS enables the user to organize the
files in a disk into directories and sub-directories in a hierarchical structure. Directories can contain
other directories. A directory within another directory is called a sub-directory.

Of course, there may be sub-directories of sub-directories, but a file name is the furthest you may
descend down the (inverted) tree of directories and files. Thus, a file name corresponds to a tree
leaf, a sub-directory to a branch, the directory to the trunk, and the root directory to the root of the
tree, hence the name ROOT DIRECTORY.
Sample of Directory Structure

ROOT


Command.com (Personal) Autoexec.bat (Accounts) Pk.bat


LEAVE INSURANCE GPF PENSION LOAN


The directory/sub-directory is represented in bold letters.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

195




5.6 DIRECTORY COMMAND

The content of each of the sub-directory cannot be viewed unless it is made active, or a sub-directory
is specified as part of the DIR command. Doing either of these requires an understanding of the
concepts of navigating around the disk.

The directory, the user is in at any point of time, is called the
WORKING/PRESENT/CURRENT directory. DOS indicates which directory you are in by displaying
the directory's name in the command prompt. For example, the following command prompt indicate
that you are in the DOS directory: C:\DOS>. Knowing which directory is current helps you find
files, and to move from one directory to another more easily. Typically, the ROOT DIRECTORY
(\) is the initial working directory. The entire specification of directory from root is called a PATH.
By itself, the DIR command is applicable to the working/present directory. The names of the sub-
directories at adjacent levels are separated by backslash (\), while specifying the path to be followed
while traveling to a sub-directory.

5.7 USING PATH TO SPECIFY THE LOCATION OF FILES

A path is the route that leads from the root directory of a drive to the file you want to use.

For example, to access the NOS.LET file in the LETTER subdirectory of NOS directory, DOS must
go from the ROOT (\) directory through the NOS directory to the LETTER directory, as shown in
the following figure:

C:\
NOS

ACCOUNT

SALARY


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

196
LETTER

NOS.LET

PROJECT

To specify the same path at the command prompt, you would type it as shown in the following
illustration:

C:\NOS\LETTER\NOS.LET

This is the path or route to the file NOS.LET. The first letter and the colon (C:) represent the drive the
file is on. The first back slash (\) represents the root directory. The second backslash separates the
NOS directory from the LETTER sub-directory. The third backslash separates the LETTER sub-
directories from the file name, NOS.LET.

Note: MS-DOS recognizes path up to 67 characters long (including the
Drive letter, colon, and backslash).

5.8 DIR COMMAND

The DIR command gives the list of is there on the disk that is mounted on the active drive.

Syntax : C:\> DIR A:\> DIR

Example





A:\> DIR


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

197
Volume in drive A has no label
Directory of A:\

COMMAND COM 23612 10-20-88 11.30a
DISKCOPY COM 4235 10-20-88 12.00p
FORMAT COM 15780 03-12-89 12.00p

3 file(s) 325013 bytes free
A:\>

As can be seen, on typing DIR followed by <Enter> key at DOS prompt, five columns of data
followed by the number of files and bytes that are free in the disk are displayed. The first column
contains the primary name of each file resident on the disk. However, most files are named with an
extension, which appear in the second column. Whereas, the third column contains the size of the file
in bytes, and the fourth and fifth columns show the date and time on which the files was created or
last modified. The last line displays the number of file(s) and remaining disk space free in bytes. It
is important to note that the DIR command only displays the names of the files and not their
contents.

5.9 CHANGING A DIRECTORY

All the names displayed using DIR command that have <DIR> besides them are directories. You
can see the list of files in another directory by changing to that directory and then using the DIR
command again.

The Change Directory (CHDIR) or CD command enables the user to travel around the directories
in a disk. Type the CD command at the command prompt.


Syntax:

A:\> CHDIR {path} or a:\> CD {path}

Examples : (Refer to the figure)

# 1. A:\>CD \NOS

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

198


This command makes the NOS sub-directory under the root directory (\) active.

# 2. A:\>CD \NOS\LETTERS

The backslash indicates the root, and LETTERS, which is a sub-directory under the NOS directory,
becomes the working directory.

# 3. A:\> CD \

The root directory becomes the working directory; i.e. you will change back to the root or main
directory. The slash typed in this command is a backslash (\). No matter which directory you are in,
this command always returns you to the root directory of a drive. The root directory does not have a
name, it is simply referred to by a backslash (\).

5.10 MAKING OR CREATING DIRECTORY

As the number of files increases in a disk, a need is felt to organize them in a meaningful way by
creating sub-directories to store a group of logically related/similar files.

To create a directory, DOS provides the MKDIR (Make Directory) or MD command.

Syntax:

A:\>MKDIR [drive:] {pathname} or A:\>MD [drive:] {pathname}

Square brackets indicate that [drive:] entry is optional.

The MD or MKDIR command creates a new empty directory whose name is the last item specified
in the pathname, in the specified drive. If active, the drive need not be specified. If the directory is
to be created as a sub-directory of the working directory on the active drive, typing MD {directory
name} at the DOS prompt or command prompt is sufficient.

Examples:

# 1. A:\> MD \ACCT\SALARY

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

199

makes a SALARY directory in the: drive, under ACCT directory.

# 2. A:\> MD C:\> SALARY

Makes a salary directory in the C: drive, under root directory.



5.11 DELETING A DIRECTORY

You may want to delete or remove a directory to simplify your directory structure. DOS provides
RD (Remove Directory) to delete a directory.

Example:

# 1. A:\> RD \ACCT\SALARY

removes the SALARY sub-directory in ACCT directory.

NOTE: You cannot delete a directory if you are in it. Before you can delete a directory, you must
type cd.. at the command prompt. At the same point of time, the directory to be deleted should be
empty.

5.12 COPYING FILES

To copy a file, DOS provides `COPY' command. When you use `copy' command, you must use the
following two parameters; the location and the name of the file you want to copy, or the source;
and the location and the file name to which you want to copy the file or the target (destination).
You separate the source and the destination or target with a space. The syntax of the `COPY'
command is

COPY {source} {destination} or,

COPY [drive:] [path] [filename] [drive:] [path] [filename]


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

200
i.e. the first set of drive, path and filename refers to the source file, and the second set of drive,
path and filename
refers to the destination file.

(a) Copying Single File

To copy the DEBUG.EXE file from the DOS directory to the NOS
directory

1. Return to the root directory by typing the following command prompt: CD\

2. Change to the DOS directory by typing the following commands at the DOS prompt: CD DOS

3. To copy the file DEBUG.EXE file from the DOS directory to the
NOS, directory type the following at the command prompt:

Copy c:\dos\debug.exe c:\nos

and the following message appears: 1 file (s) copied


Examples:

# 1. A:\> copy a:\letter\office.doc \letter\office.bak

makes a copy of the office.doc file in the current or working directory with a new name office.bak

# 2. A:\> copy office.doc a:\letters\nos.mem

copy the file office.doc from the root directory to the sub-directory LETTER under root directory with
a new name nos.mem.

If the target drive is not specified, the copied file will reside in the disk mounted on the active drive.

5.13 USE OF WILDCARD CHARACTERS


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

201
If you want to carry out a task for a group of files whose names have something in common, you can
use wildcard characters to specify groups of files. DOS recognize two wildcard characters: asterisk
(*) represents one or more characters that a group of files has in common; and the question mark
(?) represents a single character that a group of files has in common. You can use wildcards to
replace all or part of a file's name or its extension. The following table shows examples of wildcards:

Wildcard What it Represents Example

*.TXT All files with a .TXT extension JULY.TXT
LETTER.TXT

REPORT.* All files named REPORT with any REPORT.TXT
extension REPORT.LET
REPORT.WRI


M*.* All files beginning with letter M MEMO.TXT
regardless of their extension MARCH.XLI

???.* All files having 3 letter names, SUN.BMP
with any or no extension WIN.LET


You can include the wildcard in the command.

Use of wildcard characters in COPY command

# 1. A:\>COPY \letters\*.COB B:

It means, copy all files with extension *.COB from the directory LETTERS under the ROOT
directory to the working or ROOT directory of the `B' drive.




# 2. A:\> COPY B:\COMPANY\OPEL.*

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

202

The command is to copy all files with primary name OPEL (irrespective extension) in the directory
COMPANY under ROOT of the drive `B' into the current working directory of the disk mounted in
`A' drive. Incase of one drive, the system will ask for the source and
target drive.

The command,

#3.A:\>COPY C:\*.*

copies all files of the ROOT directory of the 'C' drive into the working directory of the 'A' drive.

# 4. A:\> COPY LETTE?.* B:

copies all files with primary name consisting of 6 characters in total and LETTE as the first five
characters (irrespective of extension name) into drive `B'.

# 5. A:\> COPY B:\?.DOC

copies all files having a primary name of one character with an extension .DOC from ROOT
directory of 'B' to the ROOT directory of `A' drive.

5.14 RENAMING FILES

To rename a file, DOS provides REN command. The REN command stands for "Rename".
When you use the REN command, you must include two parameters. The first is the file you want
to rename, and the second is the new name for the file. You separate the two names with a space. The
REN command follows this pattern:

REN oldname newname

Example: REN NOS.DOC NOS.MEM

Rename the old filename NOS.DOC to a new filename NOS.MEM.

5.15 DELETING FILES


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

203
This section explains how to delete or remove a file that is no longer required in the disk. DOS
provides DEL command, which means to delete.

Syntax : DEL {drive:} {path} {filename}

Example:

# 1. DEL \DOS\EDIT.HLP

delete the EDIT.HLP from the DOS directory under ROOT directory.


5.16 PRINTING A FILE

The `PRINT' command of DOS works more or less like `TYPE' com
mand, but at the same time, it enables the content of a text file
to be printed on a paper.

Syntax:
A:\> PRINT [drive:] {path} {filename}

Example:
A:\> PRINT \AIAET\LETTER\AIAET.LET

IN-TEXT QUESTIONS 5.1

1. The startup routine runs, when machine boots up is known as

a) POST
b) BOOT up
c) Operating Routine
d) I/O operation

2. Operating system is also known as:

(a) database
(b) system software

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

204
(c) hardware
(d) printer

3. What is the maximum length allowed for primary name of a computer file under DOS?

(a) 8
(b) 12
(c) 3
(d) None of the above

4. Which of the following could be a valid DOS file specification?

(a) NOSFILE.POST
(b) NOSFILE.P.OST
(c) NOSFILE.DOC
(d) NOST.FILEDOC


5. How many characters form a secondary name for a file?

(a) 8
(b) 12
(c) 3
(d) None of the above

6. What is the name given to something that the computer will automatically use unless you tell it
otherwise?

(a) a specification
(b) a wildcard
(c) a default
(d) a rule

7. As per symbolic notation of DOS, which of the following indicates the ROOT directory

(a)*
(b) >

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

205
(c) /
(d) None of the above

8. In wildcard specification `?' is used as replacement for

(a) one character
(b) two character
(c) three character
(d) none of the above

9. With DOS, you may use the `*' and `?':

(a) when changing the default settings
(b) to represent unspecified characters in a filename
(c) instead of wildcard characters
(d) in the extension but not in the drive name or the file name

10. DOS system file consists of

(a) IBMBIO.COM, IBMDOS.COM, COMMAND.COM
(b) COMMAND.COM, IBMBIO.COM, FORMAT.COM
(c) SYS.COM,IBMBIO.COM,IBMDOS.COM
(d) None of the above

11. The batch file uses the extension

a) .BAT
b) .DOC
c) .PRG
d) .DOS

12. To display the list of all the file of the disk you would type

(a) DIR
(b) COPY
(c) DIR FILES
(d) DIR AUTOEXEC.BAT

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

206

13. State whether the following questions are True(T) or False(F).

(a) Command.Com is hidden file.
(b) Primary name of a file can be of 10 characters.
(c) The command MKDIR and MD performs the same task.
(d) Under DOS .EXE is not an executable file.
(e) DIR command is used to see the content of a specific file.



5.17 WHAT YOU HAVE LEARNT

In this lesson you were introduced to one of the most popular desktop operating system and its
working environment. It explained the directory structure, file naming conventions. It also talked in
great length about the file management in terms of COPY, DEL, and MOVE. Here you learned the
steps involved in loading of operating systems into computer.

5.18 TERMINAL QUESTIONS

1. Explain in brief what do you understand by Operating system.

2. Explain the process involved in loading of Operating System.


5.19 FEEDBACK TO IN-TEXT QUESTIONS

1. 2.b3.a,4.b,5.b,6.c,7.d,8.a,9.b,10.a,11.a,12.a,13. F,F,T,F,F




INTRODUCTION TO WINDOWS 3.1


6.1 INTRODUCTION


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

207
If somebody buys a new computer today, it will probably come loaded with Windows. It is a
Graphical User Interface (GUI) program meant for IBM compatible PCs. It provides the flexibility of
using graphical icons and work interactively with the computer. One doesn't need to remember
operating system commands and type them. He just has to move the small mouse arrow key, known
as mouse pointer around the screen (better known as window) and select the require command by
pressing the click button. Each window, which represents programs, can be resized and moved around
the screen. Multiple windows can appear on the screen at the same time giving user the flexibility of
operating more than one
Program.

6.2 OBJECTIVES

At the end of this lesson you would be able to

- understand the concept of windows working environment

- differentiate between confessional character display interface and graphical user interface.

- explain about various features of Windows

- understand various Icons and their functions.

6.3 TYPES OF WINDOWS AND ICONS

Before using Windows effectively, it is very essential to understand the concept of window type and
Icons used in Windows. The entire screen is termed as Windows Desktop, on which all windows are
displayed. It is same as that of laying all your work on the surface of your working table. Here the
working table is the Windows Desktop and all your work is individual windows on the desktop.

In general, there are two types of windows and three types of Icons which window uses. The window
types are

1. Application windows, which displays the executable windows program in GUI mode. These
windows can be, opened, closed, resized and moved around the screen or the desktop.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

208
2. The other type of windows is a document window, which are generated by the executable or
application program. These document windows cannot be sized or moved outside the limit of its
parent application windows.


Windows uses three types of icons, namely application, document and program icons.

1. Application icons are the minimized version of the currently running application program. This
icon appears at the bottom of the desktop and can be maximized.

2. Document icons are the reduced document windows. When maximized, it appears within an
application window's workspace.

3. Program icons that appear within Program Manager and clicking on these icons activate the
associated applications and also load the related documents or files.

6.4 PARTS OF WINDOWS

All most all windows have common components. The components are;

1. Title Bar
2. Buttons for Minimize, Maximize and Restore
3. Borders for Resizing
4. Menu bar and Pull-down menus
5. The scroll bar

Title Bar
Control
Button
Menu Bar
Scroll Bar
Minimise and Maximise
Button
Resizing Bar

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

209






(a) Title bar

Title bar is displayed in color at the top of the windows. It contains the name, or the title of the current
windows. The windows can be moved around the window desktop using this title bar.

(b) Buttons for Minimise, Maximise and Restore

These buttons are displayed at the top-right corner of the screen. As the name suggests, minimise
button is used to reduce the current windows into an applications icon, which will appear at the
bottom of the windows desktop.

Similarly, maximise button is used to expand the current windows to take up the entire desktop.

Restore button is used to restore the state of the windows, where it was before maximization.

(c) Borders for Resizing

A thin border appears around the windows, which can be used to resize the current windows. To
resize the current windows, just place the pointer on the border (this will become two-headed arrow
) of the windows, click the mouse button, hold and drag to the desired location. The windows will
change its size. Vertical and Horizontal borders can be used to change the width and height of the
windows respectively, while corner border can be used to change width and height simultaneously.

(d) Menu bar and Pull-down menus

Menu bar is located under the Title bar and contains the related Pull-down menus for the currently
active windows. Clicking on a menu name will activate a pull-down menu with various options to
select.

(e) The scroll bar

Status Bar

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

210
When the active windows cannot accommodate the data to be displayed then it provides a scroll bar
that helps to move through the data. Vertical scroll bar allows to view data by moving up or down
through a document, whereas horizontal bar allows the movement from left to right. The vertical
scroll bar appears on the right side of the active windows and horizontal scroll bar at the bottom.

6.5 WINDOWS DIALOG BOXES

While using application program in window, sometimes it is require to change the settings within a
program for example default margin the a word processing document, default printer, font type and
size etc. All these are accomplish by window's dialog box, which appear when the menu with an
ellipsis (..) beside it is activated. It is basically serve two purposes one that it allows to change/rest
the parameters related to currently running application and displays information such as warnings,
error message etc. The displayed dialog box may contain the followings;

(a) Command Button

This button activates an action. The most commonly used command buttons are OK and CANCEL.
Command buttons with an ellipse (..) indicate a link to another dialog box.


(b) Check Box

Check box allows selecting one or more option from a list of options. When selected an X appears
besides the option selected and the corresponding option becomes active.






(c) List Box

List box displays a series of options available in a column. To select an item, move the mouse pointer
to the item and click on it. If the number of items is more than the height of the list box, then it
provides a scroll bar to move through the entire range of items in the list box.

(d) Option Buttons

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

211

It has the same features as that of check box. It allows selecting an option in a list of choices. When
selected, the small hollow circle gets filled. Once an option gets selected from the available set of
options, other options automatically get deselected.

6.6 DISK SPACE REQUIRED

Ms-Windows along with MS-DOS version 6.0 requires a minimum of 15.8 MB and maximum of 18.3
MB of free disk space. Minimum disk space assumes no optional components, network or printer
settings. However maximum disk space includes all installable components, network and printer.

6.7 WINDOWS VS. MS-DOS

Windows provides tools to accomplish all the tasks in case of file and directory management as in
MS-DOS. The main difference is how the work is done. Rather than remembering all the commands
and typing them at the DOS prompt, in Windows one can move the mouse pointer to the required
command, and windows will execute the command. Windows supports all the File and Directory
management commands of MS-DOS and it also supports Ms-DOS conventions in working with files
such as wild card characters.

6.8 WINDOWS PROGRAMS

In this section, programs provided in windows such as program Manager, File manager etc. are
discussed. These are vital part of windows operating environment and one must know how to work
and use these programs.

(a) Program Manager

When window program starts Program manager is the first windows displayed on the window
desktop. The only way to leave windows is to closing or exiting this program manager. Within
Program Manager there is some secondary window known as group windows, which appears as fully
opened window such one with title 'Main' or as group icons, which appears at the bottom of 'Main'
windows. A group icon is a group window, which can be minimized. Group windows contains
logically related programs, such as one group windows can contain all programs associated with
database while another may be for word processing.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

212




There are five default groups in Windows. They are;

Main group of windows contain all the system applications: File manager, Print Manager, MS-DOS
prompt, Windows Setup and PIF Editor.


Applications group consists of all the application found on your hard disk, while installing the
windows. How ever if, during installation process if you chose the Custom Setup option and chose not
to have Windows set up applications from your hard disk, the program manager will not contain an
Application group.

Accessories group is made of windows based applications for word processing (Write), drawing
(Paint), communications (Terminal), plus several other useful applications.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

213





Games group contains windows based games.

StartUp group has application that loaded when windows system starts initially. Any applications
can be added to this group. This group remains empty until, an application is added to it.


Windows provide the flexibility to install other group windows also.

Group windows can be resized, moved and it contains the icons for the program, which can be
executed. Program items can be added deleted in-group windows and they can be copied between
group windows also.

However neither the group windows can be moved outside the program manager nor the group icons.
By selecting the icons, one can run the associated program files. All the program items can be moved
between groups copied or renamed.


(b) File Manager

As the name suggests, File manager is used to manage or manipulate both disk and the disk files. It
provides visual representations of all disks and disk files in the system.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

214








As displayed in the above figure, the directory structure for the hard disk of the system and all the
files in the current directory, appear in a document windows, known as directory window. The
attributes of one or more file can be changed, by selecting them from the directory window. They can
also be moved between directories, or opened, renamed, printed, deleted or copied.

(i) Selecting File(s) and directories

- File Manager allows you to select one or more than one files at a time for copying, moving or
deleting or to perform other related task.

- To select a file or directory clicks the desired icon. Or press the TAB button to move to the list of
files, and then use the direction keys or arrow keys to select.

- To select consecutive files, select the first file, press and hold down the SHIFT key, and then click
the last file on the desired file list or group. Alternatively, select the first file, press and hold down
the SHIFT key and then use arrow keys to extend the selection to the last item in the group.

Window Title Window
Menu
Directory Icons
File and
subdirectory icons
of current
directory

Drive Icons
Drive label
Or Network
Drive

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

215
- To select or cancel selection of the non-consecutive files, press and hold CTRL key and click on
each file. Alternatively, press SHIFT and F8 key, use arrow keys to move to each file, use
SPACEBAR to select the file or to cancel already the selected file, then press SHIFT and F8
again.

- To select similar type of file, activate the Select Files option from the File menu bar. In the text
box of the dialog box specify the type of files to be selected. For example *.DOC to select all files
in the current directory that has .DOC as extension or secondary name.


IN-TEXT QUESTION 6.1

1. State True or False.

a. File Manager is used to start Windows.
b. Group windows and group icon can be moved out of Program Manager
c. File maintenance is done using File manager in windows.
d. To activate a program when windows starts, you need to add it to File manager.
e. Print manager and File Manager are available in Games windows.


6.9 WHAT YOU HAVE LEARNT

In this lesson you were introduced to the concept of windows working environment and graphical user
interface. It also discussed various features and components of windows. It explained with examples
the icons and their functions. This also discussed how to select files and directories.


6.10 TERMINAL QUESTIONS

1. Briefly discuss why Windows is popular.

2. Briefly explain about different components of windows and how to start windows.

3. How a group icon is different from individual program icon?

4. Which group programs are loaded when windows starts-up?

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

216

5. Can a DOS based application be used in Windows?

6.11 FEEDBACK TO IN-TEXT QUESTION

1. (a) False (b) False (c) True (d) False (e) False



FILE HANDLING IN WINDOWS 3.1

7.1 INTRODUCTION

Windows being a GUI, gives better flexibility and easier to use for file management. Using the File
Manager feature of Windows, one can easily copies, move, delete, rename files and also create and
remove directory. This avoids the painful task of remembering all the file management DOS
commands.

Windows can run two types of applications, standard DOS based applications and Windows based
applications. DOS based applications are standard DOS programs such as WordStar, dBase etc.
developed to run in DOS environment, and not specifically meant for windows. Whereas a windows
application is specifically developed to run under Windows environment which support GUI.

7.2 OBJECTIVES

At the end of this lesson you would be able to

- appreciate the GUI feature of windows
- understand the file and directory handling in windows
- use file manager for file handling in windows
- sort file using file size, name, type
- search and locate file(s)
- do file copy, move from floppy disk to hard disk drive and vice versa.

7.3 DIRECTORY AND FILE MANAGEMENT IN WINDOWS


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

217
Windows provides File manager for manipulating Directory and Files of a system. It is an essential
part of Windows and run like any other windows program. Main program consists the icon for File
Manager. Double clicking on the File Manger icon activates it from the Main program group. Other
way of activating it is to highlight the File Manager icon and hit the Return key

File Manager can be closed like any other windows program. File Manager can be minimized while
running some other application and expanded once the execution is over. The total amount of
diskspace, free diskspace available, the size of the selected file is shown for the currently open
directory on the status bar, which appears at the bottom of the File Manager.

(a) Drive Window

Currently selected drive is displayed as another windows within the File Manager window. The
command to resize, move or minimize is same as that of any other window. The only difference is
that it is divided in two parts; right one displays the directory structure of the currently selected drive
and the left part displays the contents (such as files, sub-directory etc.) of the currently selected
directory.






Right Pane of
window drive

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

218


(b) Directory Operations

File Manager provides the features to manage all the drives in your system and/or
connected to your system through network. It allows to copy, move or delete files
within a drive, between drives of the system and systems connected
through network. Once the drive is changed, directory and files under
the newly selected drive will be displayed in the current directory window.

(c) Changing Disk Drives

To change drive, click on the desired drive icon or press <CTRL> and the designated drive letter such
as C, D E etc. Other way of selecting a drive is to click on the Disk option of the File Manager menu
bar, and select the desired drive letter.

(d) Creating a New Directory

A new directory or sub-directory under an already existing directory can be created using File
Manager. First click on the File menu option of the File Manager. This will bring up the pull down
menu having Create Directory. Selecting this option will activate the Create


Directory dialog box with current directory path. To create a sub

Drive
windo
w
Left
Pane of
window
drive

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

219
directory under the current directory, type down the new sub-directory name in the text box. To create
a sub-directory under some other directory, type the entire path in the name text box. To finish the
entry and create the new sub-directory, click on the OK button.

(e) Changing Directory

To go to the desired directory under the currently selected drive, double click on the directory name.
This will make the selected directory as the currently active directory and all the sub-directory and
files under this directory will be displayed at the right pane of the document window.

File manager has the flexibility of displaying different groups of files in the currently selected
directory. Click on the View option of the File Manager menu bar, which will activate the pull-down
menu with option 'By File Type'. Selecting this will bring up the 'By File Type' dialog box. Use the
wild card characters to enter inn the name text box, the desired file type you want to see.

In File Manager, it can also be specified what all information for files can be displayed. In addition to
the File name, File path one can display file size, date and time it was created/or last modified etc. To
display all file information, select the VIEW option on the File Manager menu bar and activate the
option 'All File Details'.

In File Manager, sub-directory and file under the currently selected directory are displayed in
alphabetical order. However they can also be displayed in order of file type, date or file size. To
change the displays option, select the VIEW option on the menu bar and selected the desired option.
Available options are;




Sort by Name: Displays all files in alphabetical order of File name.
Sort by Type: Displays all files in alphabetical order of extension
Name
Sort by Date: Displays File in order of creation/last modification
Date.
Sort by Size: Display all files in order of File Size.

7.4 FILE OPERATIONS


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

220
File Manager provides tools such as copy, rename, move, rename for management of files within
directory, between directories and also between drives.

(a) Copying a Diskette

Like Diskcopy of DOS, windows also have the tool in File Manager for making copies of disk. The
source disk replaces the content of the target. However the target disk type and size should same as
that of source disk. If an unformatted disk is used in target drive, the target disk is formatted as that of
source disk type and size while copying the files. This copy option is very useful for making back-up
copy.

Insert the source disk into the drive and select the DISK option of the


File Manager menu bar, and activate the 'Copy Disk'. This will copy the files from the source disk into
the memory. Now select the target drive from the copy dialog box and click on OK button. This will
start the coping process from the source to target disk.

(b) Copying/Moving Directory or Files

In file Manager, one or more files or Directory can be copied or moved into different location using
two different methods; Drag-and-Drop method and Keyboard method.


(i) Drag-and-Drop Method

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

221

File Manager has the capabilities of copying or moving files and directories in more interactive and
visual ways as compared to MS-DOS. Open the source directory select the files to be copied and then
drag them in to the desired target directory, another drive icon, another directory window or to a file
list in a different directory window and drop them.

Confirm the copying operation, by clicking on the OK button of the dialog box. This will copy the
selected files in to the target drive. If the file(s) to be copied is/are already presents on the destination
directory or drive, confirm replace message by clicking on the YES button of the dialog box.






(ii) Using Keyboard

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

222

Instead of using mouse for the above operation, one can alternatively use the keyboard to select
COPY and MOVE command. As in the case of drag-and-drop method, the destination can be a
directory window, directory icon or drive icon. Click on the desired file name to be copied or use the
direction key to highlight it. Select the COPY or MOVE option from the File menu bar of File
Manager as per the requirement.

Alternatively press F8 for copy or F7 for MOVE operation to start. As in the case of drag-and-drop
method, COPY or MOVE dialog box appears on the screen. Enter the destination path or drive. If the
destination directory does not exist, it will ask whether to create a new one. To start the operation,
click on the OK button or press Enter key ().

7.5 DELETING FILES AND DIRECTORIES

File Manager provides greater flexibility in deleting files and directories. However in the case of
network drive, one cannot delete files or directories if he has not the privilege or permission of doing
so. File Manager allows to delete an entire directory including all its files and subdirectory in a single
command. However, in DOS, one first need to delete all the files and sub-directory of the desired
directory to be deleted.






AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

223










Select the file(s) or directory to be deleted (alternatively use tab to move the cursor to the desired
location and use direction keys to select the files). Activate the Delete option from the File menu bar
of File Manager and the delete dialog box appears on the window desktop. To delete the already
select files or directory, click on the OK button. To delete other files or directory, enter the file name
or path and click on the OK button.

This will activate directory delete dialog box. Click on YES button to confirm the deletion. Click on
Yes to All to delete all selected files or click on Cancel button to cancel the delete operation.

7.6 FILE RENAMING


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

224
File Manager allows changing the name of a file with a restriction that the new file name should
follow the DOS file naming conventions. The new file name should not be more than eight characters
long with an optional three characters extension or secondary name with permissible set of characters.



First select the file to be renamed, and then chose the Rename option from the File menu bar of File
manger. The Rename dialog box appears with name of the currently selected file in the From text box.
Now enter the new name for the file in the To text box and click OK button or press Enter key. This
completes the renaming process.

Note: One can use wild card characters for renaming files.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

225
7.7 SEARCHING FOR FILES AND DIRECTORIES

File Manager provides the tool to search a file, a group of files or subdirectories. This is particularly
helpful, if you know a particular file is on your disk, but you don't remember where the file exists.
Here you can conduct a search on your disk, directory to locate the file. The result is displayed in
Search Result window, which can be resized, minimized or maximized, closed the same way as other
window.



Click or select the directory to be searched and then choose Search option from the File menu.
Specify the filename, or use wildcard character (such and * or?) in the Search For text box to search

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

226
for a group of files or directories that have related file names or extensions. The Search Result
windows will contain all the files that meet the search criteria. To cancel the search operation, press
ESC key.

7.8 WORKING WITH FLOPPY DISKS

At times one need to copy files onto a floppy as backup or copy file from floppy to hard disk for
further processing of files. File manager provides tools to work with floppy disks.

(a) Formatting a Floppy

Before using a new floppy to receive data, it has to be prepared for that. File Manager format
command allows you to prepare a new/old floppy to receive data. The format command has three
options, which are optional.

Label

As the name suggests, it is a name for the formatted disk to identify it. A label or volume label should
not more than 11 characters long.

System Disk

While formatting a disk, it can be opted to make the disk a system or startup disk. System disk is used
to boot the system from a floppy drive. When opted, all the system files are copied into the specified
area called system area or boot sector of the floppy drive. System disk comes handy, in case the hard
disk is not working or one needs to bypass booting from hard disk for any reason.

Quick Format

This option is available for disk that has already been formatted. When selected, file Manager just
removes all information about directory and files from disk, making it faster as compared to standard
format procedure. However Quick Format does not check the disk for bad sectors.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

227
To format a disk or floppy using File Manager, insert the disk into the drive and select Format Disk
option from Disk menu bar. From the list of drives, select the appropriate drive letter. All the required
parameters are adjusted according to the selected drive.



Choose the option such as Label, System Disk or Quick Format. In case of Label option, specify the
volume label name for the disk. Complete the other areas of the dialog box and click on OK button.
This completes the entry and File Manager starts formatting the disk according to the specification
given.





AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

228

IN-TEXT QUESTIONS 7.1

Choose the best answer for each of the following questions.

1. Windows is a

(a) System Software
(b) Database Software
(c) GUI based Software
(d) None of the Above

2. Which are the following types of Icons used by Windows

(a) database, operating system
(b) program, document, application
(c)only program
(d) None of the above

3. Which of the following on a command button indicates a link to another dialog box

(a)/
(b)*
(c)..
(d) None of the above

4. File manager is a part of which group of Windows

Program Manager
Main
Application
None of the above

5. Which of the following groups of Windows contain all executable software found on your hard
disk.

(a) Main

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

229
(b) Print Manager
(c)Application
(d) None of the above


6. Which of the following allows all types of file manipulation such a COPY, MOVE etc.

(a) Print Manager
(b) File Manager
(c) System setup
(e) None of the above


7.9 WHAT YOU HAVE LEARNT

This lesson discussed windows's graphical user interface (GUI) in a great length. In the beginning it
discussed what is directory and file management. Then with examples it explained how to do
directory maintenance in-terms of create, delete and change directory. It also discussed how to sort
files by name, type, size and dates. Here you learned how to file operation in windows using File
manager and what is drag and drop method. At last it explained how to search for file and directory
and how to work using a floppy diskette in windows.

7.10 TERMINAL QUESTIONS

7.11 FEEDBACK TO IN-TEXT QUESTIONS

1. (c) 2. (b) 3. (c) 4. (b) 5. (c) 6. (b)



WINDOWS 95- AN INTRODUCTION

8.1 INTRODUCTION

Windows 95 is the upgraded version of Windows 3.x series with lots of new features embedded into
it. It is a complete paradigm shift from windows 3.x working environment.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

230
It is the entry point to a 32-bit operating/computing environment with less set of hardware
requirements. It has more compatibility with other software as compared to its previous version and
provides easy installation. It also runs most of the Windows 3.x and Ms-DOS programs. Windows 95
also provides flexibility to configure hardware, easy link to a network or setup a network, install and
uninstall programs automatically. It also has lots of other useful features like easy Internet access,
multitasking, and its most useful feature is long file names.

8.2 OBJECTIVES:

At the end of this lesson you would be able to

- understand the difference between Windows 3.11 and Windows95.
- able to work on Windows95
- appreciate the uses of Long file name
- appreciate the new look and feel of Windows95.

8.3 IMPROVED FEATURES OF WINDOWS 95

Graphical User Interface :

As compared to Windows 3.x, Windows 95 provides user-friendlier interface to work on. Its
improved graphical user interface makes learning and using Windows 95 more natural and easier for
all types of users. It is more powerful, customizable and efficient.

Start Button

Introduction of START button in Windows 95 made life much simpler while there is a need to access
multiple programs. It is the gateway of accessing most of the functionality available in the computer
loaded with Windows 95. Just Click on the Start button anytime to start any programs, open or find
documents, change windows settings, get Help, manage Files, maintain system, and much more.






AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

231
Taskbar

As the name suggests, the Task bar provides information and access to the entire task that has been
currently activated by Windows 95. Using this one can keep a track of what all programs have been
activated and switched between them.

Windows Explorer

Windows Explorer is more or less acts as a File Manager for Windows 95, but with lots of new
features. It is more efficient, faster and user friendly as compared to File Manager of Windows 3.x.

Using Explorer one can easily browse through all the drives and network resources available and
manage files.

Right Mouse Button

Clicking on the right mouse button activates a pop-up menu in any programs so as to help in
completing a task efficiently.

Long File Names

As the Ms-DOS convention follows, non-of the file used in DOS environment should be more than 8
characters of primary name and optional secondary name (extension) of three characters. However
Windows 95 has broken this barrier. Windows 95 supports long file names, maximum of 255
characters. It also allowed space to be used in between file name. This helps to make files and folders
(directory/subdirectory) easier to organize and find.

Shortcuts

As the name suggests, SHORTCUTS are the shortest way to access programs, files and other
resources in Windows 95. Instead of going through the structural process of accessing a program, one
can create "shortcuts" to access them. It creates links for easy access to files, programs, folders, and
more.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

232

Multitasking

Multitasking allows the user to activate and accomplish more than one task at a time. For example,
work on a document file in WORD programs, while copying file from other computer available in the
network. With Windows 95, 32-bit computing environment, the user can do more than one task a
time.





Easy Internet Access

One of the most useful and entirely new features is Windows 95 easy access to Internet. It provides
built-in Internet functionality to setup link and access Internet with less amount of Hardware and
Software requirement. It also provides connectivity software from Microsoft Network (MSN),
CompuServe, and America Online.

It also improves the efficiency of working on Internet with applications that support the latest Internet
technologies, such as ActiveX, Java, and streaming audio and video.

Software Compatibility

Windows 95 provides complete backward compatibility. It is easily compatible with applications
developed for MS-DOS and Windows 3.x environment. It also supports the latest 32-bit technology.
Most of the latest software packages are now built on Windows 95 operating environment.

Great Gaming Platform


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

233
Windows 95 support rich graphics, high quality audio and video. It also requires all most no editing of
Config.sys files so as to support these technologies. All this is possible because of Windows 95
compatibility with latest and hottest technologies like Plug and Play, AutoPlay, and built-in support
for MIDI and digital and surrounds video.

Hardware Compatibility

Windows 95 provides greater Hardware compatibility as compare to any other operating environment.
It has flexibility of supporting hardware from different vendors. Its Plug and Play functionality allows
to insert the hardware card into the computer and when the computer is turned on Windows 95
automatically recognizes and sets up the hardware.

Find Utility

Find Utility of Windows 95 allows you to do searches by partial name, last modified date, or full text.
In addition, you can save, rename, or view files from within the result pane, just like you can from
Windows Explorer.

Help

Windows 95 provides online help to accomplish a task. If the user is not sure how to perform a task,
Windows 95 Help will provide structured process how to accomplish the task. Simply right-click on
any object in the user interface (icons) and you'll get relevant descriptions about that object.


(a) System Requirements
CPU


Recommended 486/25 MHz-based system or
more
Memory Recommended a minimum of 8-MB memory

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

234
(RAM).
Hard Disk Space Available free hard disk space of 40-45 MB.
Display VGA or higher-resolution display
Operating System MS-DOS
Peripheral/ Miscellaneous Compatible pointing device


(b) Windows Desktop Icons

Icon Purpose

My Computer Provides direct access to local drives, printers,
Control panel, and the Dial-up Network utility.

Network Neighborhood Access to shared resources on the machine and
computers on local and wide area network.

Recycle Bin Provides drag and drop facilities, deletion of file from
folders in the machine and provides a second chance
to recover files deleted from the hard disk.

Inbox or Microsoft Outlook Universal in-box for all mail sources including faxes,
mail, exchange, and others.










AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

235





Fig. 8.1


























8.4 START BUTTON AND TASK BAR

Windows now features the Start button and Taskbar at the bottom of the screen. This bar contains the
Start button. Using this button, a program can be quickly started or file can be searched for. Quick
help on how to use windows can also be obtained from this task bar.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

236














Fig. 8.2























AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

237







Click on the Start to activate the Pop-up menu so as to open a program, find a file or folders (directory
or sub-directory), and change the settings for Windows95, Run a program or shut down the computer
and also to get help on windows.

If you have opened more than one program or windows, you can switch between them. All the opened
windows or program appears on the Start or the Task bar as a minimized icons. Click on the desired
icon to open the designated program. Similarly if you don't need a windows too frequently, click on
the minimized button of the windows. This will send the activated window as small icon to the task
bar.




(a) Steps to start a program

1. Click on the Start button, and then point to Programs option.

2. Select the program you want to run. If the program you want is not on the menu, point to the
folder that contains the program.

3. Click on the program icon or menu.

Once the selected program starts, a small icon appears on the taskbar. If you have opened more than
one program, click on the required program icon on the taskbar to make it currently activated
program.

If the desired program is not available on the program menu or one of its submenus, point to Find on
the Start menu, and then click Files Or Folders where the program resides. You can also use the Find
dialog box to locate the program file.


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

238
(b) Steps to open a recently used document

1 Click on the Start button
2 Select/point to Documents option.
3. Select the document you want to open, by clicking on it

Note:

All programs are not capable of adding files to Document menu. So if the desired document to be
opened is not listed or available in Document Menu, click on the Start button, and then select the Find
option. Select/Click "Files Or Folders" option, and then use the Find dialog box to locate the file.

8.5 MY COMPUTER

It allows looking at a glance to all the resource available on the machine such as floppy drive, CD-
ROM drive, Hard Disk etc. If you have network drives mapped as local drives they will also show up
here. Double clicking on a drive in the top level of my computer will open another window containing
the main folders on the select drive. Double clicking on any of the folders in the drive window will
open another window showing the contents of the folder.

Double clicking on either the Control Panel folder or the Printers folders in My Computer windows
will activate the respective windows for Control panel or Printers. Using this you can manipulate the
settings for your Computer or Printer the same way that you were accessing them from the Start
menu.








Fig.8.3





AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

239










My Computer is the quickest way of accessing all the resources available on the computer. Even this
can be used to copy, move, delete files among or between floppy and Hard Disk or network drives.











Fig 8.4














AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

240



My Computer also provides the tools to change the settings of the available resources. Select the
media such as floppy disk, hard disk drive you want to change the settings and right click on it. This
will activate a Pop-Up menu. Now select the Properties option from the pop-up menu. This action will
display the property windows with three options: General, Tools and Sharing. Using these three
options you can change the properties of the selected media.

8.6 WINDOWS EXPLORER

As the name suggests, Windows Explorer let you explore the contents of your computer and do file
management. It is the improved version of File Manager in Windows 3.1 or 3.11.












Fig. 8. 5











AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

241
To activate Windows Explorer, Click on the Start Button on the Task Bar and select Programs option.
This will activate another Pop-Up menu. Now select Windows Explorer
Option.

Windows Explorer displays on the left-hand side of the screen, all the folders on your computer in a
hierarchical order. On the right hand side of the screen, it displays all the files and folders in each
selected folder.













Fig 8.6

















AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

242




Windows Explorer is especially useful for copying and moving files. You can open the folder that
contains the file you want to move or copy, and then drag it to the folder you want to put it in.

(a) Steps to copy a file or folder

1. Go to My Computer or Windows Explorer
2. Select the file you want to copy by clicking on it.
3. Go to Edit Menu and Select/Click Copy option.
4. Open the folder or disk drive where you want to copy.
5. Again go to Edit Menu and Select/Click Paste option.

(b) Steps to move a file or folder

1. Go to My Computer or Windows Explorer
2. Select the file you want to move by clicking on it.
3. Go to Edit Menu and Select/Click Cut option.
4. Open the folder or disk drive where you want to move.
5. Again go to Edit Menu and Select/Click Paste option.



(c) Steps to delete a file or folder

1. Go to My Computer or Windows Explorer
2. Select the file or folder you want to delete by clicking on it.
3. Go to File Menu and Select/Click Delete option.

Note:

- Files or folder deleted are stored in the Recycle Bin until the Recycle Bin is emptied. Files or
folders can also be deleted by dragging file or folder icons onto the Recycle Bin icon. If SHIFT
key is pressed while dragging, the item will be deleted permanently from the computer without
being stored in the Recycle Bin.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

243

- To select more than one file or folder to copy, while pressing the CTRL key, click the items you
want to select.

(d) Steps to copy a file to a floppy disk

1. Insert the disk in the floppy disk drive.
2. Go to My Computer or Windows Explorer
3. Select the File you want to Copy, by clicking on the file.
4. Go to File menu, point to "Send To" option, and then select the drive you want to copy the file
to.

(e) Steps to create a new folder

1. Go to My Computer or Windows Explorer; open the folder in which you want to create a new
folder by double clicking on it.
2. Go to the File menu, point to New, and then click on the "Folder" option.
3. The new folder appears with a temporary name.
4. Type a name for the new folder, and then press ENTER.

Steps to change the name of a file or folder

1 Go to My Computer or Windows Explorer
2 Click on the file or folder you want to rename.
3. Go to the File menu, and Select/Click "Rename" option.
4. Type a new name for the file or Folder, and then press ENTER.

Note :

As Windows 95 supports long file name, a filename can be up to 255 characters, including spaces.
However, it cannot contain any of the following characters:
\ / : * ? " <>|



8.7 NETWORK NEIGHBORHOOD


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

244
A Network is a group of Computers connected to each other to share available resources such as
storage and printers. Network neighborhood takes the ability of My Computer and extends them one
step further, by giving you with the ability to view all of the Computers connected in workgroup or
network, and see what drives or Printers may be available for use. If you double click on one of the
Computers, any resources that Computer shares with others in the workgroup like- drives, directories
or printers will be listed




















Fig.8.7











AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

245
When connected to a network, the Network Neighborhood icon appears on the desktop. To browse
through the computers in the workgroup and the computers on the entire network, double click on the
icon Network Neighborhood.




Fig 8. 8













1.8 RECYCLE BIN

The files deleted by you are put in the Recycle Bin, a holding place for files that are no longer needed.
There you can also drag and drop files for quick deleting. They are, however, not actually removed
from the hard disk until the user "empty" the Recycle Bin.

It is a safety feature, built in to protect you against the possibility of deleting something you should
not have.



Fig. 8.9





AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

246












8.9 FIND

Using Windows 95 it is easy to locate files and folders on the computer. One way is to browse
through folders in My Computer. But if you want to find something quickly, you can use the Find
command on the Start menu.










Fig. 8.10









AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

247
Click on the Start button and select "Find" option. Now select the Option " Files or Folders". This will
activate the Find Dialog box. In the Find dialog box, type the name of the file or folder you are
looking for, and then click Find Now. You can also use wildcard character to Find files




Fig. 11













8.10 WORK WITH PROGRAMS

Windows 95 provides higher level of flexibility in terms of installing and removing programs.

To install a program from a floppy disk or CD-ROM

1. Select Control Panel from the Settings option of Start Menu
2. Double Click on the Add/Remove Programs icon.
3. Follow the instructions on your screen.

To install a program from a network

1. Click here to open the Add/Remove Programs dialog box.

2. if the Install/Uninstall tab is selected, and your computer is already connected to a network,
click Install button, and then click Next. Follow the instructions on your screen.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

248

Note

If you do not have a Network Install tab in the Add/Remove Programs dialog box, this feature has not
been enabled on your computer, your network, or both. See your system administrator.

If you are not already connected to the shared folder you want to install from, you must connect to it
by using My Computer or Windows Explorer, or type the path to it in the text box.


To remove a program from your computer

1. Select Control Panel from the Settings option of Start Menu
2. Double Click on the Add/Remove Programs icon.
3. Follow the instructions on your screen.

Note

Only programs that were designed for Windows 95 can be removed by using Add/Remove Programs.
For all other programs, check the program's documentation to determine which files should be
removed.





8.11 MS-DOS WINDOW

Windows 95 provides the flexibility of executing most of the DOS commands or DOS based program
without going out of Windows 95 GUI. To use DOS prompt;

1. Click the Start button, and then point to Programs.

2. Click/Select MS-DOS Prompt.




AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

249









Fig 8.12
















Tips

- To view the toolbar, click the MS-DOS icon in the title bar, and then click Toolbar.

- To switch between a full screen and a window, press ALT+ENTER.

- To quit MS-DOS, click or type Exit at the command prompt.




AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

250
8.12 CHANGE WINDOWS SETTINGS

Windows 95 provides tools to change the look and feel of the desktop window. Using these tools you
can change the desktop background, wallpaper and lots of other settings according to your choice.

To activate these tools, right click on the windows. This will display a menu now select the Properties
option.

You can also activate these tools from Control panel by selecting the Display icon.













Fig 8.13










Desktop Background

To change the background of the desktop


AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

251
- Right Click on the Desktop to view the Display properties.
- In the Pattern or Wallpaper list, click the pattern or wallpaper you want to use.












Fig. 8.14


















Tips

- To cover the entire screen with wallpaper image, click Tile.

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

252
- To center a wallpaper image, click Center.
- Patterns and wallpaper can be used simultaneously. However, you will not be able to see the
pattern, if Title is selected.

Similarly all other option such as Appearance, Screen Saver and Settings can be used. Using the
Settings option, one can select the number of colors, pixel type and display adapter for the system.










8.13 SHUT DOWN THE COMPUTER

Click the Start button, Click the Shut Down button, and then select the option Shut down the
Computer and click on the Yes button.











Fig. 8.15






AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

253

















Important

Do not turn off your computer until the "You can now safely turn off your computer" message
appears.
Choose the best answer for the following questions.

IN-TEXT QUESTIONS 8.1


1. Which of the following is introduced exclusively in Windows95?

(a) Control panel
(b) File manager
(c) Start button
(d) None of the above

2. What is the Windows 3.x series equivalent to Windows Explorer in Windows95?

(a) Program manager
(b) File manager

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

254
(c) Print manager
(d) None of the above

3. Answer whether the following statement is True (T) or False (F).

(a) Windows 95 supports file name of 255 characters including space in between.
(b) Windows 95 does not support Ms-DOS based application.
(c) Windows 95 is a application software.
(d) In Windows 95 desktop icons can be created, but can not be deleted.

4. Fill in the blanks

(a) Inbox in Windows 95 is used for ______________________.
(b) GUI stands for ________________________.


8.14 WHAT YOU HAVE LEARNT

This lesson introduced you to one of the most popular and widely used GUI operating system in
desktop environment. In the beginning it discussed what is GUI and its usefulness. It explained the
new features of Windows95 and hardware requirement for installation. You also learned about
various Windows 95 icons and their usability. Here we discussed how to do file management in
Windows 95, and also we learned how to change look and feel of Windows 95 desktop according to
user requirement.


8.15 TERMINAL QUESTIONS

(c) Briefly explain, how Windows95 is different from Windows 3.x series.
(d) Explain what do you understand by multitasking?
(e) What is the minimum hardware requirement for installing Windows95 software?
(f) What is the purpose of recycle bin?
(g) Explain the steps involved to shut down Windows95.

8.16 FEEDBACK TO IN-TEXT QUESTIONS

IN-TEXT QUESTIONS 8.1

AMIE NBCAFE STUDENTS FORUM

www.amie.nbcafe.in

255

1. (c) 2. (b) 3.(a) True (b) False (c) False (d) False 4. (a) Getting e-mail, (b) Graphical User
Interface.