INTRODUCTION
TO PROGRAMMING
Languages are a means of
communication. Normally people interact with each other through a language. On
the same pattern, communication with computers is carried out through a
language. This language is understood both by user and the machine. The Programming
language is the medium of communication between the man and the machine.
Programming is a set of instructions given to the computer to perform user
defined tasks.
Languages are a means of
communication. Normally people interact with each other through a language. On
the same pattern, communication with computers is carried out through a
language. This language is understood both by user and the machine. The Programming
language is the medium of communication between the man and the machine.
Programming is a set of instructions given to the computer to perform user
defined tasks.
PROBLEM
SOLVING
Problem solving by the computer involves the
following steps.
1)
Problem Definition 6) Running the program
2)
Analysis 7) Debugging
3)
Algorithm 8) Testing
4)
Flowchart 9) Documentation
5)
Coding
Problem solving by the computer involves the
following steps.
1)
Problem Definition 6) Running the program
2)
Analysis 7) Debugging
3)
Algorithm 8) Testing
4)
Flowchart 9) Documentation
5)
Coding
1] PROBLEM
DEFINITION
This is the first step in
computer problem solving. The problem solver should understand the problem
thoroughly in terms of the requirements. That is, what are the input and output
operations to be performed ? The programmer should extract from the problem
statement, a set of well-defined and precise tasks that can be carried out.
This is the first step in
computer problem solving. The problem solver should understand the problem
thoroughly in terms of the requirements. That is, what are the input and output
operations to be performed ? The programmer should extract from the problem
statement, a set of well-defined and precise tasks that can be carried out.
2] ANALYSIS
The given problem must be
analyzed before it is solved. This determines the data items, their types and
relationship. We should specify the operations (Arithmetic and logic) to be
performed on them and checking the suitability in terms of memory and execution
time.
The given problem must be
analyzed before it is solved. This determines the data items, their types and
relationship. We should specify the operations (Arithmetic and logic) to be
performed on them and checking the suitability in terms of memory and execution
time.
3] ALGORITHM
This is a problem solving
technique. It can be defined as a step by step procedure to solve a particular
problem. It consists of English like statements. Each statement must be precise
and well defined to perform a specific operation. When these statements are
carried out for a given set of conditions, they will produce the required
results. The word algorithm is derived from the famous Arabic author and
mathematician, Abu Jafar Mohammad Ibn Musa Al Khowarizmi. The last two terms of
the name termed as Algorithm.
This is a problem solving
technique. It can be defined as a step by step procedure to solve a particular
problem. It consists of English like statements. Each statement must be precise
and well defined to perform a specific operation. When these statements are
carried out for a given set of conditions, they will produce the required
results. The word algorithm is derived from the famous Arabic author and
mathematician, Abu Jafar Mohammad Ibn Musa Al Khowarizmi. The last two terms of
the name termed as Algorithm.
CHARACTERISTICS
OF ALGORITHM
Each and every algorithm is characterized by
the following five important characteristics.
1] Input : It may accept zero or more
inputs
2] Outputs : It should produce at least one output
(result)
3]
Definiteness : Each
instruction must be clear, well-defined and precise. There should not be any
ambiguity.
4]
Finiteness : It should
be a sequence of finite instructions. That is, it should end finite time at one
or more levels of complexity. It should be effective whenever trace manually
for the results.
5]
Effectiveness : This means
that operations must be simple and are carried out in a finite time at one or
more levels of complexity. It should be effective whenever traced manually for
the results.
Each and every algorithm is characterized by
the following five important characteristics.
1] Input : It may accept zero or more
inputs
2] Outputs : It should produce at least one output
(result)
3]
Definiteness : Each
instruction must be clear, well-defined and precise. There should not be any
ambiguity.
4]
Finiteness : It should
be a sequence of finite instructions. That is, it should end finite time at one
or more levels of complexity. It should be effective whenever trace manually
for the results.
5]
Effectiveness : This means
that operations must be simple and are carried out in a finite time at one or
more levels of complexity. It should be effective whenever traced manually for
the results.
ALGORITHMIC
NOTATIONS
While writing algorithms the following
notations are considered.
1)
Name of the
Algorithm : It specifies the
problem to be solved.
2)
Step number :
Identification tag of an instruction and it is an unsigned positive integer
3)
Explanatory
Comment : It follows the step
number and describes the operation.
4)
It should be written within a pair of square brackets.
5)
Termination : It specifies the end of the algorithm. It is generally a Stop statement and the
last instruction in the algorithm.
While writing algorithms the following
notations are considered.
1)
Name of the
Algorithm : It specifies the
problem to be solved.
2)
Step number :
Identification tag of an instruction and it is an unsigned positive integer
3)
Explanatory
Comment : It follows the step
number and describes the operation.
4)
It should be written within a pair of square brackets.
5)
Termination : It specifies the end of the algorithm. It is generally a Stop statement and the
last instruction in the algorithm.
Example 1
Algorithm to compute the area of circle
Algorithm to compute the area of circle
Algorithm :
Area of Circle Step 1 : Start
Step 2 : Read radius
Step 3 : [Compute the Area]
Area = 3.142 x radius x radius Step 4 : [Print the
Area]
Step 2 : Read radius
Step 3 : [Compute the Area]
Area = 3.142 x radius x radius Step 4 : [Print the
Area]
Print “Area of Circle = ”, Area Step 5 : [End
of algorithm]
Stop
Example 2
Algorithm to calculate the simple interest.
Stop
Example 2
Algorithm to calculate the simple interest.
Algorithm :
Simple Interest Step 1 : Start
Step 2 : [Read the value P, T, R]
Step 2 : [Read the value P, T, R]
Read P, T, R
Step 3 : [Compute the Simple Interest]
Step 3 : [Compute the Simple Interest]
SI = (
PxTxR) / 100
Step 4 : [Print the Simple Interest]
Print “Simple Interest= ”, SI Step 5 : [End of
algorithm]
Step 4 : [Print the Simple Interest]
Print “Simple Interest= ”, SI Step 5 : [End of
algorithm]
Stop
Example 3
Algorithm to find the largest of two numbers.
Example 3
Algorithm to find the largest of two numbers.
Algorithm :
Largest of two numbers Step 1 : Start
Step 2 : [Read the values A and B]
Step 2 : [Read the values A and B]
Read A, B
Step 3 : [Compare A and B]
Step 3 : [Compare A and B]
If (A>B)
Then
Print ‘A is largest’
Else
Print ‘B is largest’
End If
Step 6 : [End of algorithm]
Print ‘A is largest’
Else
Print ‘B is largest’
End If
Step 6 : [End of algorithm]
Stop
4] FLOWCHART
This is a chart showing a flow of
logic involved in solving a problem. This is defined for an algorithm. The
flowchart can be defined as a diagrammatic representation of an algorithm. It
is referred to as the blue print of an algorithm. It is also defined as a
visual or graphical representation of an algorithm. The flowchart is an easy
way to understand and analyze the problem. It is a useful aid for programmers
and system analysts.
Flowcharts make use of geometric figures, to
specify a particular operation. Those are
Geometrical Figure
Name
Function
Oval
Start and Stop
Parallelogram
Input and Output
Rectangle
Processing
Rhombus
Decision Making
Arrows
Connections
Circle
Continuation
Hexagon
Repetition / Looping
Example 1 : Draw
a flowchart to find area of triangle
4] FLOWCHART
This is a chart showing a flow of
logic involved in solving a problem. This is defined for an algorithm. The
flowchart can be defined as a diagrammatic representation of an algorithm. It
is referred to as the blue print of an algorithm. It is also defined as a
visual or graphical representation of an algorithm. The flowchart is an easy
way to understand and analyze the problem. It is a useful aid for programmers
and system analysts.
Flowcharts make use of geometric figures, to
specify a particular operation. Those are
Geometrical Figure |
Name |
Function |
|
Oval |
Start and Stop |
|
Parallelogram |
Input and Output |
|
Rectangle |
Processing |
|
Rhombus |
Decision Making |
|
Arrows |
Connections |
|
Circle |
Continuation |
|
Hexagon |
Repetition / Looping |
Example 1 : Draw
a flowchart to find area of triangle
Example 2 : Draw a flowchart to find
the Simple Interest.
5] CODING
The complete structure of a
problem to be solved by a computer is called a program. The computer does not
process an algorithm or a flowchart, but executes the program. A program is a
set of instructions to solve a particular problem by the computer and the
actual process of writing a program is called coding. Program are written using
programming languages and are fed to the computer.
6] RUNNING
THE PROGRAM :
The program can be run(executed)
in the central processing unit. This phase of problem solving by a computer involves three steps.
1)
Understand the instructions
2)
Store data and instructions
3)
Perform computations
The user prepares his/her program
and makes it ready for execution. All the instructions stored in the RAM, must
be fetched one by one to the ALU to perform corresponding operations. This is
called the fetch/execute cycle. The processed data is stored again in the RAM.
Finally, they are transferred to the output devices.
7] DEBUGGING
The process of detecting and correcting
errors(mistakes) in the program is known as debugging. There is a program
called debugger that takes object program as input and executes it and helps in
eliminating the mistakes that occur in the source program.
Generally, programmers commit three types of
errors. These are,
1)
Syntax Errors
2)
Logical Errors
3)
Run-time Errors
SYNTAX
ERRORS
This type of errors is the result
of violation of programming rules. On encountering these errors a computer
displays error message specifying the line number. It is easy to debug these
errors. For Example: If the statement of C is typed without the semicolon at
the end, then there will be an error because of a missing semicolon.
LOGICAL
ERRORS
Logical errors occur during
coding process. When the programmer codes his problem, he must take care of
correct operations to be performed. The program will be executed but produce
some unwanted results. It is very difficult to debug such errors, because the
computer does not display them. We can eliminate such errors by tracing it and
running for sample data.
RUN-TIME
ERRORS
These errors occur when we
attempt to run an ambiguous instructions. For example, an infinite loop in
program sequence which causes no output. These are also occur due to device
errors, improper sequencing of constructs, errors in system software, incorrect
data input etc., The computer will print error message. Some of run-time errors
are:
1)
Divide by zero
2)
Null pointer assignment
3)
Data overflow
8] TESTING
The process of executing the
program to test the correctness of the outputs of the problem is called
testing. The program is tested by executing with different sets of data.
Logical errors are the outcome of this process.
9]
DOCUMENTATIONS
While writing programs, it is
good programming practice to make a brief explanatory note on the program or
program segments. This explanatory note is called a comment. It explains how
the program works and how to interact with it. Thus, it helps other programmers
to understand the program.
There are two types of documentation. They
are,
1)
Internal documentation
2)
External documentation
INTERNAL
DOCUMENTATION
This documentation is a comment
statement within a program. It describes the function of the program or program
segments. These statements are not translated to machine language. Translators
simply discard these statements during the translation process.
EXTERNAL
DOCUMENTATION
This documentation is an
executable statement in a program. It may be a message to the user to respond
to the program requirement. This is accomplished using output statements. It
makes the program more attractive and interactive. Some sample examples are
given below:
Print, “Input numbers one by one” Print,
“Input the order of the matrix” Print, “Do you what to continue ?”
No comments:
Post a Comment