0% found this document useful (0 votes)
47 views15 pages

PCPF DSE MOdel Answer Key

The document describes the compilation process with a flowchart. It explains that the source code written in a text editor gets passed to the preprocessor which expands the code. The expanded code then gets passed to the compiler which converts it to assembly code. The assembly code then gets passed to the assembler which converts it to object code. Finally, the linker combines the object code with library functions to create an executable file.

Uploaded by

Nitin Vishe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views15 pages

PCPF DSE MOdel Answer Key

The document describes the compilation process with a flowchart. It explains that the source code written in a text editor gets passed to the preprocessor which expands the code. The expanded code then gets passed to the compiler which converts it to assembly code. The assembly code then gets passed to the assembler which converts it to object code. Finally, the linker combines the object code with library functions to create an executable file.

Uploaded by

Nitin Vishe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

a) Explain the compilation process with flowchart.

Preprocessor
The source code is the code which is written in a text editor and the source code file is given an extension
".c". This source code is first passed to the preprocessor, and then the preprocessor expands this code.
After expanding the code, the expanded code is passed to the compiler.
Compiler
The code which is expanded by the preprocessor is passed to the compiler. The compiler converts this
code into assembly code. Or we can say that the C compiler converts the pre-processed code into
assembly code.
Assembler
The assembly code is converted into object code by using an assembler. The name of the object file
generated by the assembler is the same as the source file. The extension of the object file in DOS is '.obj,'
and in UNIX, the extension is 'o'. If the name of the source file is 'hello.c', then the name of the object file
would be 'hello.obj'.
Linker
Mainly, all the programs written in C use library functions. These library functions are pre-compiled, and
the object code of these library files is stored with '.lib' (or '.a') extension

b) Explain the term Initialization and Finalization.


Choosing a constructor: An object-oriented language may permit a class to have zero, one, or many
distinct constructors. In the latter case, different constructors may have different names, or it may be
necessary to distinguish among them by number and types of arguments.

References and values: If variables are references, then every object must be created explicitly, and it
is easy to ensure that an appropriate constructor is called. If variables are values, then object creation
can happen implicitly as a result ofelaboration. In this latter case, the language must either permit
objects to begin their lifetime uninitialized, or it must provide a way to choose an
appropriateconstructor for every elaborated object.

Execution order: When an object of a derived class is created in C++, the compiler guarantees that the
constructors for any base classes will be executed, outermost first, before the constructor for the derived
class. Moreover, if a classhas members that are themselves objects of some class, then the constructors
for the members will be called before the constructor for the object in which they are contained. These
rules are a source of considerable syntactic and semantic complexity: when combined with multiple
constructors, elaborated objects, and multiple inheritance, they can sometimes induce a complicated
sequence of nested constructor invocations, with overload resolution, before control even enters a given
scope. Other languages have simpler rules.

Garbage collection: Most object-oriented languages provide some sort of constructor mechanism.
Destructors are comparatively rare. Their principal purpose is to facilitate manual storage reclamation
in languages like C++. If the language implementation collects garbage automatically, then the need for
destructors is greatly reduced.

c) Solve the following


?- B is 6, C is B + 2. B=8
Increase(S, T) :- -T is S + 1. ?- increase(4, A). T =5
loop(0).
loop(N) :- N>0, write('value of N is: '), write(N), nl.
S is N-1, loop(S).

d) Explain Client side and Server side scripting with example.

1. Client-side scripting :
Web browsers execute client-side scripting. It is used when browsers have all code.
Source code is used to transfer from webserver to user’s computer over the internet and
run directly on browsers. It is also used for validations and functionality for user events.
It allows for more interactivity. It usually performs several actions without going to the
user. It cannot be basically used to connect to databases on a web server. These scripts
cannot access the file system that resides in the web browser. Pages are altered on basis
of the user’s choice. It can also be used to create “cookies” that store data on the user’s
computer.
2. Server-side scripting :
Web servers are used to execute server-side scripting. They are basically used to create
dynamic pages. It can also access the file system residing at the webserver. A server-side
environment that runs on a scripting language is a web server.
Scripts can be written in any of a number of server-side scripting languages available. It
is used to retrieve and generate content for dynamic pages. It is used to require to
download plugins. In this load times are generally faster than client-side scripting. When
you need to store and retrieve information a database will be used to contain data. It can
use huge resources of the server. It reduces client-side computation overhead. The server
sends pages to the request of the user/client.

