Programming Languages. Classification and distinctive features Procedural Language A term used in...

7
Programming Languages

Transcript of Programming Languages. Classification and distinctive features Procedural Language A term used in...

Page 1: Programming Languages. Classification and distinctive features Procedural Language A term used in contrast to declarative language to describe a language.

Programming Languages

Page 2: Programming Languages. Classification and distinctive features Procedural Language A term used in contrast to declarative language to describe a language.

Classification and distinctive features Procedural Language

A term used in contrast to declarative language to describe a language where the programmer specifies an explicit sequences of steps to follow to produce a result.

Common procedural languages include Basic, Pascal and C.

Declarative Language Declarative languages describe relationships between variables in

terms of functions or inference rules and the language executor (interpreter or compiler) applies some fixed algorithm to these relations to produce a result.

Common declarative languages include logic programming languages such as Prolog

Page 3: Programming Languages. Classification and distinctive features Procedural Language A term used in contrast to declarative language to describe a language.

Classification and distinctive features

Object-oriented Language A programming languages and techniques based on the concept of

an "object" which is a data structure (abstract data type) encapsulated with a set of routines, called "methods" which operate on the data. Operations on the data can only be performed via these methods, which are common to all objects, which are instances of a particular "class".

Common declarative languages include C++ and Java.

Page 4: Programming Languages. Classification and distinctive features Procedural Language A term used in contrast to declarative language to describe a language.

Classification and distinctive features Visual Programming

Visual programming environments provides graphical or iconic elements, which can be manipulated by the user in an interactive way according to some specific spatial grammar for program construction.

Common declarative languages include Visual Basic and Visual C++.

Query Language A language in which users of a database can

(interactively) formulate requests and generate reports. The best known is SQL

Page 5: Programming Languages. Classification and distinctive features Procedural Language A term used in contrast to declarative language to describe a language.

Tracing simple programs in C++ A simple C++ program

#include <iostream.h>preprocessor directive(s)

main() {

  // A simple C++ program

  int x, y, sum;  cout << "A program which adds two integers\n";  cout << "Enter 1st integer: ";  cin >> x;  cout << "Enter 2nd integer: ";  cin >> y;  sum = x + y;  cout << "Sum is " << sum << endl;  return 0;}

program body

Page 6: Programming Languages. Classification and distinctive features Procedural Language A term used in contrast to declarative language to describe a language.

syntax of C++ The preprocessor directive ‘#include <iostream.h>’ can be fou

nd in almost all C++ programs. It provides subprograms to process standard input and standard output.

Use cin for standard input and cout for standard output. Declarative statements can be put in anywhere of the program 

body. Use a pair of double quotation marks (") to enclose a string. Special characters:

\t (horizontal tab) \n (newline character) \\ (the backslash \) \" (the double quotation mark ")

Page 7: Programming Languages. Classification and distinctive features Procedural Language A term used in contrast to declarative language to describe a language.

Data types, variables and variable assignment Variables are case-sensitive. Common simple data types

int (integer) short (16-bit integer) long (32-bit integer) char (character) float (single precision floating-point number) double (double precision floating-point number)

The type modifier unsigned indicates that the variable cannot hold negative numbers.

The reserved word typedef is used to define a new data type. C+

+ uses the equal sign (=) for assignment, e.g. ‘x = 4;’. (Use ‘==’ as ‘equal to’ in C++.)

Initialisation can be done in the declarative statements, e.g. ‘int x = 4;’

Mixed-mode assignment is possible: