Chapter – 5. CONSTRUCTORS & DESTRUCTORS

OUTSIDE DELHI: 2007

2.b. Answer the questions (i) and (ii) after going through the following class : 2

class Science
{
char Topic[20] ;
int Weightage ;
public : Science () //Function 1
{
strcpy (Topic, “Optics”) ;
Weightage =30
cout<<”Topic Activated”;
} ~Science() //Function 2
{
cout<<”Topic Deactivated”;
}
};

(i) Name the specific features of class shown by Function 1 and Function 2 in the above example.

Ans: Member function 1 is a (non-parameterized or default) constructor (, which will be executed automatically at the time of creation of an object of class Science). Member function 2 is a destructor (,which will be executed automatically at the time of destruction of an object of class Science).

(ii) How would Function 1 and Function 2 get executed ?

Ans: They will be executed automatically. Member function 1 will be executed at the time of creation of an object of class Science. Member function 2 will be executed at the time of destruction of an object of class Science.

2.c. Define a class Travel in C++ with the description given below : 4

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


Warning: include_once(../../ebooks-footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter5_g.php on line 106

Warning: include_once(): Failed opening '../../ebooks-footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter5_g.php on line 106

Warning: include_once(../../../footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter5_g.php on line 108

Warning: include_once(): Failed opening '../../../footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter5_g.php on line 108