Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CS508 Solved Subjective Final Term by Junaid

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

AL-JUNAID TECH INSTITUTE

CS508-Modern
Programming Language
(Solved Subjective)
LECTURE FROM
(23 to 45)
Junaidfazal08@gmail.com FOR MORE VISIT JUNAID MALIK
Bc190202640@vu.edu.pk
VULMSHELP.COME 0304-1659294
AL-JUNAID TECH INSTITUTE
Q.No.1 Write three concepts which are introduced in LISP first time?

Answer:

• Conditionals: such as if-then-else construct.


• Function types: where functions are just like integers and strings
• Recursion: first language to support it.
• Dynamic typing: all variable are pointers.
• Garbage-Collection.
• Programs composed of expressions.
• A symbol type.
• The whole program is a mathematical function
Q.No.2 Write a function in LISP to concatenate two lists List a=(3 4 5) List b=(c d 6)

Answer:

>(append '(3 4 5) '(c d 6))


(3 4 5 c d 6)..concatenated List
Q.No.3 Ada is strongly typed language describe how?

Answer:

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.

Q.No.4 How can we determine the size of Array in SNOBOL?

Answer:

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)
Q.No.5 In C++ ^ and ~ are used for bitwise exclusive OR and bitwise NOT
write there equivalent in ada?
Answer:

^ bitwise exclusive OR of c++ = Xor in ADA..


~ = Not in ADA
AL-JUNAID TECH INSTITUTE
Q.No.6 What code in LISP language used to compute power of x to y?

Answer:

(defun power (x y)
(if (= y 0) 1 (* x (power x (1- y)))))
This function computes the power of x to y. That is, it computes xy
by recursively multiplying x with itself y number of times.
Example;
>(power 3 4)
81
Q.No.7 A code was given about ADA case concept. Please refer topic "Case statement”

Answer:

case expression is

when choice list =>

sequence-of-statements

when choice list =>

sequence-of-statements

when others =>

sequence-of-statements
end case;

Q.No.8 Name functions that are used in List construction

Answer:

Lists can be created and extended with the help of three basic functions.

1) cons,
2) list
3) append

Q.No.9 Write IO header file for Ada.

Answer:
AL-JUNAID TECH INSTITUTE
with Ada.Text_Io; -- intent to use
use Ada.Text_Io; -- direct visibility
Q.No.10 What are operators for Logical AND && and Logical OR || used in ADA.

Answer:

Logical AND &&= And in ADA


Logical OR || = Or in ADA
Q.No.11 Features added in COBOL not included in SNOBOL.

Answer:

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.
Q.No.12 What is the functionality of KEYWORD INT|CAHR IN snobol4?

Answer:

In SNOBOL 4 Vertical bar is used to specify pattern alternation.


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.
Q.No.13 Write two comparative operators used as function for numerical
values in lisp programming language?
Answer:
Comparative operators which are used as functions for numerical values are
=, >, <, >=, <=;
Q.No.14 What is error in it >(sqrt x) in LISP?

Answer:

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.

Error: The variable X is unbound.


AL-JUNAID TECH INSTITUTE
Q.No.15 How many element in it (a (d e)) related to lisp?

Answer:

There are two elements.

Atom = a

List = (d e)
Q.No.16 Which data structure map pairs of associated data object in snobol?

Answer:

A table data structure maps pairs of associated data objects. Tables have varying
lengths and are dynamically extended if necessary.

T = TABLE()……If want to creates a table of unspecified length.

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:

T<‘A’> = 1

Associates key ‘A’ with value 1.


Q.No.17 What is predicate in lisp language conform?

Answer:

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.
Comparative operators in LISP used as functions for numerical values and return a T
or NIL. =, >, <, >=, <=;

For example 1:

(= (+ 2 4) (* 2 3))

T
AL-JUNAID TECH INSTITUTE
example 2:

(> (- 5 2) (+ 3 1))

NIL

Q.No.18 Which language first provided exception handling among c++, ada?

Answer:

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 withat
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.
Q.No.19 Write a complete program in ada to print this out put by only using put_line
command. Use the loop isn't allowed.

print this code


*
***
*****
*******

Answer:

procedure Starprint is
begin

Put ("*");
New_Line ;

