AI 3. Game 4. All F The Given: 2. Puzzle
AI 3. Game 4. All F The Given: 2. Puzzle
1. AI
2. Puzzle
3. Game
4. All f the given
1. Primitive
2. Reference
3. Integer type
4. Both reference and Primitive
1. C++..?
2. Java
3. C#
4. C# and java
1. Same
2. Different
3. Distinct
4. None of the given
1|P ag e
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
compile initially to an intermediate. Which can be run by interpretation or just in
time compilation or an appropriate virtual machine?
1. C++ and C#
2. C# and Java
3. Java and C++
4. Ada , C++
In the relationship between a get and set method is inherited, while in
it has to be maintained.
1. Java , C++
2. C++ , C#
3. Ada , Java
4. C# , Java or C++
1. Java , C#
2. C++ , C# c
3. C# , Java
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
4. Java ,C++ ..?
2|P ag e
1. CLR
2. CRL
3|P ag e
In C# can be inherited from other class but no inheritance from it. On the other
hand cannot be inherited not inheritance is possible from it is possible.
1. Private class , public class
2. Sealed class ,struct in C#
3. struct in C# , Sealed class
4. public class , inherited class
Enumeration type in C# may take any type of in contrast to C++ where it take
only
a. Numeric value, integer value
b. Value type value, numeric value
c. Primitive type value, reference type value
d. Value type value, reference type value
1. C++, C#
2. C#, C++
3. C++, Java
4. None of the given
1. Prolog,
2. Lisp,
3. Cobol
1. Arithmetic expression
2. Boolean expression
3. Numeric expression
4. Both Numeric expression and Boolean expression
In C# the value type and reference type variable are interconvert able through
concept.
1. Tagged type
2. Boxing
3. Interfaces
4. None of the given
5|P ag e
1. ODBC
2. Oracle
3. SQL Server
4. None Of given…?
1. Dynamic
2. Static
3. Both dynamic and static
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
4. Stack
6|P ag e
1. COBOL
2. LISP
3. PL/1
4. JAVA
1. Readably
2. Writeable
3. Cost
4. compile time
1. Reference pointer
2. Unary pointer
3. Class pointer
4. Binary pointer
1. Explicit
2. Punter method
3. Implementation
4. An Indirect Reference
1. Also
2. No
3. Defective
4. None of the above
1. For
2. Switch loop
3. Do while
4. While
Tasks in are processes and cannot share data but thread in do it.
1. C# , C++
2. C++ , Ada
3. Java , C#
4. Ada , Java..?
8|P ag e
9|P ag e
1. Recursion
2. For Loop
3. While Loop
4. Do-While Loop
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
10 | P a g e
1. LISP
2. PROLOG
3. Ada
4. C++
1. (Difference L1 L2)
2. (set-difference L1 L2)
3. (L1 Difference L2)
4. (L1 difference L2)
Lists can be constructed with the help of three basic functions which
are .
1. True
2. False
11 | P a g e
1. Ada
2. C
3. C++
4. LISP
1. String manipulation
2. AI
3. Business
4. Scientific
1. True
12 | P a g e
1. True
2. False
1. Scientific experiments
2. Business application
3. AI applications
4. Publishing and writing algorithm
1
2
3
4
13 | P a g e
Learning the implementation details of a language helps in the efficient use of that
language.
1. True
2. False
1. C++
2. Ada
3. C
4. PROLOG
SONOBOL is case
1. Sensitive
14 | P a g e
1. Readability
2. Writabilty
3. Portability
4. Modularity
1. String
2. Operator
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
3. Variable
15 | P a g e
1. Computer architecture
2. Readability
3. Programmer’s time
4. Windows XP
The more is the Simplicity of a language, the more it will always be readable.
1. True
2. False
1. Line Continuation
2. Line Break
We use indirect referencing operator in SNOBOL (Binary “.”, Binary $, Unary “.”, Unary
$)
Elementary types are also called in ADA (Static, user defines, builtin)
has a powerful set of operators but poor type checking (C, C++, ADA, LISP)
There are no struct, union, enum, unsigned, typedef, or pointers types in Java
17 | P a g e
ADA is strongly typed. A programming language is strongly typed if type errors are
always detected and in ADA Errors can be signaled as exceptions and handled
explicitly. Many serious errors such as computational overflow and invalid array
indexes are automatically caught and handled through this exception mechanism,
improving program reliability....?
Write a function in LISP to concatenate two lists List a=(3 4 5) List b=(c d 6)
(3 4 5 c d 6)..concatenated List.
In C++ ^ and ~ are used for bitwise exclusive OR and bitwise NOT write there equivalent
in ada
Ans:
~ = Not in ADA
(defun power (x y)
>(power 3 4)
18 | P a g e
A code was given about ADA case concept. Please refer topic "Case statement”
case expression is
sequence-of-statements
sequence-of-statements
sequence-of-statements
end case;
In SNOBOL, The size of the array can be determined at run time by using input from the
system of using a variable.
Example:
A = ARRAY(INPUT)
Lists can be created and extended with the help of three basic functions.
1. cons,
What are operators for Logical AND && and Logical OR || used in ADA.
19 | P a g e
Logical OR || = Or in ADA
COBOL has introduced hierarchical data structures (records) and nested selection
statements.
The COBOL language supported long variable names (up to 30 characters) with
hyphens, data division, and fixed-point arithmetic.
These all feature in COBOL language are those which were added or enhanced and
were not included in SNOBOL..
KEYWORD INT|CAHR
This statement assigns the pattern ‘INT’ | ‘CHAR’ to the variable KEYWORD.
KEYWORD will now get a new value which is ‘INT’ | ‘CHAR’ So we can create new
pattern by using the assignment statement.
Ans:
This code generates an error as the symbol x is not associated with any value and
thus cannot be evaluated.it will give error like this.
List = (d e)
20 | P a g e
Comparative operators in LISP used as functions for numerical values and return a T
or NIL. =, >, <, >=, <=;
For example 1:
(= (+ 2 4) (* 2 3))
example 2:
(> (- 5 2) (+ 3 1))
NIL
write two comparative operator used as function for numerical values in lisp
programming language ? 2 marks
Comparative operators which are used as functions for numerical values are
A table data structure maps pairs of associated data objects. Tables have varying lengths
T = TABLE(N)……..if want to creates a table that initially has room for N elements
Once created, table can be used in a manner similar to arrays. The only difference is that
they are indexed by the key value and not the index number. For example:
21 | P a g e
Ans;
Although PL/1 has introduce the concept of exception handling. But ADA has elaborated
this concept.
Ada was the first language to provide a structured exception handling mechanism.
Ada includes an exception handling mechanism so that these problems can be dealt
with at run-time.
Errors can be signaled as exceptions and handled explicitly.
Many serious errors such as computational overflow and invalid array indexes are
automatically caught and handled through this exception mechanism, improving
program reliability.
write a complete program in ada to print this out put by only using put_line command.
use the loop isn't allowed.
***
*****
*******
Ans.
procedure Starprint is
begin
Put ("*");
New_Line ;
Put ("***");
New_Line ;
22 | P a g e
end Starprint;
code :
**
***
****
Ans:
procedure Loopprint is
Number_Of_Time: Integer:=5;
begin
end loop;
New_Line;
End loop;
end Nested_Loops;
end Loopprint;
1. procedures and
2. Functions.
In order to select elements from a list, selectors functions are used. There are two basic
1. First (or car) takes a list as an argument and returns the first element of that list.
example:
2. rest (or cdr) takes a list as its argument and returns a new list after removing the first
examples:
(s d f).
Generality is also an important factor and deals with the applicability of the language to a
24 | P a g e
FORTRAN and hence can be used in more domains than these two languages.
Compare ADA dotimes loop with dolist and dotime in LISP (5)
Apart from recursion, in LISP we can write code involving loops using iterative non recursive
mechanism. There are two basic statements for that purpose: dotimes and dolist.
DOTIMES
It executes the body of the loop n times where count starts with 0, ends with n-1.
The result is optional and is to be used to hold the computing result. If result is given, the
function will return the value of result. Otherwise it returns NIL. The value of the count can
be used in the loop body.
DOLIST
The second looping structure is dolist. It is used to iterate over the list elements, one at a
time. Its syntax is given below:
It executes the body for each top level element x in L. x is not equal to an element of L in
each iteration, but rather x takes an element of L as its value. The value of x can be used in
the loop body. As we have seen in the case of dotimes, the result is optional and is to be
used to hold the computing result. If result is given, the function will return the value of
result. Otherwise it returns NIL.
Differentiate between ADA access types and C/C++ pointer type (5)
25 | P a g e
Unlike C, there is no notational difference for accessing a record field directly or through an
access value.
To refer to the entire record accessed by an access value use the following notation:
Print(A_Ref.all);
A predicate is a special function which returns NIL if the predicate is false, T or anything
other than NIL, otherwise. Predicates are used to build Boolean expressions in the logical
statements.
The following comparative operators are used as functions for numerical values and return
a T or NIL. =, >, <, >=, <=;
COBOL uses level numbers to show nested records; others use recursive definitions
Business applications
It was designed to look like simple English to broaden the base of computer users.
Generics are like templates in C++ and allow parameterization of subprograms and
packages with parameters which can be types and subprograms as well as values and
objects.
2. The initial expression can include variable definitions (scope is from the definition to the
end of the function in which it is defined).
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
Write types of loop in Ada.
26 | P a g e
1. For loop
2. While loop
3. Simple ..unconditional infinite loop
components that can be combined in a relatively small number of ways to get the desired
results. It is closely associated with simplicity: the more orthogonal the designs the fewer
exceptions and it make it easier to learn, read, and write programs in a programming
language. The meaning of an orthogonal feature is independent of the context. The key
parameters are symmetry and consistency. For example pointers are an orthogonal
concept.
1)S=0
S=o
-- N=LT(N,13)N+1:F(DONE)
SUM=SUM+_N:(ADD)
DONE OUTPUT=SUM
27 | P a g e
Charles Babbage is considered to be the inventor of the first computer. This machine,
known as the Analytical Engine or Difference Engine, was invented in 1820’s. In the
beginning, it could only be made to execute tasks by changing the gears which
executed the calculations. Thus, the earliest form of a computer language was
physical motion.
It was motivated by the success of power looms. It had limited capability and
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
because of the technological limitations this design could not be fully implemented.
28 | P a g e
What is the difference between >(intersection L1,L2) and (set-difference L1,L2) Lisp
functions. 5
These are set operations in LISP.
>(union L1 L2) ; returns the union of the two lists
>(intersection L1 L2) ; returns the intersection of the two lists
>(set-difference L1 L2) ; returns the difference of the two lists
Creating list functions in Lisp may be written as (append ‘(ab)’(cd)) so why we use
the single quote (‘) in front of atom or list. 3
it a shorthand notation for the function, quote. Quote is a function that takes in its
argument and sends back as its answer, the same value that went into it.
29 | P a g e
30 | P a g e
a=(1....5) integer … ( in va li d )
c,d=(1....5) float … ( in va li d )
There should be proper assignment operator (:=) . In these colon before equal is
missing ...
condition
a=b
a=c
b=a
Procedure Color is
begin BasicColor
Color:=BasicColor'PRED(RED)
end color
Asn:
31 | P a g e
1. Readability
2. Writ ability
3. Reliability
Sentence='this is ur pen'
Sentence ’my’=
Z= ’10’
Prolog is a declarative programming language where we only specify what we need rather
than how to do it. It has a simple concise syntax with built-in tree formation and
backtracking which generates readable code which is easy to maintain. It is relatively case
and type insensitive and is suitable for problem solving / searching, expert systems /
knowledge representation, language processing / parsing and NLP, and game playing.
Discuss the issue related with declaring a method/class as final java? 3 marks
A final field is like a constant: once it has been given a value, it cannot be assigned to again.
Fields and methods can also be declared final. A final method cannot be overridden in a
subclass.
With suitable examples the concept of boxing in C#. How C# is different there concept
from other languages? 3 marks
Boxing
int i = 123;
32 | P a g e
1. Positional
2. Keyword
...
Dangling pointers are those pointers that points to a heap-dynamic variable that has been
Deallocated. Automatic garbage collection prevents memory leaks and dangling pointers.
Example missing…
The fact that arrays and classes are really pointers in Java can lead to some problems. Here
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
is a simple assignment that causes aliasing:
This obviously creates problems. programmers have to be very careful when writing
programs in Java.
In Java, all parameters are passed by value, but for arrays and classes the actual parameter
is really a pointer, so changing an array element, or a class field inside the function does
change the actual parameter's element or field.
Example:
void f( int [ ] A ) {
void g() {
B[0] = 5;
f(B);
B is not null here, because B itself was passed by value however, B[0] is now 10, because
function f changed the first element of the array.
Managed code
Managed code is executed under the control of Common Language Runtime (CRL).
It has automatic garbage collection. That is, the dynamically allocated memory area which
is no longer is in use is not destroyed by the programmer explicitly. It is rather automatically
returned back to heap by the built-in garbage collector. There is no explicit memory’s
allocation and deallocation and there is no explicit call to the garbage collector.
Unmanaged code
The unmanaged code provides access to memory through pointers just like C++. It is useful
in many scenarios. For example:
An explicit declaration is a program statement used for declaring the types of variables .
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
An implicit declaration is a default mechanism for specifying types of variables i.e the first
appearance of the variable in the program.
35 | P a g e
They can also be created by <<< which is called heredoc. One should provide an identifier
after <<<, then the string, and then the same identifier to close the quotation. The closing
identifier must begin in the first column of the line.
When a string is evaluated as a numeric value, the resulting value and type are determined
as follows.
The string will evaluate as a float if it contains any of the characters '.', 'e', or 'E'.
Otherwise, it will evaluate as an integer.
The value is given by the initial portion of the string. If the string starts with valid
numeric data, this will be the value used. Otherwise, the value will be 0 (zero).
Example:
<?php
?>
Using strings in numeric expressions provides flexibility but it should be obvious that it also
is a source to numerous programming errors and mistakes. This kind of error is also very
hard to debug and detect.
What are the enumeration and subrange types? Differentiate these two in points.
- A and B
- A or B
- Example
index := 1;
index := index + 1
C, C++, and Java: use short-circuit evaluation for the usual Boolean operators (&& and ||),
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
but also provide bitwise Boolean operators that are not short circuit (& and |) Structs c++
and c# structs are public by default. Structs are basically "objects" that contain variables
inside of them.The struct type: In C#, a struct is a value type.
37 | P a g e
Difference between proper example Union type in c/c++ and ada discriminated type?
2marks
Discriminated records are like union types in C. There are however major differences
between C union types and Ada discriminated records. The union type in C is fundamentally
unsafe, and therefore unacceptable.
Division by zero is an expression? what type of error is this and either handled by
compiler or it through exception? 3marks
38 | P a g e
While in FORTRAN 77, short circuiting is there, but any side affected place must be set to
undefined. The Problem with Short Circuiting is
(a > b) || (b++ / 3)
Example:
it is possible to tell the compiler that a class is compliant with .Net Common Language
Specification.
[CLSCompliant (true)]
publc class MyClass
{
//class code
}
Define and explain “throws Clause” and the “finally Clause” with respect to exception
handling in Java. (5)
Throws Clause
Throws clause is overloaded in C++ and conveys two different meanings: one as
specification and the other as command. Java is similar in syntax but different in semantics.
The appearance of an exception class name in the throws clause of Java method specifies
that the exception class or any of its descendents can be thrown by the method.
A C++ program unit that does not include a throw clause can throw any exceptions. A Java
method that does not include a throws cannot throw any checked exception it does not
handle. A method cannot declare more exceptions in its throws clause than the methods it
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
overrides, though it may declare fewer. A method that does not throw a particular
exception, but calls another method that could throw the exception, must list the exception
in its throws clause.
39 | P a g e
A Java exception handler may have a finally clause. A finally clause always executes when
its try block executes (whether or not there is an exception). The finally clause is written as
shown below:
try {
catch (…) {
finally {
A finally clause is usually included to make sure that some clean-up (e.g., closing opened
files) is done. If the finally clause includes a transfer of control statement (return, break,
continue, throw) then that statement overrides any transfer of control initiated in the try or
in a catch clause.
Explain the Prolog features regarding its applications in real world. (5)
40 | P a g e
Classes and objects in PHP are similar to Java. A variable of the desired type is created with
the new operator. It supports Single inheritance only and uses the keyword extends to
inherit from a super class. The inherited methods and members can be overridden, unless
the parent class has defined a method as final.
41 | P a g e
Fixed stack dynamic - range of subscripts is statically bound, but storage is bound at
elaboration time e.g. C local arrays are not static
Advantage: space efficiency
Stack-dynamic - range and storage are dynamic, but fixed from then on for the variable’s
lifetime e.g. Ada declare blocks declare
begin
...
end;
Advantage: flexibility - size need not be known until the array is about to be used
Differentiate between the implicit and explicit type conversion with respect to Java. (5)
Java is much stronger than C++ in the type conversions that are allowed.
Booleans cannot be converted to other types. For the other primitive types (char, byte,
short, int, long, float, and double).
Implicit conversions:
char c = 'a';
int k = c;
long x = c;
float y = c;
double d = c;
Explicit conversions:
Explicit conversions are done via casting: the name of the type to which you want a value
converted is given, in parentheses, in front of the value.
For example,
The following code uses casts to convert a value of type double to a value of type int, and to
convert a value of type double to a value of type short:
double d = 5.6;
int k = (int)d;
Casting can be used to convert among any of the primitive types except boolean.
Atoms:
43 | P a g e
Differentiate between client side scripting and server side scripting languages? (5)
Primary objective of JavaScript is to create dynamic HTML documents and check validity of
input forms. It is usually embedded in an HTML document. It is not really related to Java
It is interpreted on the Web Server when the HTML document in which embedded is
requested by the browser. It often produces HTML code as an output and is very similar to
JavaScript. It allows simple access to HTML form data and makes form processing easy. It
also provides support for many different database management systems and hence
provides Web access to databases.
Differentiate between the Dynamic Type binding and Static type binding?
Static and Dynamic Binding
A binding is static if it occurs before run time and remains unchanged throughout
program execution.
A binding is dynamic if it occurs during execution or can change during execution
of the program.
44 | P a g e
Explain the Concept of Explicit and Implicit heap, dynamic variables and stack dynamic
storage binding? Clarify the concept with suitable examples
Examples: Dynamic objects in C++ (via new and delete) All objects in Java
Advantage:Flexibility
withAda.Text_Io;
useAda.Text_Io;
procedureHello is
Virtualians Social Network www.virtualians.pk Prepared by: Irfan Khan
begin
Put_Line("Shazia Bano!");
45 | P a g e
There is no explicit memory’s allocation and deallocation and there is no explicit calls to
the garbage collector i.e. call to destructor.
No! in c#, Pointer can be declared to hold the memory addresses of value types. That is, we
cannot have pointers for reference type.
These are good enough for most purposes, but you can define your own types just like the
integer types:
Structs: Structs in C# are designed to encapsulate lightweight objects. They are value types
(not reference types), so they're passed by value. They are sealed, which means they
cannot be derived from or have any base class other than System.ValueType, which is
derived from Object. Structs cannot declare a default (parameterless) constructor. Structs
are more efficient than classes, that’s’ why they are perfect for the creation of lightweight
objects.
Write a program in Ada that prints the text Area of your course for example “BS-
Computer Sciences.”
withAda.Text_Io;
useAda.Text_Io;
procedureBSCS is
begin
Put_Line("BS-Computer Sciences!");
End BSCS;
Implementation models?
Implementation Models:
cut <or> ! is a special predicate. And it is used in the body of a given clause so as to avoid
using clauses appearing after the given clause in the program.it is like a goal which is always
succeeded but never backtracked past.
For example, to prevent extra solutions being found by Prolog and avoid additional
How do Ada and COBOL differ by syntax and semantics in referencing a record element?
Give examples of each (5)
47 | P a g e
- COBOL uses level numbers to show nested records; others use recursive
definitions
- Examples:
COBOL
field_name OF record_name_1 OF ... OF
record_name_name
According to readability point of view COBOL record definition syntax is easier to read and
understand but according to writability point of view other languages record definition
syntax is easier to write and less time consuming.
Example:
The Ada compiler will use the type of the variable in question and there will be no
ambiguity.Enumeration types are used as attributes or properties of different objects.
48 | P a g e
PHP offers an alternative syntax for some of its control structures; namely, if, while, for,
foreach, and switch. In each case, the basic form of the alternate syntax is to change the
opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;,
A parameter association defines the association between an actual parameter and a formal
parameter.
A predicate is a special function which returns NIL if the predicate is false, T or anything
other than NIL, otherwise. Predicates are used to build Boolean expressions in the logical
statements.
Can we define members and length function of our own in LISP?if yes then explain your
answer with suit able example.
yes we can, The LISP built-in function list-length counts the number of elements in a list. For
example,
49 | P a g e
????
Write a code in SNOBOL by using indirect referencing which decreases the value by 1.
As Use of an operator for more than one purpose is known as operator overloading. Ada
allows a limited overloading of operators. C++ and Ada allow user-defined overloaded
operators…???
What will happen if user does not provide the string array as the argument to the method
in Java,will there be any kind of error or not ?
2. case A is
when 1 =>fly;
end case;
50 | P a g e
(add 4, mult 3)
51 | P a g e