Upcoming SlideShare
×

# Computer Chapter 8, 9 & 10

• 1,953 views

Lahore Business School (LBS)

Lahore Business School (LBS)

More in: Education , Technology
• Comment goes here.
Are you sure you want to
Your message goes here
Be the first to comment
Be the first to like this

Total Views
1,953
On Slideshare
0
From Embeds
0
Number of Embeds
0

Shares
38
0
Likes
0

No embeds

### Report content

No notes for slide

### Transcript

• 1. Basic Computing/ Computer Orientation Lecture 8, 9 & 10 by Sara Hassan
• 2. Chapter 8Computer Programming Fundamentals
• 3. The Problem-Solving Process Input Processing Output
• 4. 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 Chapter-8: Computer Programming Fundamentals 4
• 5. Program Planning 1. Analyze 2. Design 3. Code, Test and Debug 4. Complete the Documentation
• 6. Program Development Lifecycle Chapter-8: Computer Programming Fundamentals 6
• 7. 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
• 8. Algorithm: An Example Chapter-8: Computer Programming Fundamentals 8
• 9. 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 order Selection (branch or conditional): Asks true/false question and selects next instruction based on answer Iterative (loop): Repeats execution of block of instructions Chapter-8: Computer Programming Fundamentals 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
• 11. Flowchart symbols Chapter-8: Computer Programming Fundamentals 11
• 12. Elements of Flowcharts Symbol Name Flowline Terminal Input/Output Processing Decision
• 13. Continued… Symbol Name Connector Off page Connector Predefined process Annotation
• 14. 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
• 15. Control Structures in Flowchart Chapter-8: Computer Programming Fundamentals 15
• 16. 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
• 17. Examples of Flowchart Can you draw a flowchart to read 100 numbers and print the largest number? Product of Maximum of Sum of firsttwo numbers three numbers 100 integers Chapter-8: Computer Programming Fundamentals 17
• 18. start Read data Declare a variable “greatest” Assign the first value in the list to “greatest” Compare the number in “greatest” with next no. in the list Is next no. YES greater than “greatest” ? NO Assign next no. to “greatest”YES Are there more numbers in the list?
• 19. Solving the Break- in - ClassProblemIn order to make the classes Students Situation Break more productive and easy who want Duration on the nerves the Admin at a university wants to break formulate the policy on Less than Trivial No break giving breaks in the classes. equal to 5% They have come up with an idea of giving breaks only when they are required by 5 < x ≤ 15 % Fair 3 Min the class students and their Break duration is also to be determined by how much 15 < x ≤ 25% Modest 5 Min severely it is demanded. Break You are required to develop a flow chart to demonstrate 25 < x ≤ 50% Dire 10 Min how the policy is to work. They’ve provided you with or greater Break the following data:
• 20. startShow ofHands for Break 0 <x<5 No break 5 < x <1 5 3 mins15 < x < 25 5 mins25 < x <50 10 minsEND
• 21. 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
• 22. 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
• 23. Control structures for Pseudocode IF (condition) THEN WHILE (condition) Statement(s) 1 Statement 1 ELSE Statement 2 Statement(s) 2 Step 1 : ENDIF : Step 2 END IF (condition) THEN Statement(s) 1 Step 3 DO ENDIF Statement 1 : Statement 2 CASE expression of : : Condition-1 : statement1 : : Condition-2 : statement2 WHILE (condition) : Condition-N : statement N OTHERS: default statement(s)Sequence Selection Iteration Chapter-8: Computer Programming Fundamentals 23
• 24. Algorithm, Flowchart, Pseudocode 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