B.E. /B/Tech.
DEGREE EXAMINATION,
NOVEMBER/DECEMBER 2006
Third Semester
Computer Science and Engineering
CS1204 – OBJECT ORIENTED PROGRAMMING
(Common to Information Technology and B.E. (Part – Time) Second Semester
Regulation 2005)
(Regulation 2004)
Time: Three hours Maximum: 100 Marks
Answer ALLquestions
PART A – (10 ´ 2 = 20 marks)
1. Name the mechanism that binds together code and the data it maniputes.
2. What is the application of the scope resolution operator: in C++?
3. What are the two parts of a class specification?
4. What is an operator function? Describe the syntax of an operator function.
5. Why is it necessary to include the file iostream in all our programs?
6. Name the two ways in which a file can be opened.
7. What is default for methods in Java?
8. What is the need for Java virtual machine?
9. What is a package?
10. What is an exception?
PART B – (5 ´ 16 = 80 marks)
11. (a) Explain the following concepts of object oriented programming:
(i) Data abstraction
(ii) Inheritance
(iii) Polymorphism and
(iv) Objects
In detail with an example. (16)
(b) (i) List out any five merits of object oriented methodlogy.
(ii) Compare and contrast the following control structures with
example.
If ….else statement and switch statement and do ….. while and the while
statement.
12. (a) Write a program to overload = operator. Assign values of data members of one
object to another object of the same type.
Or
(b) Write a C++ program using inheritance to implement the following.
A newspaper agent pays two variant rates for the delivery of newspapers. A
delivery boy can earn RS. 2 on a morning delivery but only Rs. 1.50 on an evening
delivery. Boys are salaried either for a morning delivery or for an evening paper round
but not for both. Read(Input) the code for round (0 for morning and 1 for evening) and
the number of total paper rounds in one week done by a boy and compute his earning and
display it.
13. (a) Write a program to write and read data in a file using object I/O functions write
( ) and read ( ). Declare class with data members name [2]
m int bill no, int _amount
debited and int received _ amount and in balance. Add 10 records and display the list of
persons with balances. The user should have a facility to modify the existing records.
(16)
Or
(b) (i) Describe the various file modes and its syntax. (6)
(ii) Discuss the need for exception with try, catch and throw keywords. (10)
14. (a) Write short notes on the following:
Final class, abstract class, modifier final, inner classes.
Or
(b) (i) State the rules for creating an identifier in Java.
(ii) Discuss about the reference variable array and the primitive data types byte,
long, double. (10)
15. (a) Discuss how interface is implemented in Java with an example. (16)
Or
(b) What is a thread? State how synchronization is dealt while using multithreading.
(16)
****
------------------------------------------------------------------------------------------------------------------------
4th Semester (CS 252) DEC 2006
OBJECT ORIENTED PROGRAMMING
Max Marks 60
Max Time 3 Hours
Section A
I (10 * 2=20)
1. What is a manipulator? Why do we need it?
2. What is the advantage of using streams for I/O operations in C++?
3. What is name mangling?
4. What is the difference between by passing argument by value to that of reference?
5. What is the advantage of contiguous memory allocation in arrays?
6. I a and b are tow arrays of the same type, can the statement a=b work?
7. How is structure passed to a function?
8. How is memory allocated to structure variables?
9. What is null pointer?
10. Can we write a[i] as i[a]?
Section B (5 * 4=20)
II Explain the following with examples:
1. setbase
2. setfill().
III What is the difference between actual and formal arguments? Explain the relationship between them.
IV What is an array of characters? Where are they used?
V What is a structure? How can the structure be nested?
Section C (10 * 2=20)
VI What is void* pointer? What is its use?
VII What is operator overloading? Explain binary operator overloading.
VIII What is inheritance? How it is implemented? Distinguish between public and private inheritance.
IX What are virtual functions and pure virtual functions? Where are they used. Explain.
----------------------------------------------------------------------------------------------------------------------
Code: C-11 / T-22 Subject: OBJECT ORIENTED PROGRAMMING
Time: 3 Hours June 2006 Max. Marks: 100
NOTE: There are 9 Questions in all.
· Question 1 is compulsory and carries 20 marks. Answer to Q. 1. must be written in the space provided for it
in the answer book supplied and nowhere else.
· Out of the remaining EIGHT Questions answer any FIVE Questions. Each question carries 16 marks.
· Any required data not explicitly given, may be suitably assumed and stated.
Q.1 Choose the correct or best alternative in the following: (2x10)
a. How many constructors can a class have?
(A) 0 (B) 1
(C) 2 (D) any number
b. The new operator
(A) returns a pointer to the variable
(B) creates a variable called new
(C) obtains memory for a new variable
(D) tells how much memory is available
c. Consider the following statements:
int x = 22,y=15;
x = (x>y) ? (x+y) : (x-y);
What will be the value of x after executing these statements?
(A) 22 (B) 37
(C) 7 (D) Error. Cannot be executed
d. An exception is caused by
(A) a hardware problem (B) a problem in the operating system
(C) a syntax error (D) a run-time error
e. A template class
(A) is designed to be stored in different containers
(B) works with different data types
(C) generates objects which must be identical
(D) generates classes with different numbers of member functions.
f. Which of the following is the valid class declaration header for the derived class d with base classes b1 and b2?
(A) class d : public b1, public b2 (B) class d : class b1, class b2
(C) class d : public b1, b2 (D) class d : b1, b2
g. A library function exit() causes an exit from
(A) the loop in which it occurs (B) the block in which it occurs
(C) the function in which it occurs (D) the program in which it occurs
h. RunTime polymorphism is achieved by ___________
(A) friend function (B) virtual function
(C) operator overloading (D) function overloading
i. The process of building new classes from the existing one is called _________
(A) Polymorphism (B) Structure
(C) Cascading (D) Inheritance
j. An array element is accessed using
(A) a FIFO approach (B) an index number
(C) the operator (D) a member name
Answer any FIVE Questions out of EIGHT Questions.
Each question carries 16 marks.
Q.2 a. Discuss the role of inheritance in object-oriented programming. What is public, private and protected
derivation? (8)
b. Explain the meaning of polymorphism. Describe how polymorphism is accomplished in C++ taking a suitable
example? (8)
Q.3 Define a class Fraction whose objects represent rational numbers (i.e. fractions). Include integer data members
num and den for storing the numerator and denominator respectively.
a. Write the following functions for traction:
(i) parameterised constructors with one and two arguments.
(ii) copy constructors.
(iii) a function, eval-fract() for evaluating the value of the rational number.
(iv) a function, invert() for inverting the given rational number.
b. Overload >> and << operators for reading and printing the fraction object from the keyboard. (2+8+6)
Q.4 a. What do you mean by static variable and static function? Give an example? (5)
b. Write a template function to find the maximum number from a template array of size N. (8)
c. Describe the basic characteristics object-oriented programming. (3)
Q.5 a. What is meant by exceptions? How an exception is handled in C++? Explain with the help of an example. (4)
b. What do you mean by operator overloading? How unary and binary operators are implemented using the member
and friend functions? (8)
c. Explain the importance of using friend function in operator overloading with the help of an example. (4)
Q.6 Define a class Date with three variables for day, month and year.
a. Write the default and parameterised constructors,
b. Overload the operators <<,>> to read and print Date object,
c. Overload > to compare two dates.
d. Write the destructor that sets values to zero for all three variables. Define object of the class in main and call the
above defined functions. (2+2+3+3+4+2)
Q.7 a. Define the class Student which has name (char name[20]) and age(int). Define the default constructor, member
functions get_data() for taking the name and age of the Student, print() for displaying the data of Student. (5)
b. For the above defined class create an array of students of size N and write the friend function sort(Student arr[N])
which sorts the array of Students according to their age. (6)
c. Create a file namely “STUDENT.DAT” for storing the above objects in sorted order. (5)
Q.8 Consider a publishing company that markets both book and audio cassette version to its works. Create a class
Publication that stores the title (a string) and price(type float) of a publication. Derive the following two classes from
the above Publication class: Book which adds a page count (int) and Tape which adds a playing time in minutes(float).
Each class should have get_data() function to get its data from the user at the keyboard.
Write the main() function to test the Book and Tape classes by creating instances of them asking the user to fill in data
with get_data() and then displaying it using put_data(). (16)
Q.9 Write short notes on the following:
(v) Nested class.
(vi) Scope resolution operator.
(vii) this pointer.
(viii) Early binding and Late binding. (4*4=16)
--------------------------------------------------------------------------------------------------------------------------------