[go: up one dir, main page]

0% found this document useful (0 votes)
93 views16 pages

Practice Ques

Uploaded by

kavya.jagtap04
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)
93 views16 pages

Practice Ques

Uploaded by

kavya.jagtap04
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/ 16

QUESTION BANK

OBJECT ORIENTED PROGRAMMING

MODULE I
CLASS and OBJECTS

1 What is meant by paradigm? What are various programming


paradigms you are familiar with?

2 What is meant by polymorphism?

3 Explain encapsulation with the help of suitable examples.

4 Explain different access specifiers used in C++.

5 What is data hiding? What are the different mechanisms to


protect the data from the external users of class objects?

6 What are the advantages of OOP features?

7 How does C++ support polymorphism?

8 What is object-oriented programming? How is it different from


procedure-oriented programming?

9 Distinguish between the following terms:


(a) Objects and classes
(b) Data abstraction and data encapsulation
(c) Inheritance and polymorphism
(d) Dynamic binding and message passing

10 What is a reference variable? What is its major use?

11 What is the application of the scope resolution operator :: in C++?

12 What do you mean by overloading of a function? When do we use


this concept? Explain it with suitable examples.
13 Explain function overloading in C++.

14 Explain default argument functions in C++ using a suitable


example.

15 What is meant by inline functions?

16 Explain call by reference in functions.

17 Explain the following terms with respect to OOPS .Give suitable


examples
(i) Dynamic Binding
(ii) Message Passing
(iii) Reusability
(iv) Polymorphism
(v) Dynamic Allocation
(vi) Enumerated data type

18 Write a C++ program using an inline function.

19 Write a C++ program to illustrate the static function

20 State the use of static data members of a class.

21 Explain static member function and nonstatic member function


using examples.

22 Explain Nested classes and local classes with an example

23 Give the concept of array of objects and pointer to objects with


an example.

24 Explain about call by reference and return by reference with the


program.

25 Explain the basic concepts of Object oriented programming

26 Explain syntax of any two String functions.


27 Explain with suitable example, syntax of for loop in C++.

28 Differentiate between do..while and while loops on the basis of


syntax.

29 State any one use of this pointer with a suitable example.

30 State the use of scope resolution operator and its use in C++.

31 State use of a new operator.

32 Explain use of the friend function with the help of a suitable


example.

33 Explain the properties of the constructor function.

34 Explain different types of constructors using suitable examples.

35 In which order constructors and destructors are executed?


Explain with examples.

36 Describe various places at which member functions can be


defined using a suitable example.

37 What are empty classes? Can an instance of empty class be


created? Give reasons.

38 Write a C++ program that displays the first 10 odd numbers.

39 Write a C++ program to swap two numbers by call by value and


call by reference.

40

41 Fix the compilation errors and find the output of following


program #include<iostream>
using namespace std;
class Test
{
Private:
int x;
public:
Test(int x = 0) { this->x = x; }
void change(Test *t)
{ this = t; }
void print() { cout << "x = " << x << endl; }
};
int main() {
Test obj(5);
Test *ptr = new Test (10);
obj.change(ptr);
obj.print();
return 0;
}

42 Correct the syntactical and logical errors in the following and


explain program:
#include<iostream>
using namespace std;
class test {
Private:
int m;
Public:
void getdata() {
cout<<” Enter No:” ;
cin>> m;
}
void display()
{ cout<<m;
} };
int main()
{ test T;
T->getdata();
T->display();
test *p;
p=new test;
p.getdata();
(*p).display();
return 0; }

43 Define a class named ‘ Bank Account’ to represent following


members: Data members :-
- Account Number
- Name of Depositor
- Account Type
- Balance Amount
Member functions:
- Initialize members
- Deposit Amount
- Withdraw Amount
- Display Balance
Write a C++ program to test the Bank Account class for 10
customers.

44 Write a C++ program to implement friend class.

45 Define a class that represents Fruit with properties fruit name,


fruit type, fruit color. Write a program that accepts data of four
fruits and displays the results.

46 Write a C++ program to display the number of objects created


using static data member and static member function.
47 Write a C++ program that displays a decimal number in reverse
order.

48 Write a C++ program to calculate the sum of distance and display


the results using the friend function.

49 Write a C++ program to calculate the root of quadratic equations


by initializing the object using the default constructor.

