Oop QB
Oop QB
Question Bank
Que
Mod
stion Question
ule
Type
1.1 1 Write an example for object oriented programming language?
1.1 1 Which is the property of OOP that means the wrapping up of data and functions into a single unit ?
1.5 1 What is the alternative name given to the output operator in C++?
1.5 1 What is the alternative name given to the input operator in C++?
1.4 1 C++ permits initialization of the variables at run time. What is this type of initializations called?
1.10 1 A function can behave differently in the same program. What is this called?
1.1 2 Define procedure oriented programming? Write down any two of its characteristics?
1.6 2 Write down the synatax of if else statement and nested if?
1.6 2 Write down the syntax of switch statement and nested switch?
1.10 2 What is function prototyping? Write a prototype for a function ‘sum’ with three arguments one of
integer and other two float with a return type integer?
int main()
{
Que
Mod
stion Question
ule
Type
fun();
return
0;
}
1.9 2 Identify the legal function declaration(s) with default arguments?explain?
1.9 2 Consider an overloaded function add(). Identify the proper declaration for the function call add(0.75,
5)? Explain why?
1.9 2 Consider an overloaded function mul(). Identify the proper declaration for the function call mul(6,
5)? Explain why?
1.9 2 Consider an overloaded function sub(). Identify the proper declaration for the function call sub(3.25,
5.5)? Explain why?
Que
Mod
stion Question
ule
Type
(a) int sub(char a, int b);
(b) int sub(float a);
(c) double sub(double a, double b);
(d) double sub(int a,int b);
#include <iostream>
using namespace
std;
int fun(int a, int b = 1, int c =2)
{
return (a + b + c);
}
int main()
{
cout << fun(12,2);
return 0;
}
1.5 2 Analyse the code and predict the
output?why? #include <iostream>
#include <string.h>
using namespace std;
int main()
{
cout << sizeof("Examination") << endl;
cout << strlen( "Examination");
return 0;
}
1.3 2 Analyse the code and predict the
output?why? #include<iostream>
using namespace std;
int main()
Que
Mod
stion Question
ule
Type
{
int x = 1 , y = 1;
cout << ( ++x || ++y ) << endl;
cout << “x=”<<x << endl<< “y=”<<y;
return 0;
}
1.3 2 Analyse the code and predict the
output?why? #include<iostream>
using namespace std;
int main()
{
int x = 1 , y = 1;
cout << ( ++x && ++y ) << endl; cout
<< “x=”<<x << endl<< “y=”<<y;
return 0;
}
1.3 2 Analyse the code and predict the
output?why? #include<iostream>
using namespace std;
int main()
{
int x = 1 , y = 1, z = 1;
cout << ( ++x || ++y && ++z ) << endl;
cout << “x=”<<x << "y= " << y << " z=" << z ; return 0;
}
1.5 2 Analyse the code and predict the
output?why? #include<iostream>
using namespace std;
int x=6;
int main()
{
Que
Mod
stion Question
ule
Type
int x = 10;
cout << "x=" << ::x << endl;
cout << "x=" << x;
return 0;
}
1.3 2 Analyse the code and predict the
output?why? #include <iostream>
using namespace std;
int main()
{
int a = b = c = 0;
cout << a << "*" << b << "*" << c;
return 0;
}
1.3 2 Analyse the code and predict the
output?why? #include <iostream>
using namespace std;
int main()
{
for ( ; ; ) cout << "blank";
return 0;
}
1.6 2 Analyse the code and predict the
output?why? #include <iostream>
using namespace std;
int main()
{
int i;
for (i=0; i<3; i++);
}
1.5 2 Determine the output of the code?explain why?
#include <iostream>
using namespace std;
int main()
{
int i;
i = 1 + (1,4,5,6,3);
cout << i;
return 0;
}
1.5 2 Determine the output of the code?explain
why? #include <iostream>
using namespace std;
int main()
{
int a = 0, b;
b = (a = 50) + 10;
cout << a << "$" << b;
return 0;
}
1.5 2 Determine the output of the code?explain
why? #include<iostream>
using namespace std;
int main()
{
char a = 30, b = 40, c = 10;
char d = (a*b)/c;
cout << int(d);
Que
Mod
stion Question
ule
Type
return 0;
}
1.6 2 Determine the output of the code?explain why?
#include<iostream>
using namespace std;
int main()
{
static int i = 5;
if (--i)
{
cout <<
i; main();
}
return 0;
}
1.6 2 Determine the output of the code?explain
why? #include<iostream>
using namespace std;
int main()
{
int i = 5;
if (--i)
{
cout <<
i; main();
}
return 0;
}
1.6 2 Determine the output of the code?explain
why? #include <iostream>
using namespace std;
Que
Mod
stion Question
ule
Type
int main()
{
int n = 10;
for (int i = 0; i < n; i++ )
{
n++;
continue;
cout<<
n;
}
return 0;
}
1.6 2 Determine the output of the code?explain
why? #include <iostream>
using namespace std;
int main()
{
int n = 10, i;
x:
do
{
cout << "label x"<<
endl; break;
}
while( 0 ) ;
Que
Mod
stion Question
ule
Type
return 1;
}
1.6 2 Determine the output of the code?explain why?
#include <iostream>
using namespace
std;
int main()
{
int choice = 1 ;
switch(choice)
{
cout << "\nFirst
Statement"; case 1 :
cout << "\nInside Switch case 1";
case 2 :
cout << "\nInside Switch case 2";
break;
case 3 :
cout << "\nInside Switch case 3";
break;
default:
cout << "bye bye";
}
return(0);
}
1.5 2 Determine the output of the code?explain why?
#include <iostream>
using namespace
std; int main()
{
Que
Mod
stion Question
ule
Type
cout << sizeof('x')<<endl;
cout << sizeof(char)<<endl;
return 0;
}
1.6 2 Determine the output of the code?explain
why? #include <iostream>
using namespace std;
int main()
{
char m;
switch (m) {
case 'c':
cout << "Computer
Science"; case 'a':
cout <<
"Accoutant"; break;
default:
cout << "wrong choice";
}
return 0;
}
1.5 2 Determine the output of the code?explain why?
#include <iostream>
using namespace
std; int main()
{
int i = 0;
cout << (i = 0 ? 1 : 2 ? 3 : 4);
return 0;
}
1.3 2 Determine the output of the code?explain why?
Que
Mod
stion Question
ule
Type
#include <iostream>
int main()
{
if (0)
std::cout << "hello";
else
std::cout << "world";
return 0;
}
1.3 2 Determine the output of the code?explain why?
#include <iostream>
int main()
{
if (2)
std::cout << "hello";
else
std::cout << "world";
return 0;
}
1.6 3 List the basic control structures in c++?Draw the flowcharts of each?
1.5 3 What are the advantages of using new operator over function malloc()?
1.10 3 What are the steps of function selection by the compiler in function overloading?
1.6 3 List different loop statements used in C?Write down the syntax of each?
1.10 3 Write a c++ program with a function display() which is overloaded such that it can be used to display
integer, character and floating point values?
1.6 3 Write a c++ program to find largest of three numbers using nested if statement?
1.3 3 Write a c++ program to swap two numbers using temporary variables?
1.3 3 Write a c++ program to swap two numbers without using temporary variables?
1.6 3 Write a c++ program to display amstrong numbers between the specified intervals?
1.6 3 Analyse the pattern given below and write a program to display this pattern?
1.5 3 Print the value of y for given x=2 & z=4 and analyze the output.
Que
Mod
stion Question
ule
Type
a. y = x++ + ++x;
b. y= ++x + ++x;
d. y = x>z;
e. y= x>z? x:z;
f. y = x&z;
g. y= z>>2 + x<<1;
1.6 3 Analyse the following inputs and corresponding outputs and write a program to display the same
form given any positive integer as input?
Input Output
123 321
432 234
143 341
112 211
1.6 3 Analyse the following inputs and corresponding outputs and write a program to display the same
form given any two positive integers (n1,n2) as input?
Que
Mod
stion Question
ule
Type
Inputs Output
4,3 3
3,2 2
9,3 3
5,4 4
1.6 3 Analyse the following inputs and corresponding outputs and write a program to display the same
form given any positive integer as input?
Input Output
123 6
432 9
111 3
112 4
1.6 3 Analyse the inputs and corresponding outputs of each inputs given and write a program for the same
without using library functions?
Input
Output A a
B b
.
Que
Mod
stion Question
ule
Type
.
Z z
a A
b B
z Z
1.6 3 Write a C++ program to find the element occurring odd number of times in an array?
1.6 3 Write a c++ program to implement Simple Calculator using switch statement?
1.6 3 Write a c++ program to display prime numbers between two intervals?
1.6 3 Write a c++ program to display amstrong numbers between a specified interval?
1.10 4 Write a c++ program to find area of square, circle , triangle, rectangle using the concept of
polymorphism?explain?
1.4 4 Write a program to swap the values of a pair of integers by using reference variables as
arguments?explain?
2.1 1 List the two parts of class specification?
2.1 1 List any two keywords which can be used as visibility labels?
2.2 1 Write down the format for calling a member function with an example?
2.1 1 What is the difference between a member function and a normal function?
Que
Mod
stion Question
ule
Type
2.4 1 The space for member variables is allocated separately for each object why?
2.4 1 Illustrate how the space for member functions and data members are allocated in the memory?
2.1 2 How can we define a member function outside the class? Write an example?
2.1 2 How can we define a member function inside the class? Write an example?
2.1 2 Write a class declaration with 2 data members a and b as private and two member functions get()
and put() as public?
2.1 2 Write a class declaration with 3 data members a,b and c as private and a member functions sum()
and a friend function display() as public?
2.1 2 Write a class declaration with 3 data members a,b as private, data member c and two member
functions get() and put() as public?
2.1 2 Write a class declaration with a public member function void getdata(int a,float b) and define it
outside the class as inline?
2.1 2 Write a class declaration with a public member function void getdata(int a,float b) and define it
outside the class?
2.1 2 Write a class declaration with a public member function void getdata(int a,float b) and define it inside
the class?
Que
Mod
stion Question
ule
Type
2.8 2 Write a class declaration with 1 data members a as private and a friend function display() as public
create an object o. Also call the function display in the main function?
2.2 2 Write a class declaration with a public member function void getdata(int a,float b) , define it inside
the class, create an object o. Also call the function getdata in the main function?
2.6 2 Write a class declaration with 3 data members a,b as private, data member c and two member
functions get() and put() as public. Also create 5 objects using the concept of array of objects ?
2.2 2 Write a class declaration with 3 data members a,b as private, data member c and two member
functions get() and put() as public. Also create an object ‘o’ of that class?
2.2 2 Analyse the code and predict the output and explain why?
#include<iostream>
using namespace std;
class ABC
{
int a;
float b;
public:
void getdata(int c,float d)
{
a=c;
b=d;
}
};
int main()
{
ABC o;
o.getdata(3,2.3);
cout<<”value:”<<o.a;
}
2.2 2 Analyse the code and predict the output and explain why?
#include<iostream>
Que
Mod
stion Question
ule
Type
using namespace std;
class ABC
{
int a;
float b;
Public:
int a;
void getdata(int c,float d)
{
a=c;
b=d;
}
};
int main()
{
ABC o;
o.getdata(3,2.3);
cout<<”value:”<<o.a;
}
2.2 2 Analyse the code and predict the output and explain why?
#include<iostream>
using namespace std;
class ABC
{
int a;
Public
:
void getdata(int a) ;
}o;
void getdata(int c)
{a=c;
cout<<a;
}
int main()
{ o. getdata(5);}
Que
Mod
stion Question
ule
Type
2.1 2 Analyse the code and predict the output and explain why?
#include<iostream>
using namespace std;
class Test {
int x;
};
int main()
{
Test t;
cout <<
t.x; return
0;
}
2.1 3 Explain two parts of class specification?
2.1 3 Write a class declaration two member functions get() and put() as public with get() defined ouside
the class and put() defined inside the class?
2.8 3 How a friend function is declared? What are the characteristics of friend function?
2.8 3 Write a program to find largest among 2 numbers, the numbers are private members of the class, use
friend function?
2.8 3 Write a program to find sum of 2 numbers, the numbers are private members of the class, use friend
function?
2.8 3 Write a program to find product of 2 numbers, the numbers are private members of the class, use
friend function?
2.8 3 Write a program to find difference of 2 numbers, the numbers are private members of the class, use
friend function?
Que
Mod
stion Question
ule
Type
2.8 3 Write a program to perform division of 2 numbers, the numbers are private members of the class ,use
friend function?
2.8 3 Write a program to perform division of 2 numbers, one number is a private member of class A,
another number is a private member of another class B?
2.8 3 Write a program to perform addition of 2 numbers, one number is a private member of class A,
another number is a private member of another class B?
2.8 3 Write a program to perform subtraction of 2 numbers, one number is a private member of class A,
another number is a private member of another class B?
2.8 3 Write a program to perform multiplication of 2 numbers, one number is a private member of class A,
another number is a private member of another class B?
2.8 3 Write a program to swap 2 numbers, one number is a private member of class A, another number is a
private member of another class B?
2.8 3 Write a program to find largest of 2 numbers, one number is a private member of class A, another
number is a private member of another class B?
2.8 3 Write a program to find mean value of 2 numbers, one number is a private member of class A,
another number is a private member of another class B?
2.8 3 Write a program to find mean value of 2 numbers, the numbers are private members of the class ,use
friend function?
2.8 3 Write a program to find area of a rectangle, the length and breadth are private members of the class
,use friend function?
2.8 3 Write a program to find area of a square, the side is a private member of the class ,use friend
function?
Que
Mod
stion Question
ule
Type
2.8 3 Write a program to find area of a right angled triangle, the sides are private members of the class ,use
friend function?
2.8 4 Write a program to swap two numbers using the concept of reference variables and friend function?
2.2 4 Write a program to find largest of 2 numbers. Use the concept of nesting of member functions?
2.6 4 Write a program to read and display details of 10 cars using the concept of classes and arrays of
objects?
2.6 4 Write a program to read and display details of 10 employees using the concept of classes and arrays
of objects?
2.6 4 Write a program to read and display details of 10 students using the concept of classes and arrays of
objects?
2.3 4 Write a program for processing shopping list using class concept in c++?(The required unctions are:
add an item, display total value, delete an item, display all items)
3.1 1 What are the methods to pass initial values as arguments to the constructor function?
Que
Mod
stion Question
ule
Type
3.3 1 Define dynamic constructors?
3.5 1 Write an example for passing initial values as arguments to the constructor function explicitly?
3.1 1 Write an example for passing initial values as arguments to the constructor function implicitly?
3.3 2 Can we have more than one constructors in a class?if yes, what is that mechanism called?
3.3 2 What are the operators used by dynamic constructors?write its syntax?
Que
Mod
stion Question
ule
Type
3.1 2 Write any 2 features of constructor?
time T2 = T1;
#include <iostream>
using namespace
std;
class construct
{
int a, b;
public:
construct()
{
a = 0;
b = 0;
}
};
int main()
{
construct c;
cout<< "a: "<< c.a << endl << "b: "<< c.b;
Que
Mod
stion Question
ule
Type
return 1;
}
3.1 2 Predict the output and explain why?
#include <iostream>
using namespace
std;
class construct
{
public:
int a, b;
construct()
{
a = 5;
b = 6;
}
};
int main()
{
construct c;
cout<< "a: "<< c.a << endl << "b: "<< c.b;
return 1;
}
3.2 2 Predict the output and explain why?
#include <iostream>
using namespace std;
class construct
{
public:
float
area;
Que
Mod
stion Question
ule
Type
construct()
{
area = 0;
}
construct(int a, int b)
{
area = a * b;
}
void disp()
{
cout<< area<< endl;
}
};
int main()
{
construct o;
construct o2( 10,
20); o.disp();
o2.disp();
return 1;
}
3.2 2 Predict the output and explain why?
#include<iostream.h>
class constructor
{
int x;
public:
constructor(short ss)
{
cout<< "Short" << endl;
}
constructor(int xx)
{
cout<< "Int" << endl;
}
Que
Mod
stion Question
ule
Type
constructor(float ff)
{
cout<< "Float" << endl;
}
};
int main()
{
constructor c('B');
return 0;
}
3.1 2 Predict the output and explain why?
#include <iostream>
using namespace std;
class constructor
{
int a;
public:
constructor(int x)
{
a = x;
}
void display()
{
cout<< "a: "<<a << endl;
}
};
int main()
{
constructor c1(10);
constructor c2 = c1;
c1.display();
c2.display();
return 1;
}
Que
Mod
stion Question
ule
Type
3.2 2 Predict the output and explain why?
#include<iostream.h>
class constructor
{
int x;
public:
constructor(short ss)
{
cout<< "Short" << endl;
}
constructor(int xx)
{
cout<< "Int" << endl;
}
constructor(float ff)
{
cout<< "Float" << endl;
}
};
int main()
{
constructor c(2.4);
return 0;
}
3.2 3 What is a parameterised constructor? Explain with an example?
3.3 3 What are constructors with default arguments? Explain with an example program?
3.3 3 Write a program to find area of a right angled triangle,rectangle,circle using concept of constructor
overloading?
3.5 4 Write a program to overload unary operator using friend function explain?
3.5 4 Write a program to overload binary operator using friend function explain?
3.5 4 Write a program to overload ++ and --operator for prefix and postfix use?
Que
Mod
stion Question
ule
Type
3.5 4 Write a program to overload binary – operator using member function and contrast the difference
when overloading the same using friend function?
3.5 4 Write a program to overload binary + operator using member function and contrast the difference
when overloading the same using friend function?
3.5 4 Write a program to overload binary * operator using member function and contrast the difference
when overloading the same using friend function?
3.5 4 Write a program to perform multiplication using an integer and object. Use friend function?
3.5 4 Write a program to perform addition using an integer and object. Use friend function?
4.2 1 Define a class ABC that is derived publicly from class XYZ?
4.2 1 Define a class ABC that is derived privately from class XYZ?
4.2 1 Define a class ABC that is derived publicly from class XYZ and GHI?
4.4 2 What are virtual base classes?how to make a base class virtual?
4.2 2 What is public visibility mode?write an example of defining a class that is inherited from another
class publicly?
4.2 2 What is private visibility mode?write an example of defining a class that is inherited from another
class privately?
4.2 2 What happens when a class is derived from another class publicly?
4.2 2 What happens when a class is derived from another class privately?
#include<iostream>
using namespace
std;
Que
Mod
stion Question
ule
Type
class P {
public:
void print() { cout <<" Inside P"; }
};
class Q : public P {
public:
void print() { cout <<" Inside Q"; }
};
class R: public Q { };
int main(void)
{
R r;
r.print();
return
0;
}
4.2 2 Examine the code and predict the output?Explain?
#include<iostream>
using namespace
std;
class Base
{
public:
int fun() { cout << "Base::fun() called"; }
int fun(int i) { cout << "Base::fun(int i) called"; }
};
#include<iostream>
using namespace
std;
class Base
{
protected:
int a;
public:
Base() {a = 0;}
};
int main(void)
{
DerivedDerived d;
d.show();
return 0;
}
4.2 2 Examine the code and predict the output?Explain?
#include<iostream>
using namespace
std;
class Base
{
public:
int fun() { cout << "Base::fun() called"; }
int fun(int i) { cout << "Base::fun(int i) called"; }
};
int main()
{
Derived d;
d.fun();
return 0;
}
4.2 2 Examine the code and predict the output?Explain?
#include<iostream>
Que
Mod
stion Question
ule
Type
using namespace std;
class Base
{
public:
int fun() { cout << "Base::fun() called"; }
int fun(int i) { cout << "Base::fun(int i) called"; }
};
int main()
{
Derived d;
d.fun(7);
return 0;
}
4.2 2 Examine the code and predict the output?Explain?
#include<iostream>
using namespace
std;
class base {
int arr[10];
};
int main(void)
{
cout << sizeof(derived);
return 0;
}
4.2 3 Explain public inheritance with an example?
4.3 4 Write a C++ program to read and print students information using two classes and simple inheritance
4.3 4 Write a C++ program to read and print employee information using multiple inheritance?
4.3 3 Write a C++ program to add two numbers using single inheritance. Accept these two numbers from
the user in base class and display the sum of these two numbers in derived class.
4.3 3 Write a C++ program to subtract two numbers using single inheritance. Accept these two numbers
from the user in base class and display the difference of these two numbers in derived class.
4.3 3 Write a C++ program to multiply two numbers using single inheritance. Accept these two numbers
from the user in base class and display the product of these two numbers in derived class.
4.2 3 Explain the terms base class and derived class with example?
Que
Mod
stion Question
ule
Type
4.2 3 Explain about accebility in public inheritance with a simple example?
4.2 3 Write a C++ program to divide two numbers using single inheritance. Accept these two numbers
from the user in base class and display the quotient upon dividing these two numbers in derived class.
4.3 4 Write a C++ program to find mean of two numbers using single inheritance. Accept these two
numbers from the user in base class and display the mean of these two numbers in derived class.
4.3 4 Write a C++ program to find average of three numbers using single inheritance. Accept these three
numbers from the user in base class and display the average of these three numbers in derived class.
#include<iostream>
#include<fstream>
using namespace
std;
int main()
{
ofstream ofile;
ofile.open ("text.txt");
ofile << "haaai" << endl;
ofile.close();
return 0;
}
5.6 2 What happens if the following code is executed?
#include<iostream>
#include<fstream>
using namespace
std;
int main()
{
char data[100];
ifstream ifile;
ifile.open
("text.txt");
while ( !ifile.eof() )
Que
Mod
stion Question
ule
Type
{
ifile.getline (data,
100); cout << data <<
endl;
}
ifile.close()
; return 0;
}
5.6 3 What are write () and read () functions?
5.6 4 Explain about opening and closing a file and file opening modes?