Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Define class and object. Write a C++ program to create a class 'Student' with data members and member functions to read and display student information.

Class and Object

Class: A class is a user-defined data type that serves as a blueprint or template for creating objects. It binds together data members (attributes) and member functions (behaviour) into a single unit and defines their access levels (private, protected, public). A class does not occupy memory until an object is created from it.

Object: An object is an instance of a class. It is a concrete entity that occupies memory and on which the member functions operate. Many objects can be created from a single class, each having its own copy of the data members.

C++ Program: Student class

#include <iostream>
#include <string>
using namespace std;

class Student {
private:
    int roll;
    string name;
    float marks;
public:
    void readData() {
        cout << "Enter roll, name and marks: ";
        cin >> roll >> name >> marks;
    }
    void displayData() {
        cout << "\nRoll : " << roll << endl;
        cout << "Name : " << name << endl;
        cout << "Marks: " << marks << endl;
    }
};

int main() {
    Student s;        // object of class Student
    s.readData();
    s.displayData();
    return 0;
}

Sample run

Enter roll, name and marks: 5 Ram 87.5
Roll : 5
Name : Ram
Marks: 87.5

Here Student is the class (blueprint) and s is an object (instance). The private data members are accessed only through the public member functions readData() and displayData(), illustrating encapsulation.

class-object
2long10 marks

What is inheritance? Explain the different types of inheritance with diagrams. Write a program to demonstrate multilevel inheritance.

Inheritance

Inheritance is the OOP mechanism by which a new class (the derived / child class) acquires the properties (data members) and behaviour (member functions) of an existing class (the base / parent class). It promotes code reusability, supports the is-a relationship, and enables extensibility.

Syntax: class Derived : access_specifier Base { ... };

Types of Inheritance

  1. Single inheritance – one derived class inherits from one base class. A → B
  2. Multilevel inheritance – a derived class itself acts as a base for another class, forming a chain. A → B → C
  3. Multiple inheritance – one derived class inherits from two or more base classes. A, B → C
  4. Hierarchical inheritance – several derived classes inherit from one common base class. A → B, A → C, A → D
  5. Hybrid inheritance – a combination of two or more of the above types (e.g. multiple + hierarchical).

Diagrams (described): In single, an arrow points from base A up to derived B. In multilevel, arrows form a vertical chain A→B→C. In multiple, two bases A and B both point to one child C. In hierarchical, one base A fans out to several children. In hybrid, the structures are mixed (often producing a diamond shape).

Program: Multilevel Inheritance

#include <iostream>
using namespace std;

class Person {            // base
protected:
    string name;
public:
    void setName(string n) { name = n; }
};

class Student : public Person {   // derived from Person
protected:
    int roll;
public:
    void setRoll(int r) { roll = r; }
};

class Result : public Student {   // derived from Student (multilevel)
    float gpa;
public:
    void setGpa(float g) { gpa = g; }
    void show() {
        cout << "Name: " << name << ", Roll: " << roll
             << ", GPA: " << gpa << endl;
    }
};

int main() {
    Result r;
    r.setName("Sita");   // inherited from Person
    r.setRoll(12);       // inherited from Student
    r.setGpa(3.8);
    r.show();
    return 0;
}

Result inherits members of Student, which in turn inherits members of Person, demonstrating a three-level (multilevel) inheritance chain.

inheritance
3long10 marks

What are virtual functions? Explain runtime polymorphism with a C++ program demonstrating the use of virtual functions and pointers to base class.

Virtual Functions

A virtual function is a member function declared in a base class using the keyword virtual and overridden in derived classes. When a base-class pointer (or reference) points to a derived-class object, a call to a virtual function is resolved at run time according to the actual type of the object pointed to, not the type of the pointer. This mechanism is implemented through a virtual table (vtable) and is the basis of dynamic binding.

Runtime (Dynamic) Polymorphism

