algorithms behind the scenes: building applications · pdf file• system software 3...

6
8/8/11 1 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Programming Steps Behind the Scenes: Building Applications Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 2 Programming Topics Life cycle of a program Problem statement Algorithms Moving from algorithm to code – Moving from code to machine language Selecting the right programming language – Testing programs – Completing a program Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall What Is a Program? A list of instructions – Prewritten or packaged (off-the-shelf) – Custom-written Application software System software 3 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall What is Programming A problem-solving procedure Programming a computer involves specific problem solving Systems analysis and design involves general problem solving 4 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall What is Programming? Programming is a six-step procedure for producing a program - a list of instructions - for the computer Six-step procedure-part of Phase 4: Systems Development 5 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall The Life Cycle of a Program Programming is the process of translating a task into a series of commands a computer will use to perform that task Programming involves: – Identifying the parts of a task the computer can perform – Describing tasks in a specific and complete manner – Translating the tasks into a language that is understood by the computer’s CPU 6

Upload: lamdien

Post on 06-Feb-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithms Behind the Scenes: Building Applications · PDF file• System software 3 Copyright © 2011 Pearson Education, Inc ... – Includes error ... for cash 13 Copyright © 2011

8/8/11

1

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 1

Programming Steps

Behind the Scenes: Building Applications

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 2

Programming Topics

•  Life cycle of a program –  Problem statement –  Algorithms –  Moving from algorithm to code – Moving from code to machine language

•  Selecting the right programming language – Testing programs – Completing a program

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

What Is a Program?

•  A list of instructions – Prewritten or packaged (off-the-shelf) – Custom-written

•  Application software •  System software

3 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

What is Programming

•  A problem-solving procedure •  Programming a computer involves

specific problem solving •  Systems analysis and design involves

general problem solving

4

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

What is Programming?

•  Programming is a six-step procedure for producing a program - a list of instructions - for the computer

•  Six-step procedure-part of Phase 4: Systems Development

5 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

The Life Cycle of a Program

•  Programming is the process of translating a task into a series of commands a computer will use to perform that task

•  Programming involves: –  Identifying the parts of a task the computer

can perform – Describing tasks in a specific and complete

manner – Translating the tasks into a language that is

understood by the computer’s CPU 6

Page 2: Algorithms Behind the Scenes: Building Applications · PDF file• System software 3 Copyright © 2011 Pearson Education, Inc ... – Includes error ... for cash 13 Copyright © 2011

8/8/11

2

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 1 Program Specification

Step 2 Program Design

Step 3 Program Coding

Step 4 Program Testing

Step 5 Program Documentation

Step 6 Program Maintenance

What is Programming?

•  Programming is software development •  Six step procedure

7 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 1 Program Specifications

(Problem Definition or Analysis) •  Objectives •  Desired

Outputs •  Input Data •  Processing

requirements •  Document

Specifications

8

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 1 Program Specifications (Describing the Problem)

•  The problem statement is: –  The starting point of programming –  A description of tasks the program is to accomplish –  A description of how the program will execute the

tasks –  Created through interaction between the programmer

and the users –  Includes error handling, a testing plan and output

values

9 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 10

Program Goal: To compute the total pay for a fixed number of hours worked at a parking garage.

Inputs: Number of Hours Worked........................ a positive number

Outputs: Total Pay Earned .................................... a positive number

Process: The Total Pay Earned is computed as $7.50 per hour for the first eight hours worked each day. Any hours worked beyond the first eight are billed at $11.25 per hour.

Error Handling: The input Number of Hours Worked must be a positive real number. If it is a negative number or other non-acceptable character, the program will force the user to re-enter the information.

Testing Plan: INPUT OUTPUT NOTES 8 8*7.50 Testing positive input

3 3*7.50 Testing positive input

12 8*7.50 + 4*11.25 Testing overtime input

–6 Error message/ask user to reenter value

Handling error

Parking Garage Example

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 11

Output and Input Plans Output

Input

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 2 Program Design

•  Plan and create a solution •  Use structured programming

techniques –  Algorithm development –  Top-down program design or

object-oriented analysis –  Pseudocode –  Flowcharts –  Logic structures

12

Page 3: Algorithms Behind the Scenes: Building Applications · PDF file• System software 3 Copyright © 2011 Pearson Education, Inc ... – Includes error ... for cash 13 Copyright © 2011

8/8/11

3

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 2 Developing an Algorithm

•  Algorithm development: –  A set of specific, sequential

steps that describe what the computer program must do

–  Complex algorithms include decision points:

•  Binary (yes/no) •  Loop (repeating actions)

–  Visual tools used to track algorithm and decision points:

Head off to cafe

Buy textbook

