Sei sulla pagina 1di 50

PART A 1. Give the evolution diagram of OOPS concept.

Machine language Procedure language Assembly language OOPS

2. Define Object oriented programming? OOP stands for Object-Oriented Programming, the usual programming/hacking and etc. most programmers think of. Modern software engineering methodologies; however, consider OOP as the implementation/evolution of an OOD.

3. What are the features required for object-based programming Language? Data encapsulation. Data hiding and access mechanisms. Automatic initialization and clear up of objects. Operator overloading. 4. What are the characteristics of Object Oriented programming language? Some key features of the Object Oriented programming are: Emphasis on data rather than procedure Programs are divided into entities known as objects Data Structures are designed such that they characterize objects

Functions that operate on data of an object are tied together in data structures Data is hidden and cannot be accessed by external functions Objects communicate with each other through functions New data and functions can be easily added whenever necessary Follows bottom up design in program design 5. Write any four features of OOPS. Emphasis is on data rather than on procedure. Programs are divided into objects. Data is hidden and cannot be accessed by external functions. Follows bottom-up approach in program design 6. What are the Basic concepts of OOS? Objects. Classes. Data abstraction and Encapsulation. Inheritance. Polymorphism. Dynamic binding. Message passing 7. What are the benefits of OOP? Encapsulation: Objects hold together well demarcated units of functionality. They hold all data and processing pertaining to that functionality together. Objects are accessed through their public interfaces by sending messages. No need to read all the implementation code to check usability.

8. Define objects.

Objects are basic run-time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program has to handle. Each object has the data and code to manipulate the data and theses objects interact with each other

9. Rules for naming the identifiers in C++. Only alphabetic characters, digits and underscore are permitted. The name cannot start with a digit. The upper case and lower case letters are distinct. A declared keyword cannot be used as a variable name.

10. What are the operators available in C++? All operators in C are also used in C++. In addition to insertion operator << and extraction operator >> the other new operators in C++ are, : Scope resolution operator : : * Pointer-tomember 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 11. What is a scope resolution operator? A scope resolution operator (::), can be used to define the member functions of a class outside the class. Scope resolution operator is used to uncover the hidden variables. It also allowsaccess to global version of variables.Eg:#include<iostream.h>int m=10; // global variable mvoid main ( ){ int m=20; // local variable mcout<<m=<<m<<\\n;cout<<: : m=<<: : m<<\\n;} output:20 10 (: : m access global m)Scope resolution operator is used to define the function outside the class.Syntax:Return type <class name> : : <function name>Eg:Void x : : getdata()

12. What do you mean by enumerated data type? An enumerated datatype is another user-defined datatype, which provides a way forattaching names to numbers, thereby increasing comprehensibility of the code.The syntax of an enum statement is similar to that of the struct statesmen.Eg: enum shape{ circle, square, triangle}enum color{ red, blue, green, yellow}

13. What is meant by Assertions? An assertion is a statement that can be used to test our assumptions about certain parts of the program. It is a boolean expression, and by placing an assertion, we expect it to return true. Placing assertions in the code increases the robustness of the code by letting the programmer catch the logic errors in the early stages of the development. If the assertion returns true, it confirms that the assumptions about the behavior of the program is right. Otherwise, the system throws an error. 14. What is static member function? A member function that is declared as static has the following properties A static function can have access to only other static member declared in the same class A static member function can be called using the classname as follows classname ::function_name;

15. Define the term Standard Template Library (STL). The Standard Library is a fundamental part of the C++ Standard. It provides C++ programmers with a comprehensive set of efficiently implemented tools and facilities that can be used for most types of applications. 16. What are C++ storage classes? Auto:the default. Variables are automatically created and initialized when they are defined and are destroyed at the end of the block containing their definition(when they are out of scope). They are not visible outside that block auto int x;

int y; Both are same statement. auto is defalt Register:a type of auto variable. a suggestion to the compiler to use a CPU register for performance(Generally Used in loops) Static:a variable that is known only within the function that contains its definition but is never destroyed and retains its value between calls to that function. It exists from the time the program begins execution void example() { static int x = 0; // static variable x++; cout << x <<endl; } If this function is called 10 times, the output will be 1,2,3,4..etc., The value of the variable x is preserved through function calls. If this static variable is declared as a member of a class, then it will preserve the value for all the objects of the class.i.e, one copy of this data variable will be shared by all objects of the class

17. Give any four advantages of OOPS. The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program. It is possible to have multiple instances of an object to co-exist without any interference. Object oriented programming can be easily upgraded from small to large systems. Software complexity can be easily managed.

18. Give any four applications of OOPS. Real-time systems.

Simulation and modeling. Object-oriented databases. AI and expert systems.

19. What are data members and member functions? Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight, and cost and uses functions to operate on these attributes. The attributes are sometimes called as data members because they hold information. The functions that operate on these data are called as methods or member functions. Eg: int a,b; // a,b are data members Void getdata ( ) ; // member function.

20. Define tokens. The smallest individual units in a program are known as tokens. C++ has the following tokens, o Keyword o Identifiers o Constants o Strings o Operator

21. Give any four applications of c++? Since c++ allows us to create hierarchy-related objects, we can build special object-oriented libraries, which can be used later by many programmers. C++ are easily maintainable and expandable. C part of C++ gives the language the ability to get close to the machine-level details. It is expected that C++ will replace C as a general-purpose language in the near future.

22. What is keyword? The keywords implement specific C++ language features. They are explicitly reserved identifiers and cannot be used as names fro the program variables or other user defined program elements .Eg: go to, If, struct , else ,union etc. 23. What is the basic difference between class and structure? Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: Class is a successor of Structure. By default all the members inside the class are private. Structure is a default in public whereas class is a default in private and class have data hiding but structure do not

24. What are symbolic constants? There are two ways for creating symbolic constants in C++: Using the qualifier constant. Defining a set of integer constants using enum keyword.The program in any way cannot modify the value declared as constant in c++.Eg:Const int size =10;Char name [size]; 25. List the different phases of C++? How to form variable? 26. Name the input and output statement in C++. 27. Define instance in object oriented programming? One can have an instance of a class or a particular object. The instance is the actual object created at runtime. In programmer jargon, the Lassie object is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. The object consists of state and the behaviour that\'s defined in the object\'s class.

28. What Is Shared (Repeated) Inheritance?

Multiple Inheritance brings up the possibility for a class to appear as a parent more than once in a class graph (repeated inheritance), and there is then a potential to share that class. Only one instance of the class will then appear in the graph with the same name will be shared (receive a single slot) with the greatest common subtype as its type). C++ provides an alternative, where only parents specified as virtual (virtual bases) are shared within the same class lattice, allowing both shared and non-shared occurrences of a parent to coexist.