Polymorphism means "one interface, many forms." Runtime polymorphism allows the correct overridden function to be selected during execution rather than at compile time. It requires:

  1. An inheritance hierarchy,
  2. A function declared virtual in the base class and overridden in derived classes,
  3. Access through a base-class pointer or reference.

C++ Program

#include <iostream>
using namespace std;

class Shape {
public:
    virtual void area() {            // virtual function
        cout << "Area of generic shape" << endl;
    }
};

class Circle : public Shape {
    float r;
public:
    Circle(float radius) : r(radius) {}
    void area() override {
        cout << "Area of circle = " << 3.1416 * r * r << endl;
    }
};

class Rectangle : public Shape {
    float l, b;
public:
    Rectangle(float L, float B) : l(L), b(B) {}
    void area() override {
        cout << "Area of rectangle = " << l * b << endl;
    }
};

int main() {
    Shape *ptr;                 // base-class pointer
    Circle c(5);
    Rectangle rect(4, 6);

    ptr = &c;
    ptr->area();   // calls Circle::area()  -> resolved at run time

    ptr = &rect;
    ptr->area();   // calls Rectangle::area()
    return 0;
}

Output

Area of circle = 78.54
Area of rectangle = 24

The same statement ptr->area() invokes different functions depending on the object the base pointer currently refers to. Without virtual, Shape::area() would always be called (static binding); with virtual, the call is bound dynamically, achieving runtime polymorphism.

polymorphismvirtual-function
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

What is encapsulation? Why is it important?

Encapsulation is the OOP principle of wrapping data members and the member functions that operate on them into a single unit (a class), while restricting direct access to the internal data by declaring it private and exposing it only through public member functions (getters/setters). This is also called data hiding.

Importance:

  • Data security / hiding: internal state cannot be modified directly or accidentally from outside the class.
  • Controlled access: validation can be enforced inside setter functions before data is changed.
  • Modularity & maintainability: the implementation can change without affecting external code, since the public interface stays the same.
  • Reduced complexity: users interact only with a clean public interface, not the internal details.
encapsulation
5short5 marks

Define a pointer. How are objects accessed using pointers?

Pointer: A pointer is a variable that stores the memory address of another variable or object instead of a value itself. It is declared using the * operator, e.g. int *p; p = &x; where & gives the address of x.

Accessing objects using pointers: When a pointer holds the address of an object, its members are accessed using the arrow operator (->) instead of the dot operator.

class Student {
public:
    int roll;
    void show() { cout << roll << endl; }
};

Student s;
Student *ptr = &s;   // pointer to object
ptr->roll = 10;      // same as (*ptr).roll = 10;
ptr->show();         // calls member function via pointer

Here ptr->roll and ptr->show() access the data member and member function of the object through the pointer. Object pointers are also essential for dynamic object creation with new and for runtime polymorphism.

pointers
6short5 marks

What is a pure virtual function?

A pure virtual function is a virtual function that has no definition (body) in the base class and is declared by assigning 0 to it:

virtual void draw() = 0;   // pure virtual function

It acts only as a placeholder that must be overridden by every concrete derived class. A class that contains at least one pure virtual function is called an abstract class, and no object can be instantiated from it; it can only be used as a base class. Pure virtual functions are used to enforce a common interface that all derived classes are required to implement, supporting runtime polymorphism.

polymorphism
7short5 marks

Differentiate between a base class and a derived class.

Base class vs Derived class

Base classDerived class
The existing class whose members are inherited (parent / super class).The new class that inherits from the base class (child / sub class).
Defined first; does not depend on the derived class.Defined using : access Base; depends on the base class.
Provides common, general members.Adds new members and/or overrides inherited ones (specialization).
Its public/protected members become accessible to the derived class.Inherits accessible members of the base plus its own.
Example: class Vehicle { ... };Example: class Car : public Vehicle { ... };

In short, the base class represents a general concept while the derived class represents a more specialized version of it, modelling an is-a relationship (a Car is a Vehicle).

