OOPs Concept Identification and Destructor Calling Identification – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-CBSE12A-2016-02B #CPP#5632    siteicon   siteicon  

Problem Statement - OOPs Concept Identification and Destructor Calling Identification

Observe the following C++ code and answer the questions (i) and (ii). Assume all necessary files are included:

class BOOK
{
  long Code ;
  char Title[20];
  float Price;
public:
  BOOK() //Member Function 1
  {
    cout<<”Bought”<<endl;
    Code=10;strcpy(Title,”NoTitle”);Price=100;
  }
  BOOK(int C,char T[],float P) //Member Function 2
  {
    Code=C;
    strcpy(Title,T);
    Price=P;
  }
  void Update(float P) //Member Function 3
  {
    Price+=P;
  }
  void Display() //Member Function 4
  {
    cout<<Code<<”:”<<Title<<”:”<<Price<<endl;
  }
  ~BOOK()        //Member Function 5
  {
    cout<<”Book Discarded!”<<end1;
  }
};
void main()                    //Line 1
{                              //Line 2
  BOOK B,C(101,"Truth",350};   //Line 3
  for (int I=0;I<4;I++)        //Line 4
  {                            //Line 5
    B.Update(50);C.Update(20); //Line 6
    B.Display();C.Display();   //Line 7
  }                            //Line 8
}                              //Line 9  

(i) Which specific concept of object oriented programming out of the following is illustrated by member Function 1 and member Function 2 combined together?

  • Data Encapsulation
  • Polymorphism
  • Inheritance
  • Data Hiding

(ii) How many times the message ”Book Discarded!” will be displayed after executing the above C++ code? Out of Line 1 to Line 9, which line is responsible to display the message ”Book Discarded!”

Solution

TC++ #5632

(i) Polymorphism

(ii) 2 times
Line 9

Notes

i)) Member Function 1 and Member Function 2 are overloaded constructors of the class BOOK. The phenomenon of overloading is due to concept of POLYMORPHISM in the object oriented programming.

ii) The destructor will be called two times as two objects B and C have been made in line 3. Since these objects are made inside the main routine, so they will be destroyed at the time of exiting the main routine. Hence they will be called at line no. 9 only.


Share

CSKC| Created: 1-Jan-2019 | Updated: 25-Apr-2019|CBSE12A-2016









×
Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Mult-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues


Back