Page 155 - C++
P. 155
Q2 (a) Write any two similarities between Constructor and Destructor. Write the function headers for
constructor and destructor of a class student. (2)
(b) Write the output of the following C++ code. Also, write the name of the feature of Object Oriented
Programming used in the following program jointly illustrated by Function 1 to Function 3. (2)
class Race
{
int CarNo, Track;
public:
Race(); // Function 1
Race(int CN); // Function 2
Race(Race &R); // Function 3
void Register(); // Function 4
void Drive(); // Function 5
};
void main()
{
Race R;
Race T (30);
}
OR
(b) Write any four differences between Constructor and Destructor function with respect to object oriented
programming. (2)
(c) Define a class Bus in C++ with the following specifications: (4)
Data Members
1) Busno - to store Bus No
2) From – to store Place name of origin
3) To – to store Place name of destination
4) Type – to store Bus Type such as ‘O’ for ordinary
5) Distance – to store the Distance in Kilometers
6) Fare –to store the Bus Fare
Member Functions
1) A constructor function to initialize Type as ‘O’ and Freight as 500