100% found this document useful (1 vote)
261 views

Lab - 02 - Problem Solving-Flowcharts Pseudocode

This document provides an introduction to algorithms, flowcharts, and pseudocode. It explains that algorithms are a series of instructions to solve a problem, and they can be represented through flowcharts or pseudocode. The document defines pseudocode as an English-like way to describe an algorithm without using a specific programming language. It also defines flowcharts as using special symbols to visually represent the steps in an algorithm. The document provides examples of algorithms, pseudocode, and flowcharts. It includes tasks for students to write pseudocode and draw flowcharts for three problems involving finding the largest of three numbers, calculating weekly pay with overtime, and analyzing exam scores.

Uploaded by

Waseem Abbas
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
261 views

Lab - 02 - Problem Solving-Flowcharts Pseudocode

This document provides an introduction to algorithms, flowcharts, and pseudocode. It explains that algorithms are a series of instructions to solve a problem, and they can be represented through flowcharts or pseudocode. The document defines pseudocode as an English-like way to describe an algorithm without using a specific programming language. It also defines flowcharts as using special symbols to visually represent the steps in an algorithm. The document provides examples of algorithms, pseudocode, and flowcharts. It includes tasks for students to write pseudocode and draw flowcharts for three problems involving finding the largest of three numbers, calculating weekly pay with overtime, and analyzing exam scores.

Uploaded by

Waseem Abbas
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

CS114: Fundamentals of Programming

Class: BESE-10AB
Lab 02: Algorithm, Flowchart and Pseudo Code

Instructor: Ms. Hania Aslam

September 12, 2019


Lab 02: Algorithm, Flowchart and Pseudo Code

Introduction

This lab is based on introduction to Algorithms, Flowcharts and Pseudo Code.

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 Pseudo
Code and flowcharts.

Tools/Software Requirement

Microsoft Office Word

Description

What is an Algorithm?
An algorithm is a series of instructions to resolve a problem. Algorithms can be translated
into many programming languages.

Problem: How to open a locked Door.

There are two main methods of representing algorithms.

1. Flowcharts
2. Pseudo code

What is a Pseudo code?


Pseudocode is one of the tools that can be used to write a preliminary plan that can be developed
into a computer program. Pseudocode 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
calculations.

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:
Consider the following flow chart for getting a clear understanding on usage of connectors:

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 three problems:

1. Attain three numbers from the user. Determine the largest of these three numbers and display
that value to the user with an appropriate message. For simplification assume that the numbers
entered by the user are not the same.

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

 7, 5, 6
 5, 6, 7
 6, 7, 5

2. Obtain from the user an hourly pay rate and the number of hours worked for the current week.
Calculate and output their weekly pay according to the following criteria: -
i. Regular pay is the pay up to 40 hours. No overtime is paid!
ii. Overtime pay is pay for the hours over 40. Overtime is paid at a rate of 1.5 times the
hourly pay rate.
iii. Gross pay is the sum of the regular pay and the overtime pay.

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

 hourly pay rate = 20 , number of hours worked = 52


 hourly pay rate = 35 , number of hours worked = 22

3. Obtain 5 exam scores from the user and determine whether the score is passing (a score of 60
or above) score or failing score. Your solution should count the number of passing and failing
scores. Additionally, you will be calculating the average of the scores. Display average of the
scores, the number of failing scores, and the number of passing scores.
To confirm your solution trace through your flowchart and pseudocode with the following test
score values to check their accuracy:
 75, 89, 32, 55, 12

Hint: We did a similar example in the class. You can consult the slides. However, you need to
perform a few additional steps in the above case.

Note: You can draw the flow charts on MS Word or you can draw them with free online tools!!

Non-Graded Assignment
Downloading and Installing Python Environment:

Python is a popular programming language available for most modern computer operating systems.
Python is usually not included by default on Windows or other operating systems, however we can
check if any version already exists on the system.

Perform the following steps to check if python is already installed on your lab’s computer system:

1. Open command prompt by following the step mentioned below:


 Open the Windows menu and type “command” in the search bar.

2. In the Command Prompt window, type the following command and press Enter.

python
If Python is installed on your system, then this command will run python.exe and show you the
version number as shown below:

In case python is not installed on your system the following message will be displayed:

'python' is not recognized as an internal or external command, operable


program or batch file.

If python is already installed on your system then you can skip step 3 and directly jump to step 4!

3. In case, python is not installed on your system , you will need to download and install the
standard installer program for your operating system . Python is freeware that can be easily
installed on your home workstation or laptop. Select and download the version Python 3.x (latest
version) from this link:
https://www.python.org/downloads/

 Find and download the Windows installer file that matches your system.
 Open the downloaded executable file to start the installation wizard.
 Follow the instructions and make a note of where Python is installed on your system.
4. Python IDLE is an environment for writing, editing, debugging and running Python programs. It
is automatically included when you install the standard set of Python tools. Python IDLE will be
automatically installed on your system after successful completion of step 3 above. To run the
Python program development tool named IDLE you can open Windows menu and type “idle” in
the search bar.

5. A new window now will open up as shown below:


This is the main window to IDLE, and what we see right now is called the "Interpreter" (or "shell")
window. The Interpreter allows us to enter commands directly into Python, and as soon as we enter in a
command, Python will execute it and display its result. We'll be using this Interpreter window a lot while
we're exploring Python: it's very nice because we get back our results immediately. 

As per tradition, let's get Python to say hello by writing our first command into IDLE!!

6. The '>>>' sign acts as a prompt for us: Python is ready to read in a new command by giving us
that visual cue. Enter the command given below and press enter to see the outcome :

print (“Hello, Welcome to Python”)

Observe the result. The result shall look like this:


The '>>>' sign appears again as Python is ready to read in a new command from your side.

We have just installed python 3.x and have written our first python command using IDLE. We have
skipped a lot of the features of Python and IDLE: IDLE is much more than a mere editor, but it takes
some time to explore all of its features. In the future labs we will explore IDLE in detail and will learn to
write a few more useful python commands.

You might also like