Put ("***");
New_Line ;
AL-JUNAID TECH INSTITUTE
Put ("*****");
New_Line ;

Put ("******");
New_Line ;

end Starprint;

Q.No.20 Does ada believe in human programming if yes then y?

Answer:

Yes, ada believe in human programming .Programming as a human activity is the


main goal of ADA. In ADA the whole philosophy is that a programmer is a human
and all humans make mistakes. So to make it safer, Ada uses discriminates in a
record that tells what type of data is currently stored there.
Q.No.21 c or ada, which support subprograms?

Answer:

ADA supports subprograms. There are two types of subprograms:

1) Procedures
2) Functions

We can also have nesting of subprograms. A subprogram defined inside another subprogram
can be used by its parent, children, or sibling subprograms only.

Q.No.22 Write program in ada using loop to print this code

code:

*
**
***
****
***** (these stars have to print using loop)

Answer:

procedure Loopprint is

Number_Of_Time: Integer:=5;
AL-JUNAID TECH INSTITUTE
begin

for I in 1..Number_Of_Time loop

for J in 1..I loop


Put ('*');

end loop;

New_Line;
End loop;

end Nested_Loops;
end Loopprint;
Q.No.23 concepts of car,cdr, first and rest in Lisp?

Answer:

In order to select elements from a list, selectors functions are used. There are two
basic selector functions known as

1) first (or car) and


2) rest (or cdr).

The rest can be build with the help of these functions.

1. First (or car) takes a list as an argument and returns the first element of that list.

example:

>(first '(a s d f))

2. rest (or cdr) takes a list as its argument and returns a new list after removing
the first element from the list.

examples:

>(rest '(a s d f))

(s d f).

Q.No.24 Write three concepts which are introduced in LISP first time?
AL-JUNAID TECH INSTITUTE
Answer:

Generality:

Generality is also an important factor and deals with the applicability of the
language to a range of different domains. For example, C is more general purpose
than LISP or FORTRAN and hence can be used in more domains than these two
languages.
Q.No.25 Compare ADA dotimes loop with dolist and dotime in LISP.

Answer:

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
dotimes is like a counter-control for loop. Its syntax is given as below:
(dotimes (count n result) body)
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:

(dolist (x L result) body)

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.

Q.No.26 Is there anything like templates as in C++?

Answer:

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.
AL-JUNAID TECH INSTITUTE
Q.No.27 Differentiate between ADA access types and C/C++ pointer type.

Answer:

An access type in ADA roughly corresponds to a C++ pointer.


type Address_Ref is access Address;
A_Ref := new Address;
A_Ref.Postal_Code := "94960-1234";

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);

Q.No.28 Why predicate is a special function in LISP?

Answer:

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. =, >, <, >=, <=;

Q.No.29 What additional features are added in COBOL?

Answer:

COBOL uses level numbers to show nested records; others use recursive definitions Business
applications reports, decimal arithmetic, character operations - COBOL

It was designed to look like simple English to broaden the base of computer users.
AL-JUNAID TECH INSTITUTE
Q.No.30 Difference of C and C++.

Answer:

C++ Differs from C in two ways:

1) The control expression can also be Boolean

2) The initial expression can include variable definitions (scope is from the
definition to the end of the function in which it is defined).

Q.No.31 Write types of loop in Ada.

Answer:

There are three types of loops in ADA.

1) For loop

2) While loop

3) Simple… unconditional infinite loop

Q.No.32 is polymorphism allowed in ada?

Answer:

There are two means of using polymorphism in Ada. Static polymorphism is provided
through the generic parameter mechanism whereby a generic unit may at compile time be
instantiated with any type from a class of types. Dynamic polymorphism is provided
through the use of so-called class-wide types and the distinction is then made at runtime on
the basis of the value of a tag.
AL-JUNAID TECH INSTITUTE
Q.No.33 Brief note on Orthogonality.

Answer:

Orthogonality is a very important concept. It addresses how relatively small number of


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
Q.No.34 SYNTACALLY SHOW HOW CAN WE DEFINE THE LISP?

Answer:

LISP is a representative language of this style of programming.

Lisp stands for “LISt Process”. It was invented by John McCarthy in 1958 at MIT.

1. It has simple data structure (atoms and lists) and makes heavy use of recursion.

