1 / 34

Chapter 6 Programming Languages (1)

Chapter 6 Programming Languages (1). Introduction to CS 1 st Semester, 2016 Sanghyun Park. Outline. Historical Perspective Traditional Programming Concepts Procedural Units (next file) Language Implementation (next file) Object-Oriented Programming (skip)

jaspero
Download Presentation

Chapter 6 Programming Languages (1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6Programming Languages (1) Introduction to CS 1st Semester, 2016 Sanghyun Park

  2. Outline • Historical Perspective • Traditional Programming Concepts • Procedural Units (next file) • Language Implementation (next file) • Object-Oriented Programming (skip) • Programming Concurrent Activities (skip) • Declarative Programming (skip)

  3. Programming Language History • ____________ languages (e.g., 5123) • ____________ languages (e.g., ADDI R1, R2, R3) • ____________ languages (e.g., sum = a + b)

  4. First Generation Language • Machine code • Specific to the machine __________ • _____ to write • Even harder to read

  5. Second Generation Language • Assembly language • Usually a 1-1 _________ to machine code,e.g., ADDI R1, R2, R3 instead of 5123 • ______ to read and write • Still specific to the machine architecture • Better, but not by much

  6. ADDI R1,R2,R3 Assembler 5123 Assemblers • Since assembly language is _____ to machine language, _________ can be done automatically

  7. Third Generation Languages • High level, machine ___________ • Much easier to read and write,e.g., money = bills + coins instead of ADDI R1, R2, R3 • Fortran and ______ are early examples

  8. 1101 1202 5312 3300 A = B * C Compiler Compilers and Interpreters • High-level code needs to be translated into machine language • Compilers do so _______ of time • Interpreters do so ___________

  9. Programming Paradigms • Languages can be classified by ________ • Many different programming languages • Only a few programming paradigms • Imperative/Procedural programming • Object-oriented programming • Functional programming • Logic/Declarative programming

  10. Imperative Programming • Traditionally the most _________ • The approach we have seen so far • Program is a _______ of steps • Receives input • Executes a sequence of commands for some computation • Generates output • Examples: Fortran, C, COBOL, Pascal

  11. Object-Oriented Programming • Program is a collection of ________ • An object contains __________ describinghow that object should respond to various ________(icon object and list object, for example) • Interaction between objects is via __________ passing • Examples: Smalltalk, C++, Java, C#

  12. Functional Programming • This paradigm views the process of program development as connecting predefined “______ ______”, each of which accepts inputs and produces outputs Lisp Expression:(Divide (Sum Numbers) (Count Numbers)) Example: Lisp, Scheme, ML

  13. Logic/Declarative Programming • Describe the _________ not the solution • The idea here is to discover and implement a ________ problem-solving algorithm • Once this is done, problems can be solved by developing a precise _________ of the problem • A major obstacle is the discovery of the underlying problem-solving algorithm • For this reason early declarative languages were designed for use in _________ applications • More recently, formal logic within ____________ gave a tremendous boost to this paradigm; this resulted in the emergence of logic programming (e.g., Prolog)

  14. Evolution of Programming Paradigms

  15. Traditional Programming Concepts • We consider some of the concepts found in imperative and object-oriented programming languages • We will draw examples from the languagesC, C++, C#, Fortran, Java and Pascal • Appendix D contains a brief background of each lang.

  16. Variables • Hold a temporary value that can _______ • Some languages insist that a variable should have a ______, while others do not • Example: Java • To store an integer, use an int • To store a real number, use a float • To store a string, use a String

  17. Data Types • Common • integer for ______ numbers (16 or 32 bits) • float for ______ numbers (32 or 64 bits) • character for data consisting of _________(ASCII (8 bits) or Unicode(16 bits)) • Sometimes available • Boolean for 0 or 1 (1 bit) • String for string of characters (variable length) • Many others

  18. Sample Variable Declarations

  19. Literals • Value is explicitly stated in a program • int X = 10 (10 is a literal) • String Name = “Bob” (“Bob” is a literal) • Wage = hours  9.00 (9.00 is a literal) • Although sometimes necessary,the use of literals should be _______ wherever possible

  20. Literals: Problem • Example • AverageSales = Sales / 10 • AverageSalary = Salary / 10 • Pay = Hours  10 • What does 10 mean in each of the previous examples? • Literals can ______ the meaning of the statementsin which they appear • Literals can complicate the task of ________ the program • _________ should be used wherever possible

  21. Constants • Variables that are not allowed to _____ • Once defined, it can’t be changed later • Why use constants? • More ________ code • _______ to modify code

  22. Data Structures • A way of thinking _________ data itemsas ______ larger data item • Different operations can be performedon different data structures • ________ is the most basic example • We will see others later

  23. Arrays: Homogeneous • A structure that contains multiple values of the ______ kind • An array of integers • A string can be thought of as an array of _________“This is a string”

  24. Arrays: Homogeneous Example • In C, C++, Javachar B[20] = “This is a string”; • You can access any item in an array • Index starts at __, not at __ • For instance, if we execute B[2] = ‘u’,the array above will become “_____________”

  25. Arrays: Heterogeneous • A structure that contains multiple values of different kinds

  26. Assignment Statements • Assign to a variable • Value of another variable • Result of a computation • Result from a function • C, C++, Java • Total = Price + Tax; • Pascal • Total := Price + Tax;

  27. Assignment Example • What are A and B at the end of the following?int A, B;A = 2;B = 3;A = A+A;A = A+B;B = B  B;

  28. Operator Precedence • What is A at the end of the following?int A=2, B=3;A = A / B + B * A – A + B; • Most programming languages will doA = (A / B) + (B * A) – A + B; • Use ___________ to override precedenceA = A /( (B + B) * (A – (A + B)));

  29. Control Statements • Alter order of execution of statements in a program • ______-entry / ______-exit • Most common ones • if-then-else • while • switch • for

  30. If Statement

  31. While Statement

  32. Switch Statement

  33. For Statement

  34. Comments • ____________ statements within the code • Should not just repeat the code, but __________ on it • ________ by compiler • C, C++, Java /* Insert Comments here */ // Or put them here

More Related