50% found this document useful (4 votes)
3K views

CS508 Midterm Solved Current Subjective Papers Withrefernces

This document provides solved answers to questions on various programming languages and concepts. It includes questions and answers on functional programming paradigms, operators in Ada and C++, Lisp concepts like first, rest, car and cdr, Snobol patterns, recursion in Lisp, arrays and conditionals in Ada, packages and types in Ada, pattern building in Snobol, functions to construct lists in Lisp, logical values in Lisp, tagged types and extensibility in Ada, and pointers in Snobol. The document serves as a reference guide to key concepts across multiple programming languages.

Uploaded by

Aleena Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
50% found this document useful (4 votes)
3K views

CS508 Midterm Solved Current Subjective Papers Withrefernces

This document provides solved answers to questions on various programming languages and concepts. It includes questions and answers on functional programming paradigms, operators in Ada and C++, Lisp concepts like first, rest, car and cdr, Snobol patterns, recursion in Lisp, arrays and conditionals in Ada, packages and types in Ada, pattern building in Snobol, functions to construct lists in Lisp, logical values in Lisp, tagged types and extensibility in Ada, and pointers in Snobol. The document serves as a reference guide to key concepts across multiple programming languages.

Uploaded by

Aleena Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

CS508 Midterm Subjective Solved with References

Include Current Midterm Papers Year 2013


Solved by: Saher (Well Wisher / Aqualeo)

www.saher-it-soutions.com
Midterm Paper Year 2013

Q. What will be choice of language in functional program paradigm?


Answer: Page no : 63

Functional programming is a style of programming that emphasizes the


evaluation of expressions, rather than execution of commands. The expressions in
these languages are formed by using functions to combine basic values. A
functional language is a language that supports and encourages programming in a
functional style. LISP is a representative language of this style of programming.

Q. Tell the names of operates that are present in Ada but not in C++

Answer: Page no : 47

Remainder Rem

AbsoluteValue Abs

Exponentiation **

Range ..

Membership In

String Concatenation &

Q. Tell the difference between first,rest,car,cdr?

Answer: Page no : 67

First (or car) is a list selector. It takes list as argument and return first element of
list.

Rest(or cdr) is a list selector. It takes list as argument and return whole list after
excluding first element.

Q. Tell the out put if

www.saher-it-solutions.com | solved by Saher


defun y-min (x)(- x,y)

set y 2

y-min 20

Answer: Page no : 69

(y-min 20)

(setq y 2 )

20-2= 18

Q1 Write two predicate that are used in lisp. Marks 2

Answer: Page no : 68

Some other useful predicates are listed below:

atom: test if x is an atom

listp: test if x is a list

Also number, symbolp, null can be used to test whether the operand is a number,
symbol, or a null value.
Q2 Lists are used in lisp write top elements of the list given as (add 3( multp 3
4))
and (job car school) Marks 3

Answer: Page no : 64

3 and (3 4 ) are top element in first list while job , car and school are top
elements in second list.

Q3 write a two dimensional array of siz (2x8) in sonobl and intialize it to


zero.Marks 3

www.saher-it-solutions.com | solved by Saher


Answer:

N=ARRAY(‘2,5’,0)

Q4 We want to write a program in ada and want to take marks as inputs from
user and
subject 1=(100)
subject 2=(200)
subject 3=(400)
Answer:

with Ada.Text_IO; use Ada.Text_IO;


procedure Subject is
S1: String(1 .. 100)
S2: String(1 .. 200)
S3: String(1 .. 400)
Last: Integer;
begin
Put_Line("Subject1:");
Get_Line(S1, Last);
Put_Line("Subject2:");
Get_Line(S2, Last);
Put_Line("Subject3:");
Get_Line(S3, Last);

end Subject;

How we prevent user to input value that is not in this range?

Which symbol is used for alternation in Snobol?

Answer: Page no : 36

Vertical bar is used to specify pattern alternation as shown in the example below.

www.saher-it-solutions.com | solved by Saher


P1 | P2

This is example of a pattern that will match either P1 or P2.

Overloading in ada and c++?

Answer: Page no : 48

Ada allows a limited overloading of operators. The exception in Ada is that the
assignment operator (:=) cannot be overridden. It can be overridden in case of
inheritance from a special kind of “abstract class”. When you override the
equality operator ( =) you also implicitly overridethe inequality operator (/=).

"Single standard language"

Answer: Page no : 45

The need for a single standard language was felt in 1975 and the draft
requirements were given the code name strawman. Strawman was refined to
Woodman and then Tinman in 1976. It was further refined to ironman. At that
time proposals were invited for the design of a new language. Out of the 17
proposals received, four were selected and given the code names of green, red,
blue, and yellow. Initial designs were submitted in 1978 and red and green short
listed on the basis of these designs. Standard requirements were then refined to
steelman. The designs were refined further and finally Green was selected in
1979. DoD announced that the language will be called Ada. The 1995 revision of
Ada (Ada 95) was developed by a small team led by Tucker Taft. In both cases, the
design underwent a public comment period where the designers responded to
public comments.

1. what is the functionality of KEYWORD INT|CAHR IN snobol4 2

Answer: Page no : 36

KEYWORD = ‘INT’ | ‘CHAR’ This statement assigns the pattern ‘INT’ | ‘CHAR’ to
the variable KEYWORD.

www.saher-it-solutions.com | solved by Saher


2.what is error in it >(sqrt x) in LISP 3

Answer: Page no : 65

X is unbound because this symbol doesn’t have any value we will have to assign a
value using setq, setf and set.

>(setq x 3) = 3

3. How many element in it (a (d e)) related to lisp 2

Answer: Page no : 64

There are two elements in this list a and (d e)


what is predicate in lisp ?

Answer:

Predicate is a special function which return nill if predicate is not true and returns
T otherwise. Comparative operators are used as functions for numerical values
e.g = < > <= >=. Equal or eq are used for comparing non numeric values. Atom ,
Lisp , Symbolp , number , null are other useful predicates used to find out
whether x is a atom , list , symbol number or null.

What is valid or invalid statement in ADA language 5


a=(1....5) integer
b=(1....5) integer
c,d=(1....5) float
condition
a=b
a=c
b=a
Answer:

a : integer (1..5); , //syntax is valid

a=c // condition is invalid

www.saher-it-solutions.com | solved by Saher


The proposal of ada is proposed by which company.

Answer: Page no : 45

DoD announced that the language will be called Ada.

Explain briefly the expression of the LISP language.

Answer:

An S-expression(S stands for symbolic) is a convention for representing data or an


expression in a LISP program in a text form. It is characterized by the extensive
use of prefix notation with explicit use of brackets (affectionately known as
Cambridge Polish notation). S-expressions are used for both code and data in Lisp.
S-expressions were originally intended only as machine representations of
human-readable representation of symbols, but Lisp programmers soon started
using S-expressions as the default notation.

S-expressions can either be single objects or atoms such as numbers, or lists.

There are three example of two dimension array in ada we define it is valid or
not?

Answer:

1. Give silent features of packages in Ada 5

Answer:

• Packages (modules) of related types, objects, and operations can be defined.

• Packages and types can be made generic (parameterized through a template)


to help create reusable components.
2. How many types of statements are used for pattern building in SNOBOL. 2

Answer:

www.saher-it-solutions.com | solved by Saher


There are two type of statements for pattern building. These are Alternation
and

Concatenation.

Alternation

Difference between these


>(intersection L1 L2) ;
>(set-difference L1 L2);
Answer:

>(intersection L1 L2) ; returns the intersection of the two lists

>(set-differenceL1 L2) ; returns the difference of the two lists

4. Write three functions which are used to construct list in lisp

Answer:

Lists can be constructed (created and extended) with the help of three basic
functions. These are cons, list and append.
5. Write two symbols in Lisp which is used for true and false

Answer:

There are two special symbols: T and NIL for logical true and false.

6. Declare an array of float type in ADA which is reference d to days and sunday
is the first reference

Answer:

Type Days is(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);

www.saher-it-solutions.com | solved by Saher


type d is array(Days) ofFloat;

Which language firstly uses recursion? 2

Answer:

Lisp uses recursion for first time.

A:=8
B:=6
if A>B
then A:=5
else;
A=A-3
end if result? 2 marks
Answer:

Output = 5

Case statement in ada program likhna tha exact to yad ni ( inventry type add 1
in total rebbion if inventry is A or B ) 2 or statements theen is trha ki 3

Answer:

caseTODAY is

whenMON .. THU =>

WORK;

whenFRI =>

WORK; PARTY;

whenSAT | SUN =>

REST;

www.saher-it-solutions.com | solved by Saher


end case;

Define according to ada 5 marks


1 encapsulation
2 extensible types

Answer:

