Chapter – 5. CONSTRUCTORS & DESTRUCTORS

Private Members:

Travelcode of type long
Place of type character array(string)
Number_of_travellers of type integer
Number_of_buses of type integer

Public Members:

* A constructer to assign initial values of TravelCode as 201, Place as “Nainital”, Number_of_travellers as 10, Number_of_buses as 1

* A function NewTravel() which allows user to enter TravelCode, Place and Number_of travelers. Also, assign the value of Number_of_buses as per the following conditions:

Number_of_travellers Number_of_buses
Less than 20 1
Equal to or more than 20 and less than 40 2
Equal to 40 or more than 40 3

* A function ShowTravel() to display the content of all the data members on the screen.

Ans:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class Travel
{
long TravelCode;
char Place[21];
int No_of_travellers,No_of_buses;
public: Travel( )
{
TravelCode=201;
strcpy(Place,"Nainital");
No_of_travellers=5; No_of_buses=1;
}
void NewTravel( )
{
cout<<"\nEnter the Travel Code: ";
cin>>TravelCode;
cout<<"\nEnter the Place to Travel: ";
gets(Place);
cout<<"\nEnter the Number of Travellers: ";
cin>>No_of_travellers;
if(No_of_travellers>=40) No_of_buses=3;
else if(No_of_travellers>=20) No_of_buses=2;
else
No_of_buses=1;
}
void ShowTravel( )
{
cout<<"\nThe Plan Code: "<<TravelCode;
cout<<"\nThe Place of Travel: "<<Place;
cout<<"\nNumber of Travellers: "<<No_of_travellers;
cout<<"\nNumber of Buses: "<<No_of_buses;
}
};
void main( )
{
clrscr( );
Travel T;
T.NewTravel( );
T.ShowTravel( );
getch();
}


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_l.php on line 166

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_l.php on line 166

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

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_l.php on line 168