1.

Answer the question (i) to (v) after going through the following class.classBook{intBookCode ; char Bookname[20];float fees; public:Book() //Function 1{fees = 1000;BookCode = 1;strcpy (Bookname, “C++”);}void display(float C) //Function 2{cout << BookCode << “:”<< Bookname << “:”<< fees << endl;~ Book() //Function 3{cout << “End of Book Object”<< endl;}Book (intSC, char S[ ], float F); //Function 4};1. In the above program, what are Function 1 and Function 4 combined together referred as?2. Which concept is illustrated by Function3? When is this function called/ invoked?3. What is the use of Function3?4. Write the statements in main to invoke functionl and function25. Write the definition for Function4.

Answer»

1. Constructor overloading (function 1 and function 4 are constructors with different signatures in the class book)

2. Function 3 is destructor of the class. Function 3 is executed when the object of the class book goes out of scope.

3. Function 3 is destructor of the class.

  • Destructor (function3) will free resources if any that the object may have acquired during its lifetime 
  • Destructor function removes the memory of an object which was allocated by the constructor at the time of creating an object. Thus frees the unused memory.
  • 4. book b;
  • b.display (4.5);

5. Book: :Book (int sc.char.s[], float, F) //

Function 4

{

Book Code = SC

strcpy (Book name, S);

fees = F;

}



Discussion

No Comment Found

Related InterviewSolutions