About this previous year paper
Course: B.Tech (Computer Science / IT)
Subject Code: CS403
Subject Title: Object-Oriented Programming with C++
Exam Type: Theory
Duration: 3 Hours
Maximum Marks: 100
SECTION – A (10 × 2 = 20 Marks)
Short conceptual questions testing understanding of OOP fundamentals
| No. | Concept | Explanation |
|---|---|---|
| (a) | Generalization | Process of extracting common properties and behaviors from multiple classes to create a base class. |
| (b) | Abstract Class | A class with at least one pure virtual function; cannot be instantiated directly. |
| (c) | this Pointer | Implicit pointer used to refer to the invoking object inside a member function. |
| (d) | Destructor | Special member function with ~ClassName() used to free resources when an object goes out of scope. |
| (e) | Polymorphism | Ability of a function or operator to behave differently based on input or object type — achieved via overloading or virtual functions. |
| (f) | Derived Attribute | Attribute computed from other attributes, not stored directly (e.g., total = price × quantity). |
| (g) | Inheritance | Mechanism of deriving a new class from an existing one to reuse and extend its functionality. |
| (h) | Characteristics of OOPs | Encapsulation, inheritance, polymorphism, abstraction, reusability. |
| (i) | Pure Virtual Function | A virtual function declared as =0; defines an interface for derived classes. |
| (j) | Inline Function | Function expanded inline to reduce function call overhead; declared with keyword inline. |
SECTION – B (5 × 10 = 50 Marks)
Analytical and programming-based questions
(a) Copy Constructor
Used to initialize an object from another of the same class.
(b) Constructor Example – Area of Circle
#include <iostream> using namespace std; class Circle { float r; public: Circle(float radius) { r = radius; } float area() { return 3.14 * r * r; } }; int main() { Circle c1(5); cout << "Area = " << c1.area(); }
(c) Function Overloading
Functions with the same name but different parameter lists.
(d) Operator Overloading
Overloading operators for user-defined types.
Example: Binary + operator
(e) OOP vs Procedural Programming
| Feature | OOP | Procedural |
|---|---|---|
| Structure | Class-based | Function-based |
| Data | Encapsulated | Global |
| Reusability | High | Limited |
| Examples | C++, Java | C, Pascal |
(f) Sorting Ten Integers (C++)
#include <iostream> using namespace std; int main() { int a[10]; for(int i=0;i<10;i++) cin >> a[i]; sort(a, a+10); for(int i=0;i<10;i++) cout << a[i] << " "; }
(g) Command Line Arguments – Factorial
#include <iostream> #include <cstdlib> using namespace std; int main(int argc, char* argv[]) { int n = atoi(argv[1]); int f=1; for(int i=1;i<=n;i++) f*=i; cout << "Factorial = " << f; }
(h) Exception Handling
Handles runtime errors gracefully using try, catch, and throw.
SECTION – C (2 × 15 = 30 Marks)
Advanced C++ programming and conceptual application
Q3. (i) File Operations
File Handling in C++:
(ii) Class Template
template <class T> class Calculator { public: T add(T a, T b) { return a + b; } }; int main() { Calculator<int> c; cout << c.add(4, 5); }
Q4. Inheritance (All Types with Example)
| Type | Example | Description |
|---|---|---|
| Single | A → B | One base, one derived class. |
| Multiple | A,B → C | Derived from multiple base classes. |
| Multilevel | A → B → C | Derived in successive levels. |
| Hierarchical | A → B, C | One base → many derived. |
| Hybrid | Combination | Mix of above types. |
Q5. Short Notes
(i) Virtual Function
Used for runtime polymorphism — ensures that the derived class function is invoked via base class pointer.
(ii) Function Template
Generic function that works with multiple data types:
template <class T> T add(T a, T b) { return a + b; }
Summary
This Object-Oriented Programming with C++ (CS403) paper thoroughly tests:
| Topic | Core Concepts |
|---|---|
| OOP Fundamentals | Abstraction, encapsulation, inheritance, polymorphism |
| Functions & Operators | Overloading, inline, virtual functions |
| Classes & Objects | Constructors, destructors, copy constructor |
| Templates & Files | Generic programming and file I/O |
| Error Handling | Exception handling and robustness |
ofstream fout("data.txt"); fout << "Hello World!"; fout.close(); ifstream fin("data.txt"); string s; fin >> s; cout << s; fin.close();
try { int x = 5, y = 0; if(y == 0) throw "Divide by zero!"; cout << x / y; } catch(const char* msg) { cout << msg; }
class Complex { int r, i; public: Complex(int a, int b) { r = a; i = b; } Complex operator+(Complex c) { return Complex(r + c.r, i + c.i); } };
void print(int a); void print(double a);
class Demo { int x; public: Demo(int a) { x = a; } Demo(Demo &d) { x = d.x; } // copy constructor };
