Presentation on theme: "Introduction to Programming"— Presentation transcript:
1 Introduction to Programming Prof. George ZollaProf. Gary Porter (IS 2020).
2 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.
3 Programming Languages A programming language is a set of rules that provides a way of telling a computer what operations to perform.
4 What Can a Program Do? A program can only instruct a computer to: Read InputSequenceCalculateStore dataCompare and branchIterate or LoopWrite Output
5 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.
6 Calculate Add 1 to Counter A program can instruct a computer to perform mathematical operations.Add 1 to Counter
7 StoreA program will often instruct a computer to store intermediate results.Place 1 in Counter
8 Compare and BranchA 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
9 IF-THENfalsetrueEntryExitTrue statement aTest condition p
10 IF-THEN-ELSE Entry Exit Test condition p “true” statement a falsetrueEntryExitTest condition p“true” statement a“false” statement a
11 IterateA program loop is a form of iteration. A computer can be instructed to repeat instructions under certain conditions.No
12 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 decisionsTrailing decisions
13 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.
14 DO WHILE LoopNoYesEntryExitTest condition pLoop statement a
15 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.
16 DO UNTIL LoopNoYesEntryTest condition pExitLoop statement a
17 Programs are Solutions to Problems Programmers arrive at these solutions by using one or more of these devices:Logic flowchartsStructure chartsPseudocodeStructured Programming
18 Logic FlowchartsThese represent the flow of logic in a program and help programmers “see” program design.
19 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 variableassignment or mathematical operation.Decision. The diamond indicates a decision structure. A diamond always has twoflowlines 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 anotherpage. 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
20 Flowchart for a Cash Register Program Startsum=0Input pricesum=sum+priceMoreitems?tax=sum xtotal=sum+taxOutput sum, tax,and totalStopNoYes
21 Structure ChartsStructure charts illustrate the structure of a program by showing independent hierarchical steps.Major divisions are subdivided into smaller pieces of information.
22 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.
23 Pseudocode for a Cash Register Program sum=0While More items doInput pricesum=sum+priceEnd Whiletax=sum xtotal=sum+taxOutput sum, tax, total
24 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.
25 The Program Development Cycle Analyze the problemDesign the solution algorithmDesign the user interfaceWrite the codeTest and debug the programComplete the documentation
26 Levels of Programming Languages Machine languageAssembly LanguageHigh Level LanguagesFourth Generation Languages (4GL)
27 Machine Languagesdifferent for each computer processor010001110111001. . .
28 Assembly Languages main proc pay mov ax, dseg mov ax, 0b00h add ax, dx different for each computer processormain proc paymov ax, dsegmov ax, 0b00hadd ax, dxmov a1, b1mul b1, axmov b1, 04h
29 High-Level Languages Higher Level Languages 4GLs 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 .
30 Interpreter vs Compiler Translates instructions to machine code line-by-line.CompilerTranslates the entire program to machine code before running it.
31 Types of Programming Languages Machine languageProcedure-oriented languagesObject-oriented languagesEvent-driven languages
32 Procedure-Oriented Languages FORTRANCOBOLPascalCAda
33 OOED Languages Object-oriented languages Event-driven languages SmalltalkC++Ada 95Event-driven languagesVisual Basicmost Visual languages
34 Programmer’s LingoProgram - detailed set of instructions for a computerProgramming Language - tool used to create a program; defined by semantics and syntaxSemantics - the meaning of words in a languageSyntax - rules for combining symbols of a language
35 Programmer’s LingoSource Code (code) - program you write using a programming languageInterpreter - translates and executes source code statement by statement