You are on page 1of 11

J.K.K.

NATTRAJA COLLEGE OF ENGINEERING & TECHNOLOGY


Natarajapuram, (Near Erode) Kumarapalayam- 638 183.
Course Code : CS6456 Subject Name: Object Oriented Programming
Dept/Year/Semester: EEE/ II/ VI Academic Year: 2016 - 2017

QUESTION BANK WITH ANSWERS

UNIT -3: VIRTUALIZATION

PART-A 2 Marks

1. Give some characteristics of procedure-oriented language.


i. The characteristics of procedure-oriented language are,
ii. Emphasis is on doing things (algorithms).
ii. Larger programs are divided into smaller programs known as
functions.
iii. Most of the functions share global data.
iv. Data move openly around the system from function to function.
v. It employs top-down approach in program design.

2. List out the basic concepts of OOPS?


The basic concepts of OOPS are,
i. Objects.
ii. Classes.
iii. Data abstraction and Encapsulation.
iv. Inheritance.
v. Polymorphism.
vi. Dynamic binding.
vii. Message passing.

3. Define is an object?
An object is basic run-time entity in an object-oriented system.

4. Define is a class?
A class is a collection of objects of similar type. Once a class has been
defined, we can
create any number of objects belonging to the class. Class is a user-defined
data type and
behaves like built-in types of the programming language.

5. Define is an encapsulation?
Wrapping up of data and function within the structure is called as
encapsulation. The
insulation of data from direct access by the program is called as data hiding

6. Differentiate dynamic binding or late binding?


Dynamic binding means that the code associated with a given
procedure call is not
known until the time of the call at the run-time.
7. Write the process of programming in an object-oriented language?
The process of programming in an object-oriented language are,
i. Create classes that define objects and their behavior.
ii. Creating objects from class definition.
iii. Establishing communication among objects.

8. List any four advantages of OOPS.


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

9. What are the features required for object-based programming


language?
The features required for object-based programming are,
i. Data encapsulation.
ii. Data hiding and access mechanisms.
iii. Automatic initialization and clear up of objects.
iv. Operator overloading.

10. Give any four applications of the OOPS.


The four applications of OOPS are,
i. Real-time systems.
ii. Simulation and modeling.
iii. Object-oriented databases.
iv. AI and expert systems.

11. List out the operators available in C++?


The operators available in C++ are,
i. :: - Scope resolution operator.
ii. :: * - Pointer-to-member declarator .
iii. ->* - Pointer-to-member operator.
iv. .* - Pointer-to-member operator.
v. delete - Memory release operator

12. state default argument?


Default argument assigns a default value to the parameter, which does
not have
matching argument in the function call. Default values are specified when the
function is
declared.
Example:
float amount (float principle, int period, float rate=0. 15)
{
}
13. Define constant argument?
Keyword is const. The qualifier const tells the compiler that the function
should not
modify the argument. The compiler will generate an error when this condition
is violated.
This type of declaration is significant only when we pass arguments by
reference or
pointers
Example:
int strlen (const char *p);

14. definehow create an object?


Once the class has been declared, we can create object for a class
using the class
name.
Example:
classname x; //memory for x is created
15. StateHow the class is specified?
Generally class specification has two parts. They are,
i. Class declaration - It describes the type and scope of its member
ii. Class function definition - It describes how the class functions are
implemented
The general form is:
class class_name
{
private:
variable declarations; function declaration;
public:
variable declaration; function declaration;
};

16. How do you access a class member?


We can access the member function by using the following syntax:
Syntax:
Object-name. Function-name (actual arguments); Example:
x.getdata (100, 75.5);

17. What are the features of static data member?


The features of static data member are,
i. It is initialized to zero when the first object is created
ii. Only one copy of that member is created for the entire class
iii. It is only visible within the class
iv. It is stored separately rather than objects

18. State the situations that inline functions may not work?
The situations that inline functions may not work is,
i. For function returning values, if a loop, a switch, or a goto exists.
ii. For function not returning values, if a return statement exists.
iii. If function contains static variables.
v. If inline functions are recursive.

29. State a namespace? Dec-12


The namespaces are used to group the entities like class, variables,
objects, function
under a name.

20. Define abstract class?


The class that does not specify the implementation details,but specifies
only what are the
operation in the particular data structure.

