Professional Documents
Culture Documents
PART-A 2 Marks
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
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.
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,
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>
int main ()
{
int var1;
char var2[10];
return 0;
}
When the above code is compiled and executed, it produces result something as follows:
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.
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;
Output:
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.
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
#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
#include <iostream>
using namespace std;
int main()
{
int low, high, i, flag;
cout << "Prime numbers between " << low << " and " << high << " are: ";
if (flag == 0)
cout << low << " ";
++low;
}
return 0;
}
Output