Sie sind auf Seite 1von 26

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

141303-OBJECT ORIENTED PROGRAMMING

Unit - 1 1. State the characteristics of Procedure Oriented Programming. Emphasis is on doing things(Algorithms) Large programs are divided into smaller programs known as functions Most of the function share global data Data move openly around the system from function to function Functions transform data from one form to another Employs top-down approach in program design. 2. What are the features of Object Oriented Programming? Programs are divided into objects Emphasis is on data rather than procedure Data Structures are designed such that they characterize the objects Functions that operate on the data of an object are tied together Data is hidden and cannot be accessed by external functions Objects may communicate with each other through functions New data and functions can easily be added whenever necessary Follows bottom-up approach. 3. Distinguish between procedure oriented programming and object oriented programming. Emphasis is on doing things(Algorithms) Large programs are divided into smaller programs known as functions Function share global data Data move openly around the system from function to function Employs top-down approach in program design. Emphasis is on data rather than procedure Programs are divided into objects Functions that operate on the data of an object are tied together Data is hidden and cannot be accessed by external functions Follows bottom-up approach 4. Define Object Oriented Programming(OOP). Object Oriented programming is an approach that provides a way of modularizing programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand. 5. List out the basic concepts of Object Oriented Programming. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism Dynamic Binding Message Passing

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

6. Define Objects Objects are the basic run-time entities in an object oriented system. They are instance of class. They may represent a person, a place ,a bank account etc that a program has to handle. They may also represent user-define data. 7. Define Class. Class is a collection of objects of similar data types. Class is a user-defined data type. The entire set of data and code of an object can be made a user define type through a class. 8. Define Encapsulation and Data Hiding. The wrapping up of data and functions into a single unit is known as data encapsulation. Here the data is not accessible to the outside world. The insulation of data from direct access by the program is called data hiding or information hiding. 9. Define Abstraction. Abstraction refers to the act of representing the essential features without including the backgrounf details or explanations. 10. Define data members and member function. The attributes in the objects are known as data members because they hold the information. The functions that operate on these data are known as methods or member functions. 11. State Inheritance. Inheritance is the process by which objects of one class acquire the properties of objects of another class. It supports the concept of hierarchiacal classification and provides the idea of reusability. The class which is inherited is known as base or super class and class with is newly derived is known as the derived or sub class. 12. State Polymorphism. Polymorphism is an important concept of OOPs. Polymorphism means one name, multiple forms. It is the ability of a function or operator to take more than one form at different instances. 13. List and define the two types of Polymorphism. Operator Overloading the process of making an operator to exhibit different behaviors at different instances. Function Overloading Using a single function name to perform different types of tasks. The same function name can be used to handle different number and different types of arguments. 14. State dynamic Binding. Binding refers to the linking of procedure call to the code to be executed in response to the call. Dynamic Binding or late binding means that the code associated with a given procedure call is known only at the run-time 15. Define Message Passing.
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

Objects communicate between each other by sending and receiving information known as messages. A message to an object is a request for execution of a procedure. Message passing involves specifying the name of the object the name of the function and the information to be sent. 16. List out some of the benefits of OOP. Eliminate redundant code Saves development time and leads to higher productivity Helps to build secure programs Easy to partition work Small programs can be easily upgraded to large programs Software complexity can easily be managed. 17. List out the applications of OOP. Real time systems Simulation and modeling Object oriented databases Hypertext, hypermedia and expertext AI and expert systems Neural networks and parallel programming. 18. Define C++ C++ is an object oriented programming language developed by Bjarne Stroustrup. It is a super set of C. Initially it was known as C with Classes. It is a versatile language for handling large programs. 19. What are the input and output operators used in C++? The identifier cin is used for input operation. The input operator used is >>, which is known as the extraction or get from operator The Syntax is cin>>n1. The identifier cout is used for output operation. The operator used is <<, which is known as the insertion or put to operator The Syntax is cout<<Welcome. 20. List out the four basic sections in a typical C++ program or Structure of C++ Program. Include files. Class declaration Member function definition. Main function Program. 21. What is meant by Default Argument C++ allows us to assign degault values to the function parameters when the function is declared. In such a case we can call a function without specifying all its arguments. The defaults are always added from right to left. Eg. Val=amount(900,5); // Function Call

Float amount(float pncl, int period ,float rate=0.15) //Function Definition 22. Define Function Overloading.

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