2. It is an interpretive language and has many variations.

3. The two most popular versions are

 Scheme and
 Common Lisp

4. It is the most widely used AI programming language.

5. Atom and LIST are two main elements of LISP.


AL-JUNAID TECH INSTITUTE
Q.No.35 algol main feature?

Answer:

Salient features of the language are:

1. Concept of type was formalized


2. Names could have any length
3. Arrays could have any number of subscripts.Lower bound of an array could be defined
4. Parameters were separated by mode (in & out)
5. Subscripts were placed in brackets
6. Compound statements were introduced (begin ... end)
7. Semicolon as a statement separator was used
8. Assignment operator was :=
9. if had an else-if clause

Q.No.36 Babbage’s Analytical Engine.

Answer:

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.
The key features of this machine included:

1. Memory (called store),


2. jump,
3. loop, and the
4. concept of subroutines.

It was motivated by the success of power looms. It had limited capability and because of the
technological limitations this design could not be fully implemented.
AL-JUNAID TECH INSTITUTE
Q.No.37 What is the difference between >(intersection L1,L2) and (set-
difference L1,L2) Lisp Functions?

Answer:

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
Q.No.38 Give silent features of packages in Ada.

Answer:

Packages
These are primary structure used for encapsulation in.

1) Packages are used to group data and subprograms.

2) Packages can be hierarchical, allowing a structured and extensible relationship


for data and code.

3) All the standard Ada libraries are defined within packages.

4) Package definitions usually consist of two parts:

 package specification and


 package body

5) Package bodies can also declare and define data types, variables, constants,
functions, and procedures not declared in the package specification.

Q.No.39 Dangling pointer how to state in java?

Answer:

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.
AL-JUNAID TECH INSTITUTE
Q.No.40 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.

Answer:

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.

Q.No.41 What is batting-average in Ada explain with suitable example.

Answer:

The type Batting_Averages is a fixed point type whose values are evenly spaced real
numbers in the range from 0 through 1. The distance between the values is no more
than 1/1000. The actual distance between values may be 1/1024, which is 2-10.
For example:
type Batting_Averages is delta 0.001 range 0.0..1.0;
The distance between values is implemented as a power of 2.

Q.No.42 Write pattern matching statement in SNOBOL.

Answer:

In SNOBOL Space is used as the pattern matching operator and the statement has
the following form:
subject pattern
There is no assignment operator in this case. Both the subject and the pattern are
strings and this statement tries to match the pattern in the subject. It will be
successful if the match is found and will result in failure otherwise.
Example:
TRADE = ‘PROGRAMMER’
PART = ‘GRAM’
TRADE PART
AL-JUNAID TECH INSTITUTE
Q.No.43 What are interpreted and compiled languages? Give examples.

Answer:

Interpreted computing languages are languages whose source code is processed by a


software program called an interpreter that reads in the text and immediately acts upon
the instructions defined by the text. Compiled computing languages are languages whose
source code is processed by a software program called a compiler that converts the source
code into a file which can then be run directly or indirectly by a computer operating system.

 Prolog It is an interactive (hybrid compiled/interpreted) language.


 PHP is interpreted
 FORTAN is compiled
 SNOBAL is compiled

Q.No.44 Comparison between functional and imperative languages?

Answer:

A most important class of programming languages, known as the imperative languages, i


based upon the von Neumann Architecture.

This includes languages like FORTAN COBOL, Pascal, Ada, C, and many more.

While functional language is where there is no need for assignment and in it control flow is
achieved via recursion and conditional expressions.

Q.No.45 Write three concepts which are introduced in LISP first time?

Answer:

Convert the following Ada code into equivalent C code.


case ch is
when ‘A’ | ‘E’ | ‘I’ | ‘O’ | ‘U’ =>
putline(“this is an uppercase vowel”);
when ‘J’ .. ‘N’ =>
putline(“between uppercase J and N”);
when others =>
putline(“something else”);
end case;
AL-JUNAID TECH INSTITUTE
Q.No.46 What is valid or invalid statement in ADA language?

Answer:

a=(1. .. 5) integer…( invalid )


b=(1. .. 5) integer…( invalid )
c,d=(1. .. 5) float…( invalid )

Note: All Declarations are invalid.

There should be proper assignment operator (:=). In this colon before equal is missing.

