Almost 50% MCQ and 50% long from moaaz file
CS304_FinalPaper_Spring2014 Held On 28-AUG-2014
Q41. Which specification is implemented using which specifier? Your answer should be brief. (2 marks)
Q42. A person is an abstract class. Describe the salient features of abstract class Answer:- Abstract class’s objects cannot be instantiated they are used for inheriting interface and/or implementation, so that derived classes can give implementation of these concepts. 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
Q.44 Give the names of two types of containers basically known as first class containers.(2 Marks) Answer:- (page 14 Q.10 moaaz file) Sequence and associative containers are collectively referred to as the first-class containers
Q.45 In which situation do we need to implement Virtual inheritance? explain with an example (5 marks)
Q.46 In which situation virtual inheritance is implemented? Explain with example (3 marks) Answer:- (page 13 Q.3 moaaz file) In multiple inheritance while solving diamond problem virtual inheritance need to implement. The solution of avoid this problem is virtual inheritance so that in multiple inheritance only one copy of base class is generated as shown below instead of two separate copies. In virtual inheritance there is exactly one copy of the anonymous base class object Example: class Vehicle{ protected: int weight; }; class LandVehicle : public virtual Vehicle{ }; class WaterVehicle : public virtual Vehicle{ };
Q.47 Write C++ code for Try Catch in Initialization list Answer:- Example Student::Student (String aName) : name(aName) /*The constructor of String can throw a exception*/ { ... } Exception in Initialization List 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 (…) { }
Q.49 Virtual Functions Implementation example given (see page 222 and 223 handouts) What changes we should made in this example to get output Line Circle Triangle Instead of Shape Shape Shape
Q.50 Write a template function that returns the average of all elements of array. The arguments to the function should be the array name and size of the array (type int) (5 marks) Answer:- (see page 267 of handouts)
Q.51 There are some errors in the code given below, you have to Indicate the line no. with error/s Give the reason for error/s Correct the error/s. Answer:- (Page 06 Q.38 moaaz file)
Q.52 Write output of the following code. (5 marks) Int wait_time=46; Try { Cout “Entering Try-block”endl; if (wait_time>30) Throw wait_time; Cout “Leaving Try Block”endl; } Catch (int thrown_value) { Cout ”Exception thrown/n” “ wait_time equal to “” thrown_value endl; } Cout “After Catch-Block”endl;
CS304_FinalPaper_Spring2014 Held On 28-AUG-2014
Q41. Which specification is implemented using which specifier? Your answer should be brief. (2 marks)
Q42. A person is an abstract class. Describe the salient features of abstract class Answer:- Abstract class’s objects cannot be instantiated they are used for inheriting interface and/or implementation, so that derived classes can give implementation of these concepts. 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
Q.44 Give the names of two types of containers basically known as first class containers.(2 Marks) Answer:- (page 14 Q.10 moaaz file) Sequence and associative containers are collectively referred to as the first-class containers
Q.45 In which situation do we need to implement Virtual inheritance? explain with an example (5 marks)
Q.46 In which situation virtual inheritance is implemented? Explain with example (3 marks) Answer:- (page 13 Q.3 moaaz file) In multiple inheritance while solving diamond problem virtual inheritance need to implement. The solution of avoid this problem is virtual inheritance so that in multiple inheritance only one copy of base class is generated as shown below instead of two separate copies. In virtual inheritance there is exactly one copy of the anonymous base class object Example: class Vehicle{ protected: int weight; }; class LandVehicle : public virtual Vehicle{ }; class WaterVehicle : public virtual Vehicle{ };
Q.47 Write C++ code for Try Catch in Initialization list Answer:- Example Student::Student (String aName) : name(aName) /*The constructor of String can throw a exception*/ { ... } Exception in Initialization List 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 (…) { }
Q.49 Virtual Functions Implementation example given (see page 222 and 223 handouts) What changes we should made in this example to get output Line Circle Triangle Instead of Shape Shape Shape
Q.50 Write a template function that returns the average of all elements of array. The arguments to the function should be the array name and size of the array (type int) (5 marks) Answer:- (see page 267 of handouts)
Q.51 There are some errors in the code given below, you have to Indicate the line no. with error/s Give the reason for error/s Correct the error/s. Answer:- (Page 06 Q.38 moaaz file)
Q.52 Write output of the following code. (5 marks) Int wait_time=46; Try { Cout “Entering Try-block”endl; if (wait_time>30) Throw wait_time; Cout “Leaving Try Block”endl; } Catch (int thrown_value) { Cout ”Exception thrown/n” “ wait_time equal to “” thrown_value endl; } Cout “After Catch-Block”endl;
Comments
Post a Comment
Please give us your feedback & help us to improve this site.