1. Unit Overview & CCSU Exam Weightage
In the CCSU BCA 3rd Semester curriculum, Object Oriented Programming Using C++ (Course Code: BCA-301) transitions students from traditional procedural programming into modern component-oriented architecture.
- 3 Marks (Section A): Define Encapsulation, Data Hiding, or the role of the Scope Resolution Operator (
::). - 7.5 Marks (Section B): Differentiate between Procedure Oriented Programming (POP) and Object Oriented Programming (OOP) with a comparative table.
- 15 Marks (Section C): Explain the key pillars of OOP with complete C++ class syntax and execution lifecycle.
2. POP vs OOP (Procedure vs Object-Oriented Programming)
| Feature | Procedure-Oriented (e.g., C) | Object-Oriented (e.g., C++) |
|---|---|---|
| Approach | Top-down design approach | Bottom-up design approach |
| Focus | Focuses on algorithms and procedures | Focuses on data security and encapsulation |
| Data Security | Data flows freely across global functions (low security) | Data is hidden behind access specifiers (high security) |
| Overloading | Does not support function or operator overloading | Full support for polymorphism and overloading |
| Code Reusability | Limited code reusability | Extensive reusability through Inheritance |
3. The Four Core Pillars of OOP
- Encapsulation: Wrapping data members and member functions into a single unit (Class). Prevents unauthorized direct access from outside functions.
- Data Abstraction: Displaying only essential features to the outside world while hiding internal complex background details.
- Inheritance: The capability of a derived class to inherit properties and behaviors from a base class, fostering hierarchical classification.
- Polymorphism: "Many forms" — allowing a single entity (operator or function) to exhibit different behaviors based on input context (Compile-time vs Runtime polymorphism).
4. Anatomy of a Class & Object in C++
A Class is a user-defined blueprint or template from which individual Objects are instantiated. A class consumes zero memory until an object is created.
#include <iostream>
using namespace std;
// Class Definition Blueprint
class Student {
private:
int roll_no; // Private data: hidden from external functions
float percentage;
public:
// Member function to assign values
void setData(int r, float p) {
roll_no = r;
percentage = p;
}
// Member function to display details
void display() {
cout << "Roll No: " << roll_no << " | Score: " << percentage << "%" << endl;
}
};
int main() {
Student s1; // Object instantiated in memory
s1.setData(101, 88.5);
s1.display();
return 0;
}
5. Access Specifiers: Private, Public, Protected
private: Members can only be accessed by member functions inside the same class. (Default access specifier in C++).public: Members can be accessed from any function anywhere in the program.protected: Members are inaccessible from outside functions, but can be inherited and accessed by child/derived classes.
6. Scope Resolution Operator (::)
The :: operator in C++ serves three vital purposes:
- Defining member functions outside class body: Keeps class definitions clean and declarative.
- Accessing global variables: When a local variable shadows a global variable of the same name.
- Resolving multiple inheritance ambiguity: Disambiguating methods when two parent classes share identical function signatures.
class Calculator {
public:
int multiply(int a, int b); // Declaration inside class
};
// Definition outside using scope resolution ::
int Calculator::multiply(int a, int b) {
return a * b;
}
7. Solved CCSU Previous Year Exam Questions
Q1 (3 Marks - Section A): What is the significance of the this pointer in C++?
Answer: The this pointer is an implicit, constant pointer automatically passed to all non-static member functions. It points directly to the memory address of the invoking object, enabling disambiguation when parameter names match class member variables (e.g., this->roll_no = roll_no;).
Q2 (7.5 Marks - Section B): Explain Inline Functions. How do they differ from normal functions?
Answer: An Inline function (defined with the keyword inline) suggests to the compiler that the function's body should be directly inserted at the call site rather than generating a standard function call mechanism. This eliminates function-call overhead (saving registers, jumping, stack management), significantly accelerating execution of small, frequently-called routines.
8. Common Mistakes to Avoid in CCSU Exams
- Missing Semicolon after Class Closing Brace: A class definition must terminate with a semicolon:
class Test { ... };. Leaving this out causes immediate compilation failure. - Confusing Struct and Class Defaults: In C++, a
classhasprivatemembers by default, whereas astructhaspublicmembers by default. - Attempting to access Private Members with Dot Operator: Writing
s1.roll_no = 10;directly frommain()is a classic exam error. Data members must be set via public setter methods.