Lab Task 1 - Programming Logic, Pseudocode, Flowchart

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Lahore Garrison University

Digital Forensic Research and Service Center

Digital Forensic Research and Service Center

DFCS3101: Introduction to Programming

Lab Task 1: Programming Logic, Pseudocode, Flowchart

Introduction to Programming Page 1


Lahore Garrison University
Digital Forensic Research and Service Center

Lab Task 1: Programming Logic, Pseudocode, Flowchart


Introduction

Let us recall that the programming process follows a program development lifecycle with its
initial steps as understanding the problem and planning the logic. This session focuses on
‘planning the logic’ where we will learn how to develop an algorithm in the form of pseudocode
or flowchart.

Objectives

After completion of this lab session, you will have gained fundamental skills to plan the logic of
a program by ways of developing an algorithm in the form of pseudocode or flowchart.

Tools/Software Requirement

Visual Logic (http://www.visuallogic.org/download). This software provides a mechanism to


draw a flowchart which can be executed.

Description

Introduction to Algorithms

An algorithm is basically a procedure of steps that we exactly follow to solve a particular task or
problem. We can say that it is a set of rules that we need to follow while developing a program
code during problem-solving. Furthermore, if we write an algorithm before actually writing a

Introduction to Programming Page 2


Lahore Garrison University
Digital Forensic Research and Service Center
code, it becomes easy to perform the coding part. Moreover, the algorithm is in simple English
language hence, others can also easily understand it and develop the code.

Features of an algorithm:

The features of an algorithm are as follows:

Clarity: The algorithm should be very clear and unambiguous in its meaning. It should be simple
so that one can understand it easily.

Well-defined inputs: A program may require to take input from the user. Therefore, the algorithm
should clearly define the inputs.

Well-defined outputs: The algorithm should clearly specify the output that the program will
produce.

Finiteness: The algorithm should have a termination point. This means that the algorithm should
not be such that it runs infinite times or end up in loops.

Feasibility: The algorithm should be such that we can implement it easily. Hence, it should be
simple and practical to implement.

Language independent: It should be in simple English language. Since the code implementation
should result in the same output no matter which programming language we use while writing
the code.

Introduction to Flowcharts

It is basically a diagrammatic representation of an algorithm. Furthermore, it uses various


symbols and arrows to describe the beginning, ending, and flow of the program. Moreover, the
programmers use it to depicting the flow of data and instructions while problem-solving.
Flowcharting is the process of drawing a flowchart for an algorithm.

Symbols in a flowchart

The flowchart uses various symbols in the representation. These basic symbols are as follows:

Terminal: It represents the start, stop, or halt in a program’s flow. The flowchart always starts and
ends with this symbol. Besides, we represent it using an oval shape.

Input/Output: We represent it using a parallelogram. It indicates any input from the user or
output of the program.

Processing: We represent it using a rectangle. It indicates any arithmetic operation’s processing


such as addition, subtraction, multiplication, division, etc.

Introduction to Programming Page 3


Lahore Garrison University
Digital Forensic Research and Service Center
Decision: We represent it using the diamond symbol. It represents any type of decision in a
program that results in true or false. For example. if-conditions.

Connectors: We represent it using a circle. Whenever a flowchart is too large, we can use
connectors to avoid confusion.

Flow lines: These are basically arrows that represent the flow of the program.

Example:

We will be using the Visual Logic tool to draw the flowchart. Below, we see the symbols used by
Visual Logic associated to various actions performed in an algorithm. Remember that these
shapes are arbitrarily assigned and there is no hard and fast rule about this association. In the
case of Visual Logic, you do not need to remember the shape associations as these are created
automatically.

Introduction to Programming Page 4


Lahore Garrison University
Digital Forensic Research and Service Center
In the case of drawing the flowchart on paper, following association is typically used:

How to use Visual Logic? See http://www.visuallogic.org/Tutorial.html.

Example flowchart drawing: draw a flowchart to take two numbers as input from keyboard,
compare the two numbers, and show an output about which number is greater. Your flowchart
should look like the one below:

Instructions

Using Microsoft Word on computer to write pseudocode and the Visual Logic software to draw
flowchart, develop the logic for each of the following problems. Use Snipping Tool to copy the
flowchart from Visual Logic as an image. Insert this flowchart image into Microsoft Word. Crop
the image adequately in Microsoft Word. You must show the execution of at least one flowchart
in Visual Logic to the TA, along with your Word document to get your work graded.

Deliverables

Compile a single Word document by filling in the solution part and submit this Word file.

Introduction to Programming Page 5


Lahore Garrison University
Digital Forensic Research and Service Center
This lab is graded. Min marks: 0. Max marks: 10.

Lab Tasks

Q1) Develop the logic of a program that allows the user to enter two values and displays their sum and
difference.

Answer:

Solution: Pseudocode
Develop the logic of a program that allows the user to enter two values and displays their sum
and difference.
Algorithm

Step 1: Ask the user to Enter the 1st Value.


Step 2: Ask the user to Enter the 2nd value.
Step 3: Add up the both Values.
Step 4: Store in Variable "A".
Step 5: Subtract the Both Values.
Step 6: Store in Variable "B".
Step 7: Display Both Variables.

Solution: Flowchart

Introduction to Programming Page 6


Lahore Garrison University
Digital Forensic Research and Service Center

Q2) Calculate the area and circumference of a circle

Answer:

Solution: Pseudocode
Calculate the area and circumference of a circle.
Algorithm

Step 1:Ask the User to Value of Radius.


Step 2:Store in Variable "R".
Step 3:Set PI = 3.142.
Step 4:Apply the Formula Calcualte the Circumference.
Step 5:Circumference = 2*R*R*PI .
Step 6:Apply the Formula Calcualte the Area.
Step 7:Area = 2*R*PI.
Step :Displays Circumference and Area.

Solution: Flowchart
Introduction to Programming Page 7
Lahore Garrison University
Digital Forensic Research and Service Center

Q3) Calculate the area of a triangle

Answer:

Solution: Pseudocode

Solution: Flowchart

Q4) Write a program to compute the sum of the two given integer values. If the two values are the same,
then return triple their sum.
Introduction to Programming Page 8
Lahore Garrison University
Digital Forensic Research and Service Center

Answer:

Solution: Pseudocode

Solution: Flowchart

Q5) Write a program to check two given integers, and return true if one of them is 30 or if their sum is 30.

Answer:

Solution: Pseudocode

Solution: Flowchart

Q6)Write a program to print numbers from 1 to 10?

Answer:

Solution: Pseudocode

Solution: Flowchart

Q7) Write a program to output alarm if given temperature in higher than 72 degrees. If not prompt
successful execution.

Answer:

Solution: Pseudocode

Introduction to Programming Page 9


Lahore Garrison University
Digital Forensic Research and Service Center
Solution: Flowchart

Introduction to Programming Page 10

You might also like