Fundamental Programming Lect 2
-
Upload
namrah-erum -
Category
Technology
-
view
108 -
download
2
Transcript of Fundamental Programming Lect 2
![Page 1: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/1.jpg)
Instructor : Muhammad Haris
All Rights Reserved to Department of Computer Science – GCU Lahore
Programming Fundamentals
![Page 2: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/2.jpg)
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
![Page 3: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/3.jpg)
Instructor : Muhammad Haris
All Rights Reserved to Department of Computer Science – GCU Lahore
1
![Page 4: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/4.jpg)
Steps in Problem Solving
Define the Problem Design the Solution
1 2
4Programming Fundamentals | Lecture-2
![Page 5: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/5.jpg)
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
![Page 6: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/6.jpg)
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
![Page 7: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/7.jpg)
Instructor : Muhammad Haris
All Rights Reserved to Department of Computer Science – GCU Lahore
Example-1
7Programming Fundamentals | Lecture-2
![Page 8: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/8.jpg)
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
![Page 9: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/9.jpg)
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
![Page 10: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/10.jpg)
Step-2: Design the Solution
Programming Fundamentals | Lecture-2 10
START
READ number1, number2
sum = number1 + number2
DISPLAY sum
STOP
![Page 11: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/11.jpg)
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
![Page 12: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/12.jpg)
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
![Page 13: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/13.jpg)
Average of Two Numbers
Programming Fundamentals | Lecture-2 13
START
READ number1, number2
sum = number1 + number2
DISPLAY average
STOP
average = sum / 2
![Page 14: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/14.jpg)
Square of a Number
Programming Fundamentals | Lecture-2 14
START
READ number
square = number * number
DISPLAY square
STOP
![Page 15: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/15.jpg)
Acceleration
Programming Fundamentals | Lecture-2 15
START
READ v1, v2, t
change = v2 – v1
DISPLAY acceleration
STOP
acceleration = change / t
![Page 16: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/16.jpg)
Velocity
Programming Fundamentals | Lecture-2 16
START
READ d1, d2, t1, t2
positionChange = d2 – d1
DISPLAY velocity
STOP
timeChange = t2 – t1
velocity = postionChange / timeChange
![Page 17: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/17.jpg)
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
![Page 18: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/18.jpg)
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
![Page 19: Fundamental Programming Lect 2](https://reader036.fdocuments.net/reader036/viewer/2022081502/55ce3006bb61eb2e1c8b4660/html5/thumbnails/19.jpg)
Programming Fundamentals | Lecture-2 19
BE READY FOR QUIZ
IN NEXT LECTURE