B.E. /B/Tech.
DEGREE EXAMINATION, MAY/JUNE 2007
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. What are the main characteristics of OOP language?
2. What are the valid types of data that the main( ) can return in C/C++ language?
3. What are the difference between default and parameterized constructors?
4. List out the properties of a static member function.
5. What are the functions supported by file stream classes for performing I/O
operations?
6. What are the types of exceptions? C++ provides what type of exceptions.
7. Define JVM.
8. What is the major difference between interfaces and classes?
9. ‘define multithreading.
10. What are the two methods by which we may stop threads?
PART B – (5 ´ 16 = 80 marks)
11. (a) (i) Describe the advantages of OOP. (8)
(ii) What are the differences between pointers to constants and constant
pointers? (8)
Or
(b) (i) Describe the applications of OOP technology. (8)
(ii) What is inline function? Explain the situations where jinline
expansion may no work? (8)
12. (a) (i) Explain copy constructor with suitable C++ coding.
(ii) List out the rules for overloading operators. (8)
Or
(b) (i) Explain hybrid inheritance with suitable C++ coding.
(ii) Define polymorphism. Explain the different types of
polymorphism.
13. (a) Write a C++ program to read from 2 files simultaneously.
Or
(b) Explain multiple catch statement with the help of suitable C++ coding.
14. (a) Explain method overriding with suitable Java coding.
Or
(b) (i) Write a Java program for alphabetical ordering of strings.
(ii) Explain the different forms of inheritance supported in Java. (6)
15. (a) Explain various forms of interface implementation. (16)
Or
(b) Write a Java program to throw user defined exceptions.
------------------------------------------------------------------------------------------------------------------------
----
B.E/B.Tech. DEGREE EXAMINATION, NOVEMEBER/DECEMBER 2007.
Fourth Semester
Electrical and Electronics Engineering
CS 1261- OBJECT ORIENTED PROGRAMMING
(Common to Electronics and Instrumentation Engineering/Instrumentation
and control Engineering)
(Regulation 2004)
Time : Three hours Maximum : 100 marks
Answer ALL questions.
PART A- (10 x2 = 20 marks)
1. What is data encapsulation?
2. What are the benefits of OOP language?
3. what is meant by file access specifier?
4. What is dynamic initialisation of objects?
5. Name few operators which can’t be overloaded.
6. What is abstract class?
7. If a = 25 after shifting it two times on its left what would be the value? What is the
extra precaution one has to take care before evaluating this while coding in Java?
8. Define method with reference to Java. How to call it?
9. Give the life cycle of a thread.
10. What is Applet tag?
PART B- (5 X 16 = 80 marks)
11. (a) (i) Code a program in Java to illustrate the use of Interface which calculates the
simple
interest and compound interest. (10)
(ii) How to implement interface? Also explain how interface in Java help to realize the
funct-
Ionality of multiple inheritance. (6)
Or
(b) (i) Discuss on Java Applet (10)
(ii) How to create your own exceptions? Illustrate it with a small program coded in
Java
(6)
12. (a) (i) What is method overloading? Illustrate it with a program to find area of
rectangle and
Square. ( 8)
(ii) Modify the above program such that the concept of passing objects as parameter
to
methods (8)
Or
(b) (i) Write a program in Java Illustrating ladder if else statement to process the
result of
Statement. (8)
if average mark = 65 First Class
? 75 Distinction
? = 50 Second Class
? = 40 Third Class
Otherwise failed.
(ii) Use switch statement to read month and print it out. Code it in Java. (8)
13. (a) (i) List the applications of Object Oriented Programming. (8) (ii) Discuss on
basic concepts of Object Oriented Programming. (8)
(iii) Give general structure of C++ program? (4)
Or
(b) (i) How the manipulators are used to make unformatted input/output operations
one? (8)
(ii) Write short notes on inline functions and default arguments. (4+4)
14. (a) (i) What are the advantages of polymorphism? (3)
(ii) How is function overloading enhance programming art and style? Illustrate with an
example. (7)
(iii) Why is type conversion? How does it help programmers? (6)
Or
(b) (i) What are the various types of Inheritance? Discuss any one with Illustration.
(10)
(ii) Discuss the rules of operator overloading. (6)
15. (a) (i) How can you design a class? How to access data members? How is the
message commu-
nication done to access data members of other classes? (8)
(ii) Explain with example how can you use a common friend function to exchange the
private
Values of 2 classes (8)
Or
b) (i) How to invoke a constructor? Passing arguments could be done with
parameterized
constructor. Illustrate it. How to overload constructor? (10)
(ii) Describe the importance of destructors. (6)
---------------------------------------------------------------------------------------------------------------------
Code: AC11 / AT22 Subject: OBJECT ORIENTED PROGRAMMING
Time: 3
Hours
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. What will be the output of following program?
#include<iostream.h>
void main()
{
float x;
x=(float)9/2;
cout<<x;
}
(A) 4.5 (B) 4.0
(C) 4 (D)
5
b. A white space is :
(A) blank space (B) new line
(C) tab (D) all of the
above
c. The following can be declared as friend in a class
(A) an object (B) a class
(C) a public data member (D) a private data member
d. What would be the output of the following?
#include<iostream.h>
void main()
{
char *ptr=“abcd”
char ch;
ch = ++*ptr++;
cout<<ch;
}
(A) a (B) b
(C) c (D) d
e. A copy constructor takes
(A) no argument (B) one argument
(C) two arguments (D) arbitrary no. of arguments
f. Overloading a postfix increment operator by means of a member function
takes
(A) no argument (B) one argument
(C) two arguments (D) three arguments
g. Which of the following ways are legal to access a class data member
using this pointer?
(A) this.x (B) *this.x
(C) *(this.x) (D) (*this).x
h. If we store the address of a derived class object into a variable whose
type is a pointer to the base class, then the object, when accessed using this
pointer.
(A) continues to act like a derived class object.
(B) Continues to act like a derived class object if virtual functions are
called.
(C) Acts like a base class object.
(D) Acts like a base class, if virtual functions are called.
i. Which of the following declarations are illegal?
(A) void *ptr; (B) char *str = “hello”;
(C) char str = “hello”; (D) const *int p1;
j. What will be the result of the expression 13 & 25?
(A) 38 (B) 25
(C) 9 (D) 12
Answer any FIVE Questions out of EIGHT Questions.
Each question carries 16 marks.
Q.2 a. What are the shortcomings of procedure oriented
approach? (8)
b. What is the output of following
programs: (8)
(i) #include<iostream.h>
int global = 10;
void func(int & x, int y)
{
x = x – y;
y = x * 10;
cout<<x<<“\t”<< y<< “\n”;
}
void main()
{
int global = 7;
func(::global, global);
cout<<global<<“\t”<<::global<<“\n”;
func(global,::global);
cout<<global<<“\t”<<::global<<“\n”;
}
(ii) #include<iostream.h>
void main( )
{
int i, j, m;
int a[5]={8, 10, 1, 14, 16}
i = ++a[2];
m = a[i++];
cout <<i<<m;
}
Q.3 a. Illustrate the concept of function overloading with the help of an
example. Also explain how is matching done in case of overloaded
function? (6)
b. Define a class Coord having two members type int as x and y. Use this
class to define another class Rectangle which has two members of type
Coord as UpperLeftCoord and BottomRightCoord. Define the constructors
and member functions to get the length and breadth of rectangle. Write a
global function which creates an instance of the class Rectangle and
computes the area using the member functions. (10)
Q.4 a. Why is destructor function required in class? What are the special
characteristics of destructors? Can a destructor accept
arguments? (8)
b. What is meant by a constant member function? How is it declared?
Give an example. (8)
Q.5 a. Write a program to convert the polar co-ordinates into rectangular
coordinates. (hint: polar co-ordinates(radius, angle) and rectangular co-
ordinates(x,y) where x = r*cos(angle) and y = r*sin(angle)).
(8)
b. What is a function template? Write a function template to find a
maximum value from an array.
(8)
Q.6 a. What are the basic differences between manipulators and ios member
functions in Implementation? Give examples.
(8)
b. Write a program that shows the use of read() and write() to handle file
I/O involving objects. (8)
Q.7 Explain the following:
(i) Non public constructors
(ii) Inline function
(iii) Virtual functions
(iv) Types of Inheritance.
(4x4=16)
Q.8 a. Write a program to overload the unary minus operator using friend
function. (8)
b. When do we use multi catch handlers? Explain with an
example. (8)
Q.9 a. When does ambiguity arise in multiple inheritance? How can one
resolve it? Develop a program in C++ to create a derived class having
following items: name, age, rollno, marks, empcode and designation.
Design a base class student having data members as rollno, marks
and the another base class is employee having data members as
empcode and designation. These both base classes are inherited from a
single base class person with data members name and age. The program
should carry out the required input( ) and output( ) member functions for
all. (12)
b. Class Y has been derived from class X. The class Y does not contain
any data members of its own. Does the class Y require constructor. If yes,
why? (4)
------------------------------------------------------------------------------------------------------------------------
-----
MCA (Semester-2nd) June 2007
OBJECT ORIENTED PROGRAMMING USING C++ (MCA-202)
Time : 03 Hours
Maximum Marks : 60
Section – A
(1 * 9 = 9)
Q1)
(a) Explain briefly characteristics of OOPS language and mention advantages of OOPS
approach over functional programming.
(b) Explain the following terms with suitable C++ examples.
(1) Type conversion; High level compiler rule for conversion.
(2) Conditional operator
(3) Make table group of operators in increasing order of precedence.
!, ++, --, -, *, /, %, +, -, <, >, <=, >=, ==, !=, ss, +=, -=, *=, /=, %=
Q2) Create equivalent four function calculator. The program requests the user to
enter two integers. It carries out arithmetic addition of two numbers, multiples the
result with the second number, divided the new result with the first original number
and display the final result. The final result is acted upon by trigonometrical sine
function. The calculations so stated above is
carried for subsequent sets of fresh integers.
Section - B
(1 * 9 = 9)
Q3)
(a) Give the tabular difference between structures, unions and classes.
(b) Give the tabular summary of lifetime, visibilty, intialized value, stoarage and
purpose of automatic, external, automatic static variables.
Q4) Write a program to swap the two arrays of members by pointers, by reference
and by value. Compare the three ways.
Section - C
(1 * 9 = 9)
Q5)
(a) Discuss the memory management function: MALLOC, CALLOC with suitable
examples.
(b) Explain Inline member fuction and its benefits over simple function and C's macro
Q6) A survey was made to count number of 4 wheelers and 2 wheelers passing a
kilometer distance in a busy road Delhi. the survey team needs to maintain the total
count of both types of vehicles in an hour. Model this survey with class called
'SURVEY'. The data items are a type 'unsigned int' to hold the count of both kinds of
vehicles. A constructor initializes both these to zero. A member function called 4
wheel ( ) increments the count and similarity a member function called 2 wheel ( )
increments the count respectively. A member function called display ( ) the two final
total. Include prog. to test this class. The prog. should allow user to push one key to
count 4 wheelers and another for 2 wheelers. Pressing ESC to display the counts and
exit.
Section - D
(1 * 9 = 9)
Q7)
(a) Explain single operator overloading with most suitable program.
(b) Explain the concept of Abstract Classes, virtual base classes and friend functions.
Q8) Write a program to read data from xyz.dat file and write it into abc.dat file.
Section - E
(12 * 2 = 24)
Q9)
(a) A 'go to statement causes control to go to _________
(b) A function argument is a way that function resist accepting the calling
programme's value (T/F).
(c) A data item that is a part of a class is called an __________ variable.
(d) Using pointer notation write some code that will transfer 80 characters from string
s1 to string s2.
(e) Write a declaration for an overload assignment operator in class 'zeta'.
(f) A copy constructor is invoked when a function returns by reference (T/F).
(g) The statement f1.write (char*) & obj 1, size of (obj 1)); does ________
(h) Process.h is used for:
(i) N pointer to 'void' can hold pointers to _________
(j) A constructor is executed automatically when an object is __________
(k) Write a statement that will read the contents of one 'ifstream' object called 'if file'
into an array called 'buff'.
(l) A child is said to be __________ from a base class.
------------------------------------------------------------------------------------------------------------------------
---------
B.E. DEGREE EXAMINATION.
Fourth Semester 2007
Computer Science and Engineering
CS 237 — OBJECT ORIENTED PROGRAMMING
Time : Three hours Maximum : 100 marks
Answer ALL questions.
PART A — (10 ´ 2 = 20 marks)
1. How are data and functions organised in an object oriented programming?
2. Compare function overloading and default arguments.
3. What are the uses of references in functions?
4. What is dynamic binding?
5. Compare private and public access specifiers in a class.
6. Distinguish between overloaded functions and function templates.
7. What is this pointer? How is it available to member functions of a class?
8. Can the parameter of a copy constructor be passed by value? Justify your answer.
9. Compare constructor conversion and operator conversion.
10. What is the difference between system . out . print and system . out . println in
Java?
PART B — (5 ´ 16 = 80 marks)
11. Explain in detail the following principles of object oriented programming
(i) Data encapsulation and data hiding
(ii) Inheritance and polymorphism
(iii) Generic programming.
12. (a) Create a class complex to represent complex number with overloaded addition
and multiplication operators. Use them in a main program.
Or
(b) Define a class string with appropriate constructors, destructor and overloaded +,
=, and = = operators use them in a main driver program.
13. (a) What are the different forms of inheritance? Give example for them.
Or
(b) Create an abstract base class shape with two members base and height, a
member function for initialization and a pure virtual function to compute area ( ).
Derive two specific classes Triangle and Rectangle which override the function area
( ). Use these classes in a main function and display the area of a triangle and a
rectangle.
14. (a) Write a C++ program containing a possible exception. Use a try block to throw
it and a catch block to handle it properly.
Or
(b) Create a data class using Java with the following capabilities.
Out the date in multiple format such as
(i) dd – mm – yy
(ii) June 14, 2002.
15. (a) Write a Java class point to represent a two dimensional point (x, y). Extend it
to a class circle with its centre as the point and an additional radius member and
extend further to a class cylinder with additional height member.
Or
(b) Explain the concept of nested classes in Java with a suitable example.
-----------------------------------------------------------------------------------------------
ADIT / BVM / GCET
Semester 2, A.Y. 2007-2008
Internal Test
CP312– Object oriented programming
Date: 10/03/2008 Time: 12.00noon – 1.00pm Max. Marks: 20
Q.1 Answer the following questions.
1.) “Constructor can be defined as private member function.”
Is above statement True or False? Justify. [01]
2.) Which types of functions call are allowed for given prototype declaration?
int sum(int a, int b=1, int c = 0); [01]
3.) Explain Inline function with example.
Or
Explain this pointer with example. [02]
4.) Explain new and delete.
Or
What kind of ambiguities may arise in function overloading ? Explain any two. [02]
Q.2 Show the output of the following programs. If there are errors, indicate them,
correct them and then show the output. Assume required header files are included.
[04]
1.) class A
{ public:
A( ) { cout<<”Constructor \n”;}
A(A &o){cout<<”Copy constructor\n”;}
~A( ) {cout<<”Destructor\ n”;}
A fun(A a) {cout<<”Inside Function”; return(*this);}
};
void main()
{ A o1,o2;
A o3 = o2;
A o4 = o3.fun(o1);
o3 = o4;
}
2.) class B
{ int i;
public:
B(int n) { this.i = n; }
B(int k = 0) {i = k;}
void display() { cout<<I
};
void main()
{
B ob(10);
ob.display();
}
Q.3
1.) Declare a class String. It must have constructor, which allow definition of objects in
the following form. (The class String has data member str of type char *.)
String name1;
String name2 ( “Hello”);
String name3 = name2;
Write a program to overload + operator to concatenate two strings.
[05]
2.) Declare two classes called IT & CP having idno and CPI as private data members.
Overload > operator using friend function to compare CPI of two student of different
branch.
[05]
-----------------------------------------------------------------------------------------------------------------------
APRIL 2007 CAM
Time:Three hours Maximum marks:100 marks
PART A- (5 * 8 = 40marks)
Answer any FIVE questions.
All questions carry equal marks.
1. Mention the principles of object oriented programming.
2. List the benefits of object oriented programming.
3. Define tokens. What are the keywords used in C++?
4. How to pass the parameters in functions?
5. Define constructors and destructors.
6. What is meant by function overloading?
7. Explain the concept of virtual functions.
8. Discuss on file streams.
PART B-( 3 * 20 = 60 marks)
9. Discuss the applications of object oriented programming.
10. Explain the usage of inline functional and friend functions.
11. Write a program in C++ to implement the concept of
function overloading.
12. With examples discuss on the different types of
inheritances.
13. How error handling is done during file operations ?
------------------------------------------------------------------------------------------------------------------------
-
BVM/GCET/ADIT
SECOND INTERNAL TEST
CP312 – OBJECT ORIENTED PROGRAMMING
Date: 03 / 04 / 2007 Time: 12:00 P.M. to 1:00 P.M. Max Marks: 15
Note: Make suitable assumptions as and when required.
Q-1 (A)
Explain the following terms. (Any three with example) [3]
Abstract Class:- when a class contain at least one pure virtual function is known as
abstract class. Means at least one function with no body. Protected:-whenever you
want to keep a member of a base class private but still allow a derived class access to
it we require to declare it as protected
seekg():- movesthe associated file’s current get pointer offcet number of bytes from
the specified origin.
For this we have three position:
Ios:beg : seek from beginning.
Ios:cur : seek from current location.
Ios:end : seek from end. tellp() :- to find out current position of each file pointer.
Syntax:
Pos_type tellp();
(B) What is Compile time and run time polymorphism? Give the difference between
this two terms.
Ans:- which function we have to resolve first is decided at the time of compilation is
compile time polymorphism.
which function we have to resolve first is decided at the run time is run time
polymorphism.
Difference:-
Compile time : support operator overloadind, friend function nonvirtual function, early
binding, efficient,lack of flexibility, more memory allocation .
run time : support virtual, pure virtual function, late binding, not efficient, slower,
flexible, less memory allocation. [2]
(C) Can the assignment operator be overloaded by using a friend function? Give its
significance.
Ans:-
the assignment operator can be overloaded by using only member operator function
because friend function does not have a this pointer so have to pass both operand
explicitly. [1]
OR
(C) Why constructor cannot be a virtual but destructor can?
Ans:-
For virtual function 2 condition is there first is no. of argument must be same and
second is function must be of base class, but for constructor no of argument must be
different thus constructor can not be a virtual and for destructor there is no argument,
no return type so it can be virtual. [1]
Q-2 (A) Declare a class called Manager having data members name and salary. It has
two virtual functions set_data and display_data as function members. Derive two
classes called finance and system from the base class Manager. Override set_data
and display_data to initialize and display data respectively.
Define function main to show use of run time polymorphism.
#include
#include
#include
#include
class manager
{
char name[20];
int salary;
public:
virtual void set_data(char *s,int sal)
{
strcpy(name,s);
salary=sal;
}
virtual void display()
{
cout<<NAME;
cout<<SALARY;
}
};
class finance:public manager
{
public:
char nm[30];
int sal1;
public:
void set_data(char *s,int sal)
{
strcpy(nm,s);
sal1=sal;
}
void display()
{
cout<<SAL1;
cout<<NM;
}
};
class system:public manager
{
char nm1[30];
int sal2;
public:
void set_data(char *s,int sal)
{
strcpy(nm1,s);
sal2=sal;
}
void display()
{
cout<<SAL2;
cout<<NM1;
}
};
int main()
{
int s;
manager *m;
finance f1;
system s1;
manager m1;
cout<<"enter choice 1.finance << 2.system";
cin>>s;
if(s==1)
m=&f1;
else if(s==2)
m=&s1;
else
m=&m1;
m->set_data("aaa",10000);
m->display();
getch();
}
[4]
(B) Find out the output of the following.
#include
void function(int x)
{
cout << x;
}
void main()
{
float a = 20.0
int b = 20;
cout.setf(ios::left);
cout.width(5);
cout.fill(‘$’);
cout<<B<<ENDL;
cout<<B*B<<ENDL;
cout.setf(ios::hex | ios::uppercase);
cout.setf(ios::showbase | ios::showpos);
cout<<A<<ENDL;
function(b);
}
o/p= 20$$$
400
+20
0X14
[2]
(C) Write a program to make your own copy command, which display and write the
reverse case of all letters in destination file.
#include
#include
Int main(int argc, char *argv[])
{
Char ch;
If(argc!=3)
Cout<<”wrong no of argument”;
Return 1;
Ifstream in(argv[1]);
Ofstream out(argv[2]);
While(!in.eof())
{
Ch= in.get();
If(!in.eof())
{
If(islower(ch))
Ch= toupper(ch);
Else
Ch= tolower(ch);
Out.put(ch);
}
}
In.close();
Out.close();
Return 0;
}
[3]
------------------------------------------------------------------------------------------------------------------------
----------