50 Define a class named ‘ Train’ representing following members:


Data members :-
- Train Number
- Train N
- Source
- Destination
- JourneyDate
- Capacity
Member functions
- Initialize
- Input Train Data
- Display Data
Write a C++ program to test the Train Class

51 Write a C++ program that replaces the string “ Computer” in the


String “ Diploma in Computer Engineering” with string
“ Information Technology” .

52 Write a C++ program to swap two numbers using pointer

53 Write a C++ program to get and display employee details using


class and object.

54 Write a syntax of a user defined manipulator and explain it with an


example.

55 What is a copy constructor? Explain copy constructor with


example.

56 How reference variables are created.


int &n=10;
Check whether the above statement is correct or not. Give a
proper reason.

57 What is a void pointer? Write a program to demonstrate void


pointer.

58 Explain different memory management operators in c++ with


example.

59 Difference between object oriented programming and procedure


oriented programming.

60 Define function overloading.Write c++ program to define three


overloaded functions to swap to integer,swap two floats and
swap two doubles.

MODULE II
OPERATOR OVERLOADING

1 State any four points to differentiate between function


overloading and function overriding.

2 State rules of operator overloading.list the operators that can not


be overloaded and justify why they can not be overloaded?

3 What is operator overloading?

4 Justify with a suitable example when a friend function is


compulsory?

5 Why is it necessary to overload operators?

6 List the operators that can be overloaded and one that cannot be
overloaded . Give reasons why some operators cannot be
overloaded.

7 Why do we pass only one argument while overloading binary


operators? Explain with a suitable example.

8 A friend function can not be used to overload the “ =” operator.


Explain Why?

9 Write a note on overloading a new operator and delete operator.

10 What are the benefits of the operator function that performs


object conversion?

11 How will you perform a conversion from basic to user-defined


type and vice-versa ?

12 Write a C++ program to overload a unary operator.

13 Write a C++ program to overload a binary operator.

14 Write a C++ program to overload the area() function to calculate


the area of shapes like triangle ,square, circle.

15. Write a C++ program to add to complex numbers using + operator


overloading and also use this pointer.

16 If c1 and c2 are two objects of class complex then will the


statement c2=5, 0+c1; work by overloading operator + which is a
member function of class complex ?

17 How can you distinguish between a prefix and postfix increment


operator while overloading ?

18 How will data conversion be performed,


if the source object’ s class contains the conversion function.
If the destination object’ s class contains the conversions
function.
19 If objX and objY are two objects of different classes X and Y
respectively then how this statement ,
objX=objY, works ?

20 Create a class time and overland the increment (++) operator that
operates in both prefix and postfix notation and display the
calculated time.

21 Create a class point having data members x and y which


represents coordinates of a point. Using a friend function
overload the +=, ==, != operators on the objects of point class.

22 Create a class weight having data members kg and gram.


Overload all the arithmetic operators on the objects of weight
class

23 Define two classes Fahrenheit and Celsius to represent


temperature in Fahrenheit and Celsius respectively. Use a
conversion function to convert from one system to the other.

24 Define two classes Degree and Radians to represent angle in


degree and radians respectively. Use a conversion function to
convert from one system to the other.

25 Write a C++ program to overload assignment = operator.

26. Write a c++ program to perform addition of two complex numbers


using operator overloading.

27. What is type conversion? Write a program to convert Hours to


minute using type conversion.

28.

MODULE III
INHERITANCE
1 What is the difference between public and private inheritance?

2 What is the size of the object of the derived class?

3 Explain private inheritance using an example.

4 How are the constructors executed in multiple inheritance?

5 How are the constructors executed in multilevel inheritance?

6 How are the arguments passed to the base class constructor in


multiple inheritance?

7 Explain the calling sequence of destructors in inheritance.

8 What is object composition and delegation? How is it different


from inheritance?

9 What are the advantages and disadvantages of inheritance?

10 Explain the concept of abstract class.

11 Explain the concept of virtual base class.

12 What are pure virtual functions? How do they differ from normal
virtual functions?

13 What are the rules that need to be kept in mind while deciding
virtual functions?

14 What is a virtual destructor? What is its use? Explain with a


suitable example.

15 Give reason for assigning a protected visibility specifier to a class


member.

16 Write the differences between compile time and run time


polymorphism.

17 State any two forms of inheritance.Give an example of each.


