0% found this document useful (0 votes)
16 views

Chap - 1 Pythonn

This document is an introduction to programming chapter that discusses key topics like what programming is, what a program is, problem solving steps, different number systems like binary, decimal, octal and hexadecimal used by computers to represent data, and why programming languages were created. It explains that a program is a set of instructions written in a programming language and translated into machine language for computers to solve problems. It also discusses the steps of understanding the problem, planning the solution, writing algorithms and flowcharts, and then programming. Finally, it provides examples of different number systems like binary represented as 1s and 0s, decimal as our normal numbering, octal using eight symbols and hexadecimal using sixteen symbols.

Uploaded by

Parth Khurana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Chap - 1 Pythonn

This document is an introduction to programming chapter that discusses key topics like what programming is, what a program is, problem solving steps, different number systems like binary, decimal, octal and hexadecimal used by computers to represent data, and why programming languages were created. It explains that a program is a set of instructions written in a programming language and translated into machine language for computers to solve problems. It also discusses the steps of understanding the problem, planning the solution, writing algorithms and flowcharts, and then programming. Finally, it provides examples of different number systems like binary represented as 1s and 0s, decimal as our normal numbering, octal using eight symbols and hexadecimal using sixteen symbols.

Uploaded by

Parth Khurana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Introduction to Programming 1-1

Chapter
1

Introduction to Programming
Key Topics
1.1. Introduction
1.1. Introduction
1.2. What is a Program ?
It is very important to learn the basics of programming.
1.3. Problem Solving Steps Programming is the process of designing, writing, testing,
1.4. What is the Need of Programming debugging and maintaining the source code. The purpose of
Languages?
1.5. Representation of Data programming is to create a set of instructions that computers can
1.5.1. Number Systems understand to perform a specific task. The process of writing
1.5.2. Decimal (Base 10) Number
System source code often requires expertise in algorithms, flowcharts
1.5.3. Binary (Base 2) Number System and logic. After learning the basics of programming, students
1.5.4. Octal (Base 8) Number System
1.5.5. Hexadecimal (Base 16) Number can feel easy while developing their own programs.
System
1.6. Problem Solving 1.2. What is a Program ?
1.7. Techniques and tools for problems
solving A program is a set of instructions, generally written in some
1.7.1. Algorithms
1.7.1.1 Advantage of writing
programming language which are translated using compilers or
algorithms interpreter into machine language so that computer can
1.7.1.2. D i s a d v a n t a g e s / understand these instructions to solve the problems for you. The
drawbacks of writing
algorithm choice of programming language depends on nature of problem.
1.7.2. Pseudocode codes (structured A problem is an obstacle, which makes it difficult to achieve a
english)
1.7.2.1. Advantage of Using desired goal, objective. It is advised to write an algorithm and
Psedocode flow chart before writing a program.
1.7.2.2. Limitations of using
psedocode
1.7.3. Flowchart 1.3. Problem Solving Steps
1.7.3.1. Guidelines for drawing
a flowchart Learning to programming is about learning to solve the
1.7.3.2. Advantages of using problems. First step in programming is to understand the problem
flowcharts
1.7.3.3. Limitations of using
after successfully understanding the problem we have to plan
flowcharts how to fix the problem i.e understanding methods to solve the
1.8. Program development life cycle problem first then writing algorithms, after that drawing flow chart
and then finally planning to go for programming.
1-2 Introduction to Programming

1.4. What is the Need of Programming Languages?


As we all know, if we know some natural languages like English, Hindi, Punjabi or some other
language for communication can happen if and only if others also know the same language. In the
same fashion computer can understand only machine language also called Low Level Language or
Machine Level Language. The character set of machine language has only two characters in 0 and
1. As High Level Languages are English like languages and human beings can understand it easily
compared to the Low Level Languages so programming languages like BASIC, JAVA, C and C++
are easy to understand which provides better interface between humans and computer.

1.5. Representation of Data


Data representation refers to the internal method used to represent various types of data
stored on a computer. Computers use different types of numeric codes to represent various forms of
data, such as text, number, graphics and sound.

1.5.1. Number Systems


