Unit 2
Unit 2
2.1 Algorithm:
• An algorithm can be defined as complete, unambiguous and finite number of
steps for solving a given problem.
• Simply, it is the step by step description of the method to solve a problem.
• Developing an algorithm is a step of program design.
Disadvantages of algorithm.
• Writing algorithm takes a long time.
• An Algorithm is not a computer program; it is rather a concept of how a program
should be.
Example:
Write an algorithm to find the sum of two numbers entered by user.
Step 1: Start
Step 2: Declare variables A, B, SUM
Step 3: Input two numbers A and B
Step 4: SUM = A + B
Step 5: Print SUM
Step 6: Stop
2.2 Flowchart:
• Flow chart is a pictorial (diagrammatic) representation of the procedure for solving a
problem and help a great deal to analyze the problem and plan its solution in a systemic
and orderly manner. A flow chart includes a set of various Standard shaped boxes that
are interconnected by flow lines.
• Simply it is graphical representation of an algorithm.
• Flowchart facilitate communicates between programmers and business persons.
Flowchart helps in explaining the program to others. Once a flowchart is drawn, it become
easy to write the program in any high level language. A flowchart when translated in to a
proper computer language, results in a complete program.
Compiled By: Er. Ram Chandra Aryal 4
Flowchart symbols and their meanings:
Flowchart Structures:
Advantages of Flowchart:
• Flowchart provides a clear overview of the entire problem.
• It serves as a guide for program coding.
• It is a convenient method of communication.
Compiled By: Er. Ram Chandra Aryal 5
• It helps during error detection and removal.
• It is an important tool for planning and designing a new system.
• It can be used for effective analysis of the problem.
Disadvantages of flowchart:
• The flowchart can be complex when the logic of a program is quite complicated.
• Difficult to alter the flowchart. Sometimes, the designer needs to redraw the
complete flowchart to change the logic of the flowchart or to alter the flowchart.
• Since it uses special sets of symbols for every action, it is quite a tedious task to
develop a flowchart as it requires special tools to draw the necessary symbols.
• In the ease of a complex flowchart, other programmers might have a difficult time
understanding the logic and process of the flowchart.
• It is just a visualization of a program; it cannot function like an actual program.
Example:
Draw a flowchart to find the sum of two numbers entered by user.
Flowchart:
Algorithm:
Step 1: Start
Step 2: Declare variables A, B and C
Step 3: Read A, B and C
Step 4: if A>B
if A>C
print A is greater
else
print C is greater
else
if B>C
print B is greater
else
print C is greater
Step 5: Stop
• Often at times, algorithms are represented with the help of pseudo codes as
they can be interpreted by programmers no matter what their programming
background or knowledge is.
• Pseudo code, as the name suggests, is a false code or a representation of code
which can be understood by even a layman with some school level programming
knowledge.
Advantage:
• Acts as a bridge between the program and the algorithm or flowchart. Also works as
a rough documentation, so the program of one developer can be understood easily
when a pseudo code is written out. In industries, the approach of documentation is
essential. And that's where a pseudo- code proves vital.
• The main goal of a pseudo code is to explain what exactly each line of a program
should do, hence making the code construction phase easier for the programmer.
Disadvantage
• Pseudo code does not provide a visual representation of the logic of programming.
• There is no proper format for writing the for pseudo code.
• In Pseudo code there is extra need of maintain documentation.
• In Pseudo code there is no proper standard very company follow their own standard
for writing the pseudo code.
Sum=Number1+Number2
Print Sum
Example 2: Write pseudo code to check if the user entered number is odd or even
num: INPUT "Enter a number"
ELSE
OUTPUT area
END
• The source code written in any programming language is not directly executed by the
computer.
• It should be translated into to the machine readable format i.e. actual machine
language.
• The process of translation of source code into the target code is called the
compilation.
• Each programming language has its own compiler program that translates the source
code into its target code.
• The compilation process tests the program whether it contains syntax errors or not.
• If syntax errors are present, compiler cannot compile the code.
• Once the compilation is completed then the program is linked with other object
programs needed for execution, there by resulting in a binary program and then the
program is loaded in the memory for the purpose of execution and finally it is
executed.
Debugging:
Logical Errors:
A logical error is an error in a program’s source code that gives way to an unanticipated
and erroneous behavior. A logical error is classified as a type of runtime error that can
result in a program producing incorrect output.
Runtime Errors:
A Runtime Error is an error that occurs at the time of running or executing a program.
When this error occurs, the program may hang or crash displaying an error message.
There are many reasons for a runtime error, like when the program enters an infinite
loop, it triggers the runtime error. Sometimes, it also occurs due to the user’s fault. A
typical runtime error is a division by zero error.
Testing:
Integration Testing:
Integration testing is a method of testing how different units or components of a
software application interact with each other. It is used to identify and resolve any
issues that may arise when different units of the software are combined. Integration
testing is typically done after unit testing and before functional testing, and is used
to verify that the different units of the software work together as intended.
Integration testing is of four types:
(i) Top-down (ii) Bottom-up (iii) Sandwich (iv) Big-Bang
Alpha Testing:
This is a type of validation testing. It is a type of acceptance testing which is done
before the product is released to customers. It is typically done by QA people.
Example:
When software testing is performed internally within the organization.
Beta Testing:
The beta test is conducted at one or more customer sites by the end-user of the
software. This version is released for a limited number of users for testing in a real-
time environment.
Example:
When software testing is performed for the limited number of people.
Acceptance Testing:
Acceptance testing is done by the customers to check whether the delivered
products perform the desired tasks or not, as stated in requirements.
7. Program Documentation:
• From the start of the problem solving to the end of the implementation of the
program, all the tasks should be documented i.e. kept for future reference. A program
may be difficult to understand even to programmer who wrote the code after some
days.
• It is also the important part of the problem solving or program development. It helps
to those who use, maintain and extend the program in future.
• Properly documented program is necessary which will be useful and efficient in
debugging, testing, maintenance and redesign process.
Documentation may be of two types:
a. Technical document known as programmers documents which includes the problem
analysis to implementation details for that program. It is needed for future reference
for any modification, update of the program. Documentation may be in the form of
pseudo code, flowchart, E-R diagram and other standard UML diagram etc.
b. User document also known as User manual is the documentation prepared for the
end-user of the program that guides the user how to operate the program.
Documentation may include the instructions for installation of program, instruction
for using its functionality etc.
Algorithm:
Step 1: Start
Step 2: Declare variables radius and area
Step 3: Read the radius of the circle
Step 4: Compute the Area as per the formula.
Area=3.14*radius*radius
Step 5: Print the area of the circle
Step 6: Stop
Flowchart: