Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park."— Presentation transcript:

1 Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 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 Assemblers  Since assembly language is _____ to machine language, _________ can be done automatically ADDI R1,R2,R3Assembler5123

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 Compilers and Interpreters  High-level code needs to be translated into machine language  Compilers do so _______ of time  Interpreters do so ___________ CompilerA = B * C 1101 1202 5312 3300

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 __________ describing how 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 languages C, 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 statements in 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 Pascalconst pi=3.14159; const numDays=10; FortranREAL PARAMETER :: pi = 3.14159 INTEGER PARAMETER :: numDays=10 C,C++const float pi = 3.14159; const int numDays=10; Javastatic final float pi = 3.14159; static final int numDays=10;

22 Data Structures  A way of thinking _________ data items as ______ larger data item  Different operations can be performed on 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” 12334436932343345

24 Arrays: Homogeneous Example  In C, C++, Java char 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 do A = (A / B) + (B * A) – A + B;  Use ___________ to override precedence A = 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


Download ppt "Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park."

Similar presentations


Ads by Google