prof. ken regis institute for computer engineering florida state university oktober 2002prof. ken...
TRANSCRIPT
![Page 1: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/1.jpg)
Prof. Ken Regis Institute for Computer Engineering
Florida State University
Oktober 2002 Prof. Ken Regis - FIT 1-1 1
![Page 2: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/2.jpg)
Ken Regis
![Page 3: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/3.jpg)
Why learn about programming?
programming teaches you how to solve problems
programming helps you be more precise (doesn’t win you many friends though!)
why did the computer scientist stay in the shower forever?the instructions on the shampoo said “lather, rinse, repeat!”
programming gets you more out of your computer
you may not be programming, butknowing a little bit about Computer Scienceand knowing a little bit about Programmingwill help you work with people who do
![Page 4: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/4.jpg)
ProgramsA 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.
![Page 5: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/5.jpg)
You have already programmed!You wrote complex formulas in Excel
=$D5*EKSP(-LN(2)*E$4/$C5)
You used SQL to talk to databasesSELECT * FROM contacts
WHERE age BETWEEN 18 AND 35;
You programmed in MATLABfunction r = fz(x)global M p w1; X = [cos(x), sin(x); -sin(x), cos(x)]; r1 = M' - p' - X*w1'; r = r1'*r1;
![Page 6: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/6.jpg)
ProgrammingProgramming consists of two steps:
algorithmic design (the architects) coding (the construction workers)
Programming requires: a programming language to express your ideas a set of tools to design, edit, and debug your code either
a compiler to translate your programs to machine code a machine to run the executable code
or an interpreter to translate and execute your program
![Page 7: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/7.jpg)
Programming LanguagesA programming language is a set of rules
that provides a way of telling a computer what operations to perform.
![Page 8: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/8.jpg)
Levels of Programming LanguagesMachine languageAssembly LanguageHigh Level LanguagesFourth Generation Languages (4GL)Fifth Generation Languages (5GL)
![Page 9: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/9.jpg)
Machine Languagesdifferent for each computer processor
0100001101 100000 001101 11000100101 10001 1000001110111001. . .
![Page 10: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/10.jpg)
Assembly Languagesdifferent for each computer processor
main proc paymov ax, dsegmov ax, 0b00hadd ax, dxmov a1, b1mul b1, axmov b1, 04h
![Page 11: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/11.jpg)
High-Level LanguagesHigher Level Languages
Use traditional programming logic where the programming instructions tell the computer what to do and how to perform the required operations.
4GLsUse high-level English-like instructions to
specify what to do, not how to do it .
![Page 12: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/12.jpg)
Types of high level Programming Languages
Procedure-oriented languagesObject-oriented languagesEvent-driven languagesDeclarative languages
![Page 13: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/13.jpg)
Procedure-Oriented LanguagesFORTRANCOBOLPascalCAda
![Page 14: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/14.jpg)
OOED Languages
Object-oriented languagesSmalltalkC++Ada 95JavaC#
Event-driven languagesVisual Basicmost Visual languages
![Page 15: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/15.jpg)
Declarative languages (5GL)Functional(?): Lisp, Scheme, SML
Also called applicativeEverything is a function
Logic: PrologBased on mathematical logicRule- or Constraint-based
![Page 16: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/16.jpg)
![Page 17: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/17.jpg)
Lots more LanguagesThere are many programming languages out
therespecification languages, e.g. Z, UMLdocument languages, e.g. LaTeX, Postscriptcommand languages, e.g. csh, MATLABquery languages, e.g. SQLScripting languages, e.g. Perl, Python,
JavaScript, VBScript, ASP, PHP, …
![Page 18: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/18.jpg)
What determines a “good” languageFormerly: Run-time performance
(Computers were more expensive than programmers)
Now: Life cycle (human) cost is more importantEase of designing, codingDebuggingMaintenanceReusability
FADS
![Page 19: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/19.jpg)
Why so many?Why does some people speak French?Most important: the choice of paradigm, and
therefore language, depends on how humans best think about the problem
Other considerations:efficiencycompatibility with existing codeavailability of tools
![Page 20: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/20.jpg)
What can a program do?A program can only instruct a computer
to:SequenceCalculateStore dataCompare and branchIterate or LoopWrite OutputRead Input
![Page 21: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/21.jpg)
Sequence Control StructuresSequence control structures direct the order
of program instructions.The fact that one instruction follows another
—in sequence—establishes the control and order of operations.
![Page 22: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/22.jpg)
CalculateA program can
instruct a computer to perform mathematical operations.
Add 1 to
Counter
![Page 23: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/23.jpg)
StoreA program will often
instruct a computer to store intermediate results.
Place 1 in
Counter
![Page 24: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/24.jpg)
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-THENIF-THEN-ELSE
![Page 25: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/25.jpg)
IF-THEN
Test Test condition pcondition p
falsefalse truetrue
EntryEntry
ExitExitTrue True
statement astatement a
![Page 26: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/26.jpg)
IF-THEN-ELSE
falsefalse truetrue
EntryEntry
ExitExit
Test Test condition pcondition p
““true” true” statement astatement a
““false” false” statement astatement a
![Page 27: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/27.jpg)
IterateA program loop is a
form of iteration. A computer can be instructed to repeat instructions under certain conditions.
NoNo
![Page 28: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/28.jpg)
Iteration Control StructuresIteration control structures are looping
mechanisms. Loops repeat an activity until stopped. The
location of the stopping mechanism determines how the loop will work:
Leading decisionsTrailing decisions
![Page 29: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/29.jpg)
Leading DecisionsIf 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.
![Page 30: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/30.jpg)
DO WHILE Loop
NoNo
YesYes
EntryEntry
ExitExit
Test Test condition pcondition p
Loop Loop statement astatement a
![Page 31: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/31.jpg)
Trailing DecisionsIf 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.
![Page 32: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/32.jpg)
DO UNTIL Loop
Loop Loop statement astatement a
NoNo YesYes
EntryEntry
Test Test condition pcondition p
ExitExit
![Page 33: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/33.jpg)
Programs are Solutionsto ProblemsProgrammers arrive at these solutions by
using one or more of these devices:Logic flowchartsPseudocodeStructured ProgrammingUMLObject Oriented Programming
![Page 34: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/34.jpg)
Logic FlowchartsThese represent the
flow of logic in a program and help programmers “see” program design.
![Page 35: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/35.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
![Page 36: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/36.jpg)
Start
sum=0
Input price
sum=sum+price
Moreitems?
vat=sum x 0.25total=sum+vat
Output sum, vat, and total
Stop
No
Yes
![Page 37: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/37.jpg)
PsuedocodeThis 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.
![Page 38: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/38.jpg)
sum=0While More items do Input price sum=sum+priceEnd Whilevat=sum x 0.25total=sum+vatOutput sum, vat, total
![Page 39: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/39.jpg)
Structured ProgrammingStructured program languages lend
themselves to flowcharts and pseudocode.Structured programming languages work
best where the instructions have been broken up into small, manageable parts.
![Page 40: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/40.jpg)
Object Oriented ProgrammingEverything is an objectA program is a bunch of objects telling
each other what to do by sending messages
Each object has its own memory made up of other objects
Every object has a typeAll objects of a particular type can
receive the same messages(Alan Kay)
![Page 41: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/41.jpg)
The object conceptAn object is an encapsulation of data and
behaviour, modeled after real-world objectsAn object is an instance of an abstract data typeAn abstract data type is implemented via a classAn object has
identity (a unique reference) state (also called characteristics) behaviour
Behaviour is implemented via methods Methods are often implemented using structured
programmingAn objects methods and state are access via dot
notation I.e document.write(“Hello World”)
![Page 42: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/42.jpg)
Analyze the problem
Design the solution algorithm
Design the user interface
Write the code
Test and debug the program
Complete the documentation
![Page 43: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/43.jpg)
Programming and DebuggingWrite code
Syntax Rules of the language
Logic Order of execution of various parts of the program
![Page 44: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/44.jpg)
Programming and DebuggingProgramming Errors
Syntax error Misuse of syntax
e.g., typing fer instead of for
Logic errors Unintended operation of program
e.g., Infinite loop
![Page 45: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/45.jpg)
Programming and DebuggingDebugging
Tracing and resolving errors in a program Coined by Admiral Grace Hopper
Moth short-circuited a relay “bug” in the system
Removed it system “debugged” Not an exact science – more a black art Human against evil machine!
![Page 46: Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11](https://reader034.vdocuments.us/reader034/viewer/2022051622/5697bfee1a28abf838cb98e6/html5/thumbnails/46.jpg)
So really, why learn about programming?Programmers make lots of money. Programming really is fun. Programming is very intellectually
rewarding. Programming makes you feel superior to
other people. Programming gives you complete control
over an innocent, vulnerable machine, which will do your evil bidding with a loyalty not even your pet dog can rival.