Transcript
Page 1: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Programming at a high level

Page 2: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Developing a Computer Program

Programmer Writes program in source code (VB or other language)

Compiler Converts source code to machine language code

Linker Combines machine language with libraries & converts them to an

executable module Interpreter

Converts source code to machine language and executes one line at a time

Compiler Link/loadExecutable

module

Source

codeMachinelanguage Output

Input dataHigh-levellanguage

Low-levelLanguage

Page 3: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Programming Process

Grace M. HopperFirst “Bug”

Algorithm Design(underlying logic of program)

Program Composition

Debug & test(error free & reliable)

Program Documentation

Program Maintenance

Page 4: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Programming Tools

Tools to convert algorithms into computer programs Algorithm: Step-by-Step procedure for solving a

problem Example Problem: You write a letter. To mail it,

you must decide how much postage to put on the envelop.

Rule of Thumb: One stamp for every 5 sheets of paper.

Algorithm: see next slide

Page 5: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Algorithm1. Request the number of sheets of paper; call this “Sheets”

2. Divide Sheets by 5

3. Round the quotient up to the next highest whole number; call it “Stamps”

4. Reply with the number Stamps

5. Example:

INPUT(16)

ProcessingOutput

(4)

Page 6: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Flowchart Symbols

Flow Line

Start/Stop

Input/Output

Processing

Decision

Page 7: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Stamp Problem

Program: Determine the proper number of stamps for a letter

Read sheets

Set the number of stamps to sheets/5

Round the number of stamps up to the next whole number

Display the number of stamps

Start

Readsheets

Set stamps = sheets/5

Round stamps upTo next whole #

Displaystamps

End

Input

Processing

Processing

Output

Flowchart Pseudocode

Page 8: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Decisions

If condition is true,

thenProcess step(s) 1

ElseProcess step(s) 2

End if

Is condition

True?

ProcessStep(s) 1

ProcessStep(s) 2

No Yes

Flowchart Pseudocode

Page 9: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Pseudocode Structure

Start and stop begin and end

Output Return

Decisions If-then-else

Loops For While-do Repeat-until

Page 10: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Real world problems

A traffic light A vending machine An elevator An ATM

Page 11: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Mathematical problems

Calculate the summation of a list of numbers Calculate the average of a list of numbers Find the maximum number from a list Find the minimum number from a list

Page 12: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Average Grade Problem

Start

Sum=0Count = 0

InputGrade

More grades?

Sum = Sum + GradeCount = Count + 1

Average = Sum/Count

Stop

No

Yes

Flowchart Pseudocode

BEGIN Average Grade

sum=0 count = 0

DO WHILE grade > 0 sum = sum + grade count = count +1 END DO

average = sum/count

END Average Grade

Page 13: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Introduction to Search Algorithms

Search: locate an item in a list (array, vector, etc.) of information

Two algorithms: Linear search Binary search Interpolation search

Page 14: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Linear Search Tradeoffs

Benefits Easy algorithm to understand Array can be in any order

Disadvantage Inefficient (slow): for array of N elements,

examines N/2 elements on average for value in array, N elements for value not in array

Page 15: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Binary Search Algorithm1. Divide an ordered array into three sections.

middle element elements on one side of the middle element elements on the other side of the middle element

2. If the middle element is the correct value, done. Otherwise, go to step 1, using only the half of the array that may contain the correct value.

3. Continue steps 1 and 2 until either the value is found or there are no more elements to examine.

Page 16: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Binary Search Tradeoffs

Benefit Much more efficient than linear search(For array of N elements, performs at mostlog2N comparisons)

Disadvantage Requires that array elements be ordered

Page 17: Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source

Interpolation Search Tradeoffs Benefits

Much more efficient than binary search(For array of N elements, performs log2log2N

comparisons on an average)

Disadvantage Requires that array elements be ordered Elements need to be uniformly distributed for best

performance


Top Related