Object Oriented Programming Using C++ PCIT102
Object Oriented Programming Using C++ PCIT102
Part-A
Fundamental Concepts of a Programming Language
2 Marks:
1. Draw a diagram to represent the basic structure of a programin C++.
2. What do you mean by a token?
3. Differentiate between keywod and identifier.
4. Compare and contrast the variables and constants in C++. What are the rules to be followed for
identifiers?
5 Marks
5. What is the need of data types in C++? Describe different data types alongwith their
reprsentations and size in C++.
6. Give classification of operators available in C++ with the help of neat and clean diagram.
7. Define ternary operator. Compare it with if and if-else statement.
8. What do you mean by oprator precedence?
9. What is the needof type conversion? Discuss different types of type conversion in C++.
10 Marks
10. Classify the different statements available in C++.
11. Differentiate between nested if-else and switch statement.
12. Compare and contrast for, whileand do-while looping statements.
13. Differentiate between break and continue statement.
14. Why the use of goto statement is not good for quality programming?
15. What is the need of array. Discuss different types of arrays.
16. Discuss different string handling functions available in C++.
5 Marks:
5. What are the different ways to define member functions of a class. What is the role of scope
resolution operator in the definition of member function?
6. What is the need of passing objects as arguments. Discuss different ways to pass objects as
arguments to a function.
7. Discuss the benefits of retrurning objects from functions.
10 Marks:
8. Write a program to add two complex numbers using object as arguments.
9. Write a program to add two distances.
6. Discuss the role of acess specifiers in inheritance and show their visibility when they are
inherited as public, private and protected.
7. Discuss the concept of generalization and aggregation.
8. How overriding is different from the overloading.
9. What is the use of super keyword in C++?
Part-B
Pointers and Run Time Polymorphism
2 Marks:
1. What is the need of abstract class in C++?
5 Marks:
2. Write a C++ program demonstrating use of the pure virtual function with the use of
base and derived classes.
3. What is the use of this keyword in C++?
10 Marks:
4. Write a program to demonstrate friend function in C++.
Exception Handling
2 Marks:
1. Compare and contrast error and exception.
2. Draw a neat and clean diagram to show exception handling model in C++.
5 Marks:
3. Write down a detailed C++ program to demonstate the use of try, catch , throw and nested try.
10 Marks:
4. What is a user defined exception. Wirte down the scenario where we require user defined
exceptions.
5. When do we need multiple catch blocks for a single try block? Give an example.
String Handling
2 Marks:
1. How string is used in C++? How can we create string object?
5 Marks:
2. Write a programin C++ to extract character from a string.
3. Draw a neat and clean sketch to show the different streams available in C++.
10 Marks:
4. What is role of manipulators in C++. Write down different manipulators in C++.
5. Differentiate between formatted and unformatted I/O. Discuss its different functions.
5 Marks:
3. Explain the role of seekg(),seekp(),tellg(),tellp(),function in the process of random access in a
file.
4. Explain the Standard Template Library and how it is working.
10 Marks:
5. Write a C++ program using function template to find the product of two integer or
floating point type of data.
void main()
cout<<strlen(“Hello, World.\n”)<<”\n”;
(a) 123 (b) Compile time error (c) None (d) Run time Error
cout << ;
void main()
cout<<a <<”,”<<n<<endl;
void main()
int a = 20,b=100;
int &n = a;
n=a++;
n = &b;
cout<<a <<”,”<<n<<endl;
void main()
bool a=10;
cout<<a<<endl;
(a) 101 (b) 100 (c) None (d) Error: one cannot use main as identifier
8. What is the output of the following
code? #include<iostream.h>
void main()
int a=0,x;
x = ++a * --a;
cout<<++a<< “ “ << a++ << ” ” << x <<endl;
void main()
a=32;
cout<<a<<endl;
int a;
}
(a) 32 (b) 0 (c) Compile time error (d) Run time error
(d) None
14. Elements in an array are identified by a unique .
(a) variable, location (b) variable, position (c) constant, variable (e) None
(a) string literal (b) float literal (c) double literal (d) character literal
17. To execute a C++ program, one first need to translate the source code into object code. This process if
called .
do
int b=0;
cout<<b;
b++;
}while(b!=10);
(a) recursion (b) passing a reference (c) passing a value (d) None
20. Each generic type in a template function definition is preceded by the keyword
void main()
for(int i=0;i<5;i++)
cout<<a[i]<<endl;
void main()
int a[5] =
{100,2,3,22,400}; int b[5];
b=a;
for(int i=0;i<5;i++)
cout<<b[i]<<endl;
void main()
for(int i=0;i<5;i++)
cout<<a[i]<<endl;
26. To delete a dynamically allocated array named ‘a’, the correct statement is
(a) delete a; (b) delete a[0]; (c) delete []a; (d) delete [0]a;
void main()
{
int i=5,j=0;
while(i-- || j++)
cout<<i<<" "<<j<<”,”;
(a) 5 1, 4 2, 3 3, 2 4, 1 5, (b) 4 0, 3 0, 2 0, 1 0, 0 0,
int a;
bool b;
int a = 1;
void main()
int a = 100;
int a = 200;
int a = 300;
cout<<a<<",";
cout<<a<<",";
cout<<a<<",";
cout<<::a<<",";
int x=10;
(x<0)?(int a =100):(int a
=1000); cout<<a;
int a = 0;
cout<<(a = 10/a);
void main()
{
int x=0;
while(x++<5)
static x;
x+=2;
cout<<x<<" ";
}
void main()
char str1[]=”India”,
str2[]=”India”; if(str1==str2)
else
(a) Both the string are same (b) Both the string are not same
char str[8];
cin>>str;
cout<<str;
void main()
void main()
x = ptr2 - ptr1;
cout<<x;
}
(c) the address that points to ‘\0’ (d) the address that points to -1
void main()
int arr[][3]={0,11,22,33,44,55};
int *a = &arr[0][0];
cout<<arr[1][2]<<" "<<*(a+3);
void main()
{
int arr[2][3][2]={{{2,4},{7,8},{3,4},}, {{2,2},{2,3},{3,4},
}}; cout<<**(*arr+1)+2+7;
(a) 16 (b) 7
44. The design of classes in a way that hides the details of implementation from the user is known as:
46. I want a nonmember function to have access to the private members of a class. The class must declare
that function:
(a) friend (b) inline
47. The ability to reuse objects already defined, perhaps for a different purpose, with
modification appropriate to the new purpose, is referred to as
(a) Information hiding. (b) Inheritance.
48. What do you think is the outcome of calling a redefined non-virtual function using a base-class
pointer?
49. A class member that is to be shared among all objects of a class is called
(a) A const member (b) A reference parameter
(d) A class that is inherited by another class, and thus is included in that class.
51. A variable that is declared protected:
(a) Is visible only in the subclasses (and not in the class it is declared in).
(b) Is visible only in the class it is declared in.
(c) Is visible to all classes, but modifiable only in the class where it is declared.
(d) Is visible in the class it is declared in, and all of its subclasses.
(a) Each instance of a class will have its own copy of the variable.
(b) Changing the variable in one instance will have no effect on other instances of the class.
(c) There will be only one instance of the variable initialized for all classes.
(d) Every instance of the class must consider the value of the static variable before initializing.
(b) destructors
(d) The class may only exist during the planning phase
61.
#include<iostream.h>
class Base
int static i;
public:
Base(){}
};
void main()
Multi m;
In the above program, how many times Base’s constructor will be called?
(a) 1 (b) 2
62.
#include<iostream.h>
namespace N1
namespace N2
void main()
using N1::f;
int i1=f(1.0);
using N2::f;
int i2=f(1.0);
63.
#include<iostream.h>
class Base
public : int a;
protected: int b;
private: int c;
};
int d;
friend Friend;
};
class Friend
Derived derived;
};
In the above code, which of the following variables can be accessed in "Friend"?
public :
obj(){count++;}
~obj(){count--;}
};
int main()
obj G;
cout<<count; return
0;
(a) 0 (b) 5
(c) 1 (d) 6
int main()
for(int ii=0;ii<3;++ii)
switch(ii)
return 0;
}
(a) zero one one two (b) zero one two
class obj
public :
obj(){cout<<"in ";}
~obj(){cout<<"out ";}
};
int main()
obj A,B;
obj D;
obj E; return 0;
(a) in in in out in out out out (b) in in in in out out out out
class Base
public :
Base(){};
virtual ~Base(){};
};
public:
virtual ~Derived(){};
};
int main()
(b) One cannot have a ‘Base’ pointer to ‘Derived’ since it is not derived publicly
int main()
myprofessor obj;
return 0;
class Parent
public:
Parent(){Status();}
public:
Child(){Status();}
};
void main()
Child c;
class Base
public:
private:
int n;
};
class D2:public D1
int i;
void Method(){i=2;}
};
int main()
D2 test;
return 0;