introduction to programming. prof. george zolla prof. gary porter (is 2020)
TRANSCRIPT
![Page 1: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/1.jpg)
Introduction to Introduction to ProgrammingProgramming
.
Prof. George Zolla
Prof. Gary Porter (IS 2020)
![Page 2: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/2.jpg)
ProgramsPrograms
A program is a set of A program is a set of step-by-step step-by-step instructions that instructions that directs the computer directs the computer to do the tasks you to do the tasks you want it to do and want it to do and produce the results produce the results you want.you want.
![Page 3: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/3.jpg)
Programming LanguagesProgramming Languages
A programming A programming language is a set language is a set of rules that of rules that provides a way of provides a way of telling a computer telling a computer what operations what operations to perform.to perform.
![Page 4: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/4.jpg)
What Can a Program Do?What Can a Program Do?
A program can only instruct a A program can only instruct a computer to:computer to:• Read InputRead Input• SequenceSequence• CalculateCalculate• Store dataStore data• Compare and branchCompare and branch• Iterate or LoopIterate or Loop• Write OutputWrite Output
![Page 5: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/5.jpg)
Sequence Control Sequence Control StructuresStructures
Sequence control structures direct Sequence control structures direct the order of program instructions.the order of program instructions.
The fact that one instruction The fact that one instruction follows another—in sequence—follows another—in sequence—establishes the control and order establishes the control and order of operations.of operations.
![Page 6: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/6.jpg)
CalculateCalculate
A program can A program can instruct a instruct a computer to computer to perform perform mathematical mathematical operations.operations.
Add 1 to
Counter
![Page 7: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/7.jpg)
StoreStore
A program will A program will often instruct a often instruct a computer to store computer to store intermediate intermediate results.results.
Place 1 in
Counter
![Page 8: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/8.jpg)
Compare and BranchCompare and Branch
A program can instruct a computer to A program can instruct a computer to compare two items and do something compare two items and do something based on a match or mismatch which, based on a match or mismatch which, in turn, redirect the sequence of in turn, redirect the sequence of programming instructions.programming instructions.• There are two forms:There are two forms:• IF-THENIF-THEN• IF-THEN-ELSEIF-THEN-ELSE
![Page 9: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/9.jpg)
IF-THENIF-THEN
Test Test condition pcondition p
falsefalse truetrue
EntryEntry
ExitExitTrue True
statement astatement a
![Page 10: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/10.jpg)
IF-THEN-ELSEIF-THEN-ELSE
falsefalse truetrue
EntryEntry
ExitExit
Test Test condition pcondition p
““true” true” statement astatement a
““false” false” statement astatement a
![Page 11: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/11.jpg)
IterateIterate
A program loop is A program loop is a form of a form of iteration. A iteration. A computer can be computer can be instructed to instructed to repeat repeat instructions under instructions under certain certain conditions.conditions.
NoNo
![Page 12: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/12.jpg)
Iteration Control Iteration Control StructuresStructures
Iteration control structures are Iteration control structures are looping mechanisms. looping mechanisms.
Loops repeat an activity until Loops repeat an activity until stopped. The location of the stopped. The location of the stopping mechanism determines stopping mechanism determines how the loop will work:how the loop will work:
Leading decisionsLeading decisions Trailing decisionsTrailing decisions
![Page 13: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/13.jpg)
Leading DecisionsLeading Decisions
If the stop is at the beginning of If the stop is at the beginning of the iteration, then the control is the iteration, then the control is called a leading decision.called a leading decision.
The command The command DO WHILEDO WHILE performs performs the iteration and places the stop at the iteration and places the stop at the beginning.the beginning.
![Page 14: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/14.jpg)
DO WHILE LoopDO WHILE Loop
NoNo
YesYes
EntryEntry
ExitExit
Test Test condition pcondition p
Loop Loop statement astatement a
![Page 15: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/15.jpg)
Trailing DecisionsTrailing Decisions
If the stop is at the end of the If the stop is at the end of the iteration, the control mechanism is iteration, the control mechanism is called a trailing decision.called a trailing decision.
The command The command DO UNTILDO UNTIL performs performs the iteration and puts the stop at the iteration and puts the stop at the end of the loop.the end of the loop.
![Page 16: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/16.jpg)
DO UNTIL LoopDO UNTIL Loop
Loop Loop statement astatement a
NoNo YesYes
EntryEntry
Test Test condition pcondition p
ExitExit
![Page 17: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/17.jpg)
Programs are SolutionsPrograms are Solutionsto Problemsto Problems
Programmers arrive at these Programmers arrive at these solutions by using one or more of solutions by using one or more of these devices:these devices:
Logic flowchartsLogic flowcharts Structure chartsStructure charts PseudocodePseudocode Structured ProgrammingStructured Programming
![Page 18: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/18.jpg)
Logic FlowchartsLogic Flowcharts
These represent These represent the flow of logic the flow of logic in a program in a program and help and help programmers programmers “see” program “see” program design.design.
![Page 19: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/19.jpg)
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 commandsto 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 witha flowline in and the other with a flowline out.
Off-page connector. Even fairly small programs can have flowcharts that extend severalpages. 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
Common Flowchart Common Flowchart SymbolsSymbols
![Page 20: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/20.jpg)
Start
sum=0
Input price
sum=sum+price
Moreitems?
tax=sum x 0.0725total=sum+tax
Output sum, tax, and total
Stop
No
Yes
Flowchart for aFlowchart for aCash Register ProgramCash Register Program
![Page 21: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/21.jpg)
Structure ChartsStructure Charts
Structure charts illustrate the Structure charts illustrate the structure of a program by showing structure of a program by showing independent hierarchical steps.independent hierarchical steps.
Major divisions are subdivided into Major divisions are subdivided into smaller pieces of information.smaller pieces of information.
![Page 22: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/22.jpg)
PsuedocodePsuedocode
This device is not visual but is This device is not visual but is considered a “first draft” of the actual considered a “first draft” of the actual program.program.
Pseudocode is written in the Pseudocode is written in the programmer’s native language and programmer’s native language and concentrates on the logic in a concentrates on the logic in a program—not the syntax of a program—not the syntax of a programming language.programming language.
![Page 23: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/23.jpg)
sum=0While More items do Input price sum=sum+priceEnd Whiletax=sum x 0.0725total=sum+taxOutput sum, tax, total
Pseudocode for aPseudocode for aCash Register ProgramCash Register Program
![Page 24: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/24.jpg)
Structured ProgrammingStructured Programming
Structured program languages Structured program languages lend themselves to flowcharts, lend themselves to flowcharts, structure charts, and pseudocode.structure charts, and pseudocode.
Structured programming Structured programming languages work best where the languages work best where the instructions have been broken up instructions have been broken up into small, manageable parts.into small, manageable parts.
![Page 25: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/25.jpg)
Analyze the problem
Design the solution algorithm
Design the user interface
Write the code
Test and debug the program
Complete the documentation
The Program Development The Program Development CycleCycle
![Page 26: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/26.jpg)
Levels of Programming Levels of Programming LanguagesLanguages
Machine languageMachine language Assembly LanguageAssembly Language High Level LanguagesHigh Level Languages Fourth Generation Languages Fourth Generation Languages
(4GL)(4GL)
![Page 27: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/27.jpg)
Machine LanguagesMachine Languages
different for each computer processordifferent for each computer processor
01000100
001101001101 100000100000 001101001101 110001110001
0010100101 1000110001 1000010000
0111001110
111001111001
. . .. . .
![Page 28: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/28.jpg)
Assembly Assembly LanguagesLanguages
different for each computer processordifferent for each computer processor
mainmain proc payproc pay
mov ax, dsegmov ax, dseg
mov ax, 0b00hmov ax, 0b00h
add ax, dxadd ax, dx
mov a1, b1mov a1, b1
mul b1, axmul b1, ax
mov b1, 04hmov b1, 04h
![Page 29: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/29.jpg)
High-Level LanguagesHigh-Level Languages
Higher Level LanguagesHigher Level Languages• Use traditional programming logic Use traditional programming logic
where the programming instructions where the programming instructions tell the computer what to do and how tell the computer what to do and how to perform the required operations.to perform the required operations.
4GLs4GLs• Use high-level English-like instructions Use high-level English-like instructions
to specify what to do, not how to do it .to specify what to do, not how to do it .
![Page 30: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/30.jpg)
Interpreter vs CompilerInterpreter vs Compiler
InterpreterInterpreter• Translates instructions to machine Translates instructions to machine
code line-by-line.code line-by-line. CompilerCompiler
• Translates the entire program to Translates the entire program to machine code before running it.machine code before running it.
![Page 31: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/31.jpg)
Types of Programming Types of Programming LanguagesLanguages
Machine languageMachine language Procedure-oriented languagesProcedure-oriented languages Object-oriented languagesObject-oriented languages Event-driven languagesEvent-driven languages
![Page 32: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/32.jpg)
Procedure-Oriented Procedure-Oriented LanguagesLanguages
FORTRANFORTRAN COBOLCOBOL PascalPascal CC AdaAda
![Page 33: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/33.jpg)
OOED LanguagesOOED Languages
Object-oriented languagesObject-oriented languages• SmalltalkSmalltalk• C++C++• Ada 95Ada 95
Event-driven languagesEvent-driven languages• Visual BasicVisual Basic• most Visual languagesmost Visual languages
![Page 34: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/34.jpg)
Programmer’s LingoProgrammer’s Lingo
Program Program - detailed set of instructions for a - detailed set of instructions for a computercomputer
Programming LanguageProgramming Language - tool used to create a - tool used to create a program; defined by semantics and syntaxprogram; defined by semantics and syntax
SemanticsSemantics - the meaning of words in a language- the meaning of words in a language
SyntaxSyntax - rules for combining symbols of a - rules for combining symbols of a languagelanguage
![Page 35: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/35.jpg)
Programmer’s LingoProgrammer’s Lingo
Source Code (code)Source Code (code) - program you write using a programming language
InterpreterInterpreter - translates and executes source code statement by statement
![Page 36: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/36.jpg)
Programmer’s LingoProgrammer’s Lingo
Interpreter Process
![Page 37: Introduction to Programming. Prof. George Zolla Prof. Gary Porter (IS 2020)](https://reader035.vdocuments.mx/reader035/viewer/2022062407/56649ccb5503460f94993f1f/html5/thumbnails/37.jpg)
Programmer’s LingoProgrammer’s Lingo
Compiler ProcessCompiler Process