Object-Oriented Programming (BSc CSIT, CSC161): the questions likely to come
80 analyzed questions from 7 past papers (2074-2081), grouped by syllabus unit — each with its probability, how often it's been asked, and where to study the answer.
What are class templates? Write a C++ program to implement a generic 'Stack' class using templates with push and pop operations.
Class Templates
A class template is a blueprint that lets a single class definition work with any data type. The actual type is supplied as a parameter when an object is created, so the compiler generates a type-specific class on demand. This achieves generic programming and avoids code duplication.
General syntax:
template <class T>
class ClassName { /* T used as a type */ };
Generic Stack Using Templates
#include <iostream>
using namespace std;
template <class T>
class Stack {
static const int MAX = 100;
T arr[MAX];
int top;
public:
Stack() { top = -1; }
bool isEmpty() { return top == -1; }
bool isFull() { return top == MAX - 1; }
void push(T value) {
if (isFull()) { cout << "Stack Overflow\n"; return; }
arr[++top] = value;
}
T pop() {
if (isEmpty()) { cout << "Stack Underflow\n"; return T(); }
return arr[top--];
}
};
int main() {
Stack<int> s; // stack of int
s.push(10);
s.push(20);
cout << s.pop() << endl; // 20
cout << s.pop() << endl; // 10
Stack<char> cs; // same class, different type
cs.push('A');
cout << cs.pop() << endl; // A
return 0;
}
Output:
20
10
A
The same Stack template is instantiated as Stack<int> and Stack<char> without rewriting the class, demonstrating the reusability of class templates.
Working with Files and Templates
What are class templates? Write a C++ program to implement a generic 'Stack' class using templates with push and pop operations.
Explain stream classes in C++. Write a program to demonstrate formatted I/O using manipulators (setw, setprecision, setfill).
What are templates in C++? Explain function templates and class templates with a program for each.
Explain file handling in C++. Write a program to write records to a file and read them back using ifstream and ofstream.
Explain exception handling in C++. Write a program using try, catch and throw to handle division by zero.
Explain the syntax of a class template.
What is the difference between throw and rethrow?
What is the catch(...) handler used for?
Explain the difference between ifstream and ofstream.
Explain the throw keyword in C++.
Differentiate between text files and binary files.
What is a generic class?
Explain the seekg() and seekp() functions.
What is the role of the catch block in exception handling?
Explain the get() and put() functions in file handling.
Explain the cin and cout objects.
What is a template function?
What is a manipulator? Name any two.
Sit a probable paper
A full mock exam built from the most likely questions, mirroring the real paper's structure. Every slot is a real past question.
Most Probable Paper
Mirrors the real structure · 60 marks · based on 7 past papers
- 1.[10 marks]
What are class templates? Write a C++ program to implement a generic 'Stack' class using templates with push and pop operations.
Asked once (2081); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
- 2.[10 marks]
Explain stream classes in C++. Write a program to demonstrate formatted I/O using manipulators (setw, setprecision, setfill).
Asked once (2080); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
- 3.[10 marks]
What are templates in C++? Explain function templates and class templates with a program for each.
Asked once (2078); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
- 1.[5 marks]
Explain the role of the access specifier in inheritance.
This question has recurred in 3 of 7 years; so far only in internal assessments, not the board; and its topic (Inheritance: Extending Classes) appears in 86% of years.
- 2.[5 marks]
What are the benefits of object-oriented programming over procedural programming?
This question has recurred in 2 of 7 years; so far only in internal assessments, not the board; and its topic recurs in 5 of 7 years.
- 3.[5 marks]
Explain the syntax of a class template.
Asked once (2081); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
- 4.[5 marks]
What is the difference between throw and rethrow?
Asked once (2081); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
- 5.[5 marks]
What is the catch(...) handler used for?
Asked once (2080); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
- 6.[5 marks]
Explain the difference between ifstream and ofstream.
Asked once (2080); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
- 7.[5 marks]
Explain the throw keyword in C++.
Asked once (2079); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
- 8.[5 marks]
Differentiate between text files and binary files.
Asked once (2079); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
- 9.[5 marks]
What is a generic class?
Asked once (2079); so far only in internal assessments, not the board; and its topic (Working with Files and Templates) appears in 86% of years.
Behind the numbers
The raw evidence the predictions are computed from: marks per unit per year, syllabus weights, trends, and coverage.
Show the heatmap, topic table and coverage analysis
The receipt: marks per unit, per year
Each row is a syllabus unit, each column an exam year, each cell the marks that unit earned that year. Click any cell to see the actual questions behind it.
| # | Syllabus unit | Probability | Appeared | Avg marks | Syllabus weight | Exam vs syllabus | Trend | Questions |
|---|---|---|---|---|---|---|---|---|
| 1 | U8Working with Files and Templates | Very likely86% | 19.2 | 11%5 lecture hrs | Over-examinedexam 22% · syllabus 11% | Rising | none repeat18 total | |
| 2 | U6Inheritance: Extending Classes | Very likely86% | 12.5 | 13%6 lecture hrs | Balancedexam 14% · syllabus 13% | Rising | 1 recurring9 total | |
| 3 | U3Classes and Objects | Likely71% | 17 | 18%8 lecture hrs | Balancedexam 16% · syllabus 18% | Rising | none repeat13 total | |
| 4 | U4Constructors and Destructors | Very likely86% | 10 | 11%5 lecture hrs | Balancedexam 11% · syllabus 11% | Steady | none repeat10 total | |
| 5 | U2Programming Basics and Functions | Likely57% | 16.2 | 13%6 lecture hrs | Balancedexam 12% · syllabus 13% | Fading | none repeat12 total | |
| 6 | U1Introduction | Likely71% | 8 | 9%4 lecture hrs | Balancedexam 8% · syllabus 9% | Fading | 1 recurring6 total | |
| 7 | U7Pointers, Virtual Functions and Polymorphism | Likely57% | 12.5 | 11%5 lecture hrs | Balancedexam 10% · syllabus 11% | Steady | 1 recurring7 total | |
| 8 | U5Operator Overloading and Type Conversions | Likely57% | 8.8 | 13%6 lecture hrs | Under-examinedexam 7% · syllabus 13% | Steady | none repeat5 total |
Study smart, not hard
Drag the slider: studying the top 6 units in priority order covers ~84% of all observed marks.
- ~80% line
Lecture time vs exam marks
Where the exam pays more than the curriculum spends: ● lectures vs ● exam marks, as a share of the whole course. A long teal-leading bar = high-yield unit.