Sunteți pe pagina 1din 5

IV B.

Tech ((Regualr & Back)

FOURTH SEMESTER EXAMINATION-2010


EXAMINATION
PRINCIPLES OF PROGRAM
PROGRAMMING
ING LANGUA
LANGUAGE
[IT 401]
Full Marks: 70 Time: 3 Hours
Answer any SIX questions including Question No.1 which is compulsory. The figures in the margin
indicate full marks. Candidates are required to give their answers in their own words as far as practicable and
all parts of a question should be answered at one place only.

1. a) List four attributes of a good programming language. [2x10]

b) Differenciate between syntax and semantics of a programming language.

c) Find out the output of the following code with proper justification:
#include<iostream.h>
class X
{ public:
int a;
};
class Y: public X
{ public:
int a;
};
void main( )
{
X x,*p;
p=&x;
*p->a=100;
Y y,*q;
q=&y;
(*q).a=200;
X z=y;
cout<<x.a<<y.a<<z.a;
}

d) ”Virtual function involves dynamic binding whereas operator overloading


involves static binding.”Explain with example.

e) What is a constructor? State the sequence of constructor invocation in the


following derivation if the object is created for the derived class ‘ V ‘-
class V :virtual X, public Y, virtual public Z { }

f) Write an operator overloading function to overload the extraction (>>)


operator for performing the operation cin>>a, where a is an object of a
string class comprising an array member.

g) Find out the output of the following code with proper justification:
#include<iostream.h>
int count=0;
class A
{
public:
A( )
{ cout<<”object constructed:”<<++count; }
~A( )
{ cout<<”object destroyed :”<<count--; }
};
void main( )
{

A a1,a2;
{ A a3; }
{ A a4; }

h) List two operators that can not be overloaded and two operators which
can not be overloaded using a friend operator function.

i) Explain through an example how a class type can be converted to a basic


type.

j) Identify the errors in the following piece of code:


#include<iostream.h>
class Floor
{
int length,width;
public:
Floor( )
{ length=width=0; }
Floor(int x=15);
};
Floor :: Floor(int x)
{ length=width=x; }
void main( )
{
Floor ob;
if(ob.length==ob.width)
cout<<”square room”;
}

2. a) What is a programming environment? Explain briefly the effect [6]


of environment on programming language design.
b) What is BNF grammer? Write the BNF grammer for assignment [4]
statement.

3. a) Write a program in C++ to create a class Queue with an integer [6]


array as one of it’s data members. Define member functions
INSERT ( ) and REMOVE ( ) for inserting and deleting elements
from the Queue . When a Queue overflow or underflow occurs,
your program should throw an exception and handle it in a catch
block. Include other members as required and implement the
functions in the main( ).

b) What is data hiding? How can an external function access the [4]
private data members of a class?Illustrate with a suitable example.

4. a)Define a class STRING with the following attributes: [7]


Data members:
i. a dynamic array to represent a string
ii. an integer to store the length of the string
Member functions:
i. dynamic constructor to initialize the members dynamically
ii. show ( ) function to display a string
iii. a function to overload the addition (+) operator to concatenate
two strings
iv. a function to overload the negation(-) operator to reverse
a string
v. a function to overload the equality ( == )operator to compare
two strings.
Execute the program to concatenate two input strings and check whether
the resulting string is a palindrome or not using the different operator
overloading functions.
b) Differenciate between error and exception in C++. Explain the [3]
following concepts with suitable example.
i. Rethrowing exception
ii. Restricting exception

5. a) Create a class EMPLOYEE with data members name, id and [6]


gross_salary of an employee of TCS.
Include member functions:-
i. getdata( ) to input details of an employee
ii. display( ) to display the details of an employee
iii. complute( ) to calculate the salary for an employee
Derive 2 classes from EMPLOYEE: class PERMANENT and class
TEMPORARY
Class PERMANENT includes basic_salary, DA and HRA as it’s data
members
Class TEMPORARY includes no_of_hours_worked and pay_per_hour
as it’s data members.
Both these classes override the compute( ) function to calculate
the Salary for a particular type of employee. Use pointers to test
these Classes.

b) How reusability can be achieved using inheritance? What ambiguity [4]


arises in the case of multipath inheritance?Discuss the technique
that can be used to resolve this ambiguity with small example.

6. a) Discuss the different techniques using which one class type can be [5]
converted into another class type.Illustrate with suitable examples.

b) Differenciate between function overloading and function overriding. [5]


How can run time polymorphism be achieved using pointer to an
Object? Explain using a suitable example. Can we make the pointer
of derived class type to point to a base class object? Justify your
answer.

7. a) What is a stream in C++? Draw the hierarchy of derivation of stream [6]


classes, briefly explaining the functionality of each class . Discuss
briefly the different functions present in the ios class.

b) Write a class template to represent a generic vector with an integer [4]


array as it’s member. Include member functions to perform the
following tasks:
i. To create the vector V
ii. To multiply by a scalar value
iii. To display the vector in the form V ( 10, 20, 30,…….)
Where V is the vector name and 10, 20, 30 ,……. Are the elements of a
Vector.

8. Write short notes on any 4 of the following [2.5x4]


i. Firmware
ii. Abstract class
iii. Virtual computer
iv. Static data member
v. this pointer

XXXXX

S-ar putea să vă placă și