18 Can base class access the members of derived class? Give
reasons.

19 What will happen when a derived class object invokes a function


which is in base class also?

20 What is generic programming? Explain its features.

What is meant by dynamic or late binding? How is it implemented


in C++? Distinguish between late binding and early binding.

21 State the reason for making a class virtual with the help of
example

22 Write a C++ program for bubble sort using function template

23 Explain how the compiler handles calls to function templates?

24 Can we specify non-type parameters in the function template ? If


yes, how?

25 Demonstrate hybrid inheritance with the help of suitable example.

26

An educational institution wishes to maintain data of its


employees.Define all the classes to represent the above hierarchy
and write a C++ program to retrieve individual information.

27

Define classes to appropriately represent class hierarchy as


shown in above figure. Use constructors for both classes and
display Salary for a particular employee.

28 Write a C++ program using function template for finding the


minimum value contained in an array.

29 Explain how dynamic binding is achieved by the C++ compilers?


What is the size of the following classes?
30 Analyze following code and write the output:
#include<iostream>
using namespace std;
class Cat
{
public:
Void show() { cout<<” \n this is class cat” <<endl; }
};
class Fish
{
public:
Void show() { cout<<” \n this is class fish” <<endl; }
};
class CatFish: public Cat, public Fish
{
};
int main()
{
CatFish obj;
obj.show();
return 0;
}

31 How constructor are invoked in Base and Derived classes in


multiple inheritance.

32 What is the ambiguity in derived classes for multipath inheritance.


How it can be resolved using virtual base class.

MODULE IV
EXCEPTION HANDLING, FILE and I/O

1 Explain working of insertion and extraction operators in C++ with


the help of suitable examples.
2 Draw hierarchy of stream classes for file operations.

3 Explain in detail about I/O streams.

4 How does C++ provide support for its I/O handling.

5 Explain about exception handling in C++.

6 Discuss various exception handling options?

7 List down the keywords used in exception handling and their


usage.

8 List and explain use of any four file mode parameters

9 Define File pointer.

10 Give syntax of and explain various functions related to ifstream


and ofstream classes: seekp(), getline(),hide(),tail() .

11 Describe different methods of opening a file. WAP in C++ to open


a file named” BIO.txt” and write your name and other details
into that file.

12 What is the difference between the statement cin>> ch; and ch=
cin.get(); ?

13 Illustrate the difference between cin and getline() while reading


the strings with a suitable example. Also write a C++ program for
the same.

14 What are manipulators? List the various predefined manipulators


supported by C++ I/O streams.

15 What are custom manipulators? Write a custom manipulator for


inserting 8 spaces in output.

16 List and Discuss the rules for handling exceptions successfully.


17 What are the issues that need to be considered while designing
fault-tolerant software?

18 What are the different fault-tolerant design techniques available?


Explain the recovery block programming technique with a suitable
example.

19 What happens when a raised exception is not caught by any of


the catch blocks?

WAP to demonstrate the catching of all exceptions in C++.

20 What are exceptions? What are the differences between


synchronous and asynchronous exceptions?

21 Write a C++ program to compute the square root of a number.


The input value must be tested for validity. If it is negative, the
user-defined function my_sqrt() should raise an exception.

22 Write a C++ program to create data file containing list of name


and telephone numbers such as,
AAA 1234567899
BBB 1111111111

23 Write a C++ program to copy content of file ABC.txt to XYZ.txt.

24 Write a C++ program to copy content of file ABC.txt to XYZ.txt by


removing unnecessary spaces between words.

25 Write a C++ program to count the number of occurrences of a


character in a text file.

26 Write a C++ program using try block to detect and throw an


exception if the condition “ divide by zero” occurs.

27 Write a C++ program to handle exceptions with multiple catch.

28 Create a class template for stack operations and write the C++
program.

29 Develop a stack program in C++ using class template, overloaded


constructors, member functions (push, pop), friend function
(display stack content).

30 Write a C++ program to create a new file to store and retrieve the
student marks details using file I/O classes.

31 Write a C++ program to illustrate user defined manipulator.

32 How to open file with constructor,explain with example.

33 Explain try, catch and throw with an example.

http://www.vidyarthiplus.in/2011/11/anna-university-object-oriented_16.html
https://techhyme.com/exception-handling-questions/

You might also like