Procedrual Programming Unit-1-5A.pptx
Procedrual Programming Unit-1-5A.pptx
Programming
Process of writing instructions in a language for a
computer to solve a specific task
Programming languages
Medium of communication between the man and the
machine
Assembly Language
• Mnemonics (“add”, “sub”, etc.)
Assembly Language
Tools Used to Develop a Computer
Program
• Compiler
• Interpreter
• Assembler
• Debugger
• Integrated Development Environment
Integrated Development Environment
One tool that integrates compiler/interpreter, debugger and
runtime environment in a user-friendly interface
Example: Netbeans
Execution of a C Program Using IDE
Clean and Build
goto step 6
Step 6: Stop
Examples of Algorithm
Design an Algorithm to find greatest among two
numbers.
Step 1: Start
Step 2: Accept inputs from user (Num1, Num2)
Step 3: If Num1>Num2 goto Step 4 otherwise goto step
5
Step 4: Display “Num1 is greatest among two numbers”
Step 6: Stop
Flowchart
• Flowchart is a visual representation of a process or an
algorithm.
• Step- by- Step approach to solve a task.
• A flowchart is a diagram that depicts the “flow” of a
program.
• Flowcharts are drawn using certain special-purpose
symbols such as rounded rectangle, parallelograms,
rectangles, diamonds, and small circles.
• Symbols are connected by arrows called flowlines
1
6
Advantages of Flowchart
•It helps to understand the flow of program control in an
easy way.
•Developing program code by referring its flow chart is
easier.
•It helps in avoiding semantic errors.
•Any concept is better understood with the help of visual
representation.
Flowchart Design Rules
•Standard symbols should be used while drawing flowchart.
•It must begin with a “Start” and (or BEGIN) and end with
STOP (or END).
•The standard process flow should be either from top to
bottom or from left to right.
•Flowchart should be neat, clean and easy to follow.
•Arrows should be aligned properly.
Flowchart Design Rules
•Only one flow line should come out from process symbol.
•Only one flow line should enter a decision symbol, but two
or three flow-lines, one for each possible answer, can leave
the decision symbol
•If the flowchart is lengthy and complex connector symbol
should be used to reduce the number of flow lines.
•Two arrows should not intersect or cross each other.
Basic Flowchart Symbols
• Terminators
– represented by rounded rectangles
– indicate a starting or ending of a problem.
Example:
STAR END
T
2
0
Basic Flowchart Symbols
• Input/Output Operations
– represented by parallelograms
– indicate an input or output operation
Example:
Read A, B Display
SUM
Basic Flowchart Symbols
• Processes
– represented by rectangles
– indicates a process such as a mathematical
computation or variable assignment
Example:
SUM=A+B.
2
2
Basic Flowchart Symbols
• Decision
– represented by diamond shape
– For decision making
– Contains an expression, such as a condition, that
can be either true or false
Example:
Is
a>b?
2
3
Decision Structure
• A new symbol, the diamond, indicates a yes/no question.
If the answer to the question is yes, the flow follows one
path. If the answer is no, the flow follows another path.
NO YES
24
Basic Flowchart Symbols
• Connectors
• represented by a small circle
• Sometimes a flowchart will not fit on one page.
• A connector allows to connect two flowchart
segments.
Example: A
START A
25
Basic Flowchart Symbols
• Flow of data
– represented by an arrow.
– Always the flow should be from top to bottom or from
left to right.
– An arrow coming from one symbol and ending at
another symbol Represents that control passes to the symbol
the arrow points to.
Example:
26
Flowchart Examples
Draw a flowchart to add two numbers
Start
Read
Read a,a,b b
sum
sum =
= aa++
bb
Stop
Flowchart Examples
Draw a flowchart to find average of two numbers
Start
Read
Read a,a,b b
avgsum
= (a= a++ b)/2
b
Display “Average of a
and b is ‘avg’ “
Stop
Flowchart Examples
Draw a flowchart to find area of circle.
Start
Read r
areasum
= 3.14*r*r
=a+b
Stop
Review
• What do each of the following symbols
represent?
Input/Output
Operation Connector
Process Module
31
PseudoCode
• A Pseudo code is a step-By-step Representation of an algorithm
in code-like structure.
• It is an informal way of writing a program for better
understanding.
• It helps the programmer to understand logic of the program.
• It cannot be compiled nor executed.
• It uses reserved Keywords.
PseudoCode Rules
• One statement per line
• Initial keywords should capitalize.
• Indentation should be given similar as the statements are indented
in a computer program.
• Ending the statements and Looping is necessary.
• All statements should be simple and clear.
Basic Computer Operations to Write
Pseudo code Statements
1.A computer can receive information (Input)
READ (information from a file)
GET (information from the keyboard)
2. A computer can put out information (Output)
WRITE (information to a file)
DISPLAY (information to the screen)
Basic Computer Operations to Write
Pseudo code Statements
3. A computer can perform arithmetic
operations
Use actual mathematical symbols or the words for the symbols
Example: +, -, *, /
Add number to total
Total = total + number
▪ CALCULATE/ COMPUTE
Basic Computer Operations to Write
Pseudo code Statements
4. A computer can assign a value to a piece of data
i. To give data an initial value
INITIALIZE/ SET
ii. To assign a value as a result of some processing
“=”
iii. To keep a piece of information for later use
SAVE, STORE
iv. To declare a variable
DEFINE
Basic Computer Operations to Write
Pseudo code Statements
5. A computer can compare two piece of
information and select one of two alternative
actions
IF (condition) THEN
Some action
ELSE
Alternative action
ENDIF
Basic Computer Operations to Write
Pseudo code Statements
6. A computer can repeat a group of actions
i. While Loop
WHILE condition (is true)
Some action
ENDWHILE
ii. For Loop
FOR a number of times
Some action
ENDFOR
Advantages of pseudo code
1. It is easy to write pseudo code compared to code.
2. Easy to convert pseudo code to any computer
programming language.
3. It allows designer to focus on main logic.
4. It can be easily modified as compared to flowchart.
5. It can be read and understood easily.
Disadvantages of pseudo code
1. There are no standards keywords for writing pseudo codes.
2. Pseudo code cannot be compiled and executed so its
correctness cannot be verified by using computers.
3. In the case of pseudo code, a graphic representation of
program logic is not available.
4. Understanding complex logic through pseudo code can be
very difficult.
5. Branching and looping statements are difficult to show in
pseudo code.
Pseudocode Example
To add two numbers
BEGIN
DEFINE Integer Num1,Num2, Sum
READ Num1, Num2
CALCULATE Sum=Num1+Num2
DISPLAY “Sum of two numbers is ‘sum’”
END
Pseudocode Example
To find area and perimeter of a rectangle
BEGIN
DEFINE Integer length, breadth, area, perimeter
READ length, breadth
CALCULATE area= length *breadth
CALCULATE perimeter=2*(length+ breadth)
DISPLAY “Area of a rectangle is ‘area’ ”
DISPLAY “Perimeter of a rectangle is ‘perimeter’ ”
END
Pseudocode Example
To Check given number is even or odd
BEGIN
DEFINE Integer Num1
READ Num1
IF (Num%2=0) THEN
DISPLAY “The given number is even”
ELSE
DISPLAY “The given number is odd”
ENDIF
END
Practice Questions for Flowchart/
Pseudocode/Algorithm
•To print a message “Welcome to CSE”
•To calculate the sum and product of two numbers.
•To find an average of three numbers.
•Find Area Of Circle using Radius.
•To find the area and perimeter of a rectangle.
•To Calculate simple interest on principal P, rate R% and
duration T years.
Contd…
•To Convert temperature from Fahrenheit to Celsius.
•The voltage (V) between the poles of a conductor is equal to
the product of the current (I) passing through the conductor and
the resistance (R) present on the conductor. It’s demonstrated
by the V = I * R formula.