BE Computer Engineering (Pokhara University) Object Oriented Programming in C++ (PU, CMP 162) Question Paper 2078
This is the official BE Computer Engineering (Pokhara University) Object Oriented Programming in C++ (PU, CMP 162) question paper for 2078, as set in the regular annual examination. It carries 100 full marks and a time allowance of 180 minutes, across 12 questions. On Kekkei you can attempt this Object Oriented Programming in C++ (PU, CMP 162) 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 BE Computer Engineering (Pokhara University) Object Oriented Programming in C++ (PU, CMP 162) exam or solving previous years' question papers, this 2078 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt all / any as specified.
(a) Distinguish between a structure and a class in C++ with respect to default access specifiers and member functions. (b) Explain the concept of a constructor and a destructor, stating the rules they must follow. (c) Write a complete C++ program that defines a class BankAccount having private data members accountNo, balance and an owner name. Provide a parameterized constructor to initialize an account, member functions deposit(amount) and withdraw(amount) (the latter must reject withdrawals that exceed the balance), and a destructor that prints a message when an object is destroyed. Demonstrate the class in main().
(a) Define inheritance and explain the different forms of inheritance (single, multiple, multilevel, hierarchical and hybrid) with a labelled diagram for each. (b) What is the diamond problem in multiple inheritance and how does C++ resolve it using virtual base classes? (c) Using a base class Shape with a virtual function area(), derive classes Circle and Rectangle, and write a program that uses a base-class pointer to demonstrate run-time polymorphism.
(a) What is operator overloading? List the operators that cannot be overloaded in C++ and explain why an overloaded operator cannot change the precedence or arity of the operator. (b) Differentiate between overloading an operator as a member function and as a friend function, giving one situation where a friend function is necessary. (c) Design a class Complex and overload the + operator (as a member function) and the << operator (as a friend function) so that two complex numbers can be added and printed.
(a) Explain the difference between a function template and a class template with a suitable example of each. (b) Write a generic function template maximum() that returns the larger of two values of any comparable type. (c) Briefly describe what the Standard Template Library (STL) provides under the categories containers, iterators and algorithms, naming two examples of each.
Section B: Short Answer Questions
Attempt all / any as specified.
Explain the four pillars of object-oriented programming: encapsulation, abstraction, inheritance and polymorphism. Briefly state how each is supported in C++.
What is a copy constructor? When is it invoked? Write the prototype of a copy constructor for a class Student and explain the difference between a shallow copy and a deep copy.
Differentiate between compile-time polymorphism and run-time polymorphism. What is a pure virtual function and how does it make a class abstract? Give a short code fragment.
Explain the visibility of base-class members in a derived class for public, protected and private modes of inheritance using a table. Which members of the base class are never inherited?
Describe the C++ exception-handling mechanism using try, throw and catch. Write a program that throws and catches a DivideByZero exception when a division by zero is attempted.
Explain the C++ stream class hierarchy for file handling (ifstream, ofstream, fstream). Write a program that writes three lines of text to a file data.txt and then reads the file back and displays its contents on the screen.
Differentiate between text-mode and binary-mode file access in C++. Explain the use of the seekg(), seekp() and tellg() functions for random access of a file with a short example.
(a) What is function overloading and how does it differ from a function template? (b) Explain this pointer with an example, and state why an overloaded assignment operator typically returns *this.