Improper array declaration here too... only 2 dots should be there(..)

condition

a=b

a=c

b=a

Q.No.47 Write Output of the following code.

Procedure Color is

Color= BasicColor(Red, green, blue, yellow)

begin BasicColor

Color:=BasicColor'PRED(RED)

end color

Answer:

RED
AL-JUNAID TECH INSTITUTE
Q.No.48 How to compare and examine language?

Answer:

1. Readability
2. Writability
3. Reliability

Q.No.49 Pattern matching Output of code?

Answer:

Sentence='this is ur pen'
Sentence ‘ur’= ’my’
Sentence ’my’=
Z= ’10’
Q.No.50 Prolog learning curve is very high meanings of this statement.

Answer:

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.

Q.No.51 Discuss the issue related with declaring a method/class as final java?

Answer:

Final Fields and Methods


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.
Q.No.52 With suitable examples the concept of boxing in C#. How C# is
different there concept from other languages?

Answer:

Boxing
Boxing is converting any value type to corresponding object type and convert the resultant
'boxed' type back again.
int i = 123;
object box = i; // value of i is copied to the object box
if (box is int) // runtime type of box is returned as boxed value type
AL-JUNAID TECH INSTITUTE
{

Console.Write("Box contains an int"); // this line is printed


}
Q.No.53 Notation of actual /formal Parameters?

Answer:

Actual/Formal Parameter Correspondence:

1. Positional
2. Keyword

e.g. SORT(LIST => A, LENGTH => N);


Default Parameter Values
procedure SORT(LIST : LIST_TYPE;
LENGTH : INTEGER := 100);
...
SORT(LIST => A);
Q.No.54 What is quoted atom in prolog?

Answer:

Quoted atoms - sequence of characters surrounded by single quotes.


Examples: ‘Apple’ ‘hello world’
Q.No.55 Aliasing Problem in java Script? with suitable examples.

Answer:

Aliasing Problems in Java

The fact that arrays and classes are really pointers in Java can lead to some problems. Here
is a simple assignment that causes aliasing:

int [] A = new int [4];


Int [] B = new int [2];

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.
AL-JUNAID TECH INSTITUTE

Example:

void f( int [ ] A ) {

A[0] = 10; // change an element of parameter A

A = null; // change A itself


}

void g() {
int [ ] B = new int [3];

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.
AL-JUNAID TECH INSTITUTE
Q.No.56 What is monitor in java thread?

Answer:

To prevent problems that could occur by having two methods modifying the same object,
Java uses monitors and the synchronized keyword to control access to an object by a
thread. Any object that implements the "synchronized" keyword is considered to be a
monitor. A monitor is an object that can move a thread process between a blocked and
running state. Monitors are required when a process needs to wait for an external event to
occur before thread processing can continue. A typical example is when a thread can't
continue until an object reaches a certain state.
Q.No.57 What queried in prolog?

Answer:

Queries are used to retrieve information from the database. A query is a pattern that
PROLOG is asked to match against the database and has the syntax of a compound query. It
may contain variables. A query will cause PROLOG to look at the database, try to find a
match for the query pattern, execute the body of the matching head, and return an answer.

Q.No.58 How many ways the static binding can be define?

Answer:

Static Binding

A binding is static if it occurs before run time and remains unchanged throughout program
execution.

If static, type may be specified by either an explicit or an implicit declaration.

An explicit declaration is a program statement used for declaring the types of variables.

An implicit declaration is a default mechanism for specifying types of variables i.e the first
appearance of the variable in the program.
Q.No.59 What is managed and unmanaged code?

Answer:

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
AL-JUNAID TECH INSTITUTE
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:

 Pointers may be used to enhance performance in real time applications.

 In non-.net DLLs some external functions requires a pointer as a parameter,


such asWindows APIs that were written in C.

 Sometimes we need to inspect the memory contents for debugging purposes, or you
might need to write an application that analyzes another application process and
memory.
Q.No.60 Write three different methods how to write strings in PHP?

Answer:

Strings

PHP strings are created using single quote or double quote.


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.
Q.No.61 How to convert PHP string in numeric value?

Answer:

String conversion to numbers:

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
AL-JUNAID TECH INSTITUTE
$foo = 2 + "10.5"; // $foo is float (12.5)

$foo = 1 + "-1.1e3"; // $foo is float (-1099)

$foo = 1 + “Ali-1.3e3"; // $foo is integer (1)

$foo = 1 + "10 Small Cats"; // $foo is integer (11)

$foo = "10.0 cats " + 1; // $foo is float (11)

?>

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.
Q.No.62 What seal struct and abstract means in C#?

Answer:

An abstract class is any class that includes an abstract method. It is similar to Pure virtual in
C++. If a class includes an abstract method, the class must be declared abstract, too.
Q.No.63 Discuss readability problem using control statements?

Answer:

Control statements play an important role in readability.

1. We are all aware of the hazards of goto statement. If a language relies on goto
statements for control flow, the logic becomes difficult to follows and hence
understands and maintain.

2. Restricted use of goto in extreme was needed and useful as well but with the
emergence of new language constructs to handle those situations, it probably not an
issue any more.
Q.No.64 What are the enumeration and subrange types? Differentiate these two in points.

Answer:

a) An enumeration is a special kind of value type limited to a restricted and unchangeable set
of numerical values. By default, these numerical values are integers, but they can also be
longs, bytes, etc. (any numerical value except char).while subrange type is an ordered
contiguous subsequence of an ordinal type.