inheritance
8short5 marks

What is the use of the 'protected' access specifier?

The protected access specifier provides an intermediate level of access between private and public.

  • A protected member cannot be accessed directly from outside the class (like private).
  • But it can be accessed by member functions of derived (child) classes, which private members cannot.

Use: It is mainly used in inheritance so that a base class can keep its data hidden from the outside world while still allowing derived classes to use and inherit those members directly.

class Base {
protected:
    int x;        // accessible in derived classes
};
class Derived : public Base {
public:
    void set() { x = 5; }   // OK: protected member used here
};
// x is NOT accessible directly from main()
access-specifiers
9short5 marks

Write a short note on constructor overloading.

Constructor Overloading

Constructor overloading means defining more than one constructor in the same class with different parameter lists (different number, type, or order of arguments). The compiler selects the appropriate constructor based on the arguments supplied when the object is created. It is an example of compile-time (static) polymorphism and lets objects be initialized in different ways.

class Box {
    int l, b;
public:
    Box() { l = b = 0; }                 // default constructor
    Box(int x) { l = b = x; }            // one-argument constructor
    Box(int x, int y) { l = x; b = y; }  // two-argument constructor
    int area() { return l * b; }
};

int main() {
    Box b1;          // calls Box()
    Box b2(5);       // calls Box(int)
    Box b3(4, 6);    // calls Box(int, int)
    cout << b3.area();  // 24
}

Advantage: the same class can create objects with no data, partial data, or full data, improving flexibility and readability.

constructor
10short5 marks

What is a reference variable? Give an example.

A reference variable is an alias (an alternative name) for an already existing variable. It is declared with the & operator and must be initialized at the time of declaration; once bound, it cannot be made to refer to another variable. Any change made through the reference directly affects the original variable, since both share the same memory location.

Example:

int a = 10;
int &ref = a;   // ref is a reference (alias) to a
ref = 20;       // changes a to 20
cout << a;      // prints 20

Reference variables are commonly used for call-by-reference in functions, which lets a function modify the caller's argument and avoids the overhead of copying.

references
11short5 marks

Explain the difference between struct and union.

struct vs union

Both struct and union are user-defined types that group members of different data types, but they differ in memory allocation.

Featurestructunion
MemoryAllocates separate memory for each member; total size = sum of all members (plus padding).Allocates a single shared memory block equal to the size of its largest member.
Member storageAll members can hold values simultaneously.Only one member holds a meaningful value at a time.
AccessAll members can be used together.Writing to one member overwrites the others.
UseWhen all fields are needed at once.To save memory when only one field is needed at a time.
struct S { int a; char b; }; // size ~ sizeof(int)+sizeof(char)+padding
union  U { int a; char b; }; // size = sizeof(int) (largest member)

Thus a struct keeps all members alive together, whereas a union lets its members overlap in the same memory, saving space at the cost of holding only one valid member at a time.

data-types
12short5 marks

What is a manipulator? Name any two.

A manipulator is a special function (mostly defined in <iomanip> and <iostream>) that is used with the insertion (<<) or extraction (>>) operators to modify or format the input/output stream. Manipulators control things like field width, precision, number base, and line breaks.

Examples (any two):

  • endl – inserts a newline and flushes the output buffer.
  • setw(n) – sets the field width to n characters.
  • setprecision(n) – sets the number of digits of floating-point precision.
  • hex / oct / dec – display integers in hexadecimal / octal / decimal.
cout << setw(8) << setprecision(3) << 3.14159 << endl;
io

Frequently asked questions

Where can I find the BSc CSIT (TU) Object-Oriented Programming (BSc CSIT, CSC161) question paper 2075?
The full BSc CSIT (TU) Object-Oriented Programming (BSc CSIT, CSC161) 2075 (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) 2075 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) 2075 paper?
The BSc CSIT (TU) Object-Oriented Programming (BSc CSIT, CSC161) 2075 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.