C++ allows function overloading. That is, we can have more than one function with the same name in our program. The compiler matches the function call with the exact function code by checking the number and type of the arguments. 23. What is const and volatile function The qualifier const tells the compiler that the function should not modify the argument. The compiler generate an error when this condition is violated The qualifier volatile tells the compiler that the function should modify the argument. Eg: int strlen(const char *p); int strlen(volatile char *p); 24. What are all characteristics of friend function? It cannot access the member names directly and uses the dot operator. It is not in the scope of a class in which it is declared as friend. It can be invoked without an object. It cannot be called using the object of that class. It has the objects as arguments. It can be declared as either public or private. 25. What is meant by static function? Like static member variable we can also have static member function. A member function that is declared static has the following properties A static function can have access to only other static members(functions or variables) declared in the same class. A static member function can be called using the class name(instead of its objects) 26. Define static data member. A data member of a class can be qualified as static. The properties of a static member variable are It is initialized to zero when the first object of its class is created. No other initialization is permitted. Only one copy of that member is created for the entire class and is shared by all the objects of that class, no matter how many objects are created. It is visible only within the class, but its lifetime is the entire program. 27. Define Local Classes. Classes can be defined and used inside a function or a block. Such classes are called local classes. Eg: void test(int a) {.. class student //local class { . . }; .. }

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

27. Define Nested Classes. A class can contain objects of other classes.. Such classes are called Nested classes. 28. What is abstract class An abstract class is one that is not used to create objects. An abstract class is designed only to act as base class. It is a design concept in program development and provides a base upon which other class may be built. 29. What is constant object? One can create and use constant objects using const keyword before object declaration. Eg: const matrix X(m,n); // object X is constant Any attempt to modify the values of m and n will generate compile-time error. 30. Define token and identifiers. The smallest individual units in a program are known as tokens. Various tokens are keywords, identifiers constants, strings and operators. The identifiers refer to the names of variables, functions, arrays, classes etc created by the programmer. 31. State the advantages of default arguments. We can use default arguments to add new parameters to the existing function. Default arguments can be used to combine similar functions into one. 32. Why do we use default arguments? The function assigns a default value to the parameters which do not have a matching argument in the function call. They are useful in situations where some arguments always have some 33. Define Class A Class is a way to bind the data and its function together. It allows the data to be hidden from external use. The general form is Class class-name { private: var declaration; fn declaration; public var declaration; fn declaration; }; 34. List the access modes used within the class. Private: The class members are private by default. The members declared private are completely hidden from the outside world. They can be acceded from only within the class Public : The class members declared public can be accessed from any where.
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

Protected: The class members declared protected can be access from within the class and also by the friend class. 35. Define Friend function. An outside function can be made a friend to a class using the qualifier friend. The function declaration should be preceded by the keyword friend. A friend function has full access to the private members of the class or the member function of friend class can directly access the private and protected data. 36. Define data members and member functions. The attributes in the objects are known as data members because they hold the information. The functions that operate on these data are known as methods or member functions. 37. State the use of void in C++. The two normal uses of void are To specify the return type of the function when it is not returning a value To indicate an empty argument list to a function 38. Define constant pointer and pointer to a constant. The constant pointer concept does not allow us to modify the value initialized to the pointer. e.g.) char * const ptr = GOOD; The pointer to a constant concept doesnt allow us to modify the address of the pointer. E.g.) int const * ptr = &n; 39. What are the two ways of creating symbolic constants? Using the qualifier const Defining a set of integer constants using enum keyword 40. Define reference variable. Give its syntax. A reference variable provides an alias or alternate name for a previously defined variable. It must be initialized at the time of declaration. Its syntax is given by, data-type & referencename = variable-name; 41. List out the new operators introduced in C++. :: Scope resolution operator ::* Pointer to member declarator ->* Pointer to member operator .* Pointer to member operator delete Memory release operator endl Line feed operator new Memory allocation operator setw Field width operator

42. What is the use of scope resolution operator?

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

A variable declared in an inner block cannot be accessed outside the block. To resolve this problem the scope resolution operator is used. It can be used to uncover a hidden variable. This operator allows access to the global version of the variable. It takes the form, :: variable-name 43. List out the memory difreferencing operator. ::* To declare a pointer to the member of the class ->* To access a member using object name and a pointer to that member .* To access a member using a pointer to the object and a pointer to that member 44. Define the 2 memory management operators. new Memory allocation operator The new operator can be used to create objects of any data-type. It allocates sufficient memory to hold a data object of type data-type and returns the address of the object. Its general form is, Pointer variable=new data-type;

