BSc CSIT (TU) Science Object-Oriented Programming (BSc CSIT, CSC161) Question Paper 2074 Nepal
This is the official BSc CSIT (TU) (Science stream) Object-Oriented Programming (BSc CSIT, CSC161) question paper for 2074, as set in the regular annual examination. It carries 60 full marks and a time allowance of 180 minutes, across 12 questions. On Kekkei you can attempt this Object-Oriented Programming (BSc CSIT, CSC161) past paper online with a timer, get instant AI feedback and step-by-step solutions, and track the topics where you lose marks — completely free. Whether you are revising for your BSc CSIT (TU) Object-Oriented Programming (BSc CSIT, CSC161) exam or solving previous years' question papers, this 2074 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
What is object-oriented programming? Explain the basic concepts of OOP: class, object, encapsulation, inheritance and polymorphism with suitable examples.
Object-Oriented Programming (OOP)
Object-Oriented Programming is a programming paradigm that organizes software design around objects — self-contained units that bundle together data (attributes) and the functions (methods) that operate on that data — rather than around functions and logic. The real world is modeled as a collection of interacting objects.
Basic Concepts of OOP
1. Class A class is a user-defined data type that serves as a blueprint/template for creating objects. It defines the data members and member functions common to all objects of that type. No memory is allocated when a class is defined.
class Student {
int roll; // data member
public:
void setRoll(int r) { roll = r; } // member function
void show() { cout << roll; }
};
2. Object An object is an instance of a class — a concrete entity that occupies memory and has state and behaviour.
Student s1; // s1 is an object of class Student
s1.setRoll(15);
3. Encapsulation
Encapsulation is the wrapping of data and the functions that manipulate it into a single unit (the class), and restricting direct access to internal data using access specifiers (private, public, protected). It enforces data hiding: in the example above roll is private, so it can only be changed through setRoll().
4. Inheritance Inheritance lets a new class (derived class) acquire the properties and behaviour of an existing class (base class), promoting code reusability and an is-a relationship.
class Person { public: void eat() { cout << "eats"; } };
class Student : public Person { // Student inherits from Person
public: void study() { cout << "studies"; }
};
5. Polymorphism Polymorphism ("many forms") allows the same interface/name to behave differently in different contexts. It is of two kinds:
- Compile-time (static): function overloading, operator overloading.
- Run-time (dynamic): achieved through virtual functions and base-class pointers.
class Shape { public: virtual void draw() { cout << "shape"; } };
class Circle : public Shape { public: void draw() { cout << "circle"; } };
Shape* p = new Circle();
p->draw(); // calls Circle::draw() at run time
Other Features
OOP also provides abstraction (showing only essential features and hiding implementation) and message passing (objects communicate by invoking each other's methods).
What is a constructor? Explain different types of constructors (default, parameterized and copy constructor) with a C++ program for each.
Constructor
A constructor is a special member function of a class that has the same name as the class, has no return type (not even void), and is called automatically when an object is created. Its purpose is to initialize the object's data members. Constructors can be overloaded.
Types of Constructors
1. Default Constructor A constructor that takes no arguments. If the programmer defines none, the compiler supplies an implicit one.
#include <iostream>
using namespace std;
class Number {
int n;
public:
Number() { n = 0; cout << "Default: n=" << n << endl; }
};
int main() {
Number a; // default constructor invoked
return 0;
}
2. Parameterized Constructor A constructor that accepts arguments, allowing objects to be initialized with different values at creation.
#include <iostream>
using namespace std;
class Number {
int n;
public:
Number(int x) { n = x; cout << "Parameterized: n=" << n << endl; }
};
int main() {
Number a(25); // parameterized constructor invoked
return 0;
}
3. Copy Constructor
A constructor that initializes a new object as a copy of an existing object of the same class. Its parameter is a reference to an object of the same class, usually const ClassName&.
#include <iostream>
using namespace std;
class Number {
int n;
public:
Number(int x) { n = x; }
Number(const Number &obj) { // copy constructor
n = obj.n;
cout << "Copy: n=" << n << endl;
}
};
int main() {
Number a(50);
Number b(a); // copy constructor invoked
return 0;
}
Key Points
- A constructor has the same name as the class and no return type.
- It is invoked automatically; overloading lets a class have all three forms simultaneously.
- The copy constructor must take its argument by reference to avoid infinite recursion.
What is operator overloading? Write a C++ program to overload the binary '+' operator to add two complex numbers using a member function.
Operator Overloading
Operator overloading is a form of compile-time (static) polymorphism that allows the standard C++ operators (+, -, *, ==, etc.) to be given additional, user-defined meanings when applied to objects of a class. It is implemented using the keyword operator followed by the operator symbol. It improves readability by letting objects be manipulated with familiar notation, but cannot create new operators or change operator precedence/arity.
When a binary operator is overloaded using a member function, the left-hand operand is the object that invokes the function (this), and the right-hand operand is passed as the argument.
Program: Overload binary '+' to add two complex numbers (member function)
#include <iostream>
using namespace std;
class Complex {
float real, imag;
public:
Complex() { real = imag = 0; }
Complex(float r, float i) { real = r; imag = i; }
// Overload binary + as a member function
Complex operator + (Complex c) {
Complex temp;
temp.real = real + c.real; // 'real' is left operand's member
temp.imag = imag + c.imag;
return temp;
}
void display() {
cout << real << " + " << imag << "i" << endl;
}
};
int main() {
Complex c1(3.5, 2.5), c2(1.5, 4.0), c3;
c3 = c1 + c2; // invokes c1.operator+(c2)
cout << "Sum = ";
c3.display(); // Output: Sum = 5 + 6.5i
return 0;
}
Explanation: The expression c1 + c2 is interpreted by the compiler as c1.operator+(c2). The calling object c1 supplies the first operand's real/imag, and c2 supplies the second. The function returns a new Complex object holding the sum.
Output: Sum = 5 + 6.5i
Section B: Short Answer Questions
Attempt any EIGHT questions.
Differentiate between procedural and object-oriented programming.
Procedural vs Object-Oriented Programming
| Procedural Programming (POP) | Object-Oriented Programming (OOP) |
|---|---|
| Program is divided into functions/procedures. | Program is divided into objects. |
| Follows a top-down approach. | Follows a bottom-up approach. |
| Data moves freely; little importance to data security. | Emphasizes data; data is hidden and secured via encapsulation. |
| Functions and data are separate. | Data and functions are bound together in a class. |
| No access specifiers; data is mostly global and accessible to all functions. | Uses access specifiers (private, public, protected) for data hiding. |
| Does not support inheritance, polymorphism, overloading. | Supports inheritance, polymorphism, abstraction, encapsulation. |
| Adding new data/functions is harder. | Easier to extend and maintain. |
| Examples: C, Pascal, FORTRAN. | Examples: C++, Java, Python, C#. |
What is a destructor? When is it called?
Destructor
A destructor is a special member function that has the same name as the class preceded by a tilde (~), takes no arguments, and has no return type. It is called automatically to clean up an object — releasing memory or other resources (e.g., closing files, freeing heap memory allocated with new) — when the object goes out of existence. A class can have only one destructor (it cannot be overloaded).
class Demo {
public:
Demo() { cout << "Constructed\n"; }
~Demo() { cout << "Destructed\n"; } // destructor
};
When is it called?
- For a local (automatic) object, when it goes out of scope (e.g., the function/block ends).
- For a global or static object, when the program terminates.
- For a dynamically allocated object, when
deleteis applied to its pointer.
Destructors are invoked in the reverse order of object construction.
Explain the use of the scope resolution operator (::) in C++.
Scope Resolution Operator (::)
The scope resolution operator :: is used in C++ to specify or access an identifier that belongs to a particular scope. Its main uses are:
1. Defining a member function outside the class The function name is qualified with the class name so the compiler knows which class it belongs to.
class A {
void show();
};
void A::show() { cout << "inside A"; } // :: links show() to class A
2. Accessing a global variable hidden by a local variable
When a local variable has the same name as a global one, ::name refers to the global version.
int x = 10;
int main() {
int x = 5;
cout << ::x; // prints 10 (global x)
}
3. Accessing static members of a class
cout << ClassName::staticMember;
4. Accessing namespace members
std::cout << "hi"; // cout from the std namespace
Thus :: resolves which scope (class, global, or namespace) an identifier comes from.
What is inline function? Write its syntax with an example.
Inline Function
An inline function is a function whose body the compiler attempts to substitute (expand) directly at the point of each call, instead of performing a normal function call. This eliminates the overhead of function-call mechanics (stack pushing, jumping, returning), which makes it useful for small, frequently called functions. The inline keyword is only a request to the compiler — it may ignore it for large or complex functions (e.g., those with loops, recursion, or switch statements).
Syntax
inline return_type function_name(parameters) {
// function body
}
Example
#include <iostream>
using namespace std;
inline int square(int x) {
return x * x;
}
int main() {
cout << "Square = " << square(5); // expanded as 5 * 5
return 0;
}
Output: Square = 25
Note: Member functions defined inside a class body are inline by default.
Differentiate between call by value and call by reference.
Call by Value vs Call by Reference
| Call by Value | Call by Reference |
|---|---|
| A copy of the actual argument is passed to the function. | The address/reference of the actual argument is passed. |
| The formal parameter is a separate variable. | The formal parameter is an alias for the actual argument. |
| Changes made inside the function do not affect the original variable. | Changes made inside the function do affect the original variable. |
| Uses more memory (a duplicate copy is made). | More memory-efficient (no copy of large objects). |
| Safer — original data is protected. | Allows the function to modify caller's data. |
Example
void byValue(int a) { a = a + 10; } // local copy changes only
void byRef(int &a) { a = a + 10; } // original changes
int main() {
int x = 5, y = 5;
byValue(x); // x stays 5
byRef(y); // y becomes 15
cout << x << " " << y; // Output: 5 15
}
What is a namespace in C++?
Namespace in C++
A namespace is a declarative region that provides a named scope for a group of identifiers (variables, functions, classes, etc.). Its purpose is to avoid name collisions when two different libraries or parts of a program define entities with the same name. Each namespace forms a distinct scope, so identical names can coexist when placed in different namespaces.
Declaration and access
namespace First {
int value = 10;
}
namespace Second {
int value = 20;
}
int main() {
cout << First::value; // 10 — accessed with ::
cout << Second::value; // 20
}
Members are accessed using the scope resolution operator (namespace::member), or the whole namespace can be brought into scope with a using directive:
using namespace std; // makes cout, cin, etc. directly available
The Standard C++ library places all its identifiers in the std namespace, which is why we write std::cout or include using namespace std;.
Explain the new and delete operators.
new and delete Operators
C++ provides the new and delete operators for dynamic memory management — allocating and freeing memory from the heap (free store) at run time.
new operator
The new operator allocates memory for a single object or an array at run time and returns a pointer to the allocated memory (and for class types, calls the constructor).
int *p = new int; // single int
int *p2 = new int(25); // single int initialized to 25
int *arr = new int[5]; // array of 5 ints
If allocation fails, new throws a bad_alloc exception (or returns nullptr with new(nothrow)).
delete operator
The delete operator frees memory that was allocated with new, returning it to the heap and preventing memory leaks (and calling the destructor for class objects).
delete p; // free single object
delete[] arr; // free an array (note the [])
Key points
- Always free what you allocate; un-freed memory causes memory leaks.
- Use
delete[](with brackets) for memory allocated withnew[]. - Unlike C's
malloc/free,new/deleteare operators, are type-safe, and automatically invoke constructors/destructors.
What is data hiding? How is it achieved in C++?
Data Hiding
Data hiding is an OOP principle (a form of encapsulation) in which the internal data of a class is kept inaccessible from outside the class and can only be manipulated through the class's own member functions. This protects data from accidental or unauthorized modification, ensures data integrity, and hides implementation details from the user.
How it is achieved in C++
Data hiding is achieved using access specifiers:
private— members are accessible only within the class (default for a class). This is the main mechanism of data hiding.protected— accessible within the class and its derived classes.public— accessible from anywhere; used to expose a controlled interface.
Data members are declared private, and controlled access is provided through public getter/setter functions.
class Account {
double balance; // private — hidden
public:
void setBalance(double b) {
if (b >= 0) balance = b; // validated access
}
double getBalance() { return balance; }
};
Here balance cannot be touched directly (acc.balance = -500; is illegal); it is reachable only through setBalance()/getBalance().
Write a short note on the default arguments in a function.
Default Arguments
A default argument is a value automatically assigned to a function parameter by the compiler when the caller does not supply that argument. Default values are specified in the function declaration/prototype using the assignment (=) symbol.
Rules
- Default arguments must be supplied from right to left (trailing parameters). Once a parameter has a default, all parameters to its right must also have defaults.
- They are normally given only once, in the function declaration (not repeated in the definition).
- They reduce the need for function overloading and make functions flexible.
Example
#include <iostream>
using namespace std;
int sum(int a, int b = 10, int c = 20) { // b and c have defaults
return a + b + c;
}
int main() {
cout << sum(5) << endl; // 5 + 10 + 20 = 35
cout << sum(5, 15) << endl; // 5 + 15 + 20 = 40
cout << sum(5, 15, 25)<< endl; // 5 + 15 + 25 = 45
return 0;
}
Output: 35, 40, 45. When fewer arguments are passed, the compiler fills in the defaults from the right.
Frequently asked questions
- Where can I find the BSc CSIT (TU) Object-Oriented Programming (BSc CSIT, CSC161) question paper 2074?
- The full BSc CSIT (TU) Object-Oriented Programming (BSc CSIT, CSC161) 2074 (regular) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
- Does the Object-Oriented Programming (BSc CSIT, CSC161) 2074 paper come with solutions?
- Yes. Every question on this Object-Oriented Programming (BSc CSIT, CSC161) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
- How many marks is the BSc CSIT (TU) Object-Oriented Programming (BSc CSIT, CSC161) 2074 paper?
- The BSc CSIT (TU) Object-Oriented Programming (BSc CSIT, CSC161) 2074 paper carries 60 full marks and is meant to be completed in 180 minutes, across 12 questions.
- Is practising this Object-Oriented Programming (BSc CSIT, CSC161) past paper free?
- Yes — reading and attempting this Object-Oriented Programming (BSc CSIT, CSC161) past paper on Kekkei is completely free.