29. Explain some characteristics of inheritance. A class inherits the members of its direct base class. Inheritance means that a class implicitly contains all members of its direct base class, except for the constructors and destructors of the base class.

Some important aspects of inheritance are: Inheritance is transitive. If C is derived from B, and B is derived from A, then C inherits the members declared in B as well as the members declared in A. A derived class extends its direct base class. A derived class can add new members to those it inherits, but it cannot remove the definition of an inherited member. Constructors and destructors are not inherited, but all other members are, regardless of their declared accessibility. However, depending on their declared accessibility, inherited members might not be accessible in a derived class. A derived class can hide inherited members by declaring new members with the same name or signature. Note however that hiding an inherited member does not remove that member; it merely makes that member inaccessible in the derived class. An instance of a class contains a set of all instance fields declared in the class and its base classes, and an implicit conversion exists from a derived class type to any of its base class types. Thus, a reference to an instance of some derived class can be treated as a reference to an instance of any of its base classes. A class can declare virtual methods, properties, and indexers, and derived classes can override the implementation of these function members. This enables classes to exhibit polymorphic behavior wherein the actions performed by a function member invocation varies depending on the run-time type of the instance through which that function member is invoked

30. Define encapsulation?

Encapsulation is binding of attributes and behaviors. Hiding the actual implementation and exposing the functionality of any object. Encapsulation is the first step towards OOPS, is the procedure of covering up of data and functions into a single unit (called class). Its main aim is to protect the data from out side world 31. What is the usage of encapsulation? Makes Maintenance of Application Easier: Complex and critical applications are difficult to maintain. The cost associated with maintaining the application is higher than that of developing the application properly. To resolve this maintenance difficulty, the object-oriented programming language C++ created the concept of encapsulation which bundles data and related functions together as a unit called class. Thus, making maintenance much easier on the class level.

Improves the Understandability of the Application

Enhanced Security: There are numerous reasons for the enhancement of security using the concept of Encapsulation in C++. The access specifier acts as the key strength behind the concept of security and provides access to members of class as needed by users. This prevents unauthorized access. If an application needs to be extended or customized in later stages of development, the task of adding new functions becomes easier without breaking existing code or applications, there by giving an additional security to existing application.

32. Explain the advantages of Encapsulation in Object Oriented Programming Languages. Benefits of Encapsulation in oops: Encapsulation makes it possible to separate an objects implementation from its behavior to restrict access to its internal data. This restriction allows certain details of an objects behavior to be hidden. It allows us to create a \"black box\" and protects an objects internal state from corruption by its clients.

Encapsulation is a technique for minimizing interdependencies among modules by defining a strict external interface. This way, internal coding can be changed without affecting the interface, so long as the new implementation supports the same (or upwards compatible) external interface.

So encapsulation prevents a program from becoming so interdependent that a small change has massive ripple effects.

The implementation of an object can be changed without affecting the application that uses it for: Improving performance, fix a bug, consolidate code or for porting.

33. What is a scope resolution operator? Scope resolution operator is used to uncover the hidden variables. It also allowsaccess to global version of variables.Eg:#include<iostream.h>int m=10; // global variable mvoid main ( ){ int m=20; // local variable mcout<<m=<<m<<\\n;cout<<: : m=<<: : m<<\\n;} output:20 10 (: : m access global m)Scope resolution operator is used to define the function outside the class.Syntax:Return type <class name> : : <function name>Eg:Void x : : getdata()

34. Define abstraction? Hiding the complexity. It is a process of defining communication interface for the functionality and hiding rest of the things. 35. Define polymorphism? Mean by more than one form. Ability to provide different implementation based on different number/type of parameters. 36. State some of the advantages of object oriented programming? OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface. OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones. OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces. 37. What a method is? A method implements behavior.

Behavior is how an object acts and reacts, in terms of its state changes and message passing. A method is a function or procedure which is defined in a class and typically can access the internal state of an object of that class to perform some operation. 38. What Is The Difference Between Object-Based And Object-Oriented? Object-Based Programming usually refers to objects without inheritance and hence without polymorphism . These languages support abstract data types and not classes, which provide inheritance and polymorphism. following requirements: - It supports objects that are data abstractions with an interface of named operations and a hidden local state. - Objects have an associated type. - Types may inherit attributes from supertypes. object-oriented = data abstractions + object types + type inheritance

PART-B 1 Explain in details about the concepts of OOPs? (16) 2. (a) Explain in detail about Programming Elements (8) (b) What are Enumeration types? Explain in detail.(8) 2 Explain in detail about the following terms with example programs: (a)Function Invocation (8) (b)Function Prototypes (8) 3 (a) What is meant by Default arguments? Give example program (8) (b)Define Function Overloading? Explain the example program. (8) 4 (a)Explain in detail about Scope class (8)

(b)Explain in detail about Storage class with example program (8) 5 (a)Write short notes on Pointer Types (8) (b)What is meant by Assertion? Give example program (8) 6. Explain in detail about (a)Arrays and Pointers (8) (b)Standard Template Library (STL) (8)

Read more: 600206 - OOPS - Anna University Engineering Question Bank 4 U http://questionbank4u.in/questionanswer.php?course=14&semester=58&subject=148&listid=559 #ixzz1lDInxIds Under Creative Commons License: Attribution Enter to win a free tech book 101 Free Tech Books
UNIT II

PART A 1 Define the term Aggregate Type Struct . An \"aggregate\" type is a structure, union, or array type. If an aggregate type contains members of aggregate types, the initialization rules apply recursively. 2 What is Union? A union is a user-defined data or class type that, at any given time, contains only one object from its list of members (although that object can be an array or a class type). 3 Define Bit Fields. A bit field is a common idiom used in computer programming to compactly store a values as a short series of bits. A bit field is most commonly used to represent integral types of known, fixed bit-width. Perhaps the most well known usage of bit-fields is to represent single bit flags, with each flag stored in a separate bit. Both C and C++ allow integer members to be stored into memory spaces smaller than the compiler would ordinarily allow. These space-saving structure members are called bit fields, and their width in bits can be explicitly declared 4 What is the use of bit fields in a Structure declaration?