Encapsulation
The primary structure used for encapsulation in Ada is called a package. Packages
are used to group data and subprograms. Packages can be hierarchical, allowing a
structured and extensible relationship for data and code. All the standard Ada
libraries are defined within packages.

Extensible Types

Tagged types are usedto define extensible types.

Tagged Type

A tagged type is like a record which can beused to declare objects. Following is an

example of a tagged type:

typePerson is tagged record

Name : String(1..20); Age : Natural; end record;

snobol ma pointor ki jaga kia use hota ha

Answer:

The unary operator ‘$’ is used for indirect reference. Indirect reference is also an
interesting feature of SNOBOL. It is similar to a pointer in concept

How the concept of class was used in ada

Answer:

www.saher-it-solutions.com | solved by Saher


In many object oriented languages the concept of a class is overloaded. It is both
the unit of encapsulation and a type definition. Ada separates these two
concepts. Packages are used for

encapsulation and Tagged types are usedto define extensible types. Just like
classes in C++, the tagged type can be extended by making a new tagged record

based upon the original type as shown below:

typeEmployee is newPerson with record

Employee_Id : Positive;

Salary : Float;

end record;

SNOBOL4 ma imegiate assignment or entire pattern matching...

Answer:

Write Ada language code to display your name.

Answer:

With Ada.IO_txt

Use Ada.IO_txt

Begin

Procedure name is

Put_line(“Saher”);

End name;

2. LISP function to set Height = 5 and width =12 to symbol "a".

www.saher-it-solutions.com | solved by Saher


Answer:

(setf (get ‘a ‘height)5);

(setf (get ‘a ‘Width)12)

3. How Ada is different from C in terms of symbol literals and from C++

Answer:

Unlike C, the same symbolic literal can be used in two enumeration types. For
example:

typeRainbowColors is (Red, Orange, Yellow, Green, Blue, Indigo, Violet);

typeBasicColors is(Red, Green, Blue);

Ada allows a limited overloading of operators. The exception in Ada is that the
assignment operator (:=) cannot be overridden. It can be overridden in case of
inheritance from a special kind of “abstract class”. When you override the
equality operator ( =) you also implicitly overridethe inequality operator (/=).

Which language firstly use recursion? 2


A:=8
B:=6
if A>B
then A:=5
else;
A=A-3
end if result? 2 marks

Answer:

Output = 5

www.saher-it-solutions.com | solved by Saher


case statement in ada program likhna tha exact to yad ni ( inventry type add 1 in
totalrebbion if inventry is A or B ) 2 or statements theen is trha ki 3

Answer: #nature of q is not clear

Case expression is

When choice list =>

Sequence of statements

When Choice list =>

Sequence of statements

End case;

Case TODAY is

When MON .. THU =>

WORK;

When FRI =>

WORK; PARTY;

When SAT | SUN =>

REST;

end case;

Define according to ada 5 marks


1 encapsulation
2 extensible types

Answer:

www.saher-it-solutions.com | solved by Saher


The primary structure used for encapsulation in Ada is called a package. Packages
are used to group data and subprograms. Packages can be hierarchical, allowing a
structured and extensible relationship for data and code. All the standard Ada
libraries are defined within packages.

Tagged Type

Tagged types are used to define extensible types.

A tagged type is like a record which can be used to declare objects. Following is an

example of a tagged type:

type Person is tagged record

Name : String(1..20); Age : Natural; end record;

snobol ma pointor ki jaga kia use hota ha

Answer:

The unary operator ‘$’ is used for indirect reference. Indirect reference is also an
interesting feature of SNOBOL. It is similar to a pointer in concept

How the concept of class was used in ada

Answer:

In many object oriented languages the concept of a class is overloaded. It is both


the unit of encapsulation and a type definition. Ada separates these two
concepts. Packages are used for encapsulation and Tagged types are used to
define extensible types. Just like classes in C++, the tagged type can be extended
by making a new tagged record based upon the original type as shown below:

typeEmployee is newPerson with record

Employee_Id : Positive;

Salary : Float;

www.saher-it-solutions.com | solved by Saher


end record;

SNOBOL4 ma immediate assignment or entire pattern matching...

Answer:

The ‘.’ (dot) operator is used for conditional assignment only when the entire
pattern is matched. The $ is used for immediate value assignment even if the
entire pattern does not match. It is used as follows:

Pattern $ Variable

www.saher-it-solutions.com | solved by Saher

You might also like