PART-B
16-MARKS QUESTIONS WITH ANSWERS

1. List out differences between procedure oriented programming and object oriented
Programming. April/May 2016,Nov/Dec-2016,

Procedure Oriented Object Oriented Programming


Programming
Divided In POP, program is divided into In OOP, program is divided into
Into small parts called functions. parts called objects.
Importanc In POP,Importance is not given In OOP, Importance is given to the
e to data but to functions as well data rather than procedures or
as sequence of actions to be functions because it works as
done. a real world.
Approach POP follows Top Down OOP follows Bottom Up
approach. approach.
Access POP does not have any access OOP has access specifiers named
Specifiers specifier. Public, Private, Protected, etc.
Data In POP, Data can move freely In OOP, objects can move and
Moving from function to function in the communicate with each other
system. through member functions.
Expansion To add new data and function in OOP provides an easy way to add
POP is not so easy. new data and function.
Data In POP, Most function uses Global In OOP, data can not move easily
Access data for sharing that can be from function to function,it can be
accessed freely from function to kept public or private so we can
function in the system. control the access of data.
Data POP does not have any proper OOP provides Data Hiding so
Hiding way for hiding data so it is less provides more security.
secure.
Overloadi In POP, Overloading is not In OOP, overloading is possible in
ng
possible. the form of Function Overloading
and Operator Overloading.
Examples Example of POP are : C, VB, Example of OOP are : C++, JAVA,
FORTRAN, Pascal. VB.NET, C#.NET.

2. Explain about pointers with an example. April/May 2016


POINTERS:

C++ pointers are easy and fun to learn. Some C++ tasks are performed more easily with pointers, and
other C++ tasks, such as dynamic memory allocation, cannot be performed without them.
As you know every variable is a memory location and every memory location has its address defined
which can be accessed using ampersand (&) operator which denotes an address in memory. Consider
the following which will print the address of the variables defined:

#include <iostream>

using namespace std;

int main ()
{
int var1;
char var2[10];

cout << "Address of var1 variable: ";


cout << &var1 << endl;

cout << "Address of var2 variable: ";


cout << &var2 << endl;

return 0;
}
When the above code is compiled and executed, it produces result something as follows:

Address of var1 variable: 0xbfebd5c0


Address of var2 variable: 0xbfebd5b6

What Are Pointers?


A pointer is a variable whose value is the address of another variable. Like any variable or
constant, you must declare a pointer before you can work with it. The general form of a pointer variable
declaration is:
type *var-name;

Here, type is the pointer's base type; it must be a valid C++ type and var-name is the name of the
pointer variable. The asterisk you used to declare a pointer is the same asterisk that you use for
multiplication. However, in this statement the asterisk is being used to designate a variable as a
pointer.
Following are the valid pointer declaration:
int *ip; // pointer to an integer
double *dp; // pointer to a double
float *fp; // pointer to a float
char *ch // pointer to character
The actual data type of the value of all pointers, whether integer, float, character, or otherwise, is
thesame, a long hexadecimal number that represents a memory address. The only difference between
pointers of different data types is the data type of the variable or constant that the pointer points to.

Using Pointers in C++:


There are few important operations, which we will do with the pointers very frequently.

(a) we define a pointer variables


(b) assign the address of a variable to a pointer and
(c) finally access the value atthe address available in the pointer variable.

This is done by using unary operator * that returns the value of the variable located at the address specified
by its operand.

Program:

#include <iostream>
using namespace std;
int main ()
{
int var = 20; // actual variable declaration.
int *ip; // pointer variable
ip = &var; // store address of var in pointer variable
cout << "Value of var variable: ";
cout << var << endl;

// print the address stored in ip pointer variable


cout << "Address stored in ip variable: ";
cout << ip << endl;
// access the value at the address available in pointer
cout << "Value of *ip variable: ";
cout << *ip << endl;
return 0;
}

Output:

Value of var variable: 20


Address stored in ip variable: 0xbfc601ac
Value of *ip variable: 20

3. Briefly describe on the objected oriented features supported by C++.


OR
Briefly describe on the objected oriented concepts supported by C++.

Features of Object Oriented Programming (OOP)


