(Introduction To Programming) : Laboratory 1
(Introduction To Programming) : Laboratory 1
Laboratory 1
(INTRODUCTION TO PROGRAMMING)
OBJECTIVES:
1. Familiarity in pseudo code, algorithms and flowchart
2. Apply solving different techniques that will be the basis for solution.
3. Recognize various structures like sequence, selection and repetition
BASIC CONCEPTS
The process of working through details of a problem to reach a solution. There are three
approaches to problem solving: Algorithm, Flowchart, Pseudo Code.
Definiteness: Instructions must be precise and unambiguous i.e. each and every instruction should
be clear and should have only one meaning.
Finiteness: Not even a single instruction must be repeated infinitely. i.e., each instruction should be
performed in finite time.
Termination: After the algorithm gets executed, the user should get the desired result.
Any algorithm has a finite number of steps and some steps may involve decision making, repetition.
Broadly speaking, an algorithm exhibits three key features that can be given as:
Sequence: Sequence means that each step of the algorithm is executed in the
specified order.
Decision: Decision statements are used when the outcome of the process depends on some
condition.
Repetition: Repetition which involves executing one or more steps for a number of times can be
implemented using constructs like the while, do-while and for loops. These loops executed one or
more steps until some condition is true.
P rob le m So lv in g T e c hniqu e s 1
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering
ALGORITHM: AREA_of_RECTANGLE [This algorithm takes length and breadth, the sides of the
rectangle as input and computes the area of rectangle using the formula area=length * breadth.
Finally it prints the area of rectangle]
STEPS:
Step 1:[Initialize]
Start
Step 2: [Input the sides of Rectangle]
Read length, breadth
Step 3:[Compute the area of rectangle]
Area=length*breadth
Step 4:[Display the Area]
Print Area
Step 5: [Finished]
Stop
Basically, a flowchart depicts the “flow” of a program. The following table shows the symbols used
in flowchart along with its descriptions.
P rob le m So lv in g T e c hniqu e s 2
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering
Advantages of Flowcharts:
A flowchart is a diagrammatic representation that illustrates the sequence of steps that must be
performed to solve a problem. They are usually drawn in the early stages of formulating computer
solutions to facilitate communication between programmers and business people.
Flowcharts help programmers to understand the logic of complicated and lengthy problems. They
help to analyze the problem in a more effective manner Flowchart can be used to debug programs
that have error(s).
Flowchart of a complex program becomes, complex and clumsy. At times, a little bit of alteration in
the solution may require complete re-drawing of the flowchart
Essentials of what is done may get lost in the technical details of how it is done. There are no well-
defined standards that limit the details that must be incorporated in a flowchart.
Pseudocode:
It is a form of structured English that describes algorithms. It facilitates the designers to focus on the
logic of the algorithm without getting bogged down by the details of language syntax.
Pseudo code is a compact and informal high-level description of an algorithm that uses the
structural conventions of a programming language. It is meant for human reading rather than
machine reading, so it omits the details that are not essential for humans.
P rob le m So lv in g T e c hniqu e s 3
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering
Such details include keywords, variable declarations, system-specific code and subroutines. There
are no standards defined for writing a pseudo code because it is not an executable program.
Flowcharts can be considered as a graphical alternative to pseudo code, but are more spacious on
paper.
A. Sweta, who scores 60 marks in Science, 70 marks in mathematics and 75 marks in English.
Use the adjacent flowchart and provide the execution steps in calculating the average marks
of Sweta.
B. The following empty flowchart gives the steps to be followed while seeking admission to new
school. The phrases to be filled in the boxes are also given. Complete the flowchart by filling
in the number of the corresponding phrase, inside each box. For example: the number
corresponding to the first box in the flowchart is 7.
P rob le m So lv in g T e c hniqu e s 4
COE103 – Laboratory Manual PAMANTASAN NG CABUYAO – College of Engineering
P rob le m So lv in g T e c hniqu e s 5