Bitfields can only be declared inside a structure or a union, and allow you to specify some very small objects of a given number of bits in length. struct { /* field 4 bits wide */ unsigned field1 :4; /* * unnamed 3 bit field * unnamed fields allow for padding */ unsigned :3; /* * one-bit field * can only be 0 or -1 in two\'s complement! */ signed field2 :1; /* align next field on a storage unit */ unsigned :0; unsigned field3 :6; }full_of_fields; The main use of bitfields is either to allow tight packing of data or to be able to specify the fields within some externally produced data files. 5 Is There A Difference Between Being A Member Or Instance Of A Class? Yes .To use C++ terminology, an object (not a reference) is defined to be an instance of exactly one class (in classical OO), called its most derived class. An object not directly contained in any other is called the complete object .An object is a member of several classes, including all of the classes its declared (or most derived) class inherits from. With static typing and inclusion polymorphism based on class, if a polymorphic object (or reference) is made to refer to an object, that object must be a member of the polymorphic object\'s class. This also provides a good example of differing definitions among object-

oriented languages, since a member is defined as above in CLOS, but a member of a class is one of its instance variables in C++. 6 How the member functions are defined? Member functions can (and should) be used to interact with data contained within user defined types. User defined types provide flexibility in the \"divide and conquer\" scheme in program writing. In other words, one programmer can write a user defined type and guarantee an interface. Another programmer can write the main program with that expected interface. The two pieces are put together and compiled for usage. User defined types provide encapsulation defined in the Object Oriented Programming (OOP) paradigm 7 What is a Constructor? A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as class name. The constructor is invoked whenever an object of its associated class is created. It is called constructor because it constructs the values of data members of the class Eg: Class integer { public: integer( );//constructor }

