computer programs and programming languages what are low-level languages and high-level languages?...

Post on 02-Jan-2016

224 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Computer Programs and Programming Languages

What are low-level languages and high-level languages?

High-level language

High-level language

Low-levellanguage

Low-levellanguage

Machine-dependentruns only on one type of computer

Machine-dependentruns only on one type of computer Often machine-independent

can run on many different types of computers

Often machine-independentcan run on many different

types of computersMachine and assembly languages

are low-level

Machine and assembly languages are low-level

Generations of programming languages

The evolution of programming paradigms

Imperative or Procedural

Declarative

Functional

Object Oriented

Low-Level Languages

What is machine language? Only language computer

directly recognizes

Low-Level Languages

What is assembly language? Instructions made up of

symbolic instruction codes, meaningful abbreviations and codes

Source program contains code to be converted to machine language

Second-generation:Assembly language

A mnemonic system for representing programs Mnemonic names for op-codes Names for all registers 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

Assembly language example

Machine language

156C166D505630CEC000

Assembly language

LD R5, PriceLD R6, ShippingChargeADDI R0, R5 R6ST R0, TotalCostHLT

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 short sequence of machine language instructions

Converted to machine language by a program called a compiler

Procedural Languages

What is a procedural language?

Most widely used are BASIC, COBOL, and C

Uses series of English-like words to write instructions

Often called third-generation third-generation language (3GL)language (3GL)

Programmer writes instructions that tell

computer what to accomplish and how to do it

Procedural Languages

What is a compiler? Program that

converts entire source program into machine language before executing it

Procedural Languages

What is an interpreter? Program that

translates and executes one program code statement at a time

Does not produce object program

Procedural Languages

What is COBOL? Designed for business applications English-like statements make code easy to read, write,

and maintain COmmon

Business-Oriented Language

Procedural Languages

What is C? Powerful language originally designed to write system

software Requires professional programming skills

The composition of a typical imperative program or program

unit

Variable declarations in C, C++, C#, and Java

Control structures and their

representations in C, C++, C#, and

Java

The for loop structure and its representation in C++, C#, and

Java

The flow of control involving a procedure

The procedure ProjectPopulation written in the

programming language C

Executing the

procedure Demo and passing

parameters by value

Executing the procedure Demo and passing

parameters by reference

The translation process

A syntax diagram of our if-then-else pseudocode

statement

An object-oriented approach to the translation process

Object-Oriented Programming Languages

What is an object-oriented programming (OOP) language?

Used to implement

object-oriented design

Major benefit is ability to

reuse existing objects

Event-driven—checks for

and responds to set of events

C++ and Java are complete

object-oriented languages

Object is item that contains data and

procedures that act on

data

Event is action to

which program responds

Object-Oriented Programming Languages

What is C++? Includes all elements of C, plus additional features

for working with object-oriented concepts Used to develop

database and Web applications

Object-Oriented Programming Languages

What is Java? Developed by Sun

Microsystems Similar to C++ but

uses just-in-time (JIT) compiler to convert source code into machine code

Object-Oriented Programming Languages

What is a visual programming language?

Programmer writes and implements

program in segments

Visual programming environment (VPE) allows developers to

drag and drop objects to build programs

Often used in Often used in RAD RAD (rapid application (rapid application

development) development) environmentenvironment

Sometimes calledSometimes calledfifth-generation fifth-generation

languagelanguage

Provides visual or Provides visual or graphical interface for graphical interface for creating source codecreating source code

Object-Oriented Programming Languages

What is Visual Studio .NET 2003? Suite of visual programming languages and RAD tools .NET is set of technologies that allows program to run on Internet Visual Basic .NET 2003 is used to build complex object-based programs

Step 1. The programmer designs the user interface.

Step 2. The programmer assigns properties to each object on the form.

Step 4. The programmer tests the application.

Step 3. The programmer writes code to define the action of each command button.

Objects and Classes

Object = active program unit containing both data and procedures

Class = a template for all objects of the same type

An Object is often called an instance of the class.

Components of an object

Instance variable = variable within an object

Method = function or procedure within an object Can manipulate the object’s instance variables

Constructor = special method to initialize a new object instance

The structure of a class describing a coinpublic class Coin

{

private final int HEADS = 0;

private final int TAILS = 1;

private int face;

// Sets up the coin by flipping it initially.

public Coin ()

{

flip();

}

// Flips the coin by randomly choosing a face value.

public void flip ()

{

face = (int) (Math.random() * 2);

}

}

constructor

Instance variable

Method

Nonprocedural Languages and Program Development Tools

What are nonprocedural languages and program development tools?

Nonprocedural Language

The programmer writes English-like instructions or interacts with a visual environment to retrieve data from files or a

database

Nonprocedural Language

The programmer writes English-like instructions or interacts with a visual environment to retrieve data from files or a

database

Program Development Tools

User-friendly programs designed to assist both

programmers and users in creating programs

Program Development Tools

User-friendly programs designed to assist both

programmers and users in creating programs

Nonprocedural Languages and Program Development Tools

What is RPG (Report Program Generator)? Nonprocedural language used for generating reports,

performing computations, and updating files

Nonprocedural Languages and Program Development Tools

What is a fourth-generation language (4GL)? Nonprocedural language that allows access to data in

database Popular 4GL is SQL, query language that allows users to

manage data in relational DBMS

Nonprocedural Languages and Program Development Tools

What is an application generator? Program that creates source code or machine code from

specification Consists of report writer, form, and menu generator

Form provides areas for entering data

Nonprocedural Languages and Program Development Tools

What is Visual Basic for Applications (VBA)? Macro programming language

Macro—series of statements used to automate tasks

top related