b) Subrange types behave as their parent types; can be used as


AL-JUNAID TECH INSTITUTE
for variables and array indices
▪ E.g. type pos = 0 .. MAXINT;

c) Enumeration types are implemented as integers while Subrange types are the parent
types with code inserted (by the compiler) to restrict assignments to subrange variables.

Q.No.65 Division by zero is an expression? what type of error is this and


either handled by compiler or it through exception?

Answer:

Division by zero is due to Inherent limitations of arithmetic. It is run-time errors sometimes


called exceptions.
Q.No.66 Difference between proper example Union type in c/c++ and ada
discriminated type?

Answer:

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.

Q.No.67 Short circuiting in java and c and c++.

Answer:

Short Circuit Evaluation;


- A and B
- A or B
- Example
index := 1;
while (index <= length) and
(LIST[index] <> value) do
index := index + 1

C, C++, and Java: use short-circuit evaluation for the usual Boolean operators (&& and ||),
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.
Q.No.68 How to define PHP classes?
AL-JUNAID TECH INSTITUTE
Answer:

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.
Q.No.69 Define and explain “throws Clause” and the “finally Clause” with
respect to exception handling in Java.

Answer:

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
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.
The finally clause:

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
AL-JUNAID TECH INSTITUTE
in a catch clause.
Q.No.70 Explain the Prolog features regarding its applications in real world.

Answer:

We can find PROLOG in areas like:

1) Expert systems

2) Artificial intelligence,

3) Natural language understanding,

4) logical puzzles and games.

5) theorem proves construction

6) The variant of PROLOG called DATALOG is used in database management.

7) 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.
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.

Q.No.71 Write two differences between C++ and Java.

Answer:

Java is more robust than C++. Some of the reasons are:

1. Object handles are initialized to null (a keyword)


2. Handles are always checked and exceptions are thrown for failures
3. All array accesses are checked for bounds violations
4. Automatic garbage collection prevents memory leaks and dangling pointers
5. Type conversion is safer
6. Clean, relatively fool-proof exception handling
7. Simple language support for multithreading
8. Byte code verification of network applets
AL-JUNAID TECH INSTITUTE
Q.No.72 How Short circuit evolution is performed in Ada and fortran?

Answer:

In Ada, programmer can specify either short-circuit is specified with:

1. ‘and then’
2. ‘or else’

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)

Short-circuit evaluation exposes the potential problem of side effects in expressions


Q.No.73 What term Class attribute in C#?

Answer:

In C#, Attributes are used to give information to .Net compiler


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
}
Q.No.74 Describe the programming steps in Prolog?

Answer:

PROLOG programming follows the following steps:

 Declaring some facts about objects and their relationships


 Defining some rules about objects and their relationships
 Asking questions about objects and their relationships
AL-JUNAID TECH INSTITUTE
Q.No.75 Union in c++ and java difference?

Answer:

C and C++ have free unions (no tags)


- Not part of their records
- No type checking of references

Java has neither records nor unions

