CS304 Final Term Solved Subjective Set 3 by Junaid
- Type
- Final term past paper
- Course
- CS304 Object Oriented Programming
- Size
- PDF 789 KB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extensionSign in with the extension for 30 a day.
Preview text
Text from pages 2, 3, 4 of 23. Download the file for all 23 pages.
Q1. Write the names of two types of Templates. MARKS: 2
Answer: (Page 256) a. Function Templates (in case we want to write general function like printArray) b. Class Templates (in case we want to write general class like Array class)
Q2. Describe the way to declare a template function as a friend of any class. 2marks
Answer: (Page 294)
template< class T >
class B { int data; friend void doSomething( T ); // granting friendship to template doSomething in // class B friend A< T >; // granting friendship to class A in class B
Q3. Can a constructor throw an exception? How to handle the errors, when the constructor fails?
Answer: Yes, Constructor can throw an exception But In constructor if an exception is thrown than all objects created so far are destroyed. Exception due to constructor of any contained object or the constructor of a parent class can be caught in the member initialization list.
Q4. Why these operators can not be overloaded:
Answer: (Page 141) Reason: They take actual current object name, rather than value in their argument
Q5. What is graceful termination method of Error handling; give its example using C++.
Answer: (Page 330) Program can be designed in such a way that instead of abnormal termination, that causes the wastage of resources, program performs clean up tasks, mean we add check for expected errors (using if conditions), Example – Graceful Termination int Quotient (int a, int b ) { if(b == 0){ cout << “Denominator can’t “ << “ be zero” << endl; // Do local clean up exit(1);
return a / b;
Q6. How can you describe Virtual destructor? Why Virtual destructor is used?
Answer: (Page 234) When delete operator is applied to a base class pointer, base class destructor is called regardless of the object type. Only base class part of object will be deleted other parts will remain as it is this result in memory leak (wastage of memory), Virtual Destructors make it possible that complete object is being deleted so there is no memory leak (waste of memory).
Q7. Motor car can be called a good candidate for being an object so, this ibject contains Encapsulation characteristic. You are required to apply the concept of Encapsulation on “Motor Car”.
Answer: Yes Motor Care is a good candidate for apply the concept of encapsulation In Motor Car we have the following Objects which fully describes the phenomena of encapsulation.
- Steer Wheels
- Accelerate
- Change Gear
- Apply Brakes
- Turn Lights On/Off
In encapsulation we just provide the user an interface and hide the Full implementation from the user because user don’t want to know the implementation he Just want his work should be done perfectly
For example: Breaks of car, we gave just a paddle to the User and encapsulate how it works inside the engine. Same for accelerator, gear, steer wheels and turn on and off of Light.
Q8. Suppose base class and derived class has a member function with same signature. Now call that member function through the pointers to a base class object. Now, what determines that the base class member function or derived class function will be called?
Q9. What do you know about exception in initialization? Explain with example.
Answer: (Page 345)
Exception due to constructor of any contained object or the constructor of a parent class can be caught in the member initialization list.
Example
Student::Student (String aName) : name(aName) /*The constructor of String can throw a exception*/
The programmer may want to catch the exception and perform some action to rectify the problem
Example
Student::Student (String aName) try : name(aName) {
catch (…) {
Q10. How can we set the default values for non type parameters?
Answer: (Page 284) We can set default value for this non type parameters, as we do for parameters passed in ordinary functions, template< class T, int SIZE = 10 > class Array { private: T ptr[SIZE]; public: void doSomething();
Q11. Explain the statement vector <int> ivec (4,3)
Answer: This would create a vector of four elements, each one initialized to 3. ivec looks like this:
Q12. Tell the procedure of making a class abstract in C++ by giving an example.
Answer: (Page 230) In C++, we can make a class abstract by making its function(s) pure virtual. Conversely, a class with no pure virtual function is a concrete class (which object can be instantiated)
A class having pure virtual function(s) becomes abstract
Related CS304 files
All CS304 files →- CS304 Final Term Quizzes July 2023 by Sana Sheikh Final term PDF 590 KB
- CS304 Final Term Solved Subjective Final term PDF 1.8 MB
- CS304 Final Term Solved Subjective by Junaid Final term PDF 1.1 MB
- CS304 Final Term Solved MCQs by Junaid Final term PDF 2 MB
- CS304 Highlighted Handouts Lectures 1-45 Highlighted PDF 7.7 MB
- CS304 Quiz 1 Solution Quiz PDF 571 KB
Get more out of VUBuddy, for free
- Unlimited downloads
- The explanation behind every MCQ answer
- Study offline on slow data
- 30 downloads a day instead of 3
- Sign in and buy Pro Semester here
One Pro Semester membership works in both the extension and the app.