fundamental programming lect 2
Post on 15-Aug-2015
107 Views
Preview:
TRANSCRIPT
Instructor : Muhammad Haris
All Rights Reserved to Department of Computer Science – GCU Lahore
Programming Fundamentals
This Course
Problem Solving Using Computers
Implementing the Solution using a
Programming Language
1 2
The first part is mostly ignored which leads to poor programming skills
2Programming Fundamentals | Lecture-2
Instructor : Muhammad Haris
All Rights Reserved to Department of Computer Science – GCU Lahore
1
Steps in Problem Solving
Define the Problem Design the Solution
1 2
4Programming Fundamentals | Lecture-2
1. Define the Problem
After careful reading, the problem should be divided into three separate componentsInput
○ Data provided to the problemOutput
○ What is required from the solutionProcessing
○ List of actions needed to produce the required output
5Programming Fundamentals | Lecture-2
Solution of a Problemin your mind
2. Design the Solution
Solution in terms ofno. of steps
Transform
There are more than 1 ways to do that but we will use a graphical approach
which will involve usage of Geometrical Shapes
to represent different kinds of steps in a solution
6Programming Fundamentals | Lecture-2
Instructor : Muhammad Haris
All Rights Reserved to Department of Computer Science – GCU Lahore
Example-1
7Programming Fundamentals | Lecture-2
Step-1: Define the Problem
Input Output Processing
Number1 Sum Add Numbers Together
Number2
Programming Fundamentals | Lecture-2 8
Problem: Find the sum of two numbers
Step-2: Design the Solution Start by drawing a “Start” symbol Show a symbol for Input Show process symbol(s) for processing
There can be more than 1 such steps depending on the complexity of the problem
Show a symbol for Output Finish by drawing a “Stop” Symbol
Programming Fundamentals | Lecture-2 9
Step-2: Design the Solution
Programming Fundamentals | Lecture-2 10
START
READ number1, number2
sum = number1 + number2
DISPLAY sum
STOP
Legend
Programming Fundamentals | Lecture-2 11
Symbol Meaning
Terminal Symbol (Oval) : indicates the beginning and ending of a program
Input-Output Symbol (Parallelogram): shows an input or an output operation
Process Symbol (Rectangle): shows an instruction other than input or output
Other Simple Examples
Find sum of three numbers Division, multiplication, subtraction of
two/three numbers Find Average of two numbers Find square of a number Find acceleration for a given velocity
and time Find Velocity
Programming Fundamentals | Lecture-2 12
Average of Two Numbers
Programming Fundamentals | Lecture-2 13
START
READ number1, number2
sum = number1 + number2
DISPLAY average
STOP
average = sum / 2
Square of a Number
Programming Fundamentals | Lecture-2 14
START
READ number
square = number * number
DISPLAY square
STOP
Acceleration
Programming Fundamentals | Lecture-2 15
START
READ v1, v2, t
change = v2 – v1
DISPLAY acceleration
STOP
acceleration = change / t
Velocity
Programming Fundamentals | Lecture-2 16
START
READ d1, d2, t1, t2
positionChange = d2 – d1
DISPLAY velocity
STOP
timeChange = t2 – t1
velocity = postionChange / timeChange
Why to use Computers? Can do many complicated tasks at very
high speeds and can store large quantities of data
Some SituationsExtensive InputExtensive outputMethod of solution is too complicated to
implement manuallyIf done manually, it takes an excessive long
time to solve
Tasks (to be done before next lecture) Calculate area of a rectangle
area = base height
Find Cube of a Number Calculate Marks Percentage
(marks obtained / total marks) 100
Calculate Sales Taxamount (tax percent / 100)
Find “no. of minutes” and “no. of seconds” for given “no of years”
Programming Fundamentals | Lecture-2 18
Programming Fundamentals | Lecture-2 19
BE READY FOR QUIZ
IN NEXT LECTURE
top related