Q.2.
a) Define method Binding with its types.
Dynamic Method Binding in java
There are certain key points that are needed to be remembered before adhering forward where
we will be discussing and implementing static and dynamic bindings in Java later concluding
out the differences.
● private, final and static members (methods and variables) use static binding while for
virtual methods (In Java methods are virtual by default) binding is done during run
time based upon the run time object.
● The static binding uses Type information for binding while Dynamic binding uses
Objects to resolve to bind.
● Overloaded methods are resolved (deciding which method to be called when there
are multiple methods with the same name) using static binding while overridden
methods use dynamic binding, i.e, at run time.

Static Binding

The binding which can be resolved at compile time by the compiler is known as static or early
binding. The binding of all the static, private, and final methods is done at compile-time.

b) What isMessage Passing? Explain with Block Diagram.

Message Passing in terms of computers is communication between processes. It is a form of


communication used in object-oriented programming as well as parallel programming. Message passing
in Java is like sending an object i.e. message from one thread to another thread. It is used when threads do
not have shared memory and are unable to share monitors or semaphores or any other shared variables to
communicate. Suppose we consider an example of producer and consumer, likewise what producer will
produce, the consumer will be able to consume that only. We mostly use Queue to implement
communication between threads.
In the example explained below, we will be using vector(queue) to store the messages, 7 at a time and
after that producer will wait for the consumer until the queue is empty.

In Producer there are two synchronized methods putMessage() which will call form run() method of
Producer and add message in Vector whereas getMessage() extracts the message from the queue for the
consumer.

Using message passing simplifies the producer-consumer problem as they don’t have to reference each
other directly but only communicate via a queue.

c)
Explain Prolog list Append and Concatenation with example.
6
d) Differentiate between Imperative Programming and Declarative Programming.

S.NO. COMPILED LANGUAGE INTERPRETED LANGUAGE

1 A compiled language is a An interpreted language is a programming


programming language whose language whose implementations execute
implementations are typically instructions directly and freely, without
compilers and not interpreters. previously compiling a program into
machine-language instructions.
2 In this language, once the While in this language, the instructions are
program is compiled it is not directly executed by the target machine.
expressed in the instructions of
the target machine.

3 There are at least two steps to There is only one step to get from source
get from source code to code to execution.
execution.

4 In this language, compiled While in this language, interpreted programs


programs run faster than can be modified while the program is
interpreted programs. running.

5 In this language, compilation In this languages, all the debugging occurs at


errors prevent the code from run-time.
compiling.

6 The code of compiled language A program written in an interpreted


can be executed directly by the language is not compiled, it is interpreted.
computer’s CPU.

7 This language delivers better This languages delivers relatively slower


performance. performance.

8 Example of compiled language Example of Interpreted language –


– C, C++, C#, CLEO, COBOL, JavaScript, Perl, Python, BASIC, etc
etc.

Q.3.

a) Explain the Scope rule with its types.

File Scope: These variables are usually declared outside of all of the functions and blocks, at the top of
the program and can be accessed from any portion of the program. These are also called the global scope
variables as they can be globally accessed.

Block Scope: A Block is a set of statements enclosed within left and right braces i.e. ‘{‘ and ‘}’
respectively. Blocks may be nested in C(a block may contain other blocks inside it). A variable declared
inside a block is accessible in the block and all inner blocks of that block, but not accessible outside the
block. Basically these are local to the blocks in which the variables are defined and are not accessible
outside.
Function Prototype Scope: These variables range includes within the function parameter list. The scope
of the these variables begins right after the declaration in the function prototype and runs to the end of the
declarations list. These scopes don’t include the function definition, but just the function prototype.

Function Scope: A Function scope begins at the opening of the function and ends with the closing of it.
Function scope is applicable to labels only. A label declared is used as a target to go to the statement and
both goto and label statement must be in the same function.

b) What is Recursion? explain with an example.


There are no “for” or “while” loop in functional languages. Iteration in functional
languages is implemented through recursion. Recursive functions repeatedly call
themselves, until it reaches the base case.
example of the recursive function:
fib(n)
if (n <= 1)
return 1;
else
return fib(n - 1) + fib(n - 2);

c) What is Synchronization? Explain with examples.


Synchronization is built around an internal entity known as the lock or monitor. Every object has a lock
associated with it. By convention, a thread that needs consistent access to an object's fields has to acquire
the object's lock before accessing them, and then release the lock when it's done with them.

//example of java synchronized method