FEATURES OF OOP:
1. Object
2. Class
3. Data Hiding and Encapsulation
4. Dynamic Binding
5. Message Passing
6. Inheritance
7. Polymorphism
Brief Explanation of Points:

OBJECT: Object is a collection of number of entities. Objects take up space in the memory. Objects are
instances of classes. When a program is executed , the objects interact by sending messages to one
another. Each object contain data and code to manipulate the data. Objects can interact without having
know details of each others data or code.

CLASS: Class is a collection of objects of similar type. Objects are variables of the type class. Once a
class has been defined, we can create any number of objects belonging to that class. Eg: grapes bannans
and orange are the member of class fruit.
Example:
Fruit orange;
In the above statement object mango is created which belong to the class fruit.
NOTE: Classes are user define data types.

DATA ABSTRACTION AND ENCAPSULATION:


Combining data and functions into a single unit called class and the process is known
as Encapsulation.Data encapsulation is important feature of a class. Class contains both data and
functions. Data is not accessible from the outside world and only those function which are present in the
class can access the data. The insulation of the data from direct access by the program is called data
hiding or information hiding. Hiding the complexity of proram is called Abstraction and only essential
features are represented.In short we can say that internal working is hidden.

DYNAMIC BINDING: Refers to linking of function call with function defination is called binding and when it
is take place at run time called dynamic binding.

MESSAGE PASSING: The process by which one object can interact with other object is called message
passing.

INHERITANCE: it is the process by which object of one class aquire the properties or features of objects
of another class. The concept of inheritance provide the idea of reusability means we can add additional
features to an existing class without Modifying it. This is possible by driving a new class from the existing
one. The new class will have the combined features of both the classes.
Example: Robine is a part of the class flying bird which is again a part of the class bird.
POLYMORPHISM: A greek term means ability to take more than one form. An operation may exhibite
different behaviours in different instances. The behaviour depends upon the types of data used in the
operation.
Example:
Operator Overloading
Function Overloading

4. Distinguish between abstraction and encapsulation.

5. Explain the implementation of ADT with some suitable example

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class stack
{
int stk[5];
int top;
public:
stack()
{
top=-1;
}
void push(int x)
{
if(top > 4)
{
cout <<"stack over flow";
return;
}
stk[++top]=x;
cout <<"inserted" <<x;
}
void pop()
{
if(top <0)
{
cout <<"stack under flow";
return;
}
cout <<"deleted" <<stk[top--];
}
void display()
{
if(top<0)
{
cout <<" stack empty";
return;
}
for(int i=top;i>=0;i--)
cout <<stk[i] <<" ";
}
};

main()
{
int ch;
stack st;
while(1)
{
cout <<"\n1.push 2.pop 3.display 4.exit\nEnter ur choice";
cin >> ch;
switch(ch)
{
case 1: cout <<"enter the element";
cin >> ch;
st.push(ch);
break;
case 2: st.pop(); break;
case 3: st.display();break;
case 4: exit(0);
}
}
return (0);
}

OUTPUTS
1.push 2.pop 3.display 4.exit
Enter ur choice2
stack under flow
1.push 2.pop 3.display 4.exit
Enter ur choice1
enter the element2
inserted2

1.push 2.pop 3.display 4.exit


Enter ur choice1
enter the element3
inserted3

1.push 2.pop 3.display 4.exit


Enter ur choice2
deleted3

1.push 2.pop 3.display 4.exit


Enter ur choice1
enter the element5
inserted5

1.push 2.pop 3.display 4.exit


Enter ur choice3
52

1.push 2.pop 3.display 4.exit


Enter ur choice4
6. Write a C++ program to list out prime numbers between the given two
limits.

#include <iostream>
using namespace std;

int main()
{
int low, high, i, flag;

cout << "Enter two numbers(intervals): ";


cin >> low >> high;

cout << "Prime numbers between " << low << " and " << high << " are: ";

while (low < high)


{
flag = 0;

for(i = 2; i <= low/2; ++i)


{
if(low % i == 0)
{
flag = 1;
break;
}
}

if (flag == 0)
cout << low << " ";

++low;
}
return 0;
}

Output

Enter two numbers(intervals): 20 50 Prime numbers between 20 and 50 are: 23


29 31 37 41 43 47

Explain the merits and demerits of the same

You might also like