Introduction to programming
This presentation is the property of its rightful owner.
Sponsored Links
1 / 37

Introduction to Programming PowerPoint PPT Presentation


  • 62 Views
  • Uploaded on
  • Presentation posted in: General

Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020). Programs. A program is a set of step-by-step instructions that directs the computer to do the tasks you want it to do and produce the results you want. Programming Languages.

Download Presentation

Introduction to Programming

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Introduction to programming

Introduction to Programming

Prof. George Zolla

Prof. Gary Porter (IS 2020)

.


Programs

Programs

  • A program is a set of step-by-step instructions that directs the computer to do the tasks you want it to do and produce the results you want.


Programming languages

Programming Languages

  • A programming language is a set of rules that provides a way of telling a computer what operations to perform.


What can a program do

What Can a Program Do?

  • A program can only instruct a computer to:

    • Read Input

    • Sequence

    • Calculate

    • Store data

    • Compare and branch

    • Iterate or Loop

    • Write Output


Sequence control structures

Sequence Control Structures

  • Sequence control structures direct the order of program instructions.

  • The fact that one instruction follows another—in sequence—establishes the control and order of operations.


Calculate

Calculate

  • A program can instruct a computer to perform mathematical operations.

Add 1 to Counter


Store

Store

  • A program will often instruct a computer to store intermediate results.

Place 1 in Counter


Compare and branch

Compare and Branch

  • A program can instruct a computer to compare two items and do something based on a match or mismatch which, in turn, redirect the sequence of programming instructions.

    • There are two forms:

    • IF-THEN

    • IF-THEN-ELSE


If then

Entry

false

true

Exit

True statement a

IF-THEN

Test condition p


If then else

Entry

Test condition p

false

true

“false” statement a

“true” statement a

Exit

IF-THEN-ELSE


Iterate

Iterate

  • A program loop is a form of iteration. A computer can be instructed to repeat instructions under certain conditions.

No


Iteration control structures

Iteration Control Structures

  • Iteration control structures are looping mechanisms.

  • Loops repeat an activity until stopped. The location of the stopping mechanism determines how the loop will work:

  • Leading decisions

  • Trailing decisions


Leading decisions

Leading Decisions

  • If the stop is at the beginning of the iteration, then the control is called a leading decision.

  • The command DO WHILE performs the iteration and places the stop at the beginning.


Do while loop

Entry

Exit

No

Test condition p

Yes

Loop statement a

DO WHILE Loop


Trailing decisions

Trailing Decisions

  • If the stop is at the end of the iteration, the control mechanism is called a trailing decision.

  • The command DO UNTIL performs the iteration and puts the stop at the end of the loop.


Do until loop

Entry

Exit

No

Yes

Test condition p

DO UNTIL Loop

Loop statement a


Programs are solutions to problems

Programs are Solutionsto Problems

  • Programmers arrive at these solutions by using one or more of these devices:

  • Logic flowcharts

  • Structure charts

  • Pseudocode

  • Structured Programming


Logic flowcharts

Logic Flowcharts

  • These represent the flow of logic in a program and help programmers “see” program design.


Common flowchart symbols

Common Flowchart Symbols

Terminator. Shows the starting and ending points of the program. A terminator has flowlines in only one direction, either in (a stop node) or out (a start node).

Data Input or Output. Allows the user to inputdata and results to be displayed.

Processing. Indicates an operation performed by the computer, such as a variable

assignment or mathematical operation.

Decision. The diamond indicates a decision structure. A diamond always has two

flowlines out. One flowlineout is labeled the “yes” branch and the other is labeled the

“no” branch.

Predefined Process. One statement denotes a group of previously defined statements.

For instance, “Calculate m!” indicates that the program executes the necessary commands

to compute m factorial.

Connector. Connectors avoid crossing flowlines, making the flowchart easier to read.

Connectors indicate where flowlines are connected. Connectors come in pairs, one with

a flowline in and the other with a flowline out.

Off-page connector. Even fairly small programs can have flowcharts that extend several

pages. The off-page connector indicates the continuation of the flowchart on another

page. Just like connectors, off-page connectors come in pairs.

Flowline. Flowlines connect the flowchart symbols and show the sequence of operations during the program execution.

Common Flowchart Symbols


Flowchart for a cash register program

Start

sum=0

Input price

sum=sum+price

More

items?

Yes

No

tax=sum x 0.0725

total=sum+tax

Output sum, tax,

and total

Stop

Flowchart for aCash Register Program


Structure charts

Structure Charts

  • Structure charts illustrate the structure of a program by showing independent hierarchical steps.

  • Major divisions are subdivided into smaller pieces of information.


Psuedocode

Psuedocode

  • This device is not visual but is considered a “first draft” of the actual program.

  • Pseudocode is written in the programmer’s native language and concentrates on the logic in a program—not the syntax of a programming language.


Pseudocode for a cash register program

Pseudocode for aCash Register Program

sum=0

While More items do

Input price

sum=sum+price

End While

tax=sum x 0.0725

total=sum+tax

Output sum, tax, total


Structured programming

Structured Programming

  • Structured program languages lend themselves to flowcharts, structure charts, and pseudocode.

  • Structured programming languages work best where the instructions have been broken up into small, manageable parts.


The program development cycle

The Program Development Cycle

Analyze the problem

Design the solution algorithm

Design the user interface

Write the code

Test and debug the program

Complete the documentation


Levels of programming languages

Levels of Programming Languages

  • Machine language

  • Assembly Language

  • High Level Languages

  • Fourth Generation Languages (4GL)


Machine languages

Machine Languages

  • different for each computer processor

    0100

    001101100000001101110001

    001011000110000

    01110

    111001

    . . .


Assembly languages

Assembly Languages

  • different for each computer processor

    mainproc pay

    mov ax, dseg

    mov ax, 0b00h

    add ax, dx

    mov a1, b1

    mul b1, ax

    mov b1, 04h


High level languages

High-Level Languages

  • Higher Level Languages

    • Use traditional programming logic where the programming instructions tell the computer what to do and how to perform the required operations.

  • 4GLs

    • Use high-level English-like instructions to specify what to do, not how to do it .


Interpreter vs compiler

Interpreter vs Compiler

  • Interpreter

    • Translates instructions to machine code line-by-line.

  • Compiler

    • Translates the entire program to machine code before running it.


Types of programming languages

Types of Programming Languages

  • Machine language

  • Procedure-oriented languages

  • Object-oriented languages

  • Event-driven languages


Procedure oriented languages

Procedure-Oriented Languages

  • FORTRAN

  • COBOL

  • Pascal

  • C

  • Ada


Ooed languages

OOED Languages

  • Object-oriented languages

    • Smalltalk

    • C++

    • Ada 95

  • Event-driven languages

    • Visual Basic

    • most Visual languages


Programmer s lingo

Programmer’s Lingo

Program - detailed set of instructions for a computer

Programming Language - tool used to create a program; defined by semantics and syntax

Semantics- the meaning of words in a language

Syntax- rules for combining symbols of a language


Programmer s lingo1

Programmer’s Lingo

Source Code (code) - program you write using a programming language

Interpreter- translates and executes source code statement by statement


Programmer s lingo2

Programmer’s Lingo

Interpreter Process


Programmer s lingo3

Programmer’s Lingo

Compiler Process


  • Login