delete Memory release operator When a data object is no longer needed it is destroyed to release the memory space for reuse. The general form is, delete pointer variable; 45. List out the advantages of new operator over malloc (). It automatically computes the size of the data object. It automatically returns the correct pointer type. It is possible to initialize the objects while creating the memory space. It can be overloaded. 46. Define manipulators. What are the manipulators used in C++? Manipulators are operators that are used to format the data display. Themanipulators used in C++ are endl causes a linefeed to be inserted setw provides a common field width for all the numbers and forces them to be printed right justified 47. What are the three types of special assignment expressions? Chained assignment e.g., x = y = 10; Embedded assignment e.g., x = (y = 50) + 10; Compound assignment e.g., x + = 10; 48. Define implicit conversion. Whenever data types are mixed in a expression, C++ performs the conversions automatically. This process is known as implicit or automatic conversion. e.g., m = 5 + 2.75; 49. Define integral widening conversion.
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

Whenever a char or short int appears in an expression, it is converted to an int. This is called integral widening conversion. 50. What are the control structures used in C++? Sequence structure (straight line) Selection structure (branching) if else (two way branch) switch (multiple branch) Loop structure (iteration or repetition) do while (exit controlled) while (entry controlled) for (entry controlled) 51. Define Function Prototyping. The function prototype describes the function interface to the compiler by giving details such as the number and type of arguments and type of return values. It is the declaration of a function in a program. It is in the following form, type function name (argument list); where argument list -> types and names of arguments to be passed to the function 52. What are inline functions? An inline function is a function that is expanded in line when it is invoked. Here, the compiler replaces the function call with the corresponding function code. The inline function is defined as, inline function-header { function body } 53. List out the conditions where inline expansion doesnt work. For functions returning values, if a loop, a switch, or a goto exists For functions not returning values, if a return statement exists If functions contain static variables If inline functions are recursive Unit - II

54. Define Constructor. A constructor is a special member function whose task is to initialize the objects of its class. The constructor name is same as class name. It is called constructor because it constructs the values of data members of the class. 55. List some of the special characteristics of consturtor. They should be declared in the public section. They are invoked automatically when the objects are created They do not have return types, not even void and they cannot return values. They cannot be inherited , Constructors cannot be virtual.

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

56. Give the various types of constructors. There are four types Default constructor constructor that accepts no parameters Parameterized constructor It can take arguments Copy constructor It takes a reference to an object of the same class as itself as an argument. Dynamic constructor - used to allocate memory while creating objects. 57. What are the ways in which a constructor can be called? The constructor can be called in two ways, they are. By calling the constructor explicitly Eg: integer int1=integer(0,100); By calling the constructor implicitly Eg: integer int1(0,100); 58. State the dynamic initialization objects. Class objects can be initialized dynamically. The initial values of an object may be provided during run time. The advantage of dynamic initialization is that we can provide various initialization formats, using overloaded constructors. It provides flexibility of using different data formats. 59. Define Destructor. A destructor is used to destroy the objects that have been created by a constructor. It is a special member function whose name is same as the class and preceded by a tilde ~ symbol. 60. What is an operator function. Describe the syntax of an operator function. The general form is Return-type classname :: operator op(arug list) { Function body } Where return type -> type of value returned Operator -> keyword Op -> operator being overloaded. 61. List the rules for operator overloading. Only existing operators can be overloaded We cannot change the basic meaning of an operator The overloaded operator must have atleast one operand Overloaded operators follow the syntax rules of the original operators. 62. List some of operators that cannot overload in C++. we can overload all the c++ operators expect the following class member access operators(. , .*) scope resolution operator(::) size operator(sizeof) conditional operator(?:)

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

63. What are the conditions to be satisfied for casting? It must be a class member. It must not specify a return type. It must not have any arguments. 64. What are the types of type conversion? conversion from basic type to class type conversion from class type to basic type conversion from one class type to another 65. What is operator overloading? The mechanism of giving such special meanings to an operator is known as operator overloading. or In c++ you can give special meanings to operators when they are used with user defined classes. This is called operator overloading. 66. Why is it necessary to overload an operator? To define a new relation task to an operator, we must specify what it means in relation to the class to which the operator is applied. This is done with the help of a special function called operator function. Or It allows the developer to program using notation closer to the target domain and allow user types to look like types built into the language. Or The ability to tell the compiler how to perform a certain operation when its corresponding operator is used on one or more variables. 67. What is a conversion function? How it is created? Explain its syntax The type of data to the right of an assignment operator is automatically converted to the type of the variable on the left. For e.g., the statements int m; float x=3.14; m=x; Convert x to an integer before its value is assigned t0 m. thus the fractional part is truncated. 68. When is a friend function compulsory? Give an eg. A friend function is necessary when you an function outside the class. And to access the private members of the class or the member function and also friend class can directly access the private and protected data. 69. What is meant by copy constructor? A copy constructor takes a reference to an object of the same class as itself as an argument. 70. What is the need of object initialization? When the object I s declared, it may need to initialize the individual data members to some specific default values. Objects may need to be set to special values. Dynamic memory allocation may be required when an object is defined.
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