class Table{

synchronized void printTable(int n){//synchronized method

for(int i=1;i<=5;i++){

System.out.println(n*i);

try{

Thread.sleep(400);

}catch(Exception e){System.out.println(e);}

}
}

class MyThread1 extends Thread{

Table t;

MyThread1(Table t){

this.t=t;

public void run(){

t.printTable(5);

class MyThread2 extends Thread{

Table t;

MyThread2(Table t){

this.t=t;

public void run(){

t.printTable(100);

}
public class TestSynchronization2{

public static void main(String args[]){

Table obj = new Table();//only one object

MyThread1 t1=new MyThread1(obj);

MyThread2 t2=new MyThread2(obj);

t1.start();

t2.start();

Output:

10

15

20

25

100

200

300

400

500

d) Explain Polymorphism and Encapsulation with Program


Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism
that binds together code and the data it manipulates. Another way to think about encapsulation
is that it is a protective shield that prevents the data from being accessed by the code outside
this shield.

Q.4.
a) What is Type Systems ? explain with types.
Dynamic Typing:
In Dynamic Typing, type checking is performed at runtime. For example, Python is a
dynamically typed language. It means that the type of a variable is allowed to change
over its lifetime. Other dynamically typed languages are -Perl, Ruby, PHP, Javascript etc

## simple function
def add(a, b):
return a + b

## calling the function with string


print(add('hello', 'world'))

## calling the function with integer


print(add(2, 4))

Static Typing:
Static Typing is opposite to Dynamic Typing. In Static Typing, type checking is
performed during compile time. It means that the type of a variable is known at compile
time. For some languages, the programmer must specify what type each variable is (e.g
C, C++, Java), other languages offer some form of type inference(e.g. Scala, Haskell).
With Static Typing, variables generally are not allowed to change types.
String a;
a = "Java is good";

Classification of Types
b) What is Unification? Explain its rules with examples.

In unification, one or more variables being given value to make the two call terms identical. This
process is called binding the variables to values. For example, Prolog can unify the terms cat(A),
and cat(mary) by binding variable A to atom mary that means we are giving the value mary to
variable A. Prolog can unify person(Kevin, dane) and person(L, S) by binding L and S to atom
kevin and dane, respectively.

The compound term has any kind of argument like variables, list, numbers, atoms, and
compound terms. The following example shows some typical unification:

parent(A, B, C)
parent(kevin, henry, 30)
It will succeed with A, B, and C variables bound to kevin, henry, and 30, respectively.

parent(kevin, B, 25)
parent(A, henry, 30)
The 25 cannot be unified with 30, so it will fail.

c) What are the approaches to implement Inter-process Communication

Approaches of Interprocess Communication


Following are the approaches to implement Inter-process Communication:-

1. Pipes
2. Shared Memory
3. Message Queue
4. Direct Communication
5. Indirect Communication
6. Message Passing
7. FIFO

Pipe

Pipe is a unidirectional data channel in which data can be moved in only one direction at a time. For
standard input and output methods, we can use two such pipes to create two-way channels to send and
receive the data in two processes, i.e, in input and output. These are used in all POSIX(Portable Operating
System Interface) systems and various versions of Windows OS.

Shared Memory

Shared memory is a type of memory that can be used or accessed by multiple processes simultaneously.
This is done for a reason as processes can communicate with each other. That is why almost all POSIX
systems and Windows operating systems use shared memory.

Message Queue
Multiple processes can read-write the data to the message queue even without connecting. Messages are
stored in the queue till their recipient retrieves them back. Message queues are helpful for interprocess
communication and are also used by most operating systems.

Message Passing

It is a mechanism that processes synchronization and communicates with each other. But, using this
mechanism, the processes can communicate without the shared variables being restored.

Generally, the inter-process communication mechanism provides two operations that are as follows:

● send (message)
● received (message)

Direct Communication

Generally, a link is established between two communication processes in this type of communication.
However, only one link can exist in every pair of communicating processes.

Indirect Communication
When processes share a common mailbox then only indirect communication can be established. Here,
each pair of these processes shares multiple links of communication. The nature of these shared links
could be unidirectional or bi-directional.

FIFO

It is general communication between two unrelated processes. It is also considered full-duplex, which
means that one process can communicate with another and vice versa.

d) Differentiate between Scripting and Programming languages.

The key distinctions between scripting and programming are listed in the table below:

Scripting Language Programming Language

It is based on the Interpreter. It is based on the compiler.

It is used for combining existing It is used for developing from scratch.


components.

It runs inside the program and is It is independent of a parent program.


dependent on it.

It functions to convert high-level It works to convert the full program into


instructions into machine language. machine language in one go.

It does not require compiling the file and It requires to compile the file first.
running directly.

It has no file type. It contains .exe file type.


It does not support data types, graphic It has rich support graphic design, data
design, and user interface design, or types, and user interface design.
support limited.

Users can easily write and use it. It can be difficult to use and write.

It needs a host. It does not need a host as it is


self-executable.

It requires low maintenance. It requires high maintenance.

Examples of scripting languages include Examples of programming languages


VB Script, JavaScript, Perl, Ruby, and include COBOL, Java, VB, Basic, C, C++,
PHP. C#, and Pascal.

You might also like