0% found this document useful (0 votes)
13 views5 pages

OOP CPP KUK Solved Paper With Questions

The document is a solved paper for Object Oriented Programming using C++ from KUK University, covering key concepts such as data hiding, copy constructors, inline functions, and exception handling. It includes definitions, examples, and explanations of various OOP principles like function overloading, constructors, friend functions, abstract classes, and polymorphism. The paper serves as a study guide for BCA students, providing practical examples and coding snippets for better understanding.

Uploaded by

oknotokay098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

OOP CPP KUK Solved Paper With Questions

The document is a solved paper for Object Oriented Programming using C++ from KUK University, covering key concepts such as data hiding, copy constructors, inline functions, and exception handling. It includes definitions, examples, and explanations of various OOP principles like function overloading, constructors, friend functions, abstract classes, and polymorphism. The paper serves as a study guide for BCA students, providing practical examples and coding snippets for better understanding.

Uploaded by

oknotokay098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Object Oriented Programming using C++ - Solved Paper

OOP Using C++ - KUK University (Solved Paper with Questions)

OBJECT ORIENTED PROGRAMMING USING C++ (B23-CAP-201)

KUK University - BCA

COMPULSORY QUESTION

1. Define the following terms:

(i) Data Hiding:

Data hiding is the concept of restricting access to the internal details of a class. It is implemented using access

specifiers like 'private' and 'protected' in C++.

(ii) Resolution Operator:

The scope resolution operator (::) is used to define a function outside a class or to access a global variable when

there is a local variable with the same name.

(iii) Copy Constructor:

A copy constructor creates a new object as a copy of an existing object.

Example:

class Sample {

int a;

public:

Sample(int x) { a = x; }

Sample(const Sample &s) { a = s.a; }

};

(iv) Define any two string operators:

'+' Operator: Used to concatenate two strings.

'==' Operator: Used to compare if two strings are equal.

(v) Handling Uncaught Exceptions:


Object Oriented Programming using C++ - Solved Paper

Exceptions are handled using try-catch blocks. Uncaught exceptions lead to program termination.

Example:

try { throw 10; } catch (int e) { cout << "Caught " << e; }

UNIT - I

2. (a) Inline Functions:

Inline functions reduce the overhead of function calls by expanding the function at the point of its invocation.

Example:

inline int cube(int x) { return x * x * x; }

(b) Union in C++:

A union allows storing different data types in the same memory location.

Example:

union Data {

int i;

float f;

};

3. (i) Function Overloading:

Function overloading allows multiple functions with the same name but different parameters.

Example:

int add(int a, int b) { return a + b; }

float add(float a, float b) { return a + b; }

(ii) Pointer:

A pointer is a variable that stores the address of another variable.

Example:

int x = 10;

int *p = &x;

UNIT - II
Object Oriented Programming using C++ - Solved Paper

4. What is the use of constructor and destructor in C++? How do we declare them? Write a program.

Constructor initializes objects and destructor cleans them up.

Example:

class Demo {

public:

Demo() { cout << "Constructor"; }

~Demo() { cout << "Destructor"; }

};

5. What are friend functions and friend classes? Write a program.

Friend functions can access private data of a class.

Example:

class Complex {

int a, b;

public:

void set(int x, int y) { a = x; b = y; }

friend Complex add(Complex, Complex);

};

UNIT - III

6. (i) Abstract Class:

A class with at least one pure virtual function.

Example:

class Shape {

virtual void draw() = 0;

};

(ii) Virtual Base Class:

Used in multiple inheritance to avoid duplication.

Example:
Object Oriented Programming using C++ - Solved Paper

class A {};

class B : virtual public A {};

class C : virtual public A {};

class D : public B, public C {};

7. Write and explain a program to overload any unary operator.

Example:

class Sample {

int x;

public:

Sample(int a) { x = a; }

void operator++() { x = x + 1; }

void show() { cout << "x = " << x; }

};

UNIT - IV

8. What is the benefit of handling exceptions? How can you catch all exceptions? Explain with example.

Exception handling prevents crashes and handles runtime errors.

Example:

try {

throw 10;

} catch (...) {

cout << "Exception caught";

9. What do you mean by polymorphism? How can you achieve polymorphism with pointers? How late binding is different

from early binding?

Polymorphism means many forms, achieved using virtual functions.

Example:

class Base {

public:
Object Oriented Programming using C++ - Solved Paper

virtual void show() { cout << "Base"; }

};

class Derived : public Base {

public:

void show() { cout << "Derived"; }

};

Late binding happens at runtime via virtual functions.

You might also like