computer chapter 8, 9 & 10

24
Basic Computing/ Computer Orientation Lecture 8, 9 & 10 by Sara Hassan

Upload: ali-zulfiqar

Post on 19-May-2015

2.003 views

Category:

Education


5 download

DESCRIPTION

Lahore Business School (LBS)

TRANSCRIPT

Page 1: Computer Chapter 8, 9 & 10

Basic Computing/ Computer Orientation

Lecture 8, 9 & 10

by Sara Hassan

Page 2: Computer Chapter 8, 9 & 10

Chapter 8

Computer Programming Fundamentals

Page 3: Computer Chapter 8, 9 & 10

The Problem-Solving Process

Input

Processing

Output

Page 4: Computer Chapter 8, 9 & 10

Program

A program is the set of instructions that instruct the computer about the way the task is to be performed.

Instructions in a Program have three parts

Accept Input Data that needs to be processed

Act upon Input Data and process it

Provide Output to user Instructions are defined in a specific sequence

4Chapter-8: Computer Programming Fundamentals

Page 5: Computer Chapter 8, 9 & 10

Program Planning

1. Analyze

2. Design

3. Code, Test and Debug

4. Complete the Documentation

Page 6: Computer Chapter 8, 9 & 10

Program Development Lifecycle

Chapter-8: Computer Programming Fundamentals 6

Page 7: Computer Chapter 8, 9 & 10

Algorithm

Ordered sequence of finite, well defined, unambiguous instructions for completing a task.

English-like representation of logic to solve problem Step-by-step procedure for solving problem For a particular task, different algorithms can be written

Select an algorithm based on advantages and disadvantages

Different Algorithms would typically lead to trade off between memory requirements and execution speed

Chapter-8: Computer Programming Fundamentals 7

Page 8: Computer Chapter 8, 9 & 10

Algorithm: An Example

Chapter-8: Computer Programming Fundamentals 8

Page 9: Computer Chapter 8, 9 & 10

Control Structures

Specifies statements to be executed and order of execution of statements

Execution of a statement based on a decision Repetitively execute statements unless condition met

Used by Flowchart, Pseudo code Three kinds

Sequential: Instructions executed in linear orderSelection (branch or conditional): Asks true/false question and selects next instruction based on answerIterative (loop): Repeats execution of block of instructions

Chapter-8: Computer Programming Fundamentals 9

Page 10: Computer Chapter 8, 9 & 10

Flowchart

Diagrammatic representation of logic for solving task Drawn using boxes of different shapes with lines connecting

them to show the flow of control Make logic of program clearer in a visual form Diagrammatic representation forms a common medium of

communication Drawn using different kinds of symbols.

Chapter-8: Computer Programming Fundamentals 10

Page 11: Computer Chapter 8, 9 & 10

Flowchart symbols

Chapter-8: Computer Programming Fundamentals 11

Page 12: Computer Chapter 8, 9 & 10

Elements of Flowcharts Symbol Name

Flowline

Terminal

Input/Output

Processing

Decision

Page 13: Computer Chapter 8, 9 & 10

Continued… Symbol Name

Connector

Off page Connector

Predefined process

Annotation

Page 14: Computer Chapter 8, 9 & 10

Preparing a Flowchart

Common symbols that are used to draw a flowchart

Process, Decision, Data, Terminator, Connector and Flow lines Rules

Should have Start and End

Direction of flow must be from top to bottom and left to right

Relevant symbols must be used while drawing a flowchart

Sequence, selection, iterative structures may be used wherever required

Chapter-8: Computer Programming Fundamentals 14

Page 15: Computer Chapter 8, 9 & 10

Control Structures in Flowchart

Chapter-8: Computer Programming Fundamentals 15

Page 16: Computer Chapter 8, 9 & 10

Preparing a Flowchart (contd..)

Sequence: Steps executed in linear order Selection: Step to be executed next is based on decision

