Answered! C++ question: a)After the code in the catch block is executed program execution continues inside the try block.(T or F)…

C++ question:

a)After the code in the catch block is executed program execution continues inside the try block.(T or F)

Don't use plagiarized sources. Get Your Custom Essay on
Answered! C++ question: a)After the code in the catch block is executed program execution continues inside the try block.(T or F)…
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

b)All classes should be converted to templates so they can be used with different types.(T or F)

c)

Who can access private data in a class?

A.members of the class and friends
B.members of the class
C.friends of the class
D.members of the class and of derived classes

d)Operators can be overloaded as
A.members or friends of a class
B.friends of a class
C.data members of a class
D.members of a class

e) Polymorphism is implemented in C++ using a mechanism known as

A.inheritance
B.IS-A relationship
C.composition
D.late binding

Expert Answer

a.) These are few cases when and when not catch block runs

Case 1– When the code present in try block is not throwing any exception it simply executrs fully and the control is passed to then finally block and case block is skipped but important point to note is that our try block has executed fully then it checks whether the control is passed to catch block or finally block.

Case 2- When the code present in try block is throwing any exception then the control is passed to catch block and then at last to finally block.In this case also the only after try block has executed fully the control is passed to next block

So as we have seen in both cases the try block is executed fully then only the control is passed so the answer to our question is FALSE because after the code in catch has executed the control will go to finally block and not to try block

b.) Templates are a provision provided by C++ programming language allowing us to operarte functions and classes as generic types. This allows a function or class to work on many different data types without being rewritten for each one. When colabaleraly used with inheritance and overriding it gives us great utility.There are various variants of templates

  • Function templates
  • Class templates: In a class template we have to template full class to be used as generic type.
  • Variable templates

c.) Option A

A private member variable or function can be accessed only by the class members and friend functions.All the members are private by default unless and until we expilcitly label it.

d.) Option A

Operators can be overloaded as members or friends of a class.

Overloading operators using a member function is almost same as overloading operators using a friend function but the difference is that member function takes argument explicitily

Syntax of operator overloading using friend function

friend return type operator operator symbol(v1,v2) //v1,v2 are varaibles

{

statement a;

statement b;

}

These are the points to be kept in mind while overloading an operator using a member function:

  • The overloaded operator should be added as a member function of the left operand.
  • The left operand becomes the implicit *this object
  • Rest operands will serve as function parameters.

e.) Polymorphism is implemented in C++ using inheritance and late binding (explained below) the best example to it is overriding which is done as late binding. Actually polymorphism can be achievd by two things

  • First is overloading in which two functions can have same and they are identified by the number and type of arguments passed
  • Second is by function overriding which is done at run time also known as late binding but this all got backed by a mechanism called inheritance .So first inheritance is the basic mechanism and inside that we have late binding as sub-mechansim.We can choose two options in this.i.e Inheritance and late binding

Still stressed from student homework?
Get quality assistance from academic writers!