Define a class CABS in C++ with the following specification:

Private Data members
-CNo    : to store Cab Number
-Type   : to store a character ‘A’, ‘B’ or ‘C’ as City Type
-PKM   : to store per Kilometer charges
-Dist   : to store Distance traveled (in KM)

Public Member functions
-A constructor function to initialize Type as ‘A’ and CNo as ‘1111’
-A function Charges() to assign PKM as per the following table:
Type Fare
‘A’ 25
‘B’ 20
‘C’ 15

-A function Register() to allow administrator to enter the values for CNo and Type. Also, this function should call Charges() to assign PKM charges.

-A function ShowCab() to allow user to enter the value of Distance and display CNo, Type, PKM, PKM*Distance (As amount) on screen.

================================================
Solution:
================================================

class CABS
{
int CNo;
char Type;
long Dist;
long PKM;
long Amount;
public:
CABS()
{
Type='A';
CNo=1111;
}
void Charges();
void Register();
void ShowCab();
};

void CABS::Charges()
{
if(Type=='A')
PKM=25;
else if (Type=='B')
PKM=20;
else if(Type=='C')
PKM=15;
}

void CABS::Register()
{
cout<<"Enter Distance : ";
cin>>Dist;
cout<<"Enter Cab No.  : ";
cin>>CNo;
cout<<"Enter City Type: ";
cin>>Type;
Charges();
}

void CABS::ShowCab()
{
cout<<".......CAB DETAILS.......\n";
cout<<"Cab No.     : "<<CNo<<endl;
cout<<"City Type   : "<<Type<<endl;
cout<<"Distance    : "<<Dist<<endl;
cout<<"Rate Per Km.: "<<PKM<<endl;
cout<<"Cab Charges : "<<PKM*Dist<<endl;
}


No comments

Post your comments

Powered by Blogger.