Public Members:
• A constructor to assign initial values as follows:
TCode with the word “NULL”
No _of_ Adults as 0
No_ of_Children as 0
Distance as 0
TotalFare as 0
• A function AssignFare() which calculates and assigns the value of the data member Totalfare as follows For each Adult
Fare (Rs) For Kilometers 500 >=1000
300 <1000 & >=500
200 <500
For each Child the above Fare will be 50% of the Fare mentioned in the above table
For Example:
If Distance is 750, No_of_adults =3 and
No_of_Children =2
Then TotalFare should be calculated as
Num_of _Adults *300+ No_of_Children *150 i.e., 3*300+ 2 *150 =1200
• A function EnterTour() to input the values of the data members T_Code, No_of_Adults, No_of_Children and Distance ; and invoke the AssignFare() function.
• A function ShowTravel() which displays the content of all the data members for a Travel.
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<iostream.h>
class Travel
{
char T_Code[21];
int No_of_Adults,No_of_Children,Distance;
float TotalFare;
public: Travel( )
{
strcpy(T_Code,"NULL");
No_of_Adults=No_of_Children=Distance=TotalFare=0;
}
void AssignFare( )
{
if(Distance>=1000) TotalFare=No_of_Adults*500+No_of_Children*250; else if(Distance>=500) TotalFare=No_of_Adults*300+No_of_Children*150;
else
TotalFare=No_of_Adults*200+No_of_Children*100;
}
void EnterTravel( )
{
cout<<"\nEnter the Travel Code: ";
gets(T_Code);
cout<<"\nEnter the Number of Adults: ";
cin>>No_of_Adults;
cout<<"\nEnter the Number of Children: ";
cin>>No_of_Children;
cout<<"\nEnter the Distance in Kilometres: ";
cin>>Distance; AssignFare( );
}
void ShowTravel( )
{
cout<<"\nThe Travel Code: "<<T_Code;
cout<<"\nThe Number of Adults: "<<No_of_Adults;
cout<<"\nThe Number of Children: "<<No_of_Children;
cout<<"\nThe Distance in Kilometres: "<<Distance;
cout<<"\n\nThe Total Fare: "<<TotalFare;
}
};
void main( )
{
clrscr();
Travel T;
T.EnterTravel( );
T.ShowTravel( );
getch();
}