71. What are the two main functions of constructors? The two main functions are 1. It automatically initializes the object 2. It usually provides initial values for the data members of the object. 72. What are the rules for defining constructor? A constructor must have the same name as the class itself. A consequence of the above is that there cannot be more than one constructor with different names and same arguments. A constructor cannot specify a return type. Even writing void is not allowed. A constructor should not have a return statement in the body of the constructor itself. 73. What are the operators which cannot be overloaded as a friend? 1. Assignment operator = 2. Function call operator () 3. Array Subscript operator [] 4. Access to class member using pointer to object operator -> 74. What are the restrictions of operator overloading Operators do not lose their original meaning Expect (), no other operator can have a default argument. Some of the operators cannot be simply overloaded. New operators cannot be devised. Available operators with given restrictions can only be overloaded. Operator can only be overloaded for user-defined types. All overloaded must have at least one argument as user defined type. 75. Difference between overloading of unary and binary operator All operators having a single argument are unary operators. When we overload these operators as member functions, we do not need to pass any argument explicitly. The pointer pointing to invoke object is passed as an implicit argument. Operators with two operand are known as binary operators. They will have a single argument when defined as member. 76. What are function objects. Objects of the classes where () operator is overloaded. In the case objects can be written with a () and can be treated like functions. Such objects which can be called like a function are known as function objects. 77. What are the different types of conversion? Compare them A constructor converts from a foreign object to a native object while an operator converts a native object to a foreign object. 78. What is wrapper class. A Class which makes a C-like struct or abuilt-in type data represented as a class. For e.g. an integer wrapper class represents a data type int as a class
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