Go to accounting lecture

Yes No

No

No

Yes

Yes

Wake Up

Check wallet for $

Do I have > $80

Go get gas

Did I get $80 from the ATM?

Do I have my credit card?

Go to the ATM for cash

13 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 14

Step 2 Top-Down Program Design

•  Problem is divided into a series of high-level tasks •  Detailed subtasks are created from high-level

tasks –  Logically related program statements in modules

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 15

Step 2 Top-Down Program Design

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 16

Step 2 Object-Oriented Analysis

•  Classes (categories of inputs) are identified

•  Classes are defined by information (data) and actions (methods or behaviors)

•  Reusability is key •  Objects real data

and method in similar class

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

•  Outlines and summarizes the logic of the program –  Describes reasoning and logic for determining desired

outputs or results

Step 2 Pseudocode

Compute Time for Client A

Set total regular hours and total overtime hours to zero.

Get time In and Out for a job.

Compute hours past 1700 as overtime.

Add regular hours and add regular hours to total regular hours.

Add overtime hours to total overtime hours.

If more for client, go back and compute hours for next job.

17 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 2 Program Flowcharts

•  A detailed sequence of steps graphically displaying flow of actions and decision points

•  Flowchart symbols •  Processing •  Input/Output •  Decision •  Connector •  Terminal

18

Page 4: Algorithms Behind the Scenes: Building Applications · PDF file• System software 3 Copyright © 2011 Pearson Education, Inc ... – Includes error ... for cash 13 Copyright © 2011

8/8/11

4

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 2 Flowchart and Pseudocode

Underlined words are information items that appear repeatedly in the algorithm.

1. Ask the user how many hours they worked today

2. If the number of hours worked < = 8, compute total pay without overtime otherwise, compute total pay with overtime pay 3. Print total pay

Bold terms show actions that are common in programming, such as reading data, making decisions, printing, and so on.

Flowchart Pseudocode

19 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 2 Logic Structures

•  Only three logic structures needed for linking program steps in flowcharts together – Sequence structure

– Selection structure

– Loop structure

20

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 21

Sequence Logic Structure

One program statement follows another in logical order

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 22

Selection Logic Structure (IF-THEN-ELSE)

Used when a decision must be made to determine which of two paths to follow

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 23

Loop (Iteration) Logic Structures (DO UNTIL OR DO WHILE)

Iterates or repeats the process as long as a certain condition remains true – two variations

There are no more jobs

As long as there are more jobs

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 24

Complete Program Flowchart For Computing Time Worked

Page 5: Algorithms Behind the Scenes: Building Applications · PDF file• System software 3 Copyright © 2011 Pearson Education, Inc ... – Includes error ... for cash 13 Copyright © 2011

8/8/11

5

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 3 Program Coding

•  Coding – Writing program from logic created in

program-design step •  The good program

– Reliable – Well documented – Understandable to other

programmers – Structured programs using logic structures is

best programming method 25 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall 26

Step 3 Program Coding

•  Coding is the translation of an algorithm into a programming language

•  Select the appropriate language for the program and writing the program statements

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Step 3 Compilation

•  Compilation is the process of converting code into machine language – Compiler reads the source code and

translates it into machine language –  Interpreter translates source code into a line

by line intermediate form and each line is executed before the next line is compiled

•  After compilation, programmers have an executable program for testing

27 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Summary Questions •  What is a program? •  What are the steps of the Program Development

Life Cycle? •  What role does a problem statement play in

programming? •  Understand top-down design and object-oriented

analysis •  Discuss each of design tools •  How do programmers create algorithms?

28

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Summary Questions •  What is the purpose of pseudocode? •  Explain the purpose of each logic structure in

creating decision points and sequential steps in flowcharts

•  What are the qualities of a good program? •  How do programmers move from an algorithm to

code and what categories of language might they choose?

•  How does a programmer change programming code to the 1s and 0s the CPU can understand?

•  How do programmers select the right programming language for a specific task?

29 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Participation Question

An algorithm is a ______. A.  logic structure B.  program step C.  set of steps D.  problem statement E.  program instruction

30

Page 6: Algorithms Behind the Scenes: Building Applications · PDF file• System software 3 Copyright © 2011 Pearson Education, Inc ... – Includes error ... for cash 13 Copyright © 2011

8/8/11

6

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Participation Question

______ refers to text, organized like an outline, used to document the algorithm. A.  Branching B.  Coding C.  Documentation D.  Flowcharting E.  Pseudocode

31 Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Participation Question

An object, defined by a specific class, is a collection of _________ . A.  class variables B.  data and methods C.  ideas and a testing plan D.  programming languages E.  instructions

32

Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Programming Steps

•  Any questions?

33