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

function solution

1. // to find areas using functions.using switch import java.io.*; class m1 { double area(double r) {   return(3.14*r*r); } int area(int s) {   return(s*s); } double area(double l, double b) {   return(l*b); } public static void main(String args[]) throws IOException {   m1 ob= new m1(); double p; int q; double w; BufferedReader input= new BufferedReader(new InputStreamReader(System.in)); System.out.println("*** MAIN MENU ***"); System.out.println("1. Area of Circle"); System.out.println("2. Area of Square"); System.out.println("3. Area of Rectangle"); System.out.println("4. Exit"); System.out.println("Enter Choice(1-4)"); int ch=Integer.parseInt(input.readLine()); switch(ch) { case 1: System.out.println("Enter the radius"); double r=Double.parseDouble(input.readLine()); p=ob.area(r); System.out.println("Area of Circle"+p); brea...

operator s in Python