Unit III 79. What is meant by templates? Templates is one the features in c++. It is a new concept which enables us to define generic classes and functions and thus provides support for generic programming. 80. What is the need of templates? A template can be used to create a family of classes or functions to handle different data types. A template can be considered as a king of macro. When an object of a specific type is defined for actual use, the template definition for that class in substituted with the required data type. 81. What is instantiation? The process of creating a specific class from a class template is called instantiation. The compiler will perform the error analysis only when an instantiation takes place. 82. What is generic programming? Generic programming is an approach where generic types are used as parameters in algorithms so that they work for a variety of suitable data types and data structures. 83. Write the general form for creating class template. template<class T> class classname { //.. // class member specification }; 84. What is meant by function template? A specific function generated or created from a function template called template function. 85. What is the use template? Template classes and functions eliminate code duplication for different types and thus make the program development easier and more manageable. Like other functions, template functions can be overloaded. 86. Distinguish the terms class template and template class A class created from a class template is called template class. A term class template is similar to an ordinary class definition except the prefix template <class T> . 87. Write the general form for creating function template. template<class T> returntype fucntionname (arguments of type T) { //..
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

// Body of the function }; 88. How to overload a template function? A Template function may be overloaded either by template function or ordinary function or its name. In such cases, the overloading resolution is accomplished as follows; 1. call an ordinary function that has an exact match 2. call an template functions that could be created with an exact match. 3. try normal overloading resolution to ordinary functions and call the one that matches. 4. An error is generated if no match is found. 89. List some common types of bugs logic error : The logic errors occur due to poor understanding of the problem and solution procedure syntactic error: Arise due to poor understanding of the language itself. We can detect these errors by using exhaustive debugging and testing procedures. 90. What is an exception? Exceptions are peculiar problems that a program may encounter at run time. 91. What are types of exceptions? Synchronous Asynchronous 92. How is an exception handled in C++? The exceptions are handled in following ways 1. Find the problem(hit the exception) 2. Inform that an error has occurred (throw the exception) 3. Receive the error information(Catch the exception) 4. Take corrective actions(handle the exception) 93. What is synchronous and asynchronous exception? Errors such as out of range index and over flow belong to the synchronous type exceptions. The errors that are caused by events beyond the control of the program (such as keyboard interrupts) are called asynchronous exceptions. 94. What is the purpose of handling exception? The purpose of exception handling mechanism is to provide means to detect and report an exceptional circumstance so that appropriate action can be taken. The proposed exception handling mechanism in c++ is designed to handle only synchronous exceptions. 95. What are advantages of using exception handling One to detect errors To throw exceptions Take appropriate actions Get error free code.
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

96. When should a program throw an exception? When an exception is detected, it is thrown using a throw statement in the try block. 97. When do we used multiple catch handlers In the case of more than one condition to throw an exception in a Program, we can associate more than one catch statement with a try. Try { //try block } catch(type1 arg) { //catch block1 } catch(type2 arg) { //catch block1 } . . catch(typeN arg) { //catch blockN } 98. What are all the keywords used in exception handling Three keywords namely try, throw and catch The keyword try is used to preface a block of statements which may generate exceptions. This block of statements is known as try block. When an exception is detected, it is thrown using a throw statement in the try block. A catch block defined by the keyword catch catches the exception thrown by the throw statement in the try block and handles appropriately. 99. What is an exception specification? It is possible to restrict a function to throw only certain specified exceptions. This is achieved by adding a throw list clause to the function definition. The general form of using an exception specification is type function(arg-lsit) throw (type-list) { .. .. Function body .. } 100. List any 4 that should be a friends of class Template
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

A friend of a class template can be one of the following class template function template ordinary (non-template) function ordinary (non-template) function a specialization of class template a specialization of function template 101. What is partial specialization? When we define a template class, we can overload that class with other specific set of types which is a subset of original set of types. This overloading of template class is known as partial specialization.

102. What is Explicit Specialization When either a function or a class is defined explicitly for a specific type the that special definition is known as explicit specialization. This explicit overrides the normal specialization. 103. What is rethrow()? What is its use? Rethrowing the exception, once handled by a handler, can rethrown to a higher block. This process is known as rethrowing. 104. What is uncaught_expection() and why do we need it? Uncaught_exception() the function to call when we want to check before throwing any exception if some other exception is already on. 105. What is terminate () function The function to call when the exception handling mechanism does not get any proper handler for a thrown exception 106. Drawbacks of exception handling? The major drawback is uncertain termination. When we are using library functions and unaware of some specific exception if ,that exception is thrown, the program would crash. Another drawback is overhead. The code size and execution time would both increases substantially sometimes. Unit IV 107. Advantages of using inheritance We are in need of extending the functionality of an existing calss. We have multiple classes with some attributes common to them. We would like to avoid problems of inconsistencies between the common attributes. We would like to model a real-world hierarchy in our program in a natural way. 108. What are the types of inheritance? The various types of inheritance are,
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

Single inheritance Multi-level inheritance Multiple inheritance Hierarchical inheritance Hybrid inheritance 109. What is composite objects(container objects) Sometimes the object itself contains some other objects as members. Such ojects are known as composite objects. 110. What is private derivation. Inheriting class in a way that the public and proteted members of the base class becomes private member of the derived class. 111. What is protected access modifier The protected access modifier works in the same way as the private specifier for the data members of the class except that the private members of the base class are not available go the derived also but protected members of the base class are available to the derived class. 112. Give the syntax for inheritance. The syntax of deriving a new class from an already existing class is given by, class derived-class : visibility-mode base-class { body of derived class } 113. Define single inheritance. In single inheritance, one class is derived from an already existing base class. Here A is the base class and B is the derived class. 114. Define multi-level inheritance. In multi-level inheritance, a new class is derived from a class already derived from the base class. Here, class B is derived from class A and class C is further derived from the derived class B. 115. Define multiple inheritance. In multiple inheritance, a single class is derived from more than one base class. 116. Define Hierarchical inheritance. In hierarchical inheritance, more than one class is derived from a single base class. 117. Define Hybrid inheritance. Hybrid inheritance is defined as a combination of more than one inheritance.

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

118. What is a virtual base class? Here, class D inherits both classes B and C which are derived from the same base class A. Hence D has two copies of the properties of class A. This can be avoided by declaring classes B and C as virtual base classes. 119. What is an abstract class? An abstract class is one that is not used to create objects. It is designed only to act as a base class to be inherited by other classes. 120. What are the types of polymorphism? The two types of polymorphism are, Compile time polymorphism The compiler selects the appropriate function for a particular call at the compile time itself. It can be achieved by function overloading and operator overloading. Run time Polymorphism - The compiler selects the appropriate function for a particular call at the run time only. It can be achieved using virtual functions. 121. Define this pointer. A this pointer refers to an object that currently invokes a member function. For e.g., the function call a. show () will set the pointer this to the address of the object a. 122. can we use a this pointer to a friend function? Comment it this pointer cannot be used for friend function . because it is a non-member function. 123. What is a virtual function? When a function is declared as virtual, C++ determines which function to use at run time based on the type of object pointed to by the base pointer, rather than the type of the pointer. 124. What is a pure virtual function? A virtual function, equated to zero is called a pure virtual function. It is a function declared in a base class that has no definition relative to the base class. 125. How can a private member be made inheritable? A private member can be made inheritable by declaring the data members as protected. When declared as protected the data members can be inherited by the friend classes. 126. List out the rules of Virtual Functions 1. the virtual functions must be members of some class 2. they cannot be static members 3. they are accessed by using object pointers 4. a virtual function can be a friend of another class
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

5. a virtual function in a base class must be defined. 127. Difference between between access specifier and modifier. Public, private and protected are the ways we can define data members. They are known as access specifiers. All three can be specified while we are deriving a class from another class. At that point of time they are known as access modifiers. 128. Define RTTI Run Time Type Information is a mechanism to decide the type of the object at runtime 129. What is virtual table? A table consisting of pointers to all virtual functions of the class. Every class with at least on virtual function will have one copy of the virtual table. 130. Why do we need RTTI? Suggest some cases where we need to use RTTI. When the classes are designed , the user of these classes are not involved in the design, so all their requirements are not known. When the users start working with the hierarchy, they have to check specific type and provide operation that they need. The user needs operations other than those designed by the original designer. The designer of class hierarchy has no ideas of all possible applications of the class hierarchy. The class hierarchy is designed for a general purpose. RTTI enables the user to decide about the type of the object at run time and take decision at that point of time. While using templates, we may need to know about the actual data type and provide validations. We do not know the type when we are dealing with type variables like element type in the stack. RTTI can be used to find out the type of the element in the body of a template function or class. 131. What are polymorphic object. If we have a class containing a virtual function, it is possible to point to a derives class object using the base class pointer and manipulate the object. Such manipulatable objects are known as polymorphic object. 132. List the features of Dynamic_cast a. This casting operator is used only for another polymorphic object casting. b. Dynamic_cast is also known as safe cast. It succeeds only when it is properly casted. This means dynamic_cast succeeds obly when the pointer being cast is an object of the target type or derived type from it. c. The casting is done with pointers or reference only. It cannot be done with objects.

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

133. What are all issues of RTTI 1. Backward compatibility with c and casting. 2. No Efficiency 3. Using virtual functions in place of RTTI. 134. Define cross casting. Cross casting refers to casting from derived to proper base class when there are multiple base classes in case of multiple inheritance. 135. Define down casting Casting from a base class pointer to a derived class pointer is known as down casting. UNIT V 136. What are streams ? Whey they are useful? A stream is a sequence of bytes. It acts either as a source from which the input data can be obtained or as a destination to which the output data can be sent. The source stream that provides the data to the program is called the input stream and the destination stream that receives output from the programs is called the output stream. 137. What is the difference between I/O provided by C and C++? 1. Richer Set of Operations 2. Namespace is separate and not globally shared. 138. Define name space A kind of enclosure for functions, classes and variables to separate them from other entities. 139. What is the difference between manipulators and ios functions. 1. manipulators though have one distinct advantage, we can write our own manipulator and use it in the program 2. Unlike ios function, manipulators do not return the previous status. 3. ios functions are single. They cannot be combined to have multiple effects together. 4. ios functions are require nothing else then <iostream> file to be included, whereas manipulators need <iomanip> file to be included additionally. 140. Define Manipulators. Functions which are non-member but provide similar formatting mechanism as ios functions. 141. What is STL? A collection of generic classes and functions is called the Standard Template Library. STL components are part of C++ standard Library.
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

142. What are three components of STL The STL components are containers, algorithms and iterators. 143. Define containers. Containers are objects that hold data of same type. Containers are divided into three major categories: sequential, associative and derived. 144. What is iterators? What is its characteristic? An iterator is an object (like a pointer) that points to an element in a container. We can use iterators to move through the contents of containers. Iterators connect algorithms with containers and play a key role in the manipulation of data stored in the containers. 145. What are the best situations for the use of the associative containers Associate containers are designed to support direct access to elements using keys they are not sequential. Containers are best suited for fast searching, deletion and insertion of data in a structure called tree. 146. Compare the performance characteristics of the 3 containers. Container Random access Vector List Deque Fast Slow Fast Insertion or deletion in the middle Slow Fast Slow Fast at Back Fast at front Fast at both the ends Inserton or deletion at the ends

147. What is an algorithm? An algorithm is a procedure that is used to process the data contained in the containers. STL contains many different kinds of algorithms to provide support to tasks such as initializing, sorting, searching, copying and merging. Algorithms are implemented by template function 148. What is an algorithm? How STL algorithms are different from the conventional algorithm? An algorithm is a simple procedure for a given program logic. In conventional algorithm no need to implement template function but in STL we can implement template function. STL algorithms also permit us to work with two different types of containers at the same time but not in conventional algorithms. 149. List three Derived Containers. The STL provides three derived containers namely stack, queue and priority_queue. These are also known as container.

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

150. What is an associative container? Associative containers are designed to support direct access to elements using keys. They are not sequential. There are four types of associative containers Set Multiset Map Multimap 151. What is use of set and multiset containers? Containers set and multiset can store a number of items and provide operations for manipulating them using the values as the keys. Eg: a set might store objects of the student class which are ordered alphabetically using names as keys 152. Difference between set and multiset containers. The main difference between a set and a multiset is that a multiset allows duplicate items while a set does not. 153. What is use of map and multimap containers? Containers map and multimap are used to store pairs of items, one called the key and the other called the value. We can manipulate the values using the keys associated with them. The values are sometimes called mapped values. 154. Difference between map and multimap containers The main differences between a map and a multimap is that map allows only one key for a given value to be stored while multimap permits multiple keys. 155. Categorize the STL algorithm based on the nature of operations. The STL algorithms, based on the nature of operations they perform, may categorized as under. Retrieve or non-mutating algorithms Mutating algorithms Sorting algorithms Set algorithms Relational algorithms 156. What is iterators? What is its characteristic? Iterators behave like pointers and are used to access container elements. They are often used to traverse from one element to another. A process known as iterating through the container.

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

Iterators and their characteristics Iterator Access Methods Linear Linear Linear Linear Random Direction of movement Forward only Forward only Forward only Forward and backward Forward and backward I/O capability Remark

Input Output Forward Bidirectional Random

Read only Write only Read/Write Read/Write Read/Write

Cannot be saved Cannot be saved Can be saved Can be saved Can be saved

157. Applications of container classes Vector List map 158. What is need for String Objects. Character arrays have a few limitations when treated as strings. 1. they cannot be compared like other variables 2. They cannot be assigned like normal variables. 3. Initailizing with another string is not possible. 4. There are functions provided for strings in the library , prototype of which are accessible using string.h fie 159. Discuss how member function of ios can be used for formatting IO? The prototype for all the following function is <old value of stream> function_name (<specified new value>) the function set new value to the stream and return old value. 160. What is shorthand manipulator. There are some manipulators that work as a shorthand to the longer versions,e.g using boolalpha for setiosflag(ios::boolalpha). These are calles shorthand manipulators.

Department of Information Technology

141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

16 MARKS 1. Explain various OOPs concepts with eg. 2. What is a friend function? What are the merits and demerties of using friend function? 3. Explain about friend class and friend function with eg.? 4. What is inline function? Explain 5. What are the advantages of passing arguments by reference? 6. Compare object oriented methodology with structure programming. 7. Write a program in C++ to accept Number of names in an array. Write a module to write unique name is in another array 8. Write a program in c++ to input a four digit number and to write the same in words. 9. What is function polymorphism? explain with suitable eg 10. Create a class student and write a c++ program to read and display all the students in your class. 11. Describe briefly the features of input/output supported by C++ 12. Explain the nested classes with suitable eg. 13. write a C++ program to add two complex number using the concept of passing and returning objects in member function 14. What are access specifiers? how are the used to protect data in C++? 15. Explain with an eg, ow you would create s[ace for an array of objects using pointer. 16. explain the following with eg Pointer to object Array of pointers Pointer to object members 17. Explain the following with an eg. a. copy constructor b. parameterized constructor c. default argument constructor d. dynamic constructor

18. write a operator overloading program for manipulating matrics 19. Write a program to overload the assignment operator using C++ language
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

20. Explain the elements object oriented programming. 21. What are the differences between references variables and normal variables 22. Why cannot a constant value be initialized to variables of reference type 23. What are the advantages of using pointer in programming? 24. Write a program which copies the contents of one file to a new file by removing necessary spaces between words 25. What is the difference between the statements? Cin>>ch; Ch=cin.get(); 26. Write a program to overload the insertion and deletion operators in C++ 27. State the merits and demerits of object oriented methodology 28. State the rules to be followed while overloading an operator. Write a program to illustrate overloading 29. Discuss about the polymorphism and its advantages 30. Explain the 4 functions Seekg, Seekp, tellg, tellp, used for setting pointers during file operation and show how they are derived from fstream class. 31. Write a program to append to the contents of a file 32. What are the keywords used in C++ for exception handling? Describe their usage with suitable eg. 33. Write a program that generate a template class by which one can perform integer type data addition and float type data addition also 34. How are unusual error condition avoided using c++? 35. What are the various data types allowed in c++? Give one example for each type 36. Using the concept of function overloading, Write a program in c++ to find the maximum of 3 integers and three float numbers 37. Which are the c++ operators cannot be overloaded 38. What are the special features of virtual function? 39. What are the various types of inheritance? discuss any three types of inheritance 40. Write a program which initialized 10 and 200 to member data and then calculate the sum of these 41. Write a program which reads a complex number copy that into another. Use copy constructor for writing program. 42. What is function of this pointer?
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

43. What do you understand by static member and function? How to declare them. 44. What is inline function? Explain with eg. 45. What is the need for and advantages of templates? What is the difference between function template and class template 46. What is exception handling? Explain 47. for handling what type of constructors are available in C++ 48. Explain the concept of streams in c++ and give hierarchy of different types of stream. 49. what are the characteristics of function > Describe various constructors with eg 50. Define a c++ class Matrix to describe a matrix. Equip the class with functions for addition and multiplication. Overload operators suitably for input and output of the matrix. 51. What are virtual functions? Give an eg to highlight its need? 52. Give the syntax of function template. Write template function for bubble sort. Write a test program to illustrate its use. 53. give the hierarchy of console stream class 54. Explain how exceptions are handled in c++. Give examples to support your answer. 55. Implement a String class. Each object of this class will represent a characters string. Data members are the Length of the string and the actual characters String In addition to constructors, destructor access function and a print function include a subscript function. 56. Write a function to reverse a string in place (i.e., without duplicating all the characters). 57. Compare the features of object oriented programming and procedure oriented programming. Explain the organization of data and function in both paradigms. 58. Describe the following terms with suitable examples: (i)Inheritance (ii) Polymorphism (iii) Dynamic binding. (iv) Message Passing. 59. Implement a vector class, with a default constructor, a copy constructors, a destructor and Overloaded assignment operator,equality operator, stream insertion and extraction operator. 60. What are characteristic features of friend function? Give example. 61. List any 4 rules associated with operator overloading. What are the operators that cannot be overloading? What are the operator where a friend cannot be used? 62. Describe the principal features of object-oriented programming. 63. Illustrate the reserved word inline with two examples. 64. Explain the constructors and destructors. 65. Write a C++ program to implement Stack and its operations PUSH and POP.
Department of Information Technology 141303-Object Oriented Programming

ADHIPARASAKTHI COLLEGE OF ENGINEERING, G.B.Nagar, Kalavai.

66. Define Friend class and specify its importance, Explain with suitable example. 67. Explain the operators used for dynamic memory allocation with examples. 68. Explain operator overloading with the implementation of Complex numbers its numeric operations addition,subtraction,multiplication and division. 69. Write a program to overload=operator, Assign values of members of one object to another object of the same type. 70. Write a program to write and read data in a file using object Input/Output functions write ()and read().Declare class with data members name [20].int billno.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. 71. Describe the various file modes and its syntax. 72. Discuss the need for exception with try, catch and throw keywords. 73. Describe the advantages of OOP. 74. What are the difference between pointers to constants and constant pointers? 75. Describe the applications of OOP technology. 76. What is inline function? Explain the situations where inline expansion may not work? 77. Explain copy constructor with suitable C++ coding. 78. List out the rules for overloading operators. 79. Explain hybrid inheritance with suitable C++ coding. 80. Define polymorphism.Explian the different types of coding. 81. Write a C++ program to read from 2 files simultaneously. 82. Explain multiple catch statement with the help suitable C++ coding.

Department of Information Technology

141303-Object Oriented Programming