Q.No.76 Two difference b/w c++ and java.

Answer:

1. Control expression must be Boolean


2. Scope of variables defined in the initial expression is only the loop body
Q.No.77 Two difference b/w c and c++.

Answer:

1) The control expression can also be Boolean

2) The initial expression can include variable definitions, scope is from the definition to the
end of the function in which it is defined.
Q.No.78 What is notify and wait in java?

Answer:

Threads are based upon the concept of a Monitor. The wait and notify methods are used
just like wait and signal in a Monitor. They allow two threads to cooperate and based on a
single shared lock object.
Q.No.79 What is notify() and notifyall() in java?

Answer:

There is a slight difference between notify and notifyAll. As the name suggest, notify()
wakes up a single thread which is waiting on the object's lock. If there is more than one
thread waiting, the choice is arbitrary i.e. there is no way to specify which waiting thread
should be re-awakened. On the other hand, notifyAll() wakes up ALL waiting threads; the
scheduler decides which one will run.
Q.No.80 Explain Stack Dynamic variable with example?

Answer:

Fixed stack dynamic - range of subscripts is statically bound, but storage is bound at
AL-JUNAID TECH INSTITUTE
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

STUFF : array (1..N) of FLOAT;


begin
...
end;

Advantage: flexibility - size need not be known until the array is about to be used

Q.No.81 Two example of atoms in PROLOG syntax?

Answer:

Atoms:

AlphaNumaric start with lower letter


Quoted Atom sequence of character quoted by single quotes
Symbolic symbol & +-* special atom !;[]{}
Q.No.82 Two example of predefined reference type in C#?

Answer:

1) object
2) string

Q.No.83 Differentiate between client side scripting and server side scripting languages?

Answer:

JavaScript – client side scripting


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

PHP (Personal Home Page) – server-side scripting


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
AL-JUNAID TECH INSTITUTE
also provides support for many different database management systems and hence
provides Web access to databases.

Q.No.84 What is seal struct and abstract in C#

Answer:

Abstract: A class declared as 'abstract' cannot itself be instanced - it is designed only to be


a base class for inheritance.

Sealed: A class declared as 'sealed' cannot be inherited from. It may be noted that structs
can also not be inherited from. But it can inherit from other class.

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 can not 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.
Q.No.85 Differentiate between the implicit and explicit type conversion with respect to Java.

Answer:

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:

An implicit conversion means that a value of one type is changed to a value of another type
without any special directive from the programmer. A char can be implicitly converted to an
int, a long, a float, or a double.

For example:
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.
AL-JUNAID TECH INSTITUTE
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;

short s = (short)(d * 2.0);

Casting can be used to convert among any of the primitive types except boolean.

Q.No.86 In C# how many Allocation is handled through manage Code?

Answer:
There is no explicit memory’s allocation and deallocation and there are no explicit calls to
the garbage collector i.e. call to destructor.
Q.No.87 Explain the Concept of Explicit and Implicit heap, dynamic variables and
stack dynamic storage binding? Clarify the concept with suitable examples

Answer:
Explicit Heap Dynamic Variables

• Allocated and de-allocated by explicit directives, specified by the programmer,


which take effect during execution
• Referenced only through pointers or references

Examples: Dynamic objects in C++ (via new and delete) All objects in Java

Advantage: Provide dynamic storage management

Disadvantage: Inefficient and unreliable

Implicit Heap Dynamic Variables

• Allocation and de-allocation is caused by assignment statements

Example:All variables in SNOBOL

Advantage: Flexibility

Disadvantages: Inefficient, because all attributes are dynamic Loss of error detection
Q.No.88 Write Ada language procedure (Code) to display your name on screen.

Answer:
AL-JUNAID TECH INSTITUTE
withAda.Text_Io;
useAda.Text_Io;
procedureHello is
begin
Put_Line("Shazia Bano!");
endHello;
AL-JUNAID TECH INSTITUTE
Q.No.89 What are subprogram issues in different languages?

Answer:

Subprograms are complex structures in programming languages, and it follows from


this a lengthy list of issues in their design. Following are some issues with sub programming,

1. What parameter-passing method or methods are used?

2. Are the types of the actual parameters checked against the types of the formal parameters?

3. Are local variables statistically or dynamically allocated?

