Introduction To Computer Where do they all go? Programming P - - PDF document

introduction to computer
SMART_READER_LITE
LIVE PREVIEW

Introduction To Computer Where do they all go? Programming P - - PDF document

Language Levels Introduction To Computer Where do they all go? Programming P High-level Java, C# < Close to problem FORTRAN, COBOL, C++ < System independent Chapter 1 C/C++ P Low-level < Close to system Assembler < Doesnt


slide-1
SLIDE 1

Introduction To Computer Programming

Chapter 1

CS 2250, Chap 1 Slide 1 of 20

Language Levels

Where do they all go? PHigh-level

< Close to problem < System independent

PLow-level

< Close to system < Doesn’t reflect problem

Java, C# FORTRAN, COBOL, C++ C/C++ Assembler Machine

CS 2250, Chap 1 Slide 2 of 20

Relationship Between C and C++

C++ is (almost) a perfect subset of C

ANSI C C++

main functions syntax

  • perators

flow of control

  • rganization

compilation libraries

  • bject-oriented

model

prototypes const inline references new / delete classes encapsulation inheritance polymorphism RTTI templates ctors/dtors

  • verloading

CS 2250, Chap 1 Slide 3 of 20

PAdvantages

< Smaller generated code < More portable (machine independent) < Better diagnostics (debugging) < Can implement “very high-level” languages

P10 to 100 times slower than a compiled program!!

< Hybrid systems are 3 to 10 slower

Interpreter Operation

Dynamic translation

Text file Interpreter

runtime

PCPU executes the interpreter

< Program is data to interpreter < Parses each statement in the program (each every time it is executed) < Carries out the program statements

CS 2250, Chap 1 Slide 4 of 20

Compiling Programs

Multi-file programs (compare with Fig. 1.10, p. 15)

editor linker source code .c .asm compiler or assembler

  • bject

files .obj .o libraries runtime executable

CS 2250, Chap 1 Slide 5 of 20

PC was created by Dennis Ritchie in the early 1970s to write a portable version of Unix PC and Unix came together in 1973 on a DEC PDP-11/20 running the 5th edition of Unix PThe line between C and Unix is not distinct (although they are governed by two standards: ANSI and POSIX) PANSI standard

< Committee was established in 1983 < Standard adopted 1989 and became available in 1990 < Is the base document for the ANSI C++ standard < Many features of C++ were back-ported to C either because they were good features or to avoid gratuitous differences

The Origins of C

A brief history

CS 2250, Chap 1 Slide 6 of 20

slide-2
SLIDE 2

Terminator I/O Process Decision Loop Preparation Predefined process On-page connector Off-page connector Control flow Start INPUT P0 TOL N0 p = p0 - f(p0) / f’(p0) i = 0 i < N0 | p - p0 | < TOL i = I +1 yes no p0 = p no OUTPUT Failed OUTPUT p Stop yes

P32 keywords (27 from K&R and 5 added by ANSI) PDoes not provide OS/kernel services

< Networking < Multiprocessing/Multithreading < Interprocess communication or synchronization

PProvides basic programming features

< Variables, expressions, statements, control structures, and functions < Minimal compile-time and little run-time error checking < Typed but not strongly so– strict type compatibility is not enforced

PAdvanced programming features, including I/O, are provided by libraries (also governed by the ANSI standard)

C Is A Minimal Language

Lean and mean

CS 2250, Chap 1 Slide 7 of 20

PIngredients

< ½ C shortening < 1 C Sugar < 2 well-beaten eggs < 1 tsp vanilla < 1/4 C milk < 3 C flour < 2 tsp baking powder < 1/4 tsp salt

Algorithms I

A recipe for Fishin’ Cookies PCream together sugar & shortening PAdd eggs PAdd vanilla & milk and mix PSift together flour, baking powder, & salt; add to liquid and mix PRoll dough and cut PBake at 400N F for 8-10 minutes

