STARTING NOW — PAPER 1 COMPLETE SOLUTION
(File: 76437(S2)-433)
---
SECTION-A (SHORT ANSWERS)
1. Define inheritance. Types of inheritance.
Inheritance allows one class to acquire properties of another. Types: single, multilevel, multiple,
hierarchical, hybrid.
2. What is a pure virtual function?
A function declared with =0 in a base class to enforce overriding; it makes the class abstract.
3. What is data hiding? How is it achieved?
Restricting access to internal data; achieved using private/protected members.
4. Array of class objects.
A list of objects stored in consecutive memory like an array: Student s[10];.
5. Function overloading.
Multiple functions with the same name but different parameter lists.
6. Static data members.
A variable shared by all objects; declared with static inside class and defined outside.
7. Basic data types in C++.
int, float, double, char, bool, void.
8. Private vs Protected vs Public.
Private: only class. Protected: class + subclasses. Public: everywhere.
9. C++ stream classes.
iostream cin/cout; fstream files; ifstream/ofstream read/write.
10. Recursive functions.
A function calling itself until a base condition is met.
---
SECTION-B (MEDIUM ANSWERS)
11. Friend function — meaning + example.
A friend function is allowed to access private members of a class despite not being a member.
Useful when two classes need joint access or operator overloading.
class Test {
private:
int x;
public:
Test(int a){ x=a; }
friend void show(Test t);
};
void show(Test t){ cout<<t.x; }
12. Multilevel inheritance.
It forms a chain: Base Derived1 Derived2.
The bottom class inherits features from all previous levels.
Example:
class A {};
class B : public A {};
class C : public B {};
13. Types of constructors.
Default, parameterized, copy constructor. Each initializes objects differently.
14. Static members usage.
Defined once outside class. Accessed using object or class name.
Good for shared counters or configuration variables.
15. File operations.
Steps: open using fstream, perform read/write, then close using .close().
---
SECTION-C (DETAILED ANSWERS)
16. Control statements in C++
Control statements guide program flow:
1. Decision-making: if, if-else, switch
2. Looping: for, while, do-while
3. Jump: break, continue, goto, return
Example of each:
if(x>0) {}
for(int i=0;i<5;i++) {}
while(x--) {}
switch(choice) {}
They allow conditional execution, repeated execution, and structured flow control.
---
17. Polymorphism + types + implementation
Polymorphism means “many forms.”
Two types:
1. Compile-time polymorphism
Function overloading
Operator overloading
Achieved by static binding.
2. Run-time polymorphism
Virtual functions
Achieved using base class pointers and overriding
Uses dynamic binding
Example:
class Base {
public:
virtual void show(){ cout<<"Base"; }
};
class Derived: public Base {
public:
void show(){ cout<<"Derived"; }
};
Base *b = new Derived;
b->show(); // Derived
---
18. Exception handling + program
Exception handling captures runtime errors using try, throw, catch.
Program:
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
try{
if(n<0) throw "Negative number!";
cout<<"Square = "<<n*n;
catch(const char *msg){
cout<<"Error: "<<msg;
-----------‐------------------------------
(File: OOP(3rd)Dec2020 – M-76437(S2)-978)
PAPER 2 – COMPLETE SOLUTION
---
SECTION–A (Short Answers)
1. Rules of defining constructors.
Constructor name = class name, no return type, can be overloaded, must be public, automatically invoked.
2. Use of function overloading.
Allows same function name with different parameters for cleaner, flexible interfaces.
3. Define this pointer.
A pointer inside an object that stores the address of the current object.
4. What is an Abstract class?
A class having at least one pure virtual function; cannot be instantiated.
5. Explain Exception Handling.
Mechanism using try, throw, catch to manage runtime errors safely.
6. What are C++ streams?
Input/output channels like cin, cout, ifstream, ofstream.
7. Multilevel inheritance.
Inheritance across multiple levels: A B C.
8. Friend function and friend class.
A friend can access private/protected members of another class.
9. Different modes of opening files.
ios::in, ios::out, ios::app, ios::binary, ios::ate.
10. Memory allocation to classes & objects.
Memory is allocated when objects are created; each object gets its own instance variables.
---
SECTION–B (Medium Answers)
11. Storage classes in C++ (with examples).
C++ has:
auto – default local variable
static – retains value between calls
register – stored in CPU register
extern – refers to global variable defined elsewhere
Example:
static int count = 0;
Keeps its value across multiple function calls.
---
12. Advantages of new over malloc().
new calls constructor, malloc does not
new returns exact type, malloc returns void*
new supports overloading
new throws exception, malloc returns NULL
Example:
int *p = new int;
---
13. What is OOP? Give five characteristics.
Object-Oriented Programming is a paradigm using objects & classes.
Features:
1. Encapsulation
2. Abstraction
3. Inheritance
4. Polymorphism
5. Data hiding
---
14. Public, private, protected + ambiguity in multiple inheritance.
public accessible everywhere
protected accessible in subclass
private class-only
Ambiguity occurs when two base classes have same function names.
Solved using scope resolution.
---
15. Techniques of defining pure virtual function.
Declaring function with =0
Overriding in derived class
Used to create abstract base classes
Example:
virtual void show() = 0;
---
SECTION–C (Long Answers)
16. Operator Overloading (Unary + Binary)
Operator overloading allows redefining operators for user-defined types.
Unary Overloading Example (++)
class Num {
int x;
public:
Num(int a){x=a;}
Num operator++(){
x++;
return *this;
}
};
Binary Overloading Example (+)
class Sum {
int a,b;
public:
Sum(int x,int y){a=x;b=y;}
Sum operator+(Sum s){
return Sum(a+s.a, b+s.b);
};
Purpose: increase readability and allow natural operations on objects.
---
17. Private vs Protected Inheritance (With Example)
Private inheritance:
Public + protected members of base become private in derived.
Cannot be accessed further.
Protected inheritance:
Base's public & protected become protected in derived.
Accessible to next derived class.
Example:
class A { public: int x; };
class B : private A {}; // x becomes private
class C : protected A {}; // x becomes protected
Private inheritance hides the base more strictly than protected inheritance.
---
18. File modes + description
C++ offers multiple modes:
ios::in read
ios::out write
ios::app append
ios::binary binary files
ios::ate start at end
Example:
ofstream fout("[Link]", ios::out | ios::app);
Each mode controls how data is accessed and where the pointer starts.
---------------------------------------
This is the file: OOP(3rd)May2020
---
PAPER 3 – COMPLETE SOLUTION
---
SECTION–A (Short Answers)
(10 questions visible in the image)
1. What is Object Oriented Programming?
A programming paradigm based on objects & classes focusing on data abstraction, encapsulation,
inheritance, and polymorphism.
2. Define Encapsulation.
Wrapping data & methods together inside a class to restrict direct access.
3. What is a Constructor?
A special function with the same name as the class used for initializing objects.
4. Define Class and Object.
Class blueprint; Object real instance created from the class.
5. What is Operator Overloading?
Redefining operators to work with user-defined data types.
6. What is Inheritance?
Mechanism by which one class acquires properties of another.
7. What is Exception Handling?
Process of managing runtime errors using try–throw–catch.
8. Explain Function Overloading.
Functions with the same name but different parameter lists.
9. What are Virtual Functions?
Functions marked virtual that support runtime polymorphism.
10. What is a Friend Function?
A non-member function that can access private/protected members of a class.
---
SECTION–B (Medium Answers)
11. Explain different types of constructors with examples.
1. Default constructor – no parameters
2. Parameterized constructor
3. Copy constructor
4. Dynamic constructor
Example:
class A {
public:
A(){} // default
A(int x){} // parameterized
A(A &obj){} // copy
};
---
12. What are manipulators? Explain with examples.
Manipulators modify I/O formatting.
Examples:
endl newline
setw() width
setprecision() decimal control
cout << setw(10) << 123;
---
13. Describe types of inheritance.
Single
Multilevel
Multiple
Hierarchical
Hybrid
Each defines how classes share data/behaviour.
---
14. Explain early binding vs late binding.
Early binding: function call determined at compile time normal functions, overloading.
Late binding: resolved at runtime virtual functions.
---
15. What are C++ file streams? Explain.
Three major file classes:
ifstream – reading
ofstream – writing
fstream – both
Used with open(), read(), write(), close().
---
SECTION–C (Long Answers)
16. Explain Object-Oriented Programming features in detail.
OOP includes:
1. Encapsulation – protects data using classes.
2. Abstraction – hiding complexity through interfaces.
3. Inheritance – code reuse & hierarchical relationships.
4. Polymorphism – same function behaves differently (compile-time & runtime).
5. Dynamic binding – linking function calls during execution.
6. Message passing – objects communicating through functions.
OOP makes code modular, secure, maintainable, and reusable.
---
17. Explain operator overloading with examples.
Operator overloading allows operators to work with objects.
Example for binary +:
class Complex {
public:
int r,i;
Complex(int x,int y){r=x; i=y;}
Complex operator+(Complex c){
return Complex(r+c.r, i+c.i);
};
Example for unary ++:
Complex operator++(){
r++; i++;
return *this;
}
Benefits: cleaner syntax, intuitive operations.
---
18. What is inheritance? Explain its types with example.
(repeated — already answered in Q13 Section B)
(repeated)
---
(File: 2023 Sem-3 BTCS-302-18 – Exam 17-01-23)
---
PAPER 4 – COMPLETE SOLUTION
---
SECTION-A (Short Answers)
1(a) Advantage of copy constructor
Copy constructor ensures a safe, controlled copy of objects and prevents unwanted shallow copying.
1(b) Access modifiers
public, private, protected — they control visibility of class members.
1(c) Multilevel inheritance
Inheritance across multiple levels: A B C.
1(d) Call by value vs call by reference
Call by value copies data; call by reference passes address, so changes reflect on original.
1(e) Need of abstract class
Used to enforce overriding and create a common interface; cannot be instantiated.
1(f) Friend class
A class declared as friend can access private/protected members of another class.
1(g) Difference between == and =
== compares values; = assigns value.
1(h) Memory allocation for 2D integer array
Allocated as contiguous blocks row-wise in static arrays, or via pointers in dynamic arrays.
1(i) Global vs local variable
Global: accessible everywhere; Local: accessible only within the function/block.
1(j) Early vs late binding
Early: compile-time linking; Late: runtime linking using virtual functions.
---
SECTION-B (Medium Answers)
2. Friend function (with example)
A friend function is allowed access to private/protected members of a class.
class A {
private:
int x;
public:
A(int a){ x=a; }
friend void show(A);
};
void show(A obj){
cout << obj.x;
Used when two classes/functions must access internal data.
---
3. Program to read two numbers and print average
#include<iostream>
using namespace std;
int main(){
float a,b;
cin >> a >> b;
cout << "Average = " << (a+b)/2;
---
4. Exception handling + multiply two arrays
Exception handling prevents program crash using try–catch blocks.
#include<iostream>
using namespace std;
int main(){
int a[3], b[3], c[3];
try{
for(int i=0;i<3;i++){
cin >> a[i] >> b[i];
if(a[i] < 0 || b[i] < 0) throw "Negative value!";
c[i] = a[i] * b[i];
for(int i=0;i<3;i++) cout << c[i] << " ";
catch(const char *msg){
cout << "Error: " << msg;
---
5. Procedural vs Object-Oriented Programming
Procedural OOP
Based on functions Based on objects
No data hiding Strong data hiding
Less secure More secure
Hard to maintain Easy maintenance via classes
Example: C Example: C++
---
6. Overload binary * to add two complex numbers
(The question wants * but says “add”; following the instruction literally.)
class Complex{
public:
int r,i;
Complex(int a=0,int b=0){ r=a; i=b; }
Complex operator*(Complex c){
return Complex(r + c.r, i + c.i); // as per question
}
};
---
SECTION-C (Long Answers)
7. Design classes: University College Student
#include<iostream>
using namespace std;
class University {
public:
string uname;
void setU(string u){ uname = u; }
};
class College : public University {
public:
string cname;
void setC(string c){ cname = c; }
};
class Student : public College {
public:
string name;
int roll;
void setS(string n,int r){
name=n; roll=r;
void display(){
cout<<"University: "<<uname<<endl;
cout<<"College: "<<cname<<endl;
cout<<"Name: "<<name<<" Roll: "<<roll<<endl;
};
int main(){
Student s;
[Link]("PU");
[Link]("XYZ College");
[Link]("Abhinav", 101);
[Link]();
---
8. Triangle validity + factorial + palindrome
#include<iostream>
using namespace std;
int fact(int n){
int f=1;
while(n>0){ f*=n; n--; }
return f;
bool isPalindrome(int n){
int rev=0, temp=n;
while(n){
rev = rev*10 + n%10;
n/=10;
}
return rev==temp;
int main(){
int a1,a2,a3;
cin>>a1>>a2>>a3;
if(a1+a2+a3 == 180){
cout<<"Valid Triangle\n";
cout<<"Factorial of a1: "<<fact(a1)<<endl;
if(isPalindrome(a2)){
cout<<"a2 is palindrome\n";
cout<<"Factorial of a2: "<<fact(a2);
else cout<<"a2 is not palindrome\n";
else cout<<"Invalid Triangle";
---
9. Short notes: Friend Function & Pure Virtual Function
Friend Function
Non-member but has access to private/protected data
Useful in operator overloading and joint access
Example:
friend void show(A);
Pure Virtual Function
Declared with =0
Makes class abstract
Enforces overriding
Example:
virtual void display() = 0;
---
(File: M-76437(S2)-1934 – Exam
---
PAPER 5 – COMPLETE SOLUTION
---
SECTION–A (Short Answers)
1(a) Input/Output statements in C++
Use cin for input and cout for output through iostream.
1(b) Define function overloading
Multiple functions with same name but different parameter lists.
1(c) External function made friend of a class
Declare it inside class using:
friend void func();
1(d) Parameter passing by reference
Function receives the variable’s address; changes reflect on original.
1(e) Private vs Protected
Private: accessible only inside class.
Protected: class + derived class.
1(f) Constructor–Destructor order in inheritance
Constructors base to derived.
Destructors derived to base.
1(g) Are virtual functions hierarchical?
Yes, derived classes inherit virtual behavior down the hierarchy.
1(h) Early vs late binding
Compile-time linking vs runtime linking (using virtual functions).
1(i) Exception handling keywords
try, throw, catch.
1(j) File operation classes
ifstream, ofstream, fstream.
---
SECTION–B (Medium Answers)
2. Discuss any two loop statements with examples
For loop:
for(int i=0;i<5;i++){}
While loop:
while(n>0){ n--; }
Used for repeating tasks until conditions end.
---
3. What is a constructor? Types of constructors.
Constructor initializes objects automatically.
Types:
Default
Parameterized
Copy
Dynamic
Example:
A(){}
A(int x){}
A(A &obj){}
---
4. Protected base class inheritance
When a class inherits using protected, all public and protected members of base become protected in
derived.
class B : protected A {};
These members can be accessed further only inside derived or its child classes.
---
5. Abstract class + procedure to create one
A class with at least one pure virtual function.
Steps:
1. Declare a class.
2. Add a pure virtual function using =0.
3. Derive another class and override it.
4. Create objects only of the derived class.
class A{
public:
virtual void show() = 0;
};
---
6. File streams + methods of opening files
Streams: ifstream, ofstream, fstream.
Opening methods:
ofstream fout("[Link]", ios::out);
ifstream fin("[Link]", ios::in);
fstream file("[Link]", ios::in|ios::out);
Modes decide reading, writing, appending, binary etc.
---
SECTION–C (Long Answers)
7(a) Scope resolution operator — uses
:: is used to:
1. Access global variable when local exists
2. Define member functions outside class
3. Access static members
4. Inherit base-class methods explicitly
Example:
int x=10;
int main(){
int x=5;
cout<< ::x; // global
---
7(b) Operator overloading using friend function
class Complex{
public:
int r,i;
Complex(int a=0,int b=0){ r=a; i=b; }
friend Complex operator+(Complex, Complex);
};
Complex operator+(Complex a, Complex b){
return Complex(a.r+b.r, a.i+b.i);
Friend function allows access to private data of both objects.
---
8. Inheritance + types + multiple inheritance implementation
Definition:
Copying features of one class into another.
Types:
Single
Multilevel
Multiple
Hierarchical
Hybrid
Multiple inheritance example:
class A{};
class B{};
class C : public A, public B {};
C inherits from both A and B simultaneously.
---
9(a) Virtual function concept
A function declared with virtual that enables runtime polymorphism.
Base pointer derived object calls derived version.
---
9(b) Exception handling + types of exceptions
Exception handling uses try–throw–catch to manage runtime errors.
Types:
Arithmetic
Array index out-of-bounds
Memory allocation failure
User-defined exceptions
File handling errors
Example:
try{ throw 1; }
catch(int x){ cout<<"Error"; }
---
(File: M-76437(S2)-2114 – Exam 15-06-202
---
PAPER 6 – COMPLETE SOLUTION
---
SECTION–A (Short Answers)
1(a) Different data types in C++
Fundamental types: int, float, double, char, bool, void.
1(b) Define class and object
Class blueprint; Object real instance created from class.
1(c) Function components
Function signature, return type, parameters, body, local variables.
1(d) this pointer
Pointer that stores address of the current object.
1(e) Friend function
Non-member function that can access private/protected members of a class.
1(f) Use of fstream
Used to create, read, write, update files (combined file handling).
1(g) Virtual base class
Prevents duplication of base class data during multiple inheritance (solves diamond problem).
1(h) Dynamic allocation
Allocating memory at runtime using new and delete.
1(i) Use of abstract class
Provides interface and enforces overriding through pure virtual functions.
1(j) Early binding
Compile-time binding — normal functions, overloading.
---
SECTION–B (Medium Answers)
2. Program to show opening and closing of files
#include<iostream>
#include<fstream>
using namespace std;
int main(){
ofstream fout;
[Link]("[Link]");
fout << "Hello File!";
[Link]();
ifstream fin;
[Link]("[Link]");
string s;
while(getline(fin, s))
cout << s;
[Link]();
---
3. Concept of dynamic allocation of objects
Objects can be created using new at runtime instead of static declaration.
This helps when size or number of objects is unknown during compile time.
Example:
class A{ public: int x; };
A *ptr = new A; // dynamically created object
ptr->x = 10;
delete ptr; // memory freed
---
4. Function overloading + example
Defining multiple functions with same name but different parameters.
void show(int x){}
void show(double y){}
void show(int x, int y){}
Compiler decides based on argument types.
---
5. Virtual functions + example
Used to achieve runtime polymorphism. Base pointer calls derived version.
class A{
public:
virtual void show(){ cout<<"A"; }
};
class B: public A{
public:
void show(){ cout<<"B"; }
};
A *p = new B; p->show(); // B
---
6. Constructors + types
Constructors initialize objects.
Types:
Default
Parameterized
Copy
Dynamic constructor
Example:
A(){}
A(int x){}
A(A &obj){}
---
SECTION–C (Long Answers)
7. Public, private, protected + how they are declared in inheritance
Access Modifiers
public: accessible everywhere
private: class-only
protected: class + derived
Inheritance forms
class B : public A {}; // public stays as public
class C : private A {}; // public/protected private
class D : protected A {}; // public/protected protected
Explanation:
Public inheritance models “is-a” relationship.
Private inheritance hides base functionality.
Protected inheritance applies when you want partial visibility control.
---
8. Use of operator overloading + algorithm
Purpose
Allows operators like +, -, *, = to work with objects
Improves readability
Makes user-defined types behave naturally
Algorithm for operator overloading
1. Create a class with private data.
2. Declare operator function using operator<op>.
3. Define that function to perform the desired operation.
4. Return a new object with updated values.
5. Use the operator normally with objects.
Example (overload +):
class Complex{
public:
int r,i;
Complex(int a=0,int b=0){ r=a; i=b; }
Complex operator+(Complex c){
Complex temp;
temp.r = r + c.r;
temp.i = i + c.i;
return temp;
}
};
---
9. Fundamentals of Exception Handling + throwing/catching
Fundamentals
1. try block holds risky code
2. throw triggers an exception
3. catch handles that exception
4. Prevents abnormal termination
5. Supports multiple catch blocks
6. Helps manage file errors, arithmetic errors, pointer errors, etc.
Example demonstrating throw/catch
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
try{
if(n < 0) throw "Negative not allowed";
cout<<"Square = "<<n*n;
catch(const char *msg){
cout<<"Error: "<<msg;
---
PAPER 7 – COMPLETE SOLUTION
---
SECTION–A (Short Answers)
1(a) Float
A datatype to store decimal numbers (4 bytes precision).
1(b) Operator
A symbol like +, -, *, / used to perform operations.
1(c) Inline function
A function expanded at compile-time using inline keyword.
1(d) Object
Instance of a class containing data & functions.
1(e) Public
Access specifier: members accessible anywhere.
1(f) Destructor
Function called when an object is destroyed; declared as ~ClassName().
1(g) Inheritance
Mechanism where one class acquires properties of another.
1(h) Catch
Keyword used to handle exceptions thrown inside try block.
1(i) Call by value
Arguments are copied; changes don’t affect original variable.
1(j) Friend function
Non-member function that can access private & protected data of a class.
---
SECTION–B (Medium Answers)
2. Overload ++ operator (with example)
class Number{
int x;
public:
Number(int a=0){ x=a; }
Number operator++(){ // pre-increment
++x;
return *this;
};
Used to modify objects naturally like built-in types.
---
3. Virtual vs Pure Virtual (with example)
Virtual function:
Has definition in base class
Can be overridden
virtual void show(){ cout<<"Base"; }
Pure virtual function:
Declared with =0
No body in base class
Makes class abstract
virtual void show() = 0;
---
4. Program: Read file & copy to another file
#include<iostream>
#include<fstream>
using namespace std;
int main(){
ifstream fin("[Link]");
ofstream fout("[Link]");
char ch;
while([Link](ch)){
[Link](ch);
}
[Link]();
[Link]();
This copies character-by-character.
---
5. Use of exception handling
Avoids program crash
Separates error-handling code
Makes code cleaner and safe
Useful for division errors, file failures, memory issues
Example:
try{ throw 1; }
catch(int){ cout<<"Error"; }
---
6. Access specifiers with example
public accessible everywhere
private class-only
protected class + derived class
class A{
public: int x;
private: int y;
protected: int z;
};
---
SECTION–C (Long Answers)
7. Types of inheritance + concept of ambiguity
Types of inheritance
Single
Multiple
Multilevel
Hierarchical
Hybrid
Ambiguity arises in multiple inheritance
When two base classes have functions with same name:
class A{ public: void show(){ cout<<"A"; }};
class B{ public: void show(){ cout<<"B"; }};
class C: public A, public B {};
Calling [Link]() causes ambiguity.
Solved using scope resolution:
c.A::show();
c.B::show();
---
8. Functions vs Recursive functions
Normal function
Executes once when called.
Recursive function
Calls itself repeatedly until base condition.
Example:
int fact(int n){
if(n==1) return 1;
return n * fact(n-1);
Recursion is powerful for tree traversal, factorial, Fibonacci, searching algorithms, etc.
---
9. Detailed note on exception handling mechanism
Exception handling consists of:
1. try block
Contains code that may cause errors.
2. throw statement
Used to raise (throw) an exception.
3. catch block
Handles the thrown exception.
4. Multiple catch blocks
Used to handle different types.
5. Catch-all handler
catch(...) {}
6. Re-throwing exceptions
throw;
Example program
#include<iostream>
using namespace std;
int divide(int a,int b){
if(b==0) throw "Division by zero!";
return a/b;
int main(){
try{
cout << divide(10,0);
catch(const char *msg){
cout<<"Error: "<<msg;
Exception handling improves robustness and prevents program crashes.