CS508 Solved Subjective Final Term by Junaid
CS508 Solved Subjective Final Term by Junaid
CS508 Solved Subjective Final Term by Junaid
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:
Answer:
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.
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:
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
sequence-of-statements
sequence-of-statements
sequence-of-statements
end case;
Answer:
Lists can be created and extended with the help of three basic functions.
1) cons,
2) list
3) append
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:
Answer:
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:
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.
Answer:
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(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
Answer:
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.
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.
Answer:
procedure Starprint is
begin
Put ("*");
New_Line ;
Put ("***");
New_Line ;
AL-JUNAID TECH INSTITUTE
Put ("*****");
New_Line ;
Put ("******");
New_Line ;
end Starprint;
Answer:
Answer:
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.
code:
*
**
***
****
***** (these stars have to print using loop)
Answer:
procedure Loopprint is
Number_Of_Time: Integer:=5;
AL-JUNAID TECH INSTITUTE
begin
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) 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 element from the list.
examples:
(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:
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.
Answer:
Answer:
To refer to the entire record accessed by an access value use the following notation:
Print(A_Ref.all);
Answer:
The following comparative operators are used as functions for numerical values
and return
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:
2) The initial expression can include variable definitions (scope is from the
definition to the end of the function in which it is defined).
Answer:
1) For loop
2) While loop
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:
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 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.
Scheme and
Common Lisp
Answer:
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:
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:
Answer:
Packages
These are primary structure used for encapsulation in.
5) Package bodies can also declare and define data types, variables, constants,
functions, and procedures not declared in the package specification.
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.
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.
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:
Answer:
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:
Answer:
There should be proper assignment operator (:=). In this colon before equal is missing.
condition
a=b
a=c
b=a
Procedure Color is
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
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:
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
{
Answer:
1. Positional
2. Keyword
Answer:
Answer:
The fact that arrays and classes are really pointers in Java can lead to some problems. Here
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.
AL-JUNAID TECH INSTITUTE
Example:
void f( int [ ] A ) {
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.
Answer:
Static Binding
A binding is static if it occurs before run time and remains unchanged throughout program
execution.
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:
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
Answer:
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)
?>
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:
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.
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.
Answer:
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.
Answer:
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:
1) Expert systems
2) Artificial intelligence,
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.
Answer:
Answer:
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)
Answer:
[CLSCompliant (true)]
publc class MyClass
{
//class code
}
Q.No.74 Describe the programming steps in Prolog?
Answer:
Answer:
Answer:
Answer:
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
Stack-dynamic - range and storage are dynamic, but fixed from then on for the variable’s
lifetime e.g. Ada declare blocks declare
Advantage: flexibility - size need not be known until the array is about to be used
Answer:
Atoms:
Answer:
1) object
2) string
Q.No.83 Differentiate between client side scripting and server side scripting languages?
Answer:
Answer:
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;
Casting can be used to convert among any of the primitive types except boolean.
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
Examples: Dynamic objects in C++ (via new and delete) All objects in Java
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:
2. Are the types of the actual parameters checked against the types of the formal parameters?
5. If subprograms can be passed as parameters, are types of parameters checked in calls to the
passed subprograms?
Q.No.90 Differentiate between the Dynamic Type binding and Static type binding?
Answer:
A binding is static if it occurs before run time and remains unchanged throughout
program execution.
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).
Answer:
- 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:
Answer:
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 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:
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.
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.