Detailed Print – Computer Sir Ki Class

Login


Lost your password?

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


Shop
siteicon
Solved Problem#CPP#5848

Problem Statement - 02B

Observe the following C++ code and answer the questions (i) and (ii) :

class Traveller
{
  long PNR;
  char TName[20];
public :
  Traveller()                  //Function 1
  {cout<<"Ready"<<endl;}
  void Book(long P,char N[])   //Function 2
  {PNR = P; strcpy(TName, N);}
  void Print()                 //Function 3
  {cout<<PNR << TName <<endl;}
  ~Traveller()                 //Function 4
  {cout<<"Booking cancelled!"<<endl;}
};

(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function 3 respectively in the following code:

v oid main{)
{
  Traveller T;
  _____________ //Line 1
  _____________ //Line 2
}//Stops here

(ii) Which function will be executed at }//Stops here? What is this
function referred as ?

Solution

Click to open popup

Solved Problem Understanding

(i) T.Book(1234567,"Ravi");   //Line 1
    T.Print();                //Line 2

(ii) Function 4
     OR
     ~Traveller()
     It is a Destructor function.