Browse papers
A

Section A: Long Answer Questions

Attempt all / any as specified.

4 questions
1long12 marks

(a) Define a class and an object. Explain the difference between data members and member functions with a suitable example. [4]

(b) Write a complete C++ program to define a class Distance having data members feet and inches. Include a parameterized constructor to initialize the object, a member function to add two Distance objects, and a function to display the result. Demonstrate the use of the this pointer in your program. [8]

classes-and-objectsconstructors-and-destructors
2long12 marks

(a) What is meant by virtual function? Explain how run-time polymorphism is achieved in C++ using virtual functions and base class pointers. [5]

(b) Write a C++ program that defines a base class Shape with a virtual function area(). Derive classes Circle and Rectangle from it, override area() in each, and use an array of base class pointers to compute and display the area of different shapes. [7]

inheritancepolymorphism-and-virtual-functions
3long12 marks

(a) State the rules and restrictions for operator overloading in C++. Why can some operators not be overloaded? [4]

(b) Write a C++ program to create a class Complex for complex numbers and overload the + and * operators to add and multiply two complex numbers respectively. Implement at least one operator using a friend function. [8]

operator-overloadingtemplates
4long12 marks

(a) Explain the exception handling mechanism in C++ using try, catch, and throw. How can multiple catch blocks be used to handle different types of exceptions? [6]

(b) Write a C++ program that reads integers from a file named data.txt, computes their sum, and writes the result to result.txt. The program must throw and handle an exception if the input file cannot be opened. [6]

exception-handlingfile-streams
B

Section B: Short Answer Questions

Attempt all / any as specified.

8 questions
5short6 marks

Differentiate between a constructor and a destructor. Explain the concept of a copy constructor with an example and state when the default copy constructor leads to problems (shallow copy).

constructors-and-destructors
6short6 marks

Explain the different types of inheritance supported in C++ with neat diagrams. Discuss the ambiguity problem that arises in multiple inheritance and how it is resolved using virtual base classes.

inheritance
7short6 marks

What are function templates and class templates? Write a function template maximum() that returns the largest of two values of any data type, and show how it is invoked for int and double arguments.

templates
8short6 marks

What is a pure virtual function? Define an abstract base class with an example and explain why an object of an abstract class cannot be instantiated.

polymorphism-and-virtual-functions
9short6 marks

Explain the difference between text mode and binary mode file handling in C++. Describe the use of the file pointers and the functions seekg(), seekp(), and tellg() for random access in files.

file-streams
10short6 marks

Explain the meaning of static data members and static member functions of a class. Write a short program that uses a static data member to count the number of objects created from a class.

classes-and-objects
11short6 marks

Distinguish between overloading a unary operator using a member function and using a friend function. Write a program segment to overload the unary ++ operator (prefix form) for a Counter class.

operator-overloadingclasses-and-objects
12short4 marks

Write short notes on: (a) the catch(...) block (catch-all handler), and (b) rethrowing an exception.

exception-handling