Object Oriented Programming (CC-211)
Important Questions/Answers
Object Oriented Programming (CC-211) – PU Past Paper +
Important Notes
Chapter 1: Introduction to Object Oriented Design
Short Questions
Q1. Define Object Oriented Design.
(Asked in PU 2019 Short Question)
Answer:
Object Oriented Design (OOD) is a method of designing a
program by focusing on real-world entities called objects.
Instead of dividing a problem into functions (as in procedural
programming), OOD divides it into classes and objects. Each
object represents something from the real world and
combines data (attributes) with operations (methods). This
leads to modular and organized programs.
Q2. What are the advantages of Object Oriented Design?
(Asked in PU 2017 Short Question)
Answer:
The main advantages are:
1. Reusability – once a class is written, it can be reused in
other programs.
2. Modularity – large projects are easier to manage as they
are divided into classes.
3. Maintainability – changes can be made to one class
without affecting the whole system.
4. Abstraction – hides unnecessary details from the user.
5. Productivity – existing code and libraries can be reused
to save time.
6. Scalability – OOD supports large-scale systems with
thousands of interacting objects.
Q3. Briefly explain the history of Object Oriented
Programming.
(Asked in PU 2015 Short Question)
Answer:
1960s: Simula67 was the first programming language to
introduce objects and classes.
1970s: Smalltalk introduced a complete object-oriented
language with inheritance and polymorphism.
1980s: C++ combined the efficiency of C with OOP
features like classes, inheritance, and polymorphism.
1990s onwards: Java and C# were developed with strong
OOP support.
Today: OOP is widely used in C++, Java, Python, and
other languages because it is best for large and complex
software systems.
Long Questions
Q1. Discuss Object Oriented Design, its history and
advantages.
(Asked in PU 2018 Long Question, 10 Marks)
Answer:
Object Oriented Design is a design technique where problems
are solved by identifying objects and their interactions. Each
object is self-contained and represents something from the
real world.
The history of OOD begins with Simula67, which introduced
the concept of classes and objects. Later, Smalltalk expanded
it by adding inheritance and dynamic binding. C++ made OOP
popular by combining it with the speed of C. Java further
advanced OOP by adding features like garbage collection and
platform independence.
Advantages of OOD include code reusability through
inheritance, abstraction of unnecessary details, modular
structure that improves maintenance, flexibility through
polymorphism, and scalability for large systems.
Important Questions with Answers
Q1. Why is OOP better than Procedural Programming?
Answer:
Procedural programming divides a problem into functions,
but data and functions are separate. This causes problems in
large projects where data security and reusability are
required.
OOP, on the other hand, binds data and methods together in
classes. It ensures data hiding, reusability through
inheritance, and flexibility through polymorphism. Therefore,
OOP is better for large, complex, and scalable projects.
Chapter 2: Terminology and Features of OOP
Short Questions
Q1. Define class and object.
(Asked in PU 2016 Short Question)
Answer:
A class is a blueprint or template for creating objects. It
defines the properties (data members) and behaviors
(functions) of objects.
An object is an instance of a class. It is created in memory and
represents a real-world entity. For example, if “Car” is a class,
then “Toyota” or “Honda” can be objects.
Q2. Explain encapsulation with example.
(Asked in PU 2019 Short Question)
Answer:
Encapsulation means combining data and functions that work
on that data into a single unit, i.e., a class. It also protects
data from direct access by making it private.
Example:
Here, the variable marks is hidden, and access is only allowed
through functions.
Q3. What are constructors and destructors?
(Asked in PU 2018 Short Question)
Answer:
Constructor: A special function with the same name as
the class that is automatically called when an object is
created. It initializes object values.
Destructor: A special function with the same name as
the class but preceded with a tilde (~). It is automatically
called when the object goes out of scope to release
resources.
Q4. Differentiate const vs non-const functions.
(Asked in PU 2020 Short Question)
Answer:
Const function: Cannot change the data members of a
class. Declared by adding const at the end.
Example: int getValue() const;
Non-const function: Can change data members.
Long Questions
Q1. Explain the main features of OOP with examples.
(Asked in PU 2017 Long Question)
Answer:
The main features are:
1. Encapsulation: Combines data and functions in one unit.
2. Abstraction: Shows essential details, hides unnecessary
details. Example: Car class hides engine complexity.
3. Inheritance: Deriving a new class from an existing one.
Example: Student class can inherit from Person.
4. Polymorphism: Ability to take multiple forms. Example:
function overloading and operator overloading.
Q2. Explain static data members and static functions with
example.
(Asked in PU 2019 Long Question)
Answer:
Static members are shared by all objects of a class, instead of
being unique to each object. They are declared with the
keyword static.
Example:
class Counter {
static int count;
public:
Counter(){ count++; }
static int getCount(){ return count; }
};
int Counter::count = 0;
Here, every object increases the same count. The function
getCount() can be called without creating an object.
Important Questions with Answers
Q1. What is operator overloading?
Answer:
Operator overloading means redefining the behavior of an
operator for user-defined types. For example, adding two
objects of a class.
Chapter 3: Classes and Their Relationships
Short Questions
Q1. Differentiate between composition and aggregation.
(Asked in PU 2016 Short Question)
Answer:
Composition: Strong relationship. The part cannot exist
without the whole. If the container object is destroyed,
the contained object also dies.
Example: A Car and its Engine.
Aggregation: Weak relationship. The part can exist
independently of the whole.
Example: A Department and its Teachers. If the
department is deleted, teachers still exist.
Q2. Identify classes and their relationships in a University
system.
(Asked in PU 2018 Short Question)
Answer:
Classes: Student, Teacher, Course, Department.
Relationships:
o A Department has many Courses (aggregation).
o A Teacher teaches Courses (association).
o A Course is composed of Students
(composition/aggregation depending on context).
Long Questions
Q1. Explain composition and aggregation with examples.
(Asked in PU 2019 Long Question)
Answer:
In composition, objects are strongly bound. The lifetime of
the part depends on the whole. For example, a House is
composed of Rooms. If the House object is destroyed, the
Rooms are destroyed too.
In aggregation, objects are loosely bound. The lifetime of the
part is independent. For example, a Library has Books. If the
library closes, the books still exist.
Important Questions with Answers
Q1. Why do we need to identify classes and their
relationships before coding?
Answer:
Identifying classes and relationships helps in analyzing the
problem clearly. It provides a blueprint for software design.
By doing so, code becomes modular, reusable, and easier to
maintain. Without class identification, the program becomes
unstructured.
Chapter 4: Inheritance
Short Questions
Q1. Define inheritance.
(Asked in PU 2016 Short Question)
Answer:
Inheritance is the mechanism by which one class
(child/derived class) acquires properties and behaviors of
another class (parent/base class). It promotes code reuse and
avoids redundancy.
Q2. What is multiple inheritance?
(Asked in PU 2017 Short Question)
Answer:
Multiple inheritance means a derived class inherits features
from more than one base class.
Example:
class A { };
class B { };
class C : public A, public B { };
Q3. Define access modifiers in inheritance.
(Asked in PU 2018 Short Question)
Answer:
Access modifiers decide how members are inherited:
Public: members remain accessible.
Protected: members remain protected in derived class.
Private: members of base class become private in
derived class.
Long Questions
Q1. Explain different types of inheritance in C++ with
examples.
(Asked in PU 2019 Long Question, 10 Marks)
Answer:
Types are:
1. Single Inheritance – one base class and one derived
class.
2. Multiple Inheritance – derived class inherits from
multiple base classes.
3. Multilevel Inheritance – chain of inheritance
(grandparent → parent → child).
4. Hierarchical Inheritance – multiple derived classes
inherit from one base class.
5. Hybrid Inheritance – combination of types, e.g., multiple
+ multilevel.
Important Questions with Answers
Q1. What are the advantages and problems of multiple
inheritance?
Answer:
Advantages: Allows a class to reuse code from multiple
sources.
Problem: Ambiguity occurs if two base classes have the
same function. It can be solved using the scope
resolution operator or virtual inheritance.
Chapter 5: Polymorphism
Short Questions
Q1. Define polymorphism.
(Asked in PU 2016 Short Question)
Answer:
Polymorphism means "many forms". In OOP, it allows the
same function name or operator to work differently
depending on the context.
Q2. Differentiate between compile-time and run-time
polymorphism.
(Asked in PU 2019 Short Question)
Answer:
Compile-time polymorphism: Achieved through function
overloading and operator overloading. Resolved at
compile time.
Run-time polymorphism: Achieved through virtual
functions and inheritance. Resolved at runtime.
Long Questions
Q1. Explain function overloading and operator overloading.
(Asked in PU 2018 Long Question)
Answer:
Function overloading: Multiple functions with the same
name but different parameters. Example:
int add(int a, int b);
double add(double a, double b);
Operator overloading: Giving new meaning to operators.
Example: Overloading + for objects of a Complex class.
Q2. Explain polymorphism with examples.
(Asked in PU 2020 Long Question)
Answer:
Polymorphism is the ability of a function/operator to behave
differently. For example, the function draw() can be used for
both Circle and Rectangle objects. This is achieved using
virtual functions.
Important Questions with Answers
Q1. Why is run-time polymorphism important in OOP?
Answer:
Run-time polymorphism allows dynamic binding, meaning
the function that gets executed depends on the object at
runtime. This increases flexibility and allows writing general
code for multiple object types.
Chapter 6: Abstract Classes and Interfaces
Short Questions
Q1. Define abstract class.
(Asked in PU 2017 Short Question)
Answer:
An abstract class is a class that has at least one pure virtual
function. It cannot be instantiated directly but serves as a
base class.
Q2. Define interface in C++.
Answer:
C++ does not have an explicit interface keyword, but abstract
classes with only pure virtual functions are used as interfaces.
Long Questions
Q1. Differentiate between abstract class and interface.
(Asked in PU 2018 Long Question)
Answer:
Abstract Class: Can have both normal and pure virtual
functions. Used as a base class.
Interface: Contains only pure virtual functions. It defines
only behavior, not implementation.
Important Questions with Answers
Q1. Why do we use abstract classes?
Answer:
Abstract classes are used to provide a common base for
derived classes. They define a contract that all child classes
must follow. For example, a Shape abstract class with pure
virtual function draw() must be implemented by all shapes
like Circle and Rectangle.
NEW NOTES
Object Oriented Programming (CC-211) —
Chapter-wise Past Papers + Important Q&As
Chapter 1 — Introduction to Object-Oriented Design
Q (5 marks): What is Object Oriented Design (OOD)?
Asked in PU 3rd Semester, Autumn 2020 (Short Q1)
Answer (detailed, exam-ready):
Object Oriented Design (OOD) is a software design
methodology that models a system as a collection of
interacting objects. Each object encapsulates state
(data/attributes) and behavior (methods/functions). The
goal of OOD is to mirror real-world entities and relationships
in code to make software easier to build, understand and
maintain.
Key aspects to include on the exam:
Objects represent entities (examples: Student,
BankAccount).
Classes are blueprints; objects are instances.
OOD promotes encapsulation (packaging data &
operations), inheritance (reusing behavior),
polymorphism (same interface, multiple
implementations) and abstraction (exposing only
necessary details).
Practical benefits: modularity, reusability, easier testing
and maintenance. Give a short real-world example (e.g.,
class Vehicle with subclasses Car, Truck).
Q (5 marks): What are the advantages of object-oriented
design?
Asked in PU 3rd Semester, Autumn 2021 (Short Q2)
Answer (detailed, exam-ready):
List and explain 5–7 advantages with 1–2 lines each:
1. Reusability: Inheritance and class libraries let you reuse
tested code (e.g., Vehicle base for Car, Truck).
2. Maintainability: Modular classes localize changes —
fixing a class fixes all objects.
3. Scalability/Extensibility: New features can be added
with minimal change (extend classes).
4. Encapsulation/Data protection: Internal state is hidden
(private members) and accessed via controlled methods,
preventing invalid states.
5. Abstraction: Exposes only necessary methods; hides
implementation complexity.
6. Natural modeling: Maps problem domain to code
directly; easier to reason about.
7. Teamwork & productivity: Different developers can
implement different classes concurrently.
Exam tip: give 4–5 points and a short example to score full
marks.
Q (8 marks): Explain the history and importance of object-
oriented design.
Asked in PU 3rd Semester, Spring 2022 (Q1-b)
Answer (detailed, exam-ready):
History in brief:
Simula-67 (1967): Introduced classes/objects — first
OOP ideas.
Smalltalk (1970s): Advanced OOP with message passing
and dynamic binding.
C++ (1980s): Brought OOP to systems programming,
mixing efficiency of C with classes/inheritance.
1990s+: Java, C#, Python adopt OOP as mainstream
paradigms.
Importance:
OOD addressed complexity problems of procedural
programming when systems grew large. It enables
modular design, supports code reuse (libraries), enforces
data protection (encapsulation), and allows polymorphic
behaviors which reduce conditional complexity.
Conclude with: “Because of these benefits, OOD is
standard in enterprise and large-scale software.”
Important Q&A Summary — Chapter 1 (with full answers)
Why is OOP preferred over procedural programming?
Answer: OOP binds data and behavior, protecting data,
enabling reuse and easier maintenance; procedural
keeps data separate and scales poorly for complex
systems — illustrate with a short BankAccount example.
Give two real-world examples modeled as classes and
objects (explain attributes & methods).
Explain modularity and how OOD improves teamwork.
Chapter 2 — OOP Terminology & Features (Classes, Objects,
Encapsulation, Constructors, Destructors, Access Modifiers,
const vs non-const, static members, overloading)
Q (2 marks): Define class and object.
Asked in PU 3rd Semester, Autumn 2022 (Short Q4)
Answer (detailed):
Class: A blueprint that defines data members (attributes)
and member functions (behaviors).
Object: A concrete instance of that class occupying
memory and containing actual values for attributes.
Example: class Student { string name; int roll; void
show(); }; Student s1;
Q (5 marks): What is encapsulation? Explain with example.
Asked in PU 3rd Semester, Autumn 2020 (Short Q1)
Answer (detailed):
Encapsulation = bundling data and methods and restricting
direct access to some of the object’s components (access
control). Implemented using private, protected, public.
Example code and explanation:
Explain: balance is hidden; modification only via methods
which can enforce rules — prevents invalid states.
Q (8 marks): Differentiate abstraction and encapsulation
with examples.
Asked in PU 3rd Semester, Spring 2021 (Q3-a)
Answer (detailed):
Encapsulation: Mechanism to hide internal
representation and protect data (use private members
and public accessor functions). Example: Account above.
Conclude: Abstraction is about what an object does;
encapsulation is about how it stores the data safely.
Q (5 marks): Explain constructors and destructors (types and
use).
Asked in PU 3rd Semester, Spring 2020 (Short Q5)
Answer (detailed):
Constructor: Special member function called when
object is created. Types: default (no args),
parameterized, copy constructor, move constructor (C+
+11+). Use to initialize members and allocate resources.
Destructor: ~ClassName() called when object is
destroyed. Use to free resources (delete dynamic
memory, close files).
Example code for default, parameterized, copy and
destructor with small explanation when to implement
custom copy / destructor (rule of three/five).
Q (5 marks): Access modifiers — public, private, protected
(explain).
Asked in PU 3rd Semester, Autumn 2021 (Short Q4)
Answer (detailed):
public: accessible anywhere.
private: accessible only within same class.
protected: accessible in class and derived classes. Also
explain how inheritance changes accessibility (public
inheritance preserves public as public, private becomes
private, protected becomes protected) and show small
code example.
Q (8 marks): const vs non-const member functions —
explain with example.
Asked in PU 3rd Semester, Spring 2022 (Q2-c)
Answer (detailed):
A const member function guarantees it does not modify
the object’s state (except mutable members). It can be
called on const objects. Example:
Explain: Trying to modify members inside getX() causes
compile error. Mention when to use (getters, debugging
guarantee).
Q (5 marks): Static data members & static functions — what
and why?
Asked in PU 3rd Semester, Autumn 2020 (Q3)
Answer (detailed):
Static data member: Single copy shared by all objects of
class. Declared with static inside class and defined
outside: int Class::count = 0;. Example: count instances.
Static function: Can be called without object; can access
only static data. Example: static int getCount() { return
count; }. Explain use cases: counters, utility methods not
dependent on object state.
Q (10 marks): Function overloading and operator
overloading — explain with examples.
Asked in PU 3rd Semester, Autumn 2022 (Q2-b)
Answer (detailed):
Function overloading: Multiple functions with same
name but different parameter lists. Compiler resolves
calls at compile time. Example: int add(int,int); double
add(double,double);
Operator overloading: Redefining operator behavior for
user-defined types. Show operator+ for Complex or
operator<</operator>> for I/O. Explain rules: cannot
create new operators, cannot change precedence, prefer
friend functions for stream operators, explain when to
overload as member vs friend. Provide example:
Explain exam expectations: write code + describe why
returning by value, const correctness, and chaining.
Long Question (15 marks): Rule of three/five, copy
constructor, assignment operator, destructor — explain with
example of deep copy.
Asked frequently across PP collections and important for
exams
Answer (detailed, exam-ready):
Explain problem: shallow copy copies pointers — double
delete issues. Show class with dynamic array, then
implement:
Copy constructor Class(const Class &other) doing deep
copy (allocate new memory and copy elements).
Overloaded assignment Class& operator=(const Class
&other) implementing self-assignment check, free old
resources, allocate new and copy, return *this.
Destructor ~Class() deletes allocated memory.
Explain Rule of Three (if class defines any of copy ctor,
copy assignment, destructor → should define all three).
Mention Rule of Five in modern C++ adding move
constructor & move assignment. Provide full code and
small usage example. Conclude with marks checklist:
correctness, memory handling, self-assignment,
exception safety.
Important Q&A Summary — Chapter 2 (full answers)
What is this pointer?
Answer: this is a hidden pointer inside non-static
member functions referring to the calling object. Use
cases: disambiguate member and parameter names
(this->x = x), return *this for chaining, pass current
object pointer to other functions.
Explain access control in inheritance
(public/protected/private).
Answer: Show how member accessibility changes and
give sample mapping table.
Show example where marking a getter const is necessary
(explain const correctness).
Chapter 3 — Classes and Their Relationships (Identification,
Composition, Aggregation, Association, Friend)
Q (5 marks): Define composition and aggregation and show
example.
Asked in PU past papers (various years)
Answer (detailed):
Composition (strong "has-a"): A part is
created/destroyed with the whole. Example: class House
{ Room rooms[5]; }. Rooms do not exist independently.
Aggregation (weak "has-a"): Part can exist
independently. Example: class Department
{ vector<Teacher*> teachers; }. Teachers exist even if
department is deleted.
Explain representation: composition often uses object
member (by value), aggregation uses
pointers/references. Provide small code illustrating both
and mention destructor implications.
Q (5 marks): What is friend function/class? When to use?
Asked in PP collections
Answer (detailed):
friend allows a function/class to access private/protected
members of another class. Use when an external function or
another class must access internal state and exposing getters
is impractical. Example: friend void show(const A& a); Show
caution: breaks encapsulation so limit its use and prefer
public interfaces when possible.
Long Question (10 marks): Identification of classes and
relationships from a problem statement (Library/Hospital
system).
High probability long question in PU pattern — always
practice
Answer (detailed, exam-ready):
Show step-by-step method: read statement → identify nouns
(candidates for classes), group verbs to methods, detect
relationships (is-a → inheritance, has-a →
composition/aggregation). Draw UML class diagram (textual if
hand-written exam) with attributes and methods for each
class. Provide a complete example (Library → Library, Book,
Member, Librarian; relationships: Library aggregates Books,
Member borrows Book via association; Book may have
Publisher as composition or aggregation depending on
assumption). Provide marks checklist: classes identified,
relationships named, diagram drawn, justification for choices.
Important Q&A Summary — Chapter 3
How to identify classes in requirements (full answer with
example).
Difference with code-level relationships and lifetime
considerations (composition vs aggregation) — provide
concrete code patterns for each.
Chapter 4 — Inheritance (Single, Multilevel, Multiple,
Hierarchical, Virtual/Virtual base to fix diamond problem)
Q (5 marks): Define inheritance and list types.
Asked in PU 2016 Short Q
Answer (detailed):
Inheritance allows a class to acquire properties of another
class. Types: single, multiple, multilevel, hierarchical, hybrid.
Show quick code for single and multiple.
Q (10 marks): Explain ambiguity in multiple inheritance and
show solution using virtual inheritance.
Appears often in PP and solved papers
Answer (detailed):
Problem: diamond inheritance — base duplicated via
multiple paths leading to two copies of base members
(ambiguity). Example:
Explain: Using virtual inheritance ensures only one A
subobject in D; access D::x unambiguous. Also explain
alternative resolution by using scope resolution operator B::x
or C::x (but that does not fix duplicate storage). Show exam
sketch: class diagram + code + explanation how virtual works
and memory conceptually (single shared base).
Long Question (15 marks): Implement a base class Account
and derive SavingsAccount and CurrentAccount. Show
constructors, override methods, and demonstrate
polymorphism via base pointer array. Also show file
persistence (simple serialization of account data).
Expected higher-mark integrated question combining
inheritance + polymorphism + I/O
Answer (detailed, exam-ready):
Important Q&A Summary — Chapter 4
Show differences between types of inheritance with
diagram and a sample C++ syntax line for each.
Explain diamond problem and virtual base solution in
two-three lines with code snippet.
When to use public/protected/private inheritance —
give rules and examples.
Chapter 5 — Polymorphism (Compile-time & Run-time),
Abstract classes & Interfaces
Q (5 marks): What is polymorphism — compile-time vs
runtime?
Asked in PU 2016–2020 papers
Answer (detailed):
Compile-time polymorphism: Overloading
(functions/operators). Resolved by compiler based on
signature. Example: add(int,int) vs add(double,double).
Run-time polymorphism: Virtual functions and
inheritance. The function call is resolved at runtime
using v-table / dynamic dispatch. Example: Shape* s =
new Circle(); s->draw(); calls Circle::draw().
Q (8 marks): Explain abstract classes and interfaces in C++.
How to emulate an interface?
Common PP topic
Answer (detailed):
Abstract class: Contains at least one pure virtual
function (virtual void f() = 0;). Cannot instantiate. Serves
as base class with contract.
Interface: In C++, an interface is an abstract class with all
pure virtual functions (no data members or normal
functions). To implement: derive from the “interface”
and define all pure virtual methods. Example:
Explain use cases: define API/contract, support polymorphism
and multiple inheritance of interfaces.
Long Question (12–15 marks): Design Shape abstract class
with pure virtual area() and draw(). Implement Circle and
Rectangle, show polymorphic behavior using array of
Shape*, and demonstrate computing total area.
Typical exam long
Answer (detailed):
Important Q&A Summary — Chapter 5
Difference between interface and abstract class (explicit
examples).
Show when to use virtual destructor and why.
Provide example of upcasting and downcasting and
mention dynamic_cast briefly.
Chapter 6 — Generic Programming: Templates & STL
Q (5 marks): What is a template? Provide function template
example.
Asked in PU 2016–2018 papers
Answer (detailed):
Template allows writing generic code for multiple types.
Function template example:
Explain: compiler generates concrete functions for types
used; advantages: code reuse and type safety.
Q (10–15 marks): Implement a class template for Stack and
show push/pop, plus a demonstration using int and string.
Common long/expected question
Answer (detailed):
Q (8 marks): What is STL — list components and give short
example using vector and sort.
PP/expected
Answer (detailed):
STL components: Containers (vector, list, deque, map, set),
Iterators, Algorithms (sort, find), Functors/Function objects.
Example:
Explain iterators concept and complexity notes (vector
random access O(1) vs list O(n)).
Important Q&A Summary — Chapter 6
Provide advantages of templates vs macros.
Show sample code of custom comparator lambda for
sort on objects (e.g., sort Students by marks).
Mention typical exam points: syntax
template<typename T>, typename vs class, instantiation
rules.
Chapter 7 — Object Streams (Data & Object Serialization,
File I/O for objects)
Q (8–10 marks): Explain object serialization with example.
How to serialize objects with dynamic memory?
Appears in lab & long PP tasks
Answer (detailed, exam-ready):
Serialization: converting object state to a stream for
storage/transfer. Two approaches:
1. Text serialization: write fields as text (readable).
Example:
2. Binary serialization: write raw memory
— only works for POD (Plain Old Data). Not safe for
pointers or objects with v-tables.
Dynamic memory handling:
For pointers/dynamic arrays, you must serialize the
pointed-to data explicitly (write the length then the
elements), and on deserialization allocate memory and
read elements back.
Example:
Custom serialize()/deserialize():
Implement methods that write field by field and perform
deep serialization for pointer members.
If object graphs have pointers referencing same object,
need more advanced schemes (IDs). For exams, mention
deep copy and pointer handling and show code snippet
for writing/reading dynamic array.
Exam tip: mention limitation of write/read for non-POD and
recommend operator overloads operator<</operator>> for
text serialization and custom serialize for deep structures.
Long Question (10–15 marks): Write code to save/load a list
of Student objects with dynamic name strings and scores.
Show how to handle pointers.
Expected long
Answer (detailed):
Show class Student with string name; int roll; vector<int>
marks; implement friend ostream &operator<<(ostream
&out,const Student &s) and friend istream
&operator>>(istream &in, Student &s) writing name, roll,
count of marks, then marks. For binary, write sizes and then
write for each mark after converting to char buffer. Include
sample read/write loops and explain error checking. Provide
small main showing saving N students and loading back
printing confirmation.
Important Q&A Summary — Chapter 7
Explain difference text vs binary serialization.
How to serialize objects with pointers (describe process).
Provide short code skeleton for operator<</operator>>.
Chapter 8 — Exception Handling
Q (5 marks): What is exception handling? (try, catch, throw)
Asked in PU 2016 Short Q
Answer (detailed):
Exception handling lets you handle runtime errors gracefully.
throw raises an exception, try encloses code that might
throw, and catch receives the thrown exception. Example:
Explain stack unwinding (destructors run) and RAII (Resource
Acquisition Is Initialization) to manage resources
automatically.
Q (10 marks): Implement user-defined exception class and
show multiple catch blocks and rethrowing.
Common long/PP
Answer (detailed):
Define custom exception:
Us
e in code:
Explain rethrow: inside a catch block call throw; to rethrow
current exception to higher level; useful for logging then
rethrowing. Explain when to catch by reference and order of
catch blocks (most specific first).
Important Q&A Summary — Chapter 8
Why use exception handling (reliability, separation of
error handling)?
Differences between exceptions and error codes.
Show RAII example using std::unique_ptr or std::fstream
to demonstrate automatic cleanup.
Chapter 9 — High-Value Past Paper Long Problems
(Complete Model Answers)
Below are the long problems that commonly appear in CC-
211 past papers and full model answers you should memorize
or adapt in exams.
Long Problem A: Algebra class (operator>> and
getDifferentObjects)
Asked in PU 3rd Semester, Spring 2023 (Solved PP)
Question text (paraphrased): Implement class Algebra with
private ints a and b (non-negative), provide getter/setter
enforcing non-negative, overload operator>> for input,
implement getDifferentObjects(Algebra arr[], int size, int
&newSize) returning new array of objects not equal to the
caller, if none return NULL and set newSize to 0.
Answer (complete, exam-ready):
(Write full code as shown below in exam — include
comments and explanation after code.)
Explain after code: validation, equality operator, returning
nullptr when none found. Show sample main() usage and
output expectations. Marking checklist: input operator,
equality correct, getDifferentObjects logic, memory
management (delete by caller), enforcement of non-negative.
Long Problem B: Bank System with Inheritance &
Persistence
(Typical exam integrative problem)
Question (paraphrased): Design Account base with virtual
withdraw/deposit/display; two derived classes
SavingsAccount and CurrentAccount with different withdraw
rules; show polymorphism and file save/load.
Answer (condensed, exam-ready):
Provide class definitions: Account with protected
members id, balance, virtual functions, virtual
destructor.
Derived classes override withdraw() (savings: no
overdraft; current: allow overdraft up to limit).
Demonstrate array Account* accounts[] and calling
display() for polymorphism.
For persistence, implement saveAllAccounts(const
vector<Account*>& v) which uses operator<< or writes
type + fields, then in load reconstruct objects by type.
Important exam marks: virtual destructor, correct
overrides, file read/write format and error handling,
explanation of polymorphism benefits.
(Write short code skeleton and explanation.)
Long Problem C: Template Stack / STL usage problem
Question (typical long): Implement generic stack and show
push/pop and usage with custom objects; show using STL
vector and sort with comparator.
Answer (exam-ready):
Provide template<class T> class Stack implementation using
std::vector<T> as underlying container. Show usage with
Stack<int> and Stack<Student> where Student has operator<
or lambda comparator. Also show using std::sort(v.begin(),
v.end(), [](const Student&a,const Student&b){return
a.marks>b.marks;}); to sort by marks descending. Explain
complexity and template advantages.
Final — Consolidated Important Q&A (All Chapters) —
Memorize these model answers
Below are the high-yield question & model answer templates
you should memorize and practice writing fast in the exam.
Each is given in the condensed form you can directly
handwrite.
1. Define class and object; short example.
o Class = blueprint; object = instance. Example: class
Student{ string name; int roll; void show();};
Student s;
2. Encapsulation: define + code example.
o Answer: bundling data & functions, hide data using
private, provide public accessors, show Account
example.
3. Constructor & destructor: types and example.
o Answer: default, parameterized, copy; destructor
~Class(); show code with dynamic allocation and
destructor frees memory.
4. Copy constructor vs assignment operator — deep copy
example.
o Write complete class with dynamic array,
implement copy constructor and operator= with
self-assignment check.
5. Static member example for counting objects.
o Show static int count; increment in constructor,
decrement in destructor, static int getCount().
6. Operator overloading: + and stream operators for a
Complex class.
o Show operator+ as member and operator<< as
friend.
7. Polymorphism: virtual functions & virtual destructor.
o class Shape { public: virtual void draw() = 0; virtual
~Shape() {} }; Example usage with Shape* s = new
Circle(); s->draw(); delete s;
8. Diamond problem: explanation + virtual base example.
o Code snippet with virtual public inheritance and
explanation of single base subobject.
9. Templates: function template and class template
example (Stack<T>).
o Show syntax and simple usage.
10. Serialization: text vs binary, pointer handling
example.
o Explain writing sizes then contents, reading with
allocation.
11. Exception handling: user defined exception
example and use of try/catch/throw.
o Provide class MyException: public exception { ... }
and usage snippet.
12. Identification of classes from problem statement
— steps and example (Library)
o Nouns → classes, verbs → methods; determine
relationships; sketch class diagram in 4–6 lines