1.Explain about Generic subprograms in Ada?
Generic Subprograms in Ada
Ada provides parametric polymorphism through a construct that supports the construction of multiple versions of
program units to accept parameters of different data types. The compiler upon request from the user program constructs the different versions of the subprogram. Because the versions of the subprogram all have the same name, this provides the illusion that a single subprogram can process data of different types on different calls. Because program units of this sort are generic in nature, they are sometimes called generic units.
The same mechanism is used to allow different versions of a single subprogram to include uses of different subprograms. This is useful in providing the functionality of subprograms passed as parameters.
2.Explain about abstract data types in C++ with an example.?
Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details.
Data abstraction is a programming (and design) technique that relies on the separation of interface and implementation
Now, if we talk in terms of C++ Programming, C++ classes provides great level of data abstraction. They provide sufficient public methods to the outside world to play with the functionality of the object and to manipulate object data, i.e., state without actually knowing how class has been implemented internally.
For example, your program can make a call to the sort() function without knowing what algorithm the function actually uses to sort the given values. In fact, the underlying implementation of the sorting functionality could change between releases of the library, and as long as the interface stays the same, your function call will still work.
In C++, we use classes to define our own abstract data types (ADT). You can use the cout object of class ostream to stream data to standard output like this:
3.Write short notes on the basic elements of PROLOG?
Prolog is a programming language based on a fragment of first-order predicate logic.
Formulas of first-order logic are formed using basic predicates (and terms), logical connectives and quantifiers.
A basic predicate is used to represent a basic statement about individual elements of the domain we are taking into account. The elements of the domain are denoted by terms.
For instance: even(2), divisible(15,3), greaterThan(5*7,1+1) etc. .
In Prolog, basic predicates are denoted by identifiers beginning with lower case letters. Terms denoting elements of the domain are formed using variables, constants and function symbols.
A basic predicate is used to represent a basic statement about individual elements of the domain we are taking into account. The elements of the domain are denoted by terms.
For instance: even(2), divisible(15,3), greaterThan(5*7,1+1) etc. .
In Prolog, basic predicates are denoted by identifiers beginning with lower case letters. Terms denoting elements of the domain are formed using variables, constants and function symbols.
Elements of Prolog: Expressions, Unification, and Resolution
Prolog is a particularly simple programming language. It consists of a single data structure (which we will refer to here as expression trees) and a single operation on those data structures (called unification). The deductive calculus that it implements is equally simple. There is one inference rule (resolution) and no axioms. Despite all this it is an extremely powerful programming language. It can be used to implement Turing Machines, or theorem provers for full First-Order Logic, or Prolog itself, for example.
5.Compare the functional programming languages with imperative
Languages.?
The functional programming paradigm was explicitly created to support a pure functional approach to problem solving. Functional programming is a form of declarative programming. In contrast, most mainstream languages, including object-oriented programming (OOP) languages such as C#, Visual Basic, C++, and Java –, were designed to primarily support imperative (procedural) programming.
Characteristic | Imperative approach | Functional approach |
---|---|---|
Programmer focus | How to perform tasks (algorithms) and how to track changes in state. | What information is desired and what transformations are required. |
State changes | Important. | Non-existent. |
Order of execution | Important. | Low importance. |
Primary flow control | Loops, conditionals, and function (method) calls. | Function calls, including recursion. |
Primary manipulation unit | Instances of structures or classes. | Functions as first-class objects and data collections. |
Although most languages were designed to support a specific programming paradigm, many general languages are flexible enough to support multiple paradigms. For example, most languages that contain function pointers can be used to credibly support functional programming. Furthermore, in C# 3.0 and Visual Basic 9.0, explicit language extensions have been added to support functional programming, including lambda expressions and type inference. LINQ technology is a form of declarative, functional programming.
0 comments:
Post a Comment