+ All Categories
Home > Technology > Fundamental Programming Lect 2

Fundamental Programming Lect 2

Date post: 15-Aug-2015
Category:
Upload: namrah-erum
View: 84 times
Download: 2 times
Share this document with a friend
Popular Tags:
19
Instructor : Muhammad Haris All Rights Reserved to Department of Computer Science – GCU Lahore Programming Fundamentals
Transcript
Page 1: Fundamental Programming Lect 2

Instructor : Muhammad Haris

All Rights Reserved to Department of Computer Science – GCU Lahore

Programming Fundamentals

Page 2: Fundamental Programming Lect 2

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

Instructor : Muhammad Haris

All Rights Reserved to Department of Computer Science – GCU Lahore

1

Page 4: Fundamental Programming Lect 2

Steps in Problem Solving

Define the Problem Design the Solution

1 2

4Programming Fundamentals | Lecture-2

Page 5: Fundamental Programming Lect 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

Page 6: Fundamental Programming Lect 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

Page 7: Fundamental Programming Lect 2

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

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

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

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

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

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

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

Square of a Number

Programming Fundamentals | Lecture-2 14

START

READ number

square = number * number

DISPLAY square

STOP

Page 15: Fundamental Programming Lect 2

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

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

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

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

Programming Fundamentals | Lecture-2 19

BE READY FOR QUIZ

IN NEXT LECTURE


Recommended