Human beings use decimal (base 10) number systems for counting and measurements (probably
because decimal system uses 10 distinct digits (0-9). Computers uses binary (base 2) number system,
as they are made from binary digital components (known as transistors), operating in two states - on
and off. In computing, we also use hexadecimal (base 16) or octal (base 8) number systems as a
compact form for representing binary numbers.

1.5.2. Decimal (Base 10) Number System


Decimal number system has ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, called digits. The Base
or radix of the decimal number is 10, as it includes total 10 decimal digits from 0 to 9.
Example (43)10, (75)10, (823)10

1.5.3. Binary (Base 2) Number System


Binary number system has two symbols: 0 and 1, called bits. It is also a positional notation, for
example,
(10110)2 = 1×2^4 + 0×2^3 + 1×2^2 + 1×2^1 + 0×2^0
Binary number is formed with the combination of two digits 0 and 1. As binary includes two
values, therefore, the base of this is 2.
A binary digit is called a bit. Eight bits is called a byte (why 8-bit unit? probably because 8=23).

1.5.4. Octal (Base 8) Number System


Octal number system has eight symbols: 0, 1, 2, 3, 4, 5, 6, and 7. Any octal number includes only
8 digits. As it includes total 8 digits, therefore the base of this is 8.
e.g. (56)8, (76)8 are octal numbers.

1.5.5. Hexadecimal (Base 16) Number System


Hexadecimal number system uses 16 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F,
called hex digits. It is a positional notation, for example,
Introduction to Programming 1-3
A3EH = 10×16^2 + 3×16^1 + 14×16^0
We shall denote a hexadecimal number (in short, hex) with a suffix H. Some programming
languages denote hex numbers with prefix 0x (e.g., 0x1A3C5F), or prefix x with hex digit quoted
(e.g., x'C3A4D98B').
Each hexadecimal digit is also called a hex digit. Most programming languages accept lowercase
'a' to 'f' as well as uppercase 'A' to 'F'.
A computer uses binary system in their internal operations, as they are built from binary digital
electronic components. However, writing or reading a long sequence of binary bits is cumbersome
and error-prone. Hexadecimal system is used as a compact form or shorthand for binary bits. Each
hex digit is equivalent to 4 binary bits.
Modern computers are built up with transistors. Whenever an electric current pass into the
transistors, either an ON or OFF status will be established. Therefore, the computer can only recognize
two numbers: 0 for OFF, and 1 for ON, which can be referred to as a BIT. There is nothing in
between Bit 0 and Bit 1 (eg Bit 0.5 doesn't exist). Hence computers can be said to be discrete
machines. The number system consisting only of two numbers is called Binary System. And to
distinguish the different numbering systems, the numbers human use, ie 1,2,3,4..., will be called
Decimals (since they are based 10 numbers) from now on.
Now the question is how, can computer understand numbers larger than 1? The answer is
simple, 2 is simply 1+1, (like 10 = 9+1 for human) the numbers are added and overflow digit is carred
over to the left position. So (decimal) 2 is represented in Binary as 10. To further illustrate the
relationship, I have listed the numbers 1 to 9 in both systems for comparison:

Decimal Binary Octal Hexa Decimal


Base 10 Base 2 Base 8 Base 16

0 0000 0000 00 0
1 0000 0001 01 1
2 0000 0010 02 2
3 0000 0011 03 3
4 0000 0100 04 4
5 0000 0101 05 5
6 0000 0110 06 6
7 0000 0111 07 7
8 0000 1000 10 8
9 0000 1001 11 9
10 0000 1010 12 A
11 0000 1011 13 B
1-4 Introduction to Programming

12 0000 1100 14 C
13 0000 1101 15 D
14 0000 1110 16 E
15 0000 1111 17 F
16 0001 0000 20 10
17 0001 0001 21 11
18 0001 0010 22 12

You may ask why I always put 8 binary digits there. Well, the smallest unit in the computer's
memory to store data is called a BYTE, which consists of 8 BITS. One Byte allows upto 256
different combinations of data representation (28= 256). What happens when we have numbers
greater than 256? The computer simply uses more Bytes to hold the value, 2 Bytes can hold values
upto 65536 (216) and so forth.

1.6. Problem Solving


Problem solving is the process of working through details of a problem to reach a solution.
Problem solving may include mathematical or systematic operations and can be a gauge of an
individual's critical thinking skills. Much of that confidence comes from having a good process to use
when approaching a problem. With one, you can solve problems quickly and effectively. Without
one, your solutions may be ineffective, or you'll get stuck and do nothing, with sometimes painful
consequences.
There are four basic steps in solving a problem:
1. Defining the Problem : First step is you have to understand the problem in detail. Combining
problems that are valuable to solve, with defining exactly what you are trying to solve, can
drastically improve the effectiveness of the problem solving process. The secret to defining the
problem is really about attitude. Try to see every problem as an opportunity.
2. Analyze and Generating Alternatives : If the desired result is not obtained, then chose the
alternate method to resolve the problem. Once the individual has decided the "what should be"
model, this target standard becomes the basis for developing a road map for investigating
alternatives.
3. Evaluating and selecting alternatives : Once the problem is properly analyzed and a
successful method is formulated then select the best solution and carry out your plans.
4. Implementing solutions : Implementation is a way of minimizing resistance to subsequent
changes.

1.7. Techniques and tools for problems solving


We can solve problems by using various techniques and tools. The various tools used to solve
the problem areas under:
Introduction to Programming 1-5
(1) Algorithm (Simple English)
(2) Pseudocode (Structured English),
(3) Flow Charts
(4) A real programming language.

1.7.1. Algorithms
A sequential solution of any program that is written in human language is called algorithm.
Algorithm is first step of the solution process. After the analysis of problem, programmers write the
algorithm of that problem. Step by step procedure designed to perform an operation, which (like a
map or flowchart) will lead to the sought result if followed correctly. Algorithms have a definite
beginning and a definite end, and a finite number of steps.
Algorithms resemble recipes. Recipes tell you how to accomplish a task by performing a
number of steps. For example, to bake a cake, the steps are: preheat the oven; mix flour, sugar, and
eggs thoroughly; pour into a baking pan, and so on.
Notice that the algorithm is described as a series of logical steps in a language that are easily
understood. For a computer to actually use these instructions, they need to be written in a language
that a computer can understand, known as a programming language.
Example of Algorithms:
Write an algorithm to find out whether the given no is even or odd.
Step1 : Start
Step 2 : Input Number
Step 3 : Get the remainder by dividing the number with 2.
Step 4 : If the remainder = 0 then
Step 5 : print Number is even
Step 6 : else
Step 7 : print Number is odd
Step 8 : Stop

1.7.1.1 Advantage of writing algorithms


• Effective communication : Algorithm is written using English like language; algorithm is a
better way of communicating the logic to the concerned people.
• Effective Analysis : with the help of algorithm, problems can be analyzed effectively. There
can be number of algorithms for solving a given problem.
• Proper Documentation : The selected algorithm has to be documented. The algorithm serves
as a good documentation which is required to identify the logical errors.
• Easy and Efficient Coding : The algorithm acts as blueprint during program development
• Program Debugging : Debugging is nothing but identifying the logical errors in an algorithm
/program. Algorithms help in debugging so that we can identify the logical errors easily.
• Program maintenance : Maintaining the software becomes much easier.
1-6 Introduction to Programming
1.7.1.2. Disadvantages/drawbacks of writing algorithm
• Complex Logic : For complicated logics, the flowcharts becomes complex.
• Alteratations and Modifications : If there is a change in the logic, the flowchart has to be
completely rewritten and requires lot of time.
• Reproduction : In case of any problem, reproduction of flowchart becomes a problem since
the flowchart symbols cannot be typed

1.7.2. Pseudocode codes (structured english)


Pseudocode is a kind of "Structured English" for describing algorithms. Pseudocode is not an
actual programming language. It allows the designer to focus on the logic of the algorithm without
being distracted by details of language syntax. At the same time, the pseudocode needs to be
completed. It describes the entire logic of the algorithm so that implementation becomes a rote
mechanical task of translating line by line into source code. It uses short phrases to write code for
programs before you actually create it in a specific language. Once you know what the program is
about and how it will function, then you can use pseudocode to create statements to achieve the
required results for your program. Pseudocode is another programming analysis tool that is used for
planning a program.
Pseudocode makes creating programs easier. Programs can be complex and long; preparation
is the key. Flowcharts were used to map out programs before writing one line of code in a language.
However, they were difficult to modify and with the advancement of programming languages, it was
difficult to display all parts of a program with a flowchart. It is challenging to find a mistake without
understanding the complete flow of a program. That is where pseudocode becomes more appealing.
To use pseudocode, all you do is write what you want your program to say in English. Pseudocode
allows you to translate your statements into any language because there are no special commands
and it is not standardized. Writing out programs before you code can enable you to better organize
and see where you may have left out needed parts in your programs. All you have to do is write it
out in your own words in short statements. Let's look at same examples as in case of writing
algorithm.
Start Program
Take two variable A and Rem
Enter input numbers A
Rem = A mod 2
If Rem =0 then
Print A is even
Else
Print A is odd
End Program
Structured English Pseudocode is a notation for representing six specific structured programming
constructs: SEQUENCE, WHILE, IF-THEN-ELSE, REPEAT-UNTIL, FOR, and CASE.
Introduction to Programming 1-7

INPUT Wait for or accept data from keyboard


 Equals
+-*/ Plus, Minus, Multiply, Divide
DISPLAY Show on screen
READ Get data from disc
WRITE Put data onto disc
IF…THEN ENDIF Do one or more instructions if the condition is met
IF…THEN ELSE Do one alternative or the other depending on whether or not the
ENDIF condition is met
REPEAT UNTIL Repeat one or more instructions until sufficient repetitions have
occurred. (Check at end)
WHILE…DO Repeat instructions until sufficient repetitions have occurred.
ENDWHILE (Check at start)

Sequence : Sequential control is indicated by writing one action after another, each action on
a line by itself, and all actions aligned with the same indent. The actions are performed in the
sequence (top to bottom) in which they are written.
Example (non-computer)
Brush teeth
Wash face
Comb hair
Smile in mirror
IF-THEN-ELSE
Binary choice on a given Boolean condition is indicated by the use of four keywords: IF,
THEN, ELSE, and ENDIF. The general form is:
IF condition THEN
sequence 1
ELSE
sequence 2
ENDIF
WHILE
The WHILE construct is used to specify a loop with a test at the top. The beginning and ending
of the loop are indicated by two keywords WHILE and ENDWHILE. The general form is:
WHILE condition
sequence
ENDWHILE
1-8 Introduction to Programming
The loop is entered only if the condition is true. The "sequence" is performed for each iteration.
At the conclusion of each iteration, the condition is evaluated and the loop continues for as long as
the condition is true.
CASE
A CASE construct indicates a multiway branch based on conditions that are mutually exclusive.
Four keywords, CASE, OF, OTHERS, and ENDCASE, and conditions are used to indicate the
various alternatives. The general form is:
CASE expression OF
condition 1 : sequence 1
condition 2 : sequence 2
...
condition n : sequence n
OTHERS:
default sequence
ENDCASE
The OTHERS clause with its default sequence is optional.
REPEAT-UNTIL
This loop is similar to the WHILE loop except that the test is performed at the bottom of the
loop instead of at the top. Two keywords, REPEAT and UNTIL are used. The general form is:
REPEAT
sequence
UNTIL condition
The "sequence" in this type of loop is always performed at least once, because the test is
peformed after the sequence is executed. At the conclusion of each iteration, the condition is evaluated,
and the loop repeats if the condition is false. The loop terminates when the condition becomes true.
FOR
This loop is a specialized construct for iterating a specific number of times, often called a
"counting" loop. Two keywords, FOR and ENDFOR are used. The general form is:
FOR iteration bounds
sequence
ENDFOR
In cases where the loop constraints can be obviously inferred, it is best to describe the loop
using problem domain vocabulary.

1.7.2.1. Advantage of Using Psedocode


Following are some advantages of using psedocode.
1. Converting a pseudocode to programming language is much easier than converting a flowchart.
This provides a handy reference during coding.
2. Any logical person can write pseudocode, even with no coding skills.
3. Modification in pseudocode is much easier than modification in flow charts.
Introduction to Programming 1-9
1.7.2.2. Limitations of using psedocode
1. While pseudocode is easy to read, it does not provide as good a map for the programmer as a
flowchart does. It does not include the full logic of the proposed code.
2. The lack of standards is probably the main disadvantage of pseudocode. Different people uses
different rules for writing pseudocode, hence communication becomes complex.

1.7.3. Flowchart
A flowchart is a diagram that represents a process or algorithm. The steps are represented by
a series of boxes or other specialized symbols, then connected with arrows. Flowcharts are ideal for
communicating a step-by-step process to others. 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. 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.
Before writing a program, the programmer draws a plan that involves the various steps that are
to be executed. What are the steps and what is the order in which they will be executed is very
important. By making a strategy before making a program, it becomes very easier to make programs.
These are two design approaches, which can be explained as:
You can imagine a tree like structure, in which when you are following top-down appoarch you
move from root node to leaf node and when you follow bottom-up approach, you follow leaf node
to root node.
In a top-down implementation, the implementation starts from the top of the hierarchy and
proceeds to the lower levels. First the main module is implemented, then its subordinates are
implemented, and their subordinates, and so on.
In a bottom-up implementation, the process is the reverse. The development starts with implementing
the modules at the bottom of the hierarchy and proceeds through the higher levels until it reaches the
top.
Top-down and bottom-up implementation should not be confused with top-down and bottom -
up design. When we precede top-down, for testing a set of modules at the top of the hierarchy, stubs
will have to be written for the lower level modules that the set of modules under testing invoke. On
the other hand, when we precede bottom-up, all modules that are lower in the hierarchy have been
developed and driver modules are needed to invoke these modules under testing.
Top-down versus bottom-up is also a pertinent issue when the design is not detailed enough. In
such cases, some of the design decisions have to be made during development.

1.7.3.1. 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 below.
1-10 Introduction to Programming

Start or end of the program

Computational steps or processing function of a program

Input or output operation

Decision making and branching

Connector or joining of two parts of program on the same page.

Off-page connector

Magnetic Tape

Magnetic Disk

Flow lines

Subroutine Symbol

Display

Figure 1.1 : Flow Chart Symbols

1.7.3.2. Advantages of using flowcharts


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.
Introduction to Programming 1-11
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

1.7.3.3. 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.
Example 1 : Draw a flowchart to check whether number a number is odd or even.

START

Input num

Is True
num%2=0

Number is even
False

Number is odd

STOP

Figure 1.2
1-12 Introduction to Programming
Example 2 : Draw a flow chart to find greatest among three numbers A,B and C.

START

Input A,B,C

False Is True
A>B

print B print A

STOP

Figure 1.3
Example 3 : Draw a flow chart to find greatest among three numbers A,B and C.

START

Input A,B,C

True False True False


Is Is Is
B>C A>B A>B

print B
print C print B print A

STOP

Figure 1.4
Introduction to Programming 1-13
Example 4 : Draw a flow chart to find sum of First 10 Natural numbers

Figure 1.5
Example 5 : Draw a flow chart to find sum of First 10 Odd numbers

False

True

Figure 1.6
1-14 Introduction to Programming
Example 6 : Draw a flowchart for computing factorial of a number num (num!)
Where num! = 1 ´ 2 ´ 3 ´ …… num .

True

False

Figure 1.6
Input : num = 4
Output : fact = 24
Introduction to Programming 1-15

1.8. Program development life cycle


The process of developing software, according to the desired needs of a user, by following a
basic set of interrelated procedures is known as Program Development Life Cycle. Most of these
activities overlap and are dependent on previous
activity in the sense that output of previous activity
acts like input to next activity. That's why these
activities have to be performed in linear and fixed
order only. The basic set of procedures that are
followed by various organizations in their program
development methods are as follows:
1. PROBLEM DEFINITION
2. PROGRAM DESIGN
3. CODING
4. DEBUGGING
5. TESTING
6. DOCUMENTATION
7. MAINTENANCE Figure 1.7
1. Problem Definition : This stage is the formal definition of the task. It includes the specification
of inputs, outputs, processing requirements, any business level constraints as decided by the client
etc. This step is very crucial for the completion of a satisfactory program. It is impossible to solve a
problem by using a computer, without a clear understanding and identification of the problem, it is
not advisable, because, inadequate identification and understanding of the problem definitely leads
to poor performance of the solution. It may also leave some bugs in the program that may be very
difficult to identify and rectify later on. This step is the process of becoming familiar with the
problem. If he does not spend enough time initially, he may find that his well written program may
fail to solve the real problem.
This step includes the reviewing of the design document that was prepared for the program, as
well as any system wide information that would be helpful. The process ends when all the
programmer's questions have been resolved and the requirements of the program are understood.
Understanding the purpose of a program usually involves understanding of Inputs, Processing, Outputs.
It means program design must clear the programmer about various Inputs, various processing and
outputs involved. Input describes what type of input will be given, processing describes what type of
processing will be required to perform on input to convert it into outputs and outputs describe what
output is exactly required by the client.
2. Program Design : Once the problem has been identified, the next stage is the program
design.. For this, instructions have to be given to a computer in an unambiguous way. A computer is
both fast and versatile, but it is dependent on the programmer in the sense that it requires the
meticulous specification of what actions it should take. For the user, there is seldom an opportunity
to allow the computer to make an undirected decision. Therefore the programmer must decide, prior
to writing his program, exactly which steps the computer should take to solve an identified problem,
1-16 Introduction to Programming
how many and what inputs will be given and in which form, which methods or techniques should be
used. First, it must be clear to the programmer how the problem is to be solved. Only then he can
instruct the computer about how to solve the problem. To clearly understand the process of solving
a problem, many tools are available to the programmer. These tools are called program design tools,
and involves algorithm, flowchart, decision tables etc. The techniques that are useful in program
design include:
Modular Programming : Method in which long programs are divided into smaller programs
or modulates that can be designed, coded and debugged separately with a minimum amount of
interaction
Top Down design : A method in which the overall task is first defined in terms of generalised
sub-tasks that, in turn, are subsequently further defined. The process continues downward until the
sub-tasks are defined in a form suitable for execution by the computer
Structured Programming : A method in which programs are written according to specifically
defined forms; that is only certain kinds of program logic are allowed although the forms allowed
may be nested within one another to handle complex situations.
The software designer can off course use a combination of techniques. Flowcharting, top
down design, structured programming and modular programming are not mutually exclusive.
3. Coding : The third step is the process of transforming the program logic design documents
into a computer language format. This stage translates the program design into computer instructions.
These instructions are the actual program or the software product. During this step the programmer
eliminates all the syntax and formal errors from the program and all logic errors are detected and
resolved during this process. This step is walk through has been held.
4. Debugging : This stage is the discovery and correction of programming errors. Few programs
run correctly the first time, so debugging is an important and time consuming stage of software
development. Programming theorists often refer to program debugging and testing as verification
and validation, respectively. Verification ensures that the program does what the programmer intends
to do. Validation ensures that the program gives the correct results for a set of test data. The tools
that can be used to debug programs are given below:
• Simulators.
• Logic Analysers.
• Breakpoints.
• Trace routines.
• Memory Dumps.
• Software Interrupts.
5. Testing : This stage is the validation of the program. Testing ensures that the program
performs correctly the required tasks. Program testing and program debugging are closely related.
Testing is essentially a later stage of debugging in which the program is validated by trying it on a
suitable set of cases.
Program testing is, however, more than a simple matter of exercising the program a few times.
Exhaustive testing of all possible cases is the best alternative, but this processes is usually impractical.
Introduction to Programming 1-17
Formal validation methods exist, but are only applicable to very simple programs. Thus, program
testing requires a choice of test cases. Among the rules that can aid in program testing are the
following:
• Make the test plan part of the program design.
• Check all trivial and special cases.
• Select test data on a random basis.
• Plan and document software testing just like hardware testing.
• Use the maximum and minimum values of all variables as test data.
• Use statistical methods in planning and evaluating complex tasks. There are two goals in
preparing a test plan.
Firstly, a properly detailed test plan demonstrates that the program specifications are understood
completely. Second, the test plan is used during the program testing to prove the correctness of the
program. During this step a general approach to the testing of the program is prepared and
documented, indicating the number of tests needed and the purpose of each test.
6. Maintenance : This stage is the updating and correcting of the program to account for
changing conditions or field experience. Proper testing and documentation should significantly reduce
the frequency and extent of required maintenance. Unlike student programs that used for a long
time. Changes may occur due to:
• Newly discovered bugs.
• Specification changes.
• Specification expansion.
• New equipment.
The costs involved in program maintenance are usually grossly underestimated by most
programmers. It has been studied that in a typical programming environment, over 50% of the time
is spent on maintaining the existing programs. So, it becomes really necessary to reduce the costs
and the time spent on maintenance. This can be done by the use of the following steps:
• Clarity and readability of code.
• Portability and generality.
• Structured code.
• Modularity.
• Debugging and testing.
• Documentation.

Exercise
Q.1. What is an algorithm and how it helps in programming?
Q.2. What is the difference between Machine Level Language and High Level Language ?
Q.3. What is the role of programming in software development?
1-18 Introduction to Programming
Q.4. How documentation helps us to develop a software?
Q.5. What do you means by pseudo codes? What are the advantages of it?
Q.6. How high level languages improves the programming?
Q.7. What does you means by languages? Explain various types of languages?
Q.8. What is flowchart? Explain the various symbols used in flowchart with example?
Q.9. Explain the various tools used to represent program logic?
Q.10. What does you means by translators? Explain various types of translators?
Q.11. What are the various approaches to develop a software?
Q.12. Discuss the various tools which are used to represent the program logic?

You might also like