CBSE (Science) Class 12CBSE
Share
Notifications

View all notifications

Observe the Following C++ Code and Answer the Questions (I) and (Ii): - CBSE (Science) Class 12 - Computer Science (C++)

Login
Create free account


      Forgot password?

Question

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

class Passenger
{
   long PNR;
   char Name[20];
public:
   Passenger () · //Function 1
   { cout<<"Ready"<<endl; }

   void Book(long P,char N[]) //Function 2
   { PNR = P; strcpy(Name, N);}

   void Print () //Function 3
   { cout«PNR << Name <<endl; }
   
   -Passenger() //Function 4
   { cout<<"Booking cancelled! "<<endl;}
};

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

void main()
{
   Passenger P;
   _________      //Line 1
   _________      //Line 2
}//Ends here

2) Which function will be executed at } // Ends here? What is this function referred as?

Solution

1)P.Book(1234567,"Ravi");   //Line 1

P.Print();  //Line 2

2) ~Passenger()

it is a Destructor Function

  Is there an error in this question or solution?

APPEARS IN

Solution Observe the Following C++ Code and Answer the Questions (I) and (Ii): Concept: Member of a Class - Data Members and Member Functions (Methods).
S
View in app×