You are on page 1of 7

Department of Software Engineering

CS-114: Fundamentals of Programming


Class: BESE-13

Lab 02: Flowcharts and Pseudocode


CLO: Define basic algorithms for identifying and solving real-world problems

Date: September 20th, 2022

Instructor: Dr. Hashir Kiani

Lab Engineer: Ms. Sundas Dawood


Lab 02: Flowcharts and Pseudocode

Introduction
In this lab, we will continue to learn the concepts of pseudocode and flowcharts.

Objectives
The purpose of this lab is to enable students to understand the basics of problem solving in
programmatic context. Students will be representing solutions to different problems as
flowcharts and pseudo code.

Tools/Software Requirement
Microsoft Word

Description
What is an Algorithm?

An algorithm is procedure consisting of a finite set of instructions that provides a solution to


a problem. In other word, an algorithm is a step-by-step procedure to solve a given problem.
Algorithms can be translated into many programming languages.

There are two main methods of representing algorithms.

1. Pseudo code
2. Flowchart

What is a Pseudocode?

Pseudocode is a tool that can be used to write a preliminary plan for the development of a
computer program. It is a generic way of describing an algorithm without the use of any specific
programming language syntax. In fact, it serves as an English like way to state an algorithm.
Example: Write a pseudo code for converting temperature entered by the user in centigrade to
Fahrenheit.

Solution:
BEGIN
DISPLAY “Enter Centigrade: "
INPUT centigrade_value
CALCULATE Fahrenheit = (1.8 * centigrade_value) + 32
DISPLAY Fahrenheit
END

What is a Flowchart?

A flowchart provides a detailed picture of the algorithm using special symbols to represent
various program statements. A flowchart will usually be drawn from top to bottom showing the
exact order of the steps. Arrows are used to depict the “flow” of a program.

Figure 1: Representing a Flowchart


Basic Flowchart Symbols
There are different types of symbols representing different operations in this flowchart:

Rounded rectangles
It represents the terminals of a program (e.g. Start, End)
Parallelograms
It represents the Input and out operation. (e.g. Display a Message,
Read Hours)
A rectangle
It represents process e.g. A mathematical calculation.

A diamond
It represents decision making process e.g. A condition is analyzed,
where answer is usually either True or False.

Flow Lines
Arrow shows the direction of flow of instructions.

Connectors
They are used to join one part of the flowchart with another part
of the flowchart.

Flow Chart Guidelines:


1. Think of a logical plan to solve a problem
2. Identify the tasks in chronological order
3. Organize them by type and corresponding shape
4. Draw your chart
5. Flowchart can have only one start and one stop symbol
6. Try to keep it neat i.e. Arrows should not cross each other
7. Confirm your flowchart
Example: Draw a flowchart for calculating average of two numbers.
Solution:

Example: Flowchart for going to the market to purchase a pen.


Solution:

The connectors connecting two parts of the same flowchart are referenced using a number (number 1 in
the circle in this case).
Lab Tasks:
Write pseudo codes and draw flowcharts for the following problems:

1. Take a string (sentence in English) as input from the user. Calculate the number of vowels
present in that string and display the result.

To confirm your solution trace through your flowchart and pseudocode with the following test
values to check their accuracy:

• Input: “Hello World” Output: 3


• Input: “Fundamentals of Programming” Output: 8

2. Take 10 numbers as input from the user. Find out how many numbers in that list are duplicate
and display the result.

To confirm your solution trace through your flowchart and pseudocode with the following
test values to check their accuracy:

• Input = [1,2,3,4,5,6,7,8,9,10] Output = 0


• Input = [11,2,7,3,7,6,7,2,9,10] Output = 2

3. Take a number “n” as input from the user. Display the first “n” numbers in the Fibonacci
sequence. Fibonacci Sequence: 1,1,2,3,5,8……….(next number is sum of previous two numbers)

To confirm your solution trace through your flowchart and pseudocode with the following test
score values to check their accuracy:

• Input: 3 Output: 1,1,2


• Input: 8 Output: 1,1,2,3,5,8,13,21

4. Take a number as input from the user and display the number of digits in that number.

To confirm your solution trace through your flowchart and pseudocode with the following test
score values to check their accuracy:

• Input: 3891 Output: 4


• Input: 35 Output: 2
5. Take a number as input from the user. Convert it to binary and display the result.

To confirm your solution trace through your flowchart and pseudocode with the following test
score values to check their accuracy:

• Input: 12 Output: 1100


• Input: 86 Output: 1010110

6. Take a number as input from the user. Find its square root and display it. Your solution should
be accurate to at least 2 decimal places. You should only use the basic mathematical operations
to solve this problem.

To confirm your solution trace through your flowchart and pseudocode with the following test
score values to check their accuracy:

• Input: 16 Output: 4
• Input: 32 Output: 5.66

You might also like