Skip to main content


Sri Aurobindo Public School, Baddi
CLASS XII: Test-1
Topic : Class and Objects/Constructor and destructor

1. Write the output of the following C++ program code                                    3
Note : Assume all required header files are already being  included in the program.
class Eval
{
Char Level;
int Point;
public:
Eval(){Level=’E’;Point=0;}
void Sink(int L)
{ Level- =L; }
void
Float(int L)
{  Level+=L ;
Point++;  }
void Show()
{ cout<<Level<<”#”<<Point<<endl;  }};

void main()
{  Eval E;
E.Sink(5);
E.Show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();   }

2. Write the definition of a class Photo in C++  with following description  :               4                             
Private Members–
Pno         //Data member for Photo Number (an integer)
Category        //Data member for Photo Category (a string)
Exhibit          //Data member for Exhibition Gallery (a string)
FixExhibit           //A member function to assign  Exhibition Gallery as per Category  as shown in the following table 

Category             Exhibit
Antique             Zaveri
Modern              Johnsen
Classic               Terenida
Public Members
 Register() //A function to allow user to enter values Pno, Category and call FixExhibit() function
 ViewAll() // A function to display all the data members

3. What is a copy constructor ? Give a su itable example in C++ to illustrate with its definition within a class and a declaration of an object with the help of it.            2
(b)  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; }}
;
(i)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


Comments

Popular posts from this blog