taken. Different path followed for True and False Iterative: Condition is checked. Either next step in sequence is

executed or control goes back to one of the already executed steps to make a loop

Limitations

May run into multiple pages, difficult to understand

Updating with changing requirements

Chapter-8: Computer Programming Fundamentals 16

Page 17: Computer Chapter 8, 9 & 10

Examples of Flowchart

Chapter-8: Computer Programming Fundamentals 17

Product of two numbers

Product of two numbers

Maximum of three numbersMaximum of

three numbersSum of first 100 integersSum of first 100 integers

Can you draw a

flowchart to read 100 numbers and print

the largest number?

Page 18: Computer Chapter 8, 9 & 10

start

Read data

Is next no. greater than

“greatest” ?

Assign the first value in the list to “greatest”

Compare the number in “greatest” with next

no. in the list

Assign next no. to “greatest”

Declare a variable “greatest”

Are there more numbers in the list?

YES

YES

NO

NO

Page 19: Computer Chapter 8, 9 & 10

Solving the Break- in - Class Problem

In order to make the classes more productive and easy on the nerves the Admin at a university wants to formulate the policy on giving breaks in the classes. They have come up with an idea of giving breaks only when they are required by the class students and their duration is also to be determined by how much severely it is demanded. You are required to develop a flow chart to demonstrate how the policy is to work. They’ve provided you with the following data:

Students who want break

Situation Break Duration

Less than equal to 5%

Trivial No break

5 < x ≤ 15 % Fair 3 Min Break

15 < x ≤ 25% Modest 5 Min Break

25 < x ≤ 50% or greater

Dire 10 Min Break

Page 20: Computer Chapter 8, 9 & 10

start

Show of Hands for

Break

0 < x < 5

No break

5 < x <1 5

3 mins

15 < x < 25

5 mins

END

25 < x <50

10 mins

Page 21: Computer Chapter 8, 9 & 10

Pseudo code

Consists of short, readable and formally-styled English language used for explaining an algorithm.

Does not include details like variable declarations, subroutines etc.

Short-hand way of describing computer program Not based on any programming language Uses structured constructs of programming language but is

not machine readable Cannot be compiled or executed No standard for syntax of pseudo code exists Easily translated into a programming language

Chapter-8: Computer Programming Fundamentals 21

Page 22: Computer Chapter 8, 9 & 10

Preparing Pseudo code

Written using structured English Commonly used terms to represent actions

Inputting data: INPUT, GET, READ

Outputting data: OUTPUT, PRINT, DISPLAY

Calculations: COMPUTE, CALCULATE

Incrementing: INCREMENT Control structures

Sequence structure: sequence of steps executed in linear order

Selection constructs: if-statement, case statement

Iterative statements: WHILE, DO-WHILE

Chapter-8: Computer Programming Fundamentals 22

Page 23: Computer Chapter 8, 9 & 10

Control structures for Pseudo code

Chapter-8: Computer Programming Fundamentals 23

IF (condition) THEN Statement(s) 1ELSE Statement(s) 2ENDIFStep 1

Step 2

Step 3

:::

WHILE (condition) Statement 1 Statement 2 : :END

DO Statement 1 Statement 2 : : WHILE (condition)

CASE expression of Condition-1 : statement1 Condition-2 : statement2 : Condition-N : statement N OTHERS: default statement(s)

IF (condition) THEN Statement(s) 1ENDIF

Sequence Selection Iteration

Page 24: Computer Chapter 8, 9 & 10

Algorithm, Flowchart, Pseudo code Algorithm: A sequence of instructions used to solve a

particular problem Flowchart and Pseudo code: Tools to document and represent

algorithm

Flowchart : Graphical representation of algorithm

Pseudo code: Readable, formally styled English like language representation of algorithm

No knowledge of programming language required to write or understand flowchart or pseudo code

Chapter-8: Computer Programming Fundamentals 24