Title: Introduction to Programming
1Introduction to Programming
Prof. George Zolla Prof. Gary Porter (IS 2020)
.
2Programs
- 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.
3Programming Languages
- A programming language is a set of rules that
provides a way of telling a computer what
operations to perform.
4What 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
5Sequence Control Structures
- Sequence control structures direct the order of
program instructions. - The fact that one instruction follows anotherin
sequenceestablishes the control and order of
operations.
6Calculate
- A program can instruct a computer to perform
mathematical operations.
Add 1 to Counter
7Store
- A program will often instruct a computer to store
intermediate results.
Place 1 in Counter
8Compare 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
9IF-THEN
Test condition p
10IF-THEN-ELSE
11Iterate
- A program loop is a form of iteration. A computer
can be instructed to repeat instructions under
certain conditions.
No
12Iteration 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
13Leading 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.
14DO WHILE Loop
15Trailing 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.
16DO UNTIL Loop
Loop statement a
17Programs are Solutionsto Problems
- Programmers arrive at these solutions by using
one or more of these devices - Logic flowcharts
- Structure charts
- Pseudocode
- Structured Programming
18Logic Flowcharts
- These represent the flow of logic in a program
and help programmers see program design.
19Common Flowchart Symbols
20Flowchart for aCash Register Program
21Structure Charts
- Structure charts illustrate the structure of a
program by showing independent hierarchical
steps. - Major divisions are subdivided into smaller
pieces of information.
22Psuedocode
- This device is not visual but is considered a
first draft of the actual program. - Pseudocode is written in the programmers native
language and concentrates on the logic in a
programnot the syntax of a programming language.
23Pseudocode for aCash Register Program
sum0 While More items do Input price
sumsumprice End While taxsum x
0.0725 totalsumtax Output sum, tax, total
24Structured 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.
25The 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
26Levels of Programming Languages
- Machine language
- Assembly Language
- High Level Languages
- Fourth Generation Languages (4GL)
27Machine Languages
- different for each computer processor
- 0100
- 001101 100000 001101 110001
- 00101 10001 10000
- 01110
- 111001
- . . .
28Assembly Languages
- different for each computer processor
- main proc pay
- mov ax, dseg
- mov ax, 0b00h
- add ax, dx
- mov a1, b1
- mul b1, ax
- mov b1, 04h
29High-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 .
30Interpreter vs Compiler
- Interpreter
- Translates instructions to machine code
line-by-line. - Compiler
- Translates the entire program to machine code
before running it.
31Types of Programming Languages
- Machine language
- Procedure-oriented languages
- Object-oriented languages
- Event-driven languages
32Procedure-Oriented Languages
- FORTRAN
- COBOL
- Pascal
- C
- Ada
33OOED Languages
- Object-oriented languages
- Smalltalk
- C
- Ada 95
- Event-driven languages
- Visual Basic
- most Visual languages
34Programmers 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
35Programmers Lingo
- Source Code (code) - program you write using a
programming language - Interpreter - translates and executes source code
statement by statement
36Programmers Lingo
Interpreter Process
37Programmers Lingo