8 Define parameterized constructor. Constructor with arguments is called parameterized constructor. Eg;Class integer{ int m,n;public:integer(int x,int y){ m=x;n=y;} To invoke parameterized constructor we must pass the initial values as arguments to theconstructor function when an object is declared. This is done in two ways 1.By calling the constructor explicitlyeg:integer int1=integer(10,10);

2.By calling the constructor implicitlyeg:Integer int1(10,10);

9 Define default constructor The constructor with no arguments is called default constructor Eg: Class integer { int m,n; Public: Integer( ); . }; integer::integer( )//default constructor { m=0;n=0; } the statement integer a; invokes the default constructor

10 Define Dynamic Constructor Allocation of memory to objects at time of their construction is known as dynamic constructor. The memory is allocated with the help of the NEW operator

Eg:Class string{ char *name;int length;public:string( ){ length=0;name=new char[length +1];} void main( ){ string name1(Louis),name3(Lagrange);}

11 What is the ambiguity between default constructor and default argument constructor? The default argument constructor can be called with either one argument or no arguments. when called with no arguments ,it becomes a default constructor. When both these forms are used in a class ,it cause ambiguity for a statement such as A a; The ambiguity is whether to call A::A() or A::A(int i=0)

12 Define copy constructor. A copy constructor is used to declare and initialize an object from another object. It takes a reference to an object of the same class as an argumentEg: integer i2(i1);would define the object i2 at the same time initialize it to the values of i1.Another form of this statement is Eg: integer i2=i1;The process of initializing through a copy constructor is known as copy initialization.

13 Define default argument constructor. The constructor with default arguments are called default argument constructorEg:Complex(float real,float imag=0); The default value of the argument imag is 0 The statement complex a(6.0) assign real=6.0 and imag=0 the statement complex a(2.3,9.0) assign real=2.3 and imag=9.0

14 Define Destructor. It is used to destroy the objects that have been created by constructor. Destructor name is same as class name preceded by tilde symbol(~) Eg;~integer(){ } A destructor never takes any arguments nor it does it return any value. Thecompiler upon exit from the program will invoke it.Whenever new operator is used to allocate memory in the constructor, we should use delete to free that memory.

15 Write some special characteristics of constructor.

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 therefore, and they cannot return values They cannot be inherited, though a derived class can call the base class They can have default arguments Constructors cannot be virtual function

16 Define multiple constructors (constructor overloading). The class that has different types of constructor is called multiple constructors. Eg: #include<iostream.h> #include<conio.h> class integer { int m,n; public: integer( ) //default constructor { m=0;n=0; } integer(int a,int b) //parameterized constructor { m=a; n=b; } integer(&i) //copy constructor { m=i.m; n=i.n; } void main() { integer i1; //invokes default constructor integer i2(45,67);//invokes parameterized constructor integer i3(i2); //invokes copy constructor } 17 How the objects are initialized dynamically? To call parameterized constructor we should the pass values to the object ie,for the constructor integer(int a,int b)it is invoked by integer a(10,18)this value can be get during run time. i.e., for above constructorint p,q;cin>>p>>q;integer a(p,q);

18 What is static data member? Static variable are normally used to maintain values common to the entire class. Feature: It is initialized to zero when the first object 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 It is only visible within the class, but its life time is the entire class type and scope of each static member variable must be defined outside the class

It is stored separately rather than objects Eg: static int count//count is initialized to zero when an object is created. int classname::count;//definition of static data member

19 What is static member function? A member function that is declared as static has the following properties A static function can have access to only other static member declared in the same class A static member function can be called using the classname as follows classname ::function_name;

20 What is the use of this keyword? This is always a reference to the object on which the method was invoked. thiscan be used inside any method to refer to the current object.Box(double w,double h,double d){This. width = w;This. height= h;This. depth = d; } 21 Difference between Structure and Union? While structure enables us treat a number of different variables stored at different in memory , a union enables us to treat the same space in memory as a number of different variables. That is a Union offers a way for a section of memory to be treated as a variable of one type on one occasion and as a different variable of a different type on another occasion. Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members. Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members. Example: union exforsys_t { char c; int i;

float f; } exforsys;

Defines three elements: exforsys.c exforsys.i exforsys.f Each one with a different data type. Since all of them are referring to the same location in memory, the modification of one of the elements will affect the value of all of them. We cannot store different values in them independent from each other. 22 What do you mean by dynamic initialization of variables? C++ permits initialization of the variables at run-time. This is referred to asdynamic initialization of variables.In C++ ,a variable can be initialized at run-time using expressions at the placeof declaration as,........int n =strlen(string);..float area=3.14*rad*rad;Thus declaration and initialization is done simultaneously at the place where the variables is used for the first time. 23 Differences between struct in C and classes in C++ In C++, a structure is a class defined with the struct keyword.[1] Its members and base classes are public by default. A class defined with the class keyword has private members and base classes by default.. 24 25 What Is A Meta-Class? A Meta-Class is a class\' class. If a class is an object, then that object must have a class (in classical OO anyway). Compilers provide an easy way to picture MetaClasses 26 Is A Class An Object? In C++ no, because C++ classes are not instances of an accessible class (a

Meta-Class) and because C++ classes are not accessible to programs. Classes are objects in 3 Level Systems and above because classes are instances of meta-classes. But classes play a dual role, because objects can only be declared to be instances of a class (and class objects instances of a meta-class). In 1 Level (single-hierarchy) systems, all classes are objects.

27 Is An Object A Class? In a Level 3 System and above yes, but only instances of a Meta-Class are Classes. Instances of a Class (ordinary objects) are not classes (excluding hybrid systems). However, all objects may be classes in single hierarchy systems, since any object may act as a class (provide object instantiation or act as a shared parent).

28 What is static member of class? A static member belongs to the class rather than to the instances of the class. In C# data fields, member functions, properties and events can be declared static. When any instances of the class are created, they cannot be used to access the static member. To access a static class member, use the name of the class instead of an instance variable Static methods and Static properties can only access static fields and static events. Like: int i = Car.GetWheels; Here Car is class name and GetWheels is static property. Static members are often used to represent data or calculations that do not change in response to object state.

29 What is the property of class? Property is a member that provides access to an attribute of an object or a class. Examples of properties include the length of a string, the size of a font, the caption of a window, the name of a customer, and so on.

30 What is an Interface? An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. 31 what is an inline function ? An inline function is a function that is expanded in line when it is invoked. That is compiler replaces the function call with the corresponding function code. The inline functions are defined as Inline function-header { function body } 32 What Is Dynamic Binding? Binding refers to the linking of a function call to the code to be executed in response to the call. Dynamic Binding means that the code associated with the given function call is not known until the time of call at runtime. A Function call associated with a polymorphic reference depends on dynamic type of that reference. 33 Is There A Difference Between Being A Member Or Instance Of A Class? Yes (but be careful of context). To use C++ terminology, an object (not a reference) is defined to be an instance of exactly one class (in classical OO), called its most derived class. An object not directly contained in any other is called the complete object .An object is a member of several classes, including all of the classes its declared (or most derived) class inherits from. With static typing and inclusion polymorphism based on class, if a polymorphic object (or reference) is made to refer to an object, that object must be a member of the polymorphic object\'s class.

34 What Is The Difference Between Static And Dynamic Typing? Static typing refers to types declared in a program at compile-time, so no type information is available on objects at run-time. Dynamic typing uses the inherent types of polymorphic objects, keeping track of the types of objects at run-time. Statically typed dynamic binding is a compromise (usually implemented with tables of function pointers and offsets), and is how statically-typed OO languages provide polymorphism. Some approaches provide both static and dynamic typing, sometimes with static typing providing type-safe programs and dynamic typing providing multiple-polymorphism

Static typing is more efficient and reliable, but loses power. Typical restrictions include only allowing a common set of base class functions (or any common functions for the more general subtyping or parametric polymorphic cases) to be available on formal objects and a lack of multiple-polymorphism both of which are overcome with dynamic typing.

35 What is the difference between abstract class and interface? We use abstract class and interface where two or more entities do same type of work but in different ways. Means the way of functioning is not clear while defining abstract class or interface. When functionality of each task is not clear then we define interface. If functionality of some task is clear to us but there exist some functions whose functionality differs object by object then we declare abstract class. We can not make instance of Abstract Class as well as Interface. They only allow other classes to inherit from them. And abstract functions must be overridden by the implemented classes. Here are some differences in abstract class and interface

PART-B 1 Explain in detail about Structure with syntax and write example program. (16) 2 (a)Define Union. Explain with example program. (8) (b)Explain in detail about Bit -Field Structures. (8) 3. (a)Define Member Function and explain in detail about function inside the class body with example program . (8) (b)What is Parameterized constructor? Give syntax and example program (8) 4. Define Member Function and explain in detail about function outside the class body with example program. (16) 5. (a)What is Default constructor? Give syntax and example program (8) (b)What is Copy constructor? Give syntax and example program (8)

6. Write short notes on a. Static Member function (8) b. This Pointer (8) 7. What is Destructor? Give syntax and example program (16) 8. Write short notes on a. Classes with necessary syntax and example program (8) b. Reference Semantics (8)

Read more: 600206 - OOPS - Anna University Engineering Question Bank 4 U http://questionbank4u.in/questionanswer.php?course=14&semester=58&subject=148&listid=560 #ixzz1lDJ4S7Ho Under Creative Commons License: Attribution Enter to win a free tech book 101 Free Tech Books
UNIT III

PART A 1. How is it that polymorphism enables you to program in the general rather than in the specific. Discuss the key advantages of programming Polymorphism enables the programmer to concentrate on the processing of common operations that are applied to all data types in the system without going into the individual details of each data type. The general processing capabilities are separated from the internal details of each type. 2. What Is Polymorphism? What are its types? Polymorphism is a ubiquitous concept in object-oriented programming and is defined in many ways, so many definitions are presented from: Websters\', Author, Strachey, Cardelli and Wegner, Booch, Meyer, Stroustrup, and Rumbaugh. Polymorphism is often considered the most powerful facility of an OOPL. . They are Function overloading

Operator overloading

3. What is Pure-Polymorphism? When a method is declared as abstract/virtual method in a base class and which is overridden in a base class. If we create a variable of a type of a base class and assign an object of a derived class to it, it will be decided at a run time, which implementation of a method is to be called.This is known as Pure-Polymorphism or Late-Binding. 4. What Are Multi-Methods And Multiple-Polymorphism? Multi-methods involve two primary concepts, multiple-polymorphism and lack of encapsulation. These issues are orthogonal. Multiple-polymorphism implies more than one parameter can be used in the selection of a method. Lack of encapsulation implies all arguments can be accessed by a multi-method (although packages can be used to restrict access, as in CLOS). Multimethods can also imply a functional prefix notation, although the CLOS designers (who coined the term \"multi-method\") consider the functional and receiver based forms (messages) equivalent.

5. What Is Specialization/Generalization/Overriding? To create a subclass is specialization, to factor out common parts of derived classes into a common base (or parent) is generalization .Overriding is the term used in C++ for redefining a method in a derived class, thus providing specialized behavior. All routines in Smalltalk are overridable and non\"frozen\" features in Eiffel can be \"redefined\" in a derived class. Whenever a method is invoked on an object of the base class, the derived class method is executed overriding the base class method, if any. 6. What is Overriding? A process of creating different implementation of a method having a same name as base class, in a derived class. It implements Inheritance.

7. What is constructor A special function Always called whenever an instance of the class is created. Same name as class name No return type Automatically call when object of class is created Used to initialize the members of class class Test { int a,b; Test() { a=9; b=8; } };

Here Test() is the constructor of Class Test.

8. How a base class method is hidden?? 9. What is the difference between break & continue statements? Break: We can force immediate termination of a loop, bypassing the conditional, the loop expression & any remaining code in the body of the loop. When a break statement is encountered

in a loop, the loop is terminated & the program control resumes at the next statement following the loop. Continue: useful to force early termination. it continue running the loop, but stop processing the remainder of the code in its body for this particular iteration 10. What is method overloading? In C++, method overloading and method overriding are two different features to support objectoriented programming. Method overloading is the ability for functions of the same name to be defined as long as these methods have different signatures; method overriding is the ability of the inherited class rewriting the virtual method of the base class.

11. Can constructors have parameters? Yes, constructors can have parameters. so we can overload it. 12. What is friend function? As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be listed in the class definition. 13. Distinguish between static binding and dynamic binding. Explain the use of virtual functions and the vtable in dynamic binding. 14. What is Function overloading? Give an example. Function overloading means we can use the same function name to create functionsthat perform a variety of different tasks.Eg: An overloaded add ( ) function handles different data types as shown below.// Declarations i. int add( int a, int b); //add function with 2 arguments of same type ii. int add( int a, int b, int c); //add function with 3 arguments of same type iii. double add( int p, double q); //add function with 2 arguments ofdifferent type//Function callsadd (3 , 4); //uses prototype ( i. )add (3, 4, 5); //uses prototype ( ii. )add (3 , 10.0); //uses prototype ( iii. )

15. What are Overloaded function selection algorithms?

16. What is Operator overloading? C++ has the ability to provide the operators with a special meaning for a data type. This mechanism of giving such special meanings to an operator is known as Operator overloading. It provides a flexible option for the creation of new definitions for C++ operators. 17. List out the Operators that cannot be overloaded. Class member access operator (. , .*) Scope resolution operator (::) Size operator ( sizeof ) Conditional operator (?:)

18. What is the purpose of using Operator function? Write its syntax. To define an additional task to an operator, we must specify what it means in relation to the class to which the operator is applied. This is done by Operator function , which describes the task. Operator functions are either member functions or friend functions. The general form is return type classname :: operator (op-arglist ) { function body } where return type is the type of value returned by specified operation. Op-operator being overloaded. The op is preceded by a keyword operator. operator op is the function name.

19. Write at least four rules for Operator overloading. Only the existing operators can be overloaded. The overloaded operator must have at least one operand that is of user defined data type. The basic meaning of the operator should not be changed. Overloaded operators follow the syntax rules of the original operators. They cannot be overridden. 20. How will you overload Unary & Binary operator using member functions?

When unary operators are overloaded using member functions it takes no explicit arguments and return no explicit values. When binary operators are overloaded using member functions, it takes one explicit argument. Also the left hand side operand must be an object of the relevant class.

21. How will you overload Unary and Binary operator using Friend functions? When unary operators are overloaded using friend function, it takes one reference argument (object of the relevant class)When binary operators are overloaded using friend function, it takes two explicit arguments 22. How an overloaded operator can be invoked using member functions? In case of Unary operators, overloaded operator can be invoked as op object_name or object_name op In case of binary operators, it would be invoked as Object . operator op(y) where op is the overloaded operator and y is the argument.

23. How an overloaded operator can be invoked using Friend functions? In case of unary operators, overloaded operator can be invoked asOperator op (x);In case of binary operators, overloaded operator can be invoked asOperator op (x , y)

24. List out the operators that cannot be overloaded using Friend function. Assignment operator = Function call operator ( ) Subscripting operator [ ] Class member access operator

25. What is meant by Overloading Operators? C++ overloading is the mechanism by which the language standard operators are used for customized operations of the classes. For example if we are trying to write a string class, we

would very simply ask for \"+\" operator to handle string concatenation, \"-\" for removing one part of string from another etc., This will put the users at ease. They need not worry about the internal handling of string operations or memory allocations. Instead they can start writing cleaner code concentrating only on the application functionality. Code Reusability becomes easier. That is what, is the only problem/drawback with c++ overloading. These operators can be overloaded globally or on a class-by-class basis. Overloaded operators are implemented as functions and can be member functions or global functions. 26. What is meant by iterator in C++ Iterators Iterators are pointer-like objects that allow programs to step through the elements of a container sequentially without exposing the underlying representation. Iterators can be advanced from one element to the next by incrementing them. Some iterators can also be decremented or allow arbitrary jumps from one element to another, as we will see later. When they are dereferenced, iterators yield a reference to a container element. In addition, they can be compared to each other for equality or inequality.An iterator in C++ is a concept that refines the iterator design pattern into a specific set of behaviors that work well with the C++ standard library . 27. How are iterators are classified into five categories ? according to their abilities, iterators are classified into five categories: Iterator Category Description Providers input_iterator Read values with forward movement. These can be incremented, compared, and dereferenced. istream output_iterator Write values with forward movement. These can be incremented and dereferenced. ostream, inserter forward_iterator Read or write values with forward movement. These combine the functionality of input and output iterators with the ability to store the iterators value. bidirectional_iterator Read and write values with forward and backward movement. These are like the forward iterators, but you can increment and decrement them. list, map, multimap, set, multiset random_access_iterator Read and write values with random access. These are the most powerful iterators, combining the functionality of bidirectional iterators with the ability to do pointer arithmetic and pointer comparisons. array, deque, string, vector

28. What are the types associated with an iterator? There are two types that might vary depending on the iterator type: The Distance Type An operation like advance() obviously needs an argument that indicates how far to advance the iterator .

The Value Type An iterator can be dereferenced. It then returns a reference to a value stored in a container. The type of this referenced value also depends on the respective iterator 29. What is meant by Trivial Iterator A Trivial Iterator is an object that may be dereferenced to refer to some other object. Arithmetic operations (such as increment and comparison) are not guaranteed to be supported. 30. What is meant by Input Iterator An Input Iterator is an iterator that may be dereferenced to refer to some object, and that may be incremented to obtain the next iterator in a sequence. Input Iterators are not required to be mutable. 31. What is meant by Containers The C++ Containers (vectors, lists, etc.) are generic vessels capable of holding many different types of data. Containers can hold standard objects (like the int in the above example) as well as custom objects, as long as the objects in the container meet a few requirements: The object must have a default constructor, an accessible destructor, and an accessible assignment operator.

PART -B 1 (a)Write short notes on Abstract Data Type (ADT) Conversions.(8) (b)Explain in detail about Unary Operator Overloading with example program. (8)

2 (a)Explain in detail about Binary Operator Overloading with example program.(8) (b)Define Function selection algorithm. Explain it with one example program. (8) 3 (a)Explain in detail about Pointer Operators.(8) (b).Explain in detail about Pointer to class member with example program (8) 4 (a)Explain in detail about Friend Function with example program.(8) (b)Discuss about the Over loadable Operators. (8)

Read more: 600206 - OOPS - Anna University Engineering Question Bank 4 U http://questionbank4u.in/questionanswer.php?course=14&semester=58&subject=148&listid=561 #ixzz1lDJGh4cm Under Creative Commons License: Attribution Enter to win a free tech book 101 Free Tech Books
UNIT IV

PART A 1 What is Generic programming? Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters. C++ has can support Generic Programming very well through its template system, but to fully express the ideas of Generic Programming in C++ one must use a variety of template techniques. This document describes many of these techniques, which are used by nearly all generic libraries written in C++. 2 What is Function Template? C++ Function templates are those functions which can handle different data types without separate code for each of them. For a similar operation on several kinds of data types, a programmer need not write different versions by overloading a function. It is enough if he writes a C++ template based function

3 What is Class Template?

C++ Class Templates are used where we have multiple copies of code for different data types with the same logic. If a set of functions or classes have the same functionality for different data types. One good area where this C++ Class Templates are suited can be container classes. 4 How to declare C++ Class Templates ? Declaration of C++ class template should start with the keyword template. A parameter should be included inside angular brackets. The parameter inside the angular brackets, can be either the keyword class or typename. This is followed by the class body declaration with the member data and member functions. What are Streams? What are Streams? Advantages of C++ Class Templates: 5 One C++ Class Template can handle different types of parameters. Compiler generates classes for only the used types. If the template is instantiated for int type, compiler generates only an int version for the c++ template class. Templates reduce the effort on coding for different data types to a single set of code. Testing and debugging efforts are reduced.

6 What are the streams ? The stream is the central concept of the iostream classes. stream\'s characteristics are determined by its class and by customized insertion and extraction operators. A stream is an object where a program can either insert or extract characters to or from it. The standard input and output stream objects of C++ are declared in the header file iostream. 7 What is Standard Input Stream? Generally, the device used for input is the keyboard. For inputting, the keyword cin is used, which is an object. The overloaded operator of extraction, >>, is used on the standard input stream, in this case: cin stream. Syntax for using the standard input stream is cin followed by the operator >> followed by the variable that stores the data extracted from the stream.

For example:

int prog; cin >> prog;

8 What are Manipulators? Setw, endl are known as manipulators.Manipulators are operators that are used to format the display. The endl manipulatorwhen used in an output statement causes a linefeed to be inserted and its effect is similarto that of the newline character\\n. Eg: Cout<<setw(5)<<sum<<endl;

9 What are the types of Manipulators? endl Manipulator: This manipulator has the same functionality as the \\n newline character.

For example:

cout << \"Exforsys\" << endl; cout << \"Training\";

produces the output: Exforsys Training

setw Manipulator: This manipulator sets the minimum field width on output. The syntax is: setw(x) Here setw causes the number or string that follows it to be printed within a field of x characters wide and x is the argument set in setw manipulator. The header file that must be included while using setw manipulator is <iomanip.h>

#include <iostream.h> #include <iomanip.h>

void main( ) { int x1=12345,x2= 23456, x3=7892; cout << setw(8) << Exforsys << setw(20) << Values << endl << setw(8) << E1234567 << setw(20)<< x1 << end << setw(8) << S1234567 << setw(20)<< x2 << end << setw(8) << A1234567 << setw(20)<< x3 << end; }

The output of the above example is: setw(8) setw(20)

Exforsys Values E1234567 12345 S1234567 23456 A1234567 7892 setfill Manipulator: This is used after setw manipulator. If a value does not entirely fill a field, then the character specified in the setfill argument of the manipulator is used for filling the fields.

#include <iostream.h> #include <iomanip.h> void main( ) { cout << setw(10) << setfill(\'$\') << 50 << 33 << endl; }

The output of the above program is $$$$$$$$5033 This is because the setw sets 10 width for the field and the number 50 has only 2 positions in it. So the remaining 8 positions are filled with $ symbol which is specified in the setfill argument. setprecision Manipulator: The setprecision Manipulator is used with floating point numbers. It is used to set the number of digits printed to the right of the decimal point. This may be used in two forms: fixed scientific

These two forms are used when the keywords fixed or scientific are appropriately used before the setprecision manipulator. The keyword fixed before the setprecision manipulator prints the floating point number in fixed notation. The keyword scientific before the setprecision manipulator prints the floating point number in scientific notation.

#include <iostream.h> #include <iomanip.h> void main( ) { float x = 0.1; cout << fixed << setprecision(3) << x << endl; cout << sceintific << x << endl; }

The above gives ouput as: 0.100 1.000000e-001

10 What uis meant by function adaptors A function adaptor is an instance of a class that adapts a namespace-scope or member function so that the function can be used as a function object. A function adaptor may also be used to alter the behavior of a function or function object .Each function adaptor defined by the Standard C++ Library provides a constructor that takes a namespace-scope or member function. The adaptor also defines a function call operator that forwards its call to that associated global or member function.

PART B

1 What is generic programming? What are its advantages and state some of its Applications? (16) 2 What is Function template? Write a suitable example program. (16) 3 (a)Explain how the compiler process calls to a function template. (8) (b)Explain overloaded function templates. With suitable example program. (8) 4 (a)Explain multiple arguments function templates. (8) (b)Define user defined template arguments. (8) 5 What is a class template? Explain the syntax of a class template with suitable program. (16) 6 (a)Draw console stream class hierarchy and explain its members. (8) (b)Explain the various methods of performing formatted stream I/O operations. (8) 6. What are manipulators? List the various predefined manipulators supported by c++ a. I/O streams. (8) b. Explain how standard manipulators are implemented. (8)

Read more: 600206 - OOPS - Anna University Engineering Question Bank 4 U http://questionbank4u.in/questionanswer.php?course=14&semester=58&subject=148&listid=562 #ixzz1lDJO8LIW Under Creative Commons License: Attribution Enter to win a free tech book 101 Free Tech Books
UNIT V

UNIT V INHERITANCE PART A

1. What do you mean by pure virtual functions? 2. What is a Virtual Functions in class? A virtual function is a member function of the base class and which is redefined by the derived class. When a derived class inherits the class containing the virtual function, it has ability to redefine the virtual functions.

A virtual function has a different functionality in the derived class according to the requirement. The virtual function within the base class provides the form of the interface to the function. Virtual function implements the philosophy of one interface and multiple methods . 3. What are the advantages of inheritance? It permits code reusability. Reusability saves time in program development. It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional. 4. Distinguish between inheriting interface and inheriting implementation. How do inheritance hierarchies designed for inheriting interface differ from those designed for inheriting implementation? 5. Distinguish between virtual functions and pure virtual functions 6. Why Use Inheritance? Inheritance is a natural way to model the world or a domain of discourse, and so provides a natural model for OOA and OOD (and even OOP).This is common in the AI domain, where semantic nets use inheritance to understand the world by using classes and concepts for generalization and categorization, by reducing the real-world\'s inherent complexity. Inheritance also provides for code and structural reuse. In the above Computer class diagram, all routines and structure available in class Computer are available to all subclasses throughout the diagram. All attributes available

in Personal computers are also available to all of its subclasses. This kind of reuse takes advantage of the is-a-kind-of relationship .Class libraries also allow reuse between applications, potentially allowing order-of-magnitudeincreases in productivity and reductions in defect rates (program errors), as library classes have already been tested and further use provides further testing providing even greater reliability.

7. Define inheritance? Inheritance provides a natural classification for kinds of objects and allows for the commonality of objects to be explicitly taken advantage of in modelingand constructing object systems. Natural means we use concepts, classification, and generalization to understand and deal with the complexitiesof the real world. Inheritance is the process by which objects of one class acquire the properties of another class. It supports the concept of hierarchical classification. It provides the idea of reusability. We can add additional features to an existing class without modifying it by deriving a new class from it.

8. Define multiple inheritance? Multiple Inheritance occurs when a class inherits from more than one parent. For example, a person is a mammal and an intellectual_entity, and a document may be an editable_item and a kind of literature.

9. What Is Dynamic Inheritance? Dynamic inheritance allows objects to change and evolve over time. Since base classes provide properties and attributes for objects, changing base classes changes the properties and attributes of a class. A previous example was a window changing into an icon and then back again, which involves changing a

base class between a window and icon class. 10. What is Inheritance? Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class.

11. What is hierarchical inheritance? If a number of classes are derived from a single base class then it is called hierarchical inheritance 12. What is multilevel inheritance? If a class is derived from a class, which in turn is derived from another class, is called multilevel inheritance. This process can be extended to any number of levels. Eg: Base class Grand father Intermediate Base class Father Derived class Child 13. What is hybrid inheritance? It is the combination of one or more types of inheritance. Multilevel inheritance Multiple inheritance The class result will have both the multilevel and multiple inheritances. Student Arts Engineering M e d i c a l CSE ECE Civil AB Student Test Result Sports

14. What is meant by single inheritance? If a single class is derived from a single base class is called single inheritance. Eg: Base class Derived class Here class A is the base class from which the class D is derived. Class D is the public derivation of class B hence it inherits all the public members of B. But D cannot access private members of B. 15. Explain some characteristics of inheritance. Some important aspects of inheritance are:

Inheritance is transitive. If C is derived from B, and B is derived from A, then C inherits the members declared in B as well as the members declared in A. A derived class extends its direct base class. A derived class can add new members to those it inherits, but it cannot remove the definition of an inherited member.

Constructors and destructors are not inherited, but all other members are, regardless of their declared accessibility. However, depending on their declared accessibility, inherited members might not be accessible in a derived class.

A derived class can hide inherited members by declaring new members with the same name or signature. Note however that hiding an inherited member does not remove that member; it merely makes that member inaccessible in the derived class.

An instance of a class contains a set of all instance fields declared in the class and its base classes, and an implicit conversion exists from a derived class type to any of its base class types. Thus, a reference to an instance of some derived class can be treated as a reference to an instance of any of its base classes.

A class can declare virtual methods, properties, and indexers, and derived classes can override the implementation of these function members. This enables classes to exhibit polymorphic behavior wherein the actions performed by a function member invocation varies depending on the run-time type of the instance through which that function member is invoked

Access specifiers 16. What is two types of access specifiers ? public and private are access specifiers. There is one other access specifier: protected 17. What are the differences between the Accesses specifies public ,private and protected? Public variables, are variables that are visible to all classes. Private variables, are variables that are visible only to the class to which they belong.

Protected variables, are variables that are visible only to the class to which they belong, and any subclasses. Deciding when to use private, protected, or public variables is sometimes tricky. You need to think whether or not an external object (or program), actually needs direct access to the information. If you do want other objects to access internal data, but wish to control it, you would make it either private or protected, but provide functions which can manipulate the data in a controlled way

18. Explain the syntax for declaring of access specifiers The syntax of access specifiers is as follows:

access_specifier: //access_specifier data new_access_specifier: //new_access_specifier data . 19. Explain the syntax for declaring the derived class

20. What are the different forms of Inheritance supported by C++? 21. What is Visibility mode? In C++, while doing inheritance we are using the Visibility mode, it can be either private or public. If it is private we cannot acess any of the members of base class, So there is no inheritance. 1. When the base class is privately inherited by the derived class,public members of the base class becomes private members of the derived class. 2. When the base class is publicly inherited,public members of the base class become public members of the derived class.

3. When a base class is derived in protected mode,both the public and protected members of the class become protected members of the derived class.

22. What are the different inheritance Visibility modes supported by C++? 1. Visibility Modifier : 1. Public : A member declared as public is accessible by the member functions within its class and any class that derives it. 2. Private : A member declared as private is accessible by the member functions of its class only. 3. Protected : A member declared as protected is accessible by the member functions within its class and any class immediately derived from it.

23. Give any two Benefits of Inheritance Reusability:

Inheritance helps the code to be reused in many situations. The base class is defined and once it is compiled, it need not be reworked. Using the concept of inheritance, the programmer can create as many derived classes from the base class as needed while adding specific features to each derived class as needed.

Saves Time and Effort:

The above concept of reusability achieved by inheritance saves the programmer time and effort. Since the main code written can be reused in various situations as needed.

Increases Program Structure which results in greater reliability.

Polymorphism

24. What are virtual Functions? C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes . The whole function body can be replaced with a new set of implementation in the derived class. 25. Give the syntax of virtual function? Virtual functio Virtual functions are member functions declared with the keyword virtual. For example, the general syntax to declare a Virtual Function uses:

class classname //This denotes the base class of C++ virtual function { public: virtual void memberfunctionname() //This denotes the C++ virtual function { ............. ............ } };

26. What are the properties of C++ Virtual Function C++ virtual function is, A member function of a class

Declared with virtual keyword Usually has a different functionality in the derived class A function call is resolved at run-time

27. What is the reason for using C++ Virtual Function : The most prominent reason why a C++ virtual function will be used is to have a different functionality in the derived class. For example a Create function in a class Window may have to create a window with white background. But a class called CommandButton derived or inherited from Window, may have to use a gray background and write a caption on the center. The Create function for CommandButton now should have a functionality different from the one at the class called Window 28. What is the difference between a non-virtual c++ member function and a virtual member function The difference between a non-virtual c++ member function and a virtual member function is, the non-virtual member functions are resolved at compile time. This mechanism is called static binding. Where as the c++ virtual member functions are resolved during run-time. This mechanism is known as dynamic binding. 29. Define Pure Virtual Function? Pure Virtual Function is a Virtual function with no body. A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero. class Shape { public: virtual void draw() = 0; }; 30. Give the syntax of Pure Virtual Functions? Since pure virtual function has no body, the programmer must add the notation =0 for declaration of the pure virtual function in the base class. General Syntax of Pure Virtual Function takes the form:

class classname //This denotes the base class of C++ virtual function { public: virtual void virtualfunctioname() = 0 //This denotes the pure virtual function in C++ };

31. Why might you declare a pure virtual function and also write a definition (body)? Give as many reasons or situations as you can. There are three main reasons you might do this. #1 is commonplace, #2 is pretty rare, and 3 is a workaround used occasionally by advanced programmers working with weaker compilers.

32. Give any two rules for Virtual functions Rules for Using Virtual Functions Here is a set of rules for using the technique demonstrated above to create smart and powerful hierarchies of objects. It\'s as complete a set of rules as I\'ve been able to deduce from my use of this technique so far: 1. The final ancestor (\"base class\" in C++ terminology) must have a property called _me which stores a reference its final \"descendant\" in the hierarchy.

2. The new scripts of all inherited objects must pass either a reference to themselves or their descendants downward to the new scripts of their ancestors. 3. Give birth to your ancestor before doing anything else in a new script. (Gee, Freud would have a field day with this terminology!) 4. Always use the _me of me to call scripts within the same object, or scripts that could be overridden by an object\'s descendants. 5. Always use ancestor to explicitly call the scripts of your ancestors. Never use the syntax \"the ancestor of me\" to do this, since it won\'t call the scripts you expect in objects that have long chains of descendants. 6. Be very careful in using the value of _me during new scripts. Remember that _me won\'t refer to a useable, complete object until after all new scripts are done executing. Specifically, none of an object\'s \"descendants\" will have their ancestor property set up yet, because the ancestors are still in the middle of being created. It appears to be okay to store the value of _me for later use during a new script (such as adding it to the actorList) but otherwise use _me with extreme caution within new scripts.

33. Distinguish between virtual functions and pure virtual functions stinguish between virtual functions and pure virtual functions A virtual function must have a definition in the class in which it is declared. A pure virtual function does not provide a definition. Classes derived directly from the abstract class must provide definitions for the inherited pure virtual functions in order to avoid becoming an abstract base class

34. What are Abstract Classes? An abstract class is a class that is designed to be specifically used as a base class. An abstract class contains at least one pure virtual function. You declare a pure virtual function by using a pure specifier (= 0) in the declaration of a virtual member function in the class declaration. The following is an example of an abstract class: class AB { public:

virtual void f() = 0; };

35. What are Exceptions? Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers.

To catch exceptions we must place a portion of code under exception inspection. This is done by enclosing that portion of code in a try block. When an exceptional circumstance arises within that block, an exception is thrown that transfers the control to the exception handler. If no exception is thrown, the code continues normally and all handlers are ignored.

A exception is thrown by using the throw keyword from inside the try block. 36. What is Exception Handling? Exception handling is a mechanism that separates code that detects and handles exceptional circumstances from the rest of your program. Note that an exceptional circumstance is not necessarily an error. When a function detects an exceptional situation, you represent this with an object. This object is called an exception object. In order to deal with the exceptional situation you throw the exception

37. What is meant by RTTI (Run-Time Type Information, Run-Time Type Identification refers to a C++ system that keeps information about an object\'s data type in memory at runtime. Run-time type information can apply to simple data types, such as integers and characters, or to generic objects. This is a C++ implementation of a more generic concept called reflection. Run Time Type Identification (RTTI) provides some information about objects at run time such as the name of its type. 38. What are the applications of Applications of RTTI There are many possible applications of RTTI, but two of them are , (i)persistency and

(ii)application generators 39. Define Persistency Persistency means, that these objects can be saved to permanent storage i.e. a file and later the program will be able to restore the original state from that file. 40. List the various of Applications of Persistency Saving and Loading Applications Data Distributed applications Saving and Loading the Current State of the Application Configuring Applications

41. Define Application Generators Application Generators are program development tools making the program development process quick and easy. They provide a set of components and a nice graphical user interface, where someone can build an application by adding and configuring components. 42. What are the advantage of Application Generators. The main advantage of such systems, that the developer does not need deep programming knowledge and the application can be built quickly 43. What are the disadvantage of Application Generators. It has two disadvantages: a. lower performance and b. limited capabilities.

PART B 1. (a) What are the differences between the accesses specifies private and protected? (8) (b)What are base and derived classes? Write a program to use these classes. (8)

2. (a)What are the different forms of inheritance? Explain with an example. (8) (b)What is class hierarchy? Explain how inheritance helps in building class hierarchies. (8) 3. What is visibility mode? What are the different visibility modes supported by C++? (16) 4.What are the differences between inheriting a class with public and private visibility mode? (16) 5. (a)What are virtual classes? Explain the need for virtual classes while building class. (8) (b) What are abstract classes? Explain the role of abstract class while building a class Hierarchy. (8) 6. Discuss cost and benefits of inheritance(16). 7.(a) Justify the need for virtual functions in C++.(8) (b). what are the rules that need to be kept in mind in deciding virtual functions? (8) 8. (a) Explain code reuse with suitable example.(8) (b) Explain the details about runtime type identifications with suitable example program. (8) 9.Explain the details about exception handling.(16) 10.What are virtual functions? Describe a circumstance in which virtual functions would be appropriate.

Read more: 600206 - OOPS - Anna University Engineering Question Bank 4 U http://questionbank4u.in/questionanswer.php?course=14&semester=58&subject=148&listid=563 #ixzz1lDJcp6tP Under Creative Commons License: Attribution Enter to win a free tech book 101 Free Tech Books

Potrebbero piacerti anche