CHAPTER 1 Overview of Programming and Problem Solving
What is a computer program? What is programming? l PROGRAM –list of instructions to be performed by computer l PROGRAMMING –planning sequence of steps for computer to follow.
List the three phases of developing computer programs. l 1) Problem-Solving phase –Analysis & Specification Define the problem Define what the solution must do –General solution (algorithm) steps to solve problem –Verify Does solution actually solve the problem?
3 phases of developing pgms l 2) Implementation –Translate algorithm into programming language –Program tested –Errors corrected
3 phases of developing pgms l 3) MAINTENANCE CHANGE?? –Correction defects –Adaptation changes in ext. environment –Enhancement extend functionality
A Tempting Shortcut? GOAL THINKING CODE REVISE DEBUG TEST CODE Shortcut?
What is an algorithm? l step-by-step procedure l solves problem in finite time l e.g., Washing hair, recipes, CHILTON'S
What is a programming language? l Set of –rules –symbols –keywords l used to construct a program. ALGORITHM LANGUAGE PROGRAM
What is documentation? l Text and comments l making program easier l for others to understand, l use, and modify.
Define Bit, Byte. l Bit –a binary digit, 1 or 0 l Byte –a group of bits, usually 8
11 Bit Permutations 1 bit bits bits bits Each additional bit doubles the number of possible permutations
Bits, Binary System, Byte l All computer data is stored as a sequence of bits. l The binary (base-two) number system represents computer bits as numbers. l A byte can store 256 different combinations. 256 = 2 8
Contrast machine language, assembly language, and high- level languages. l Machine language –binary coded instructions –used directly by computer l C
l Assembly language –low level language –mnemonics –represents machine language instructions for a particular computer MOV X, 5
l High Level language –statements resemble spoken languages –or mathematical notation l Pascal, FORTRAN, COBOL, C++, BASIC, C
l C++: X = 5; l Assembly:mov word ptr [x], 5 l Machine:C l Binary: l
List advantages of high-level programming language? l Easier to use –(closer to English / Math) l Solve problems faster l Portable –(may run on many machines)
What does a compiler do? an assembler? l A compiler translates a high level language program into machine code. l An assembler translates an assembly language program into machine code. C++ Pgm MS Visu C++ Compiler PC machine language
Three C++ Program Stages other code from libraries, etc. other code from libraries, etc. written in machine language written in machine language written in machine language written in machine language written in C++ written in C++ via compilervia linker SOURCEOBJECT EXECUTABLE myprog.cppmyprog.objmyprog.exe
Origins of C++ l C –Dennis Ritchie developed at Bell Labs –Late 1960s –Systems programming language (90% Unix) l C++ –Bjarne Stroustrup of Bell Labs –1985 –Object-oriented features added
Some C++ History l 1972 : Dennis Ritchie at Bell Labs designs C and 90% of UNIX is then written in C l Late 70’s : OOP becomes popular l Bjarne Stroustrup at Bell Labs adds features to C to form “C with Classes” l 1983 : Name C++ first used l 1998 : ISO/ANSI standardization of C++
List four basic control structures used in programming. l SEQUENCE –series of statements –one statement executed after another –(wash hair algorithm)
SEQUENCE Statement...
l SELECTION –executes statements depending upon certain conditions
SELECTION (branch) IF Condition THEN Statement1 ELSE Statement2 Statement1 Statement Statement2 Condition... True False
l LOOP –repeats statements while certain conditions are met
LOOP (repetition) Statement Condition... False True WHILE Condition DO Statement1
l PROCEDURE –breaks up a program into smaller subprograms
SUBPROGRAM (function) SUBPROGRAM1... SUBPROGRAM1 a meaningful collection of SEQUENCE, SELECTION, LOOP, SUBPROGRAM
What is Computer Science? The Computing Curriculum 1991 (ACM/IEEE) l Algorithms and Data Structures l Architecture l Artificial Intelligence and Robotics l Database and Information Retrieval l Human-Computer Communication l Numerical and Symbolic Computation l Operating Systems l Programming Languages l Software Engineering l Social and Professional Context
Drawing in Processing Automatic creation of display window Window has a coordinate system for drawing
Let's draw a point: point() point(x, y) – draws a point at the location x, y Try it in Processing: point(50, 50) Unexpected token: null Compiler errors appear in the bottom pane All lines must be terminated with a semicolon ; Try drawing several points