CS 2250, Chap 1 Slide 8 of 20

PINPUT initial approximation p0: tolerance TOL; maximum number of iterations N0 POUTPUT approximate solution p or message of failure PStep 1 Set i = 1 PStep 2 While i < N0 do steps 3 - 6 P Step 3 Set p = p0 - f(p0) / f’(p0) P Step 4 if | p - p0 | < TOL then OUTPUT(p) and STOP P Step 5 set i = i + 1 P Step 6 set p0 = p PStep 7 OUTPUT “Method failed after N0 iterations; STOP

Algorithms II

Newton-Raphson: roots of f(x) = 0

CS 2250, Chap 1 Slide 9 of 20

Flowcharts

The basic elements

CS 2250, Chap 1 Slide 10 of 20

Algorithms III

Newton-Raphson: roots of f(x) = 0

CS 2250, Chap 1 Slide 11 of 20

PFocuses on how (i.e., the algorithms) to solve a problem PDecomposes problem into functions and function interfaces PChanges have wide spread effects – global data makes the program fragile PFunctions have varying degrees of coupling through global data

< Developed as a unit < Debug as a unit < Validate as a unit

Functional Model

The oldest model

updateInventory( ) { } printReport ( ) { }

CS 2250, Chap 1 Slide 12 of 20

slide-3
SLIDE 3

PData flow

< Maps data input to data output < Design data structures first < Design processes / functions last

PData hiding

< Packages data and the functions that work on the data together in a module (a file in C) < Data is still in global scope but access is allowed only through the module functions

PAbstract Data Type (ADT)

< Programmer created data type < struct in C

Data Driven Models

‘70s through mid ‘80s process data data

CS 2250, Chap 1 Slide 13 of 20

PCharacteristics of functional & data models PA tool for managing complexity PChange resilient

< Change is localized < Intra-object functions may be coupled < Extra-object functions are decoupled

PNatural organization for data and functions

< Objects encapsulate data and functions together < Supports ADTs: multiple objects of a type may be created (class is a type specifier or ADT) < Supports data hiding: data access is controlled through key words

Object Model

State of the art Name

Data Attributes Functions Behaviors Operations

Class Notation

CS 2250, Chap 1 Slide 14 of 20

PRequirements PAnalysis PDesign Development PImplementation PValidation PMaintenance PRetire

Software Life Cycle Phases

Typical phases

}

CS 2250, Chap 1 Slide 15 of 20

Waterfall Model

IEEE process standard P1074, 1/1/91 (see Fig 1.16, p. 25)

}

pre-development process

} development

process

{

post-development process

explore concept system allocation require- ments design

imple- ment install

  • peration

& support mainten- ance retire CS 2250, Chap 1 Slide 16 of 20

Iterated Waterfall Model

Iteration allows corrections & refinements (see Fig 1.16)

system requirements design coding testing maintenance

Pneed Pproblem domain Porganization/structure Pimplementation Pvalidate Pfix/update

CS 2250, Chap 1 Slide 17 of 20

Spiral Model

A contemporary life cycle PInception

< idea is sufficiently well founded to warrant entering the elaboration phase < strategic/tactical

PElaboration

< requirements articulated & prioritized < testing planned

PConstruction

< allocate resources < requirements & evaluation criteria examined < Code

PTransition

< phased delivery < move to next component < evaluate improvements and corrections an increment iteration

CS 2250, Chap 1 Slide 18 of 20

slide-4
SLIDE 4

PAnalyze the problem

< Outputs < Inputs < Formulas < Perform hand calculation

PSelect / develop algorithm PWrite program PTest and correct

Design and Development

Details on pp. 33 - 39

CS 2250, Chap 1 Slide 19 of 20

PRushing to code PForgetting to back up program PFailing to understand that computers do exactly as told PProgramming error classifications

< Syntax < Run-time < Logical

Common Errors

See pp. 37 - 38

CS 2250, Chap 1 Slide 20 of 20