4. If subprograms can be passed as parameters, what is the referencing environment of such a


subprogram?

5. If subprograms can be passed as parameters, are types of parameters checked in calls to the
passed subprograms?

6. Can subprograms be overloaded?

7. Can subprograms be generic?

8. Is neitherseparate or independent compilation possible?

Q.No.90 Differentiate between the Dynamic Type binding and Static type binding?

Answer:

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.
AL-JUNAID TECH INSTITUTE
Q.No.91 What is the run time environment in case of C# similar to JVM in
case of Java programming language?

Answer:

It is Similar to Java and C++ in many respects. The .NET platform is centered on a Common
Language Runtime (CLR - which is similar to a JVM) and a set of libraries which can be
exploited by a wide variety of languages which are able to work together by all compiling to
an intermediate language (IL).

Q.No.92 How do Ada and COBOL differ by syntax and semantics in


referencing a record element? Give examples of each.

Answer:

In ADA, Record types are like structures in C.


type Address is record
Street : Unbounded_String;
City : Unbounded_String;
Postal_Code : String(1..10);
end record;

- 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.
Q.No.93 SNOBOL stands for what?

Answer:

SNOBOL stands for StriNg Oriented SymBOlic Language.


AL-JUNAID TECH INSTITUTE
Q.No.94 How many character types are supported in Ada Language?

Answer:

There are two built in character types in Ada,

1) Simple 8-bit ASCII Characters

2) Wide_Character that support 16-bit Unicode/ISO standard 10646.

These are good enough for most purposes, but you can define your own types just like the
integer types.

Q.No.95 Write a program in Ada that prints the text Area of your course for
example “BS-Computer Sciences.”

Answer:

withAda.Text_Io;
useAda.Text_Io;
procedureBSCS is
begin
Put_Line("BS-Computer Sciences!");
End BSCS;

Q.No.96 Whose better among C/C++ and Ada according to overloading concept..

Answer:

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.
Q.No.97 Implementation models.

Answer:

Implementation Models:
Pass-by-value (in mode): Either by physical move or access path
Q.No.98 What is the function of cut(!) predicate in PROLOG?

Answer:

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
AL-JUNAID TECH INSTITUTE
succeeded but never backtracked past.

For example, to prevent extra solutions being found by Prolog and avoid additional
computations that are not desired or required in a program.
Q.No.99 Give two examples of errors when pointers are wrongly used?

Answer:

Dangling pointers:

A pointer points to a heap-dynamic variable that has been deallocated.

Lost Heap-Dynamic Variables:

A heap-dynamic variable that is no longer referenced by any program pointer. The process of
losing heap-dynamic variables is called memory leakage
Q.No.100 We studied several reasons to study programming languages.
With that context in mind discuss:
(a) Increased capacity to express programming concepts
(b) Improved background for choosing appropriate languages and show the output.
Discuss the difference between enumeration types of C and Ada. Which is better and why?

Answer:

Although Just like C, an enumeration type in Ada is a sequence of ordered enumeration


literal, It is however different from C in many respects:
There is no arithmetic defined for these types.

Example
S1, S2 : State;
S1 := S1 + S2; -- Illegal
Unlike C, the same symbolic literal can be used in two enumeration types.

Example:
type RainbowColors is (Red, Orange, Yellow, Green, Blue, Indigo, Violet);
type BasicColors is (Red, Green, Blue);
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.
Q.No.101 Why it is necessary to use (:) in control flow statement?

Answer:

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
AL-JUNAID TECH INSTITUTE
opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;,
endforeach;, or endswitch;, respectively.

Q.No.102 Difference between Actual Parameter and Predicate parameter?

Answer:

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.
Q.No.103 Can we define members and length function of our own in LISP?if
yes then explain your answer with suit able example.

Answer:

yes we can, The LISP built-in function list-length counts the number of elements in a list. For
example,
USER(33): (list-length '(2 3 5 7 11 13 17 19))
8
a function can be implemented recursively. A given list L is created by either one of the two
constructors, namely nil or a cons:

Case 1: L is nil.
The length of an empty list is zero.

Case 2: L is constructed by cons.


Then L is composed of two parts, namely, (first L) and (rest L). In such case, the length
of L can be obtained inductively by adding 1 to the length of (rest L).

You might also like