Module - 1 PAC and Pesudocode
Module - 1 PAC and Pesudocode
Important: No Re-exam
http://www.vpropel.in/
JAVA - IDE
JAVA - Eclipse
Step 1) Installing Eclipse Open your browser and type https://www.eclipse.org/
Reference: https://www.guru99.com/install-eclipse-
Output will be displayed as shown below.
java.html
Problem Solving Techniques
Problem Solving: Definition
• It is a process of identifying the problem,
developing an algorithm or approach, then
converting algorithm into computer code or program
Processing
Actions needed to obtain the required output
Output
List of Output Required
Problem Analysis Chart (PAC)
• According to Sprankle and Hubbard, (2012), the initial step for
a programs need to do when get a problem is to analyze and
understand the requirements.
• To easily analyze the problem, a Problem Analysis Chart (PAC)
was introduced. This chart have four section:
• The given data
• The required result
• The processing involved
• A list of solution alternative
PAC - Table
Problem Analysis Chart (PAC)
1. A program is required to find average of five
numbers.
Given Data Required Result
Number_1 Average of 5 numbers
Number_2
Number_3
Number_4
Number_5
Identification of Output
2
Processing Definiteness
4
Processing Finiteness
5
Possessing Effectiveness
6
Characteristics of a good algorithm
• Finiteness: An algorithm must terminate in a finite number of steps
• Precision: the steps are precisely stated or defined.
• Effectiveness: it should be primitive easily convert able into program
statement
• Generality: The algorithm must be complete in itself so that it can
be used to solve problems of a specific type for any input data.
• Input/output: Each algorithm must take zero, one or more quantities
as input data produce one or more output values.
• An algorithm can be written in English like sentences - Pseudo Code
• Visual Representation of Algorithms – Flow chart
Pseudocode
• It is a simpler version of a programming code in plain English
which uses short phrases to write code for a program before
it is implemented in a specific programming language.
• It does not have a specific syntax like any of the programming
languages and thus cannot be executed on a computer.
• Many time algorithms are presented using pseudocode since
they can be read and understood by programmers who are
familiar with different programming languages
Pseudocode
• Pseudocode allows you to include several control structures
such as While, If-then-else, Repeat-until, for and case, which is
present in many high-level languages.
Keywords : INPUT, COMPUTE,PRINT, INCREMENT, DECREMENT,
IF/ELSE, WHILE, TRUE/FALSE
Advantages of Pseudocode
Reduced complexity
Increased flexibility
Ease of understanding
Pseudocode
• The programming process is a complicated one.
• You must first understand the program specifications.
• Then you need to organize your thoughts and create
the program.
• You must break the main tasks that must be
accomplished into smaller ones in order to be able
to eventually write fully developed code.
• Writing Pseudocode will save you time later during
the construction & testing phase of a program's
development.
Example
Write a pseudocode to display the sum of two numbers
entered by user.
input num1
input num2
COMPUTE Result = num1 + num2
PRINT Result
Flowchart
A graphical representation of the sequence of operations in an
information system or program.
Information system flowcharts show how data flows from
source documents through the computer to final
distribution to users.
Program flowcharts show the sequence of instructions in a
single program or subroutine. Different symbols are used
to draw each type of flowchart.
A Flowchart
shows logic of an algorithm
emphasizes individual steps and their interconnections
e.g. control flow from one action to the next
Flowchart
A flow chart is an organized
combination of shapes, lines
and text that graphically
illustrate a process or
structure.
Flowchart
Flowchart symbol Function Description
Start/End Also called “Terminator” symbol. It indicates
where the flow starts and ends.
Process Also called “Action Symbol,” it represents a
process, action, or a single step.
Decision A decision or branching point, usually a yes/no or
true/ false question is asked, and based on the
answer, the path gets split into two branches
Input
Lft
Lcm Lft x 30
Print
Lcm
STOP
Examples
Write an algorithm and draw a flowchart that will read
the two sides of a rectangle and calculate its area.
Examples
Pseudocode
• Input the width (W) and Length (L) of a rectangle
• Calculate the area (A) by multiplying L with W
• Print A
Examples
START
Input
W, L
ALxW
Print
A
STOP
Exercise
Write PAC, Pseudocode and draw a flowchart that will
calculate the roots of a quadratic equation
Three Basic Language Structures
• Sequence structure
• Selection structure
• Repetition structure
Three Basic Language Structures
Flowcharts for three constructs
Pseudocode for three constructs
Examples
Create PAC, Pseudocode, Flowchart to check whether a number is
odd or even.
PAC
Given Data Required Result
n1 Display Odd or Even
Input num1
Is
Yes num1 No
Mod
2==0?
STOP
Examples
Create PAC, Pseudocode, Flowchart to print the numbers 0 to “n”
value.
PAC
Given Data Required Result
n Sum of the n numbers
Input n
i=0
While False
(i<=n)
True
Print “i”
STOP
Programming Or Implementation Phase
• Transcribing the logical flow of solution steps in
flowchart or algorithm to program code and run the
program code on a computer using a programming
language.
• Programming phase takes 5 stages:
• Coding.
• Compiling.
• Debugging.
• Run or Testing.
• Documentation and maintenance.
Programming Or Implementation Phase
• Once the program is coded using one of the
programming language, it will be compiled to ensure
there is no syntax error.
NO SYNTAX
ERROR
EXECUTE OR
RUN
DOCUMENTATION OR
MAINTENANCE
Coding
• Translation or conversion of each operation in the
flowchart or algorithm (Pseudocode) into a computer-
understandable language.
• Coding should follow the format of the chosen
programming language.
Compiling and Debugging
• Compiling - Translates a program written in a particular high–level
programming language into a form that the computer can understand
• Compiler checks the program code so that any part of source code
that does not follow the format or any other language requirements
will be flagged as syntax error.
• This syntax error in also called bug, when error is found the
programmer will debug or correct the error and then recompile the
source code again
• Debugging process is continued until there is no more error in
program
Testing
• The program code that contains no more error is called
executable program. It is ready to be tested.
• When it is tested, the data is given and the result is verified
so that it should produced output as intended.
• Though the program is error free, sometimes it does not
produced the right result. In this case the program faces logic
error.
• Incorrect sequence of instruction is an example that causes
logic error.
Documentation and Maintenance
• When the program is thoroughly tested for a substantial period of time
and it is consistently producing the right output, it can be documented.
• Documentation is important for future reference. Other programmer
may take over the operation of the program and the best way to
understand a program is by studying the documentation.
• Trying to understand the logic of the program by looking at the source
code is not a good approach.
• Studying the documentation is necessary when the program is
subjected to enhancement or modification.
• Documentation is also necessary for management use as well as audit
purposes.