How to develop a program:::
Program development is the process of creating application programs. The program
development life cycle (PDLC) is the process that contains the six phases of program development:
analyzing, designing, coding, debugging, testing, and documentation and maintaining
application software.It is an iterative process.
The following are six steps in the Program Development Life Cycle:
1. Analyze the problem. The computer user must figure out the problem, need to completely
comprehend problem, and then has to decide how to resolve the problem.
2. Design the program. A flow chart is important to use during this step of the PDLC. This is a visual
diagram of the flow containing the program. This step will help you break down the problem. we
can also use algorithms.
3. Code the program. This is using the language of programming to write the lines of code. The code
is called the listing or the source code. The computer user will run an object code for this step.
4. Debug the program. The computer user must debug. This is the process of finding the "bugs" on
the computer and fix them.
5. Testing the program(Formalize the solution) One must run the program to ensure no runtime and
logic(semantic) errors.
6. Document and maintain the program. This step is the final step of gathering everything together.
Internal documentation is involved in this step because it explains the reason one might have made
a change in the program or how to write a program. Later given to the user, during a long run, it
might encounter issues that are to be resolved by the developer.
Algorithm:
An algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain
order to get the desired output. Algorithms are generally created independent of underlying languages,
i.e. an algorithm can be implemented in more than one programming language.
There are no well-defined standards for writing algorithms. Algorithms are never written to support a
particular programming code.
characteristics of an Algorithm
An algorithm has the following characteristics:
Input: An algorithm requires some input values. An algorithm can be given a value other than 0 as
input.
Output: At the end of an algorithm, you will have one or more outcomes.
Unambiguity(definiteness): A perfect algorithm is defined as unambiguous, which means that its
instructions should be clear and straightforward.
Finiteness: An algorithm must be finite. Finiteness in this context means that the algorithm should
have a limited number of instructions, i.e., the instructions should be countable.
Effectiveness: Because each instruction in an algorithm affects the overall process, it should be
adequate. Every step must be basic and has to essential.
Language independence: An algorithm must be language-independent, which means that its
instructions can be implemented in any language and produce the same results.
Advantages and disadvantages of an Algorithm
Designing an algorithm has following advantages :
Effective Communication: Since algorithm is written in English like language, it is simple
to understand step-by-step solution of the problems.
Easy Debugging: Well-designed algorithm makes debugging easy so that we can identify
logical error in the program.
Easy and Efficient Coding: An algorithm acts as a blueprint of a program and helps during
program development.
Independent of Programming Language: An algorithm is independent of programming
languages and can be easily coded using any high level language.
An algorithm has following disadvantages :
Developing algorithm for complex problems would be time consuming and difficult to
understand.
Understanding complex logic through algorithms can be very difficult.
Now, use an example to learn how to write algorithms.
Problem 1: Create an algorithm that multiplies two numbers and displays the output.
Step 1 − Start
Step 2 − declare three integers x, y & z
Step 3 − define values of x & y
Step 4 − multiply values of x & y
Step 5 − store result of step 4 to z
Step 6 − print z
Step 7 − Stop
Problem 2: Create an algorithm that finds an area of a circle for a given radius and displays the output.
Step 1 − Start
Step 2 − declare two variables radius and area
Step 3 − define the value for the radius
Step 4 – using the formula pi*r*r calculate area (note :: pi=3.147)
Step 5 − store the result of step 4 to the area
Step 6 − print the area
Step 7 − Stop
Problem 3: Create an algorithm that finds whether the given geometric shape is square or rectangle then
find its area and perimeter and display the output.
Step 1 − Start
Step 2 − declare four variables length, breadth, area, and perimeter
Step 3 − define the value for length and breadth
Step 4 – if length==breadth then it is square goto step 5 else it is a rectangle goto step
6
Step 5 – using the formula 4*length for perimeter and length*length for the area,
calculate the perimeter and area of a square, go to step 7
Step 6 – using the formula 2*(length+breadth) for perimeter and length*breadth for
the area, calculate the perimeter and area of a rectangle, go to step 7
Step 7 − store the result of step 5 or step 6 in the perimeter and area depending on the
decision
Step 8 – print the perimeter and area
Step 9 – Stop
Problem 4: Create an algorithm that finds the sum of the first n natural numbers and displays the output.
Step 1 − Start
Step 2 – Declare variables n, sum and i
Step 3 – Define variable n, sum =0 and i=1
Step 4 –Repeat step 4 to 6 until i <= n
Step 5 –Update sum as sum = sum + i
Step 6 –Increment i
Step 7 –Print sum
Step 8 – Stop
Exercise::
Problem 5: Create an algorithm that finds the largest among two numbers and displays the output.
Problem 6: Create an algorithm that finds an average of 5 numbers and displays the output.
Problem 7: Create an algorithm that finds the roots of the quadratic equation ax2 + bx + c = 0 and
displays the output.
Problem 8: Create an algorithm that interchange the value of two numbers and displays the output.
Flowchart :
A flowchart is a diagrammatic representation of sequence of logical steps of a program.
Flowcharts use simple geometric shapes to depict processes and arrows to show relationships and
process/data flow.
Flowchart Symbols
Here is a chart for some of the common symbols used in drawing flowcharts.
Symbol Symbol Name Purpose
Used at the beginning and end of the algorithm to show
Start/Stop
start and end of the program.
Process Indicates processes like mathematical operations.
Input/ Output Used for denoting program inputs and outputs.
Stands for decision statements in a program, where
Decision answer is usually Yes or No.
Shows relationships between different shapes.
Arrow
Connects two or more parts of a flowchart, which are on
On-page Connector
the same page.
Connects two parts of a flowchart which are spread over
Off-page Connector
different pages.
Guidelines for Developing Flowcharts
These are some points to keep in mind while developing a flowchart −
Flowchart can have only one start and one stop symbol
On-page connectors are referenced using numbers
Off-page connectors are referenced using alphabets
General flow of processes is top to bottom or left to right
Arrows should not cross each other
Now, use an example to learn how to draw a flowchart.
Problem 1: A flowchart that multiplies two numbers
Problem 2: A flowchart that finds an area of a circle for a given radius.
Problem 3: A flowchart that finds whether the given geometric shape is square or rectangle then find its
area and perimeter.
Start
Read length (l)
& breadth (b)
True False
If
(l==b)?
Perimeter=4*l Perimeter=2*(l+b)
Area=l*l Area=l*b
Print area
and
perimeter
Stop
Problem 4: A flowchart that finds sum of first N natural numbers displays the output.
Exercise::
Problem 5: A flowchart that finds largest among two numbers .
Problem 6: A flowchart that finds average of 5 numbers .
Problem 7: A flowchart that finds roots of quadratic equation ax2 + bx + c =0.
Problem 8: A flowchart that interchange the value of two numbers.
Difference between Algorithm and Flowchart::
On the basis of Algorithm Flowchart
Basic An algorithm is a step-by-step The Flowchart is the most widely used
method for solving some problem. graphical representation of an algorithm
An algorithm refers to a set of and procedural design workflows. It uses
instructions that define the various symbols to show the operations and
execution of work to get the decisions to be followed in a program.
expected results.
Comprehensibility Algorithm is hard to understand. Flowchart is easy to understand.
Implementation There are no rules employed for Predefined rules are implemented for
algorithms. flowcharts.
Symbols used It uses plain text, which is written in It uses symbols such as parallelogram,
plain English language. rectangle, diamond, etc.
Debugging Algorithms are easy to debug. Flowcharts are hard to debug.
Nature Algorithms are the program's Flowcharts are the graphical
pseudocode. representation of logic.
Branching and In algorithms, it is easy to show In Flowcharts, branching and looping are
looping branching and looping. difficult to represent.
Different types of errors in programming languages:
Errors are the problems or faults that occur in the program, which make the behavior of the program
abnormal, and experienced developers can also make these faults. Programming errors are also known
as bugs or faults, and the process of removing these bugs is known as debugging.
These errors are detected either during the time of compilation or execution. Thus, the errors must be
removed from the program for the successful execution of the program.
Syntax error:: Syntax errors are also known as compilation errors as they occur at the compilation time,
or we can say that the syntax errors are thrown by the compilers. These errors mainly occur due to
mistakes while typing or do not follow the syntax of the specified programming language. These
mistakes are generally made by beginners only because they are new to the language. These errors can
be easily debugged or corrected.
Commonly occurred syntax errors are:
o If we miss the parenthesis (}) while writing the code.
o Displaying the value of a variable without its declaration.
o If we miss the semicolon (;) at the end of the statement.
Run-time error:: Sometimes the errors exist during the execution time even after the successful
compilation known as run-time errors. When the program is running, and it is not able to operate is
the main cause of the run-time error.
The division by zero is a common example of the run-time error. Array index out of bounds, string
index out of bounds, etc., are also the most frequent run-time errors. These errors are very difficult to
find, as the compiler does not point to these errors.
Semantic errors ::Semantic errors are the errors that occurred when the statements are not
understandable by the compiler or error that leads to an undesired output.
The following can be the cases for the semantic error:
Use of a un-initialized variable.
int i;
i=i+2;
Type compatibility
int b = "javatpoint";
Errors in expressions
int a, b, c;
a+b = c;
Array index out of bound
int a[10];
a[10] = 34;