CS 6301 – PROGRAMMING AND DATA STRUCTURES II
CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
II YR / III SEM
QUESTION BANK
UNIT 1
1. Define object oriented programming?
OOP is an approach that provides a way of modularizing programs by creating partitioned memory areas for both data and functions that can be used as an templates for creating copies of such modules on demand.
2. List some features of OOP?
· Emphasis is on data rather than procedures.
· Programs that are divided into what are known as objects.
· Follows bottom – up approach in program design.
· Functions that operate on the data of an object are tried together in the data structure.
3. List out the benefits of OOPS.
· Through inheritance, We can eliminate redundant code and extend the use of existing classes.
· The principle of data hiding helps the programmer to build secure programs.
· It is possible to have multiple instances of an object to co-exist without any interference.
· Object oriented systems can be easily upgraded from small to large systems.
· Software complexity can be easily managed.
4. List out the applications of OOPS.
· Real time systems
· Simulation and modeling
· Object oriented data bases
· AI and expert systems
· Neural networks and Parallel programming
· Decision support and Office automation systems
· CAD/CAM systems.
5. State the difference between c and c++.
CC / C++
C++
(i). This is a Procedural programming language / This is an Object-oriented programming Language
(ii) Global variable can be declared / It is an error to declare a variable as global
(iii) Function prototypes are optional / All functions must be prototyped.
(iv) Local variables can be declared only as Local variables / It can be declared any where
(v) We can call a main() function / within This is not allowed
a program.
6. Define Class?
· A Class is a collection of objects of similar type.
· The classes are user-defined data types and behave like built-in types of a programming language.
· A class is a way to bind the data and its associated functions together.
· A class is a user-defined data type with a template that serves to define its properties.
· A class is a blueprint that defines the variables & the methods common to all objects of a certain kind.
7. What do you mean by object?
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.
8. What is meant by Encapsulation?
The wrapping up of data and function into a single unit(class) is known as Encapsulation.
9. What do you mean by Data abstraction?
Abstraction refers to the act of representation of essential features without including the background details or explanations. Classes use the concept of abstraction & are defined as a list of abstraction attributes such as size, weight & cost & functions to operate on these attributes.
10. What is meant by storage class specifiers?
Storage class specifiers tell the compiler how to store the subsequent variable. There are five storage class specifiers supported by C++:
i. extern ii. static iii.register iv. autov.mutable
11. 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
12. What is the use of static data member?
The static data member informs the compiler that only one copy of the data member exit and all objects of the class should share that variable without duplicating it for each instance of the class.
13. What are the properties of a static data member?
The properties of a static data member are,
· It is initialized to zero when the first object is created and no other initialization is permitted.
· Only one copy of that member is created and shared by all the objects of that class.
· It is visible only within the class, but the life time is the entire program.
·
14. What is a const member function?
If a member function does not alter any data in the class, then we may declare it as a const member function.
e.g. : void getbalance ( ) const;
voidmul(intint) const,;
15. Explain about static member functions.
· A member function can have access to only other static members declared in the same class
· A static member function can be called using the class name as follows
Classname :: function name;
16. What do you mean by constructor?
· Constructor is a member function
· It initializes the objects of its class
· It has the same name as the class
· It is automatically invoked when the objects are created
· It constructs the value of the data members of the class
· It has no return type.
15. Give the various types of constructors.
There are four types of constructors. They are
· Default constructors – A constructor that accepts no parameters
· Parameterized constructors – The constructors that can take arguments
· Copy constructor – It takes a reference to an object of the same class as itself as an argument
· Dynamic constructors – Used to allocate memory while creating objects
17.What does 'this' pointer refer to?
'this' is a pointer that points to the object for which this function was called.
Application of ‘this’ pointer:
It is used to return the object it points to.
Eg: The statement
return *this;
inside a member function will return the object that invoked the function.
18. What are the features required for object oriented language?
• Data encapsulation.
• Data hiding and access mechanisms.
• Automatic initialization and clear up of objects.
• Operator overloading.
• Inheritance.
• Dynamic binding.
19. 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.
20. What is a scope resolution operator?
Scope resolution operator is used to uncover the hidden variables. It also allows access to global version of variables.
Eg:
#include<iostream. h>
int m=10; // global variable m
void main ( )
{
int m=20; // local variable m
cout<”m=”<m<”\n”;
cout<”: : m=”<: : m<”\n”;
}
output:
20
10 (: : m access global m)
21. what is the use of scope resolution operator?
Scope resolution operator is used to define the function outside the class.
Syntax:
Return type <class name> : : <function name>
Eg: Void x : : getdata()
22. Write some special characteristics of constructor.
Some special characteristics of constructor are,
i. They should be declared in the public section.
ii. They are invoked automatically when the objects are created.
iii. They do not have return types, not even void and therefore, and they cannot return values.
iv. They cannot be inherited, though a derived class can call the base class
v. They can have default arguments.
vi. Constructors cannot be virtual function.
16 marks
1. What is a static member and what are common characteristics
2. Explain about pointers with example
3 Explain the basic concepts of Object oriented programming
4 What are the difference between pointers to constants and constant topointers (8)
5. Write a C++ program to illustrate the static function (8)
6. Write a C++ program using this pointer.
UNIT 2
1. What are copy constructors? Explain with example?
The constructor that creates a new class object from an existing object of the same class.Eg:- integer i2(i1) or integer i2 = i1 would define the object i2 at the same time initialize the values of i1.
2. Define Compile time polymorphism / Early Binding / static Binding
Compile time polymorphism is implemented by using the overloaded functions and overloaded operators. The overloaded operators or functions are selected for invokation by matching arguments both by type and number. This information is known to the compiler at the compile time therefore the compiler is able to select the appropriate function for a particular function call at the compile time itself.
This is called as ‘Early Binding’ or ‘Static Binding’ or ‘Static Linking’ or ‘Compile time polymorphism’. Early binding simply means an object is bound to its function call at the compile time.
3. Define Runtime Polymorphism?
At runtime, when it is known what class objects are under consideration, the appropriate version of the function is invoked. Since the function is linked with a particular class much later after its compilation, this process is termed as ‘late binding’. It is also known as dynamic binding because the selection of the appropriate function is done dynamically at run time. This runtime polymorphism can be achieved by the use of pointers to objects and virtual functions.
4. What do you mean by Dynamic constructors?
The constructors can be used to allocate memory while creating objects. This will enable the system to allocate the right amount of memory for each object, thus resulting in saving of memory. Allocation of memory to objects at the time of their construction is known as dynamic construction of objects. The memory is allocated with the help of ‘new’ operator.
5. What is meant by inheritance?
The mechanism of deriving a new class from an old one is called inheritance. The old class is referred to as the base class and the new one is called the derived class or the subclass.
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
}
6. Define operator overloading?
A language feature that allows a function or operator to be given more than one definition. For instance C++ permits to add two variables of user defined types with the same syntax that is applied to the basic types. The mechanism of giving such special meaning to an operator is known as operator overloading.
7. Give the operator in C++ which cannot be overloaded?
· Sizeof ->size of operator
· :: - scope resolution opertor
· ?: - conditional operator
· . - Membership operator
· .* - pointer to member operator
8. Give any four rules for operator overloading?
· Only existing operators can be overloaded.
· The overloaded operator must have at least one operand that is of user defined type.
· We cannot used friend functions to overload certain operators.
· Overloaded operators follow the syntax rules of the original operators.
9. Define function overloading.
A single function name can be used to perform different types of tasks. The same function name can be used to handle different number and different types of arguments. This is known as function overloading or function polymorphism.
10. 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., f or above constructor
int p,q;
cin>p>q;
integer a(p,q);
11. What are the types in inheritance?
· Single inheritance
· Multiple inheritance
· Multilevel inheritance
· Hierarchical inheritance
· Hybrid inheritance
12. What's the difference between public, private, and protected?
· A member (either data member or member function) declared in a private section of a class can only be accessed by member functions and friends of that class
· A member (either data member or member function) declared in a protected section of a class can only be accessed by member functions and friends of that class, and by member functions and friends of derived classes
· A member (either data member or member function) declared in a public section of a class can be accessed by anyone.
13. What do you mean by virtual function?
When we use the same function name in both the base and derived classes, the function in base class is declared as virtual using the keyword virtual preceding its normal declaration.
When a function is made virtual c++ determines which function to use at runtime based on the type of object pointed to by the base pointer, rather than the type of the pointer. Thus by making the base pointer to point to different objects, we can execute different versions of the virtual function.
14. What are the rules for virtual function?
· They cannot be static members
· They are access by using object pointers
· A virtual function can be a friend of another class.
15. What are pure virtual functions? Write the syntax.
A pure virtual function is a function declared in a base class that has no definition relative to the base class. In such cases, the compiler requires each derived class to either define the function or redeclare it as a pure virtual function. A class containing pure virtual functions cannot be used to declare any object of its own. It is also known as “donothing” function.
The “do-nothing” function is defined as follows: virtual void display ( ) =0;
16 MARKS
1. Explain Nested classes with an example
2. Explain the copy constructors with an example? (8)
3. What is operator overloading? How many arguments are required in the definition of an overloaded binary operator?
4. Explain the different types of polymorphism (16)
5 Explain various types of Inheritance.
6. Explain briefly about function overloading with a suitable example
UNIT 3
1. What is an abstract class?
An abstract class is one that is not used to create objects. An abstract class is designed only to act as a base class.