70 likes | 187 Views
Programming Languages. 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 .
E N D
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
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.
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
#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 TracingsimpleprogramsinC++ AsimpleC++program
syntaxofC++ • Thepreprocessordirective ‘#include<iostream.h>’ canbefoundinalmostallC++programs.Itprovidessubprogramstoprocessstandardinputandstandardoutput. • Usecinforstandardinputandcoutforstandardoutput. • Declarativestatementscanbeputinanywhereoftheprogrambody. • Useapairofdoublequotationmarks(")toencloseastring. • Specialcharacters: • \t(horizontaltab) • \n(newlinecharacter) • \\(thebackslash\) • \"(thedoublequotationmark")
Datatypes,variablesandvariableassignment • Variablesarecase-sensitive. • Commonsimpledatatypes • int(integer) • short(16-bitinteger) • long(32-bitinteger) • char(character) • float(singleprecisionfloating-pointnumber) • double(doubleprecisionfloating-pointnumber) • Thetypemodifierunsignedindicatesthatthevariablecannotholdnegativenumbers. • Thereservedwordtypedefisusedtodefineanewdatatype. • C++usestheequalsign(=)forassignment,e.g. ‘x=4;’.(Use ‘==’ as ‘equalto’ inC++.) • Initialisationcanbedoneinthedeclarativestatements,e.g. ‘intx=4;’ • Mixed-modeassignmentispossible: