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...

CLASS and OBJECTS

CLASS and OBJECTS 1.Give the output of the following program ( Assuming that all required header files are  included in the program )     :                class TEMP { static int a; float b; public: TEMP( ) { b=10; } void INTEMP( ) { a++; b=a+10; } void OUTTEMP( ) { cout<<a*i<<"$"<<b-3<<endl; } }; int TEMP::a=2; void main() { TEMP ob[5]; for(int x=1;x<5;x++) ob[x].INTEMP( ); for(x=1;x<5;x++) ob[x].OUTTEMP( );}  2.  Define a class Travel in C++ with the description given below: Private Members: T_Code of type string No_of_Adults of type integer No_of_Children of type integer Distance of type integer TotalFare of type float Public Members: A constructor to assign initial values as follows : T_Code with the word “NULL” No_of_Adults as 0 No_of_Children as 0 Distance as 0 TotalFare as 0 A func...
CYBER OLYMPIAD SYLLABUS Cyber Olmpiad CLASS-2 Total Questions : 35   Time : 1 hr. Syllabus Section – 1 : Patterns, Measuring Units, Odd One Out, Series Completion,  Geometrical Shapes, Analogy, Ranking Test, Grouping of Figures, Coding-Decoding, Embedded Figures. Section – 2 : Introduction to Computers, General Information about Computers, Parts of Computer, Uses of Computer, Learning to use Keyboard and Mouse, Introduction to MS-Paint, Latest Developments in the field of IT. Section – 3 : Higher Order Thinking Questions - Syllabus as per Section – 2.          Questions are based on Windows 7 and MS-Office 2010. CLASS-3 Total Questions : 35   Time : 1 hr. Syllabus Section – 1 : Patterns, Analogy and Classification, Coding-Decoding, Mirror Images, Embedded Figures, Alphabet Test, Ranking Test, Grouping of Figures, Figure Matrix, Geometrical Shapes, Days and Dates & Possible Combinations. Section – 2...