220 likes | 637 Views
Chapter 6: Programming Languages. Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear. Generations of programming languages. Second-generation: Assembly language. A mnemonic system for representing machine instructions Mnemonic names for op-codes
E N D
Chapter 6:Programming Languages Computer Science: An OverviewEleventh Edition by J. Glenn Brookshear
Second-generation: Assembly language • A mnemonic system for representing machine instructions • Mnemonic names for op-codes • Identifiers: Descriptive names for memory locations, chosen by the programmer
Assembly Language Characteristics • One-to-one correspondence between machine instructions and assembly instructions • Programmer must think like the machine • Inherently machine-dependent • Converted to machine language by a program called an assembler
Machine language156C166D505630CEC000 Assembly languageLD R5, PriceLD R6, ShipChargeADDI R0, R5 R6ST R0, TotalCostHLT Program Example
Third Generation Language • Uses high-level primitives • Similar to our pseudocode in Chapter 5 • Machine independent (mostly) • Examples: FORTRAN, COBOL • Each primitive corresponds to a sequence of machine language instructions • Converted to machine language by a program called a compiler
The evolution of programming paradigms *different ways of thinking about communicating with the machine
A function for checkbook balancing constructed from simpler functions Sample pseudocode: Imperative language: Total_credits <- sum of all Credits Temp_balance <- Old_balance + Total_credits Total_dedits <- sum of all Debits Balance <- Temp_balance – Total_debits Notice this code requires temporary storage to complete. Sample pseudocode: Functional language (LISP): (Find_diff (Find_sum Old_balance Credits) (Find-sum Debits)) This code uses information as it goes – no temporary storage needed for the final output.
Programming Concepts Generally, a program consists of three categories: • Declarative • Imperative • Comments
The composition of a typical imperative program or program unit
Object-Oriented Languages • A class is the declaration of what makes up the object. • The object is an instance (specific occurrence) of the class. These attribute can be declared within the object. • Declarative statements • Variables and their data types (primitive, special) • Imperative statements • Methods – procedures CLASS CIRCLE OBJECTS
Data Types Primitive • Integer: Whole numbers • Real (float): Numbers with fractions • Character: Symbols • Boolean: True/false
Variable Declarations float Length, Width; int Price, Total, Tax; char Symbol; boolean Answer; • With assignment: int Price = 0; char Choice = ‘A’; boolean Answer = true; float Length = 12.5;
Data Structures • The conceptual shape or arrangement of data deals with data structures. • Arrays • Aggregate type
The conceptual structure of the aggregate type (record) Employee
Control Statements • Conditional statements • Loops • While • Until • For • Case (branching) • If-then-else
The for loop structure and its representation in C++, C#, and Java