Tuesday, 17 April 2018

12-D Prog-3 Define a class Travel Plan

Define a class Travel Plan for the following description

/*12-C Prog-3 Define a class Travel Plan
private:
Tcode int
Tname string
Source string
Destination string
Distance float
Fare int

->Function Calfare() which calculates and returns fare according to following
criteria.

Distance    Fare
<= 1000      500
> 1000 and <=2500        750
>2500  100

public:
->Function ReadData() to read the data members and
  call function Calfare() to calculate fare;
->Function ShowData() to print the values of all the data members.*/

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class TravelPlan
{
   int Tcode;
   char Tname[20];
   char Source[30];
   char Destination[30];
   float Distance;
   int Fare;

   int calFare();

   public:
   void ReadData();
   void ShowData();
};
int TravelPlan :: calFare()
{
  if(Distance <= 1000)
   return 500;
  else  if(Distance <= 2500)
   return 750;
  else
   return 1000;
}
void TravelPlan :: ReadData()
{
  cout<<"\n Enter Travel code \n";
  cin>>Tcode;
  cout<<"\n Enter Travel Name ";
  gets(Tname);
  cout<<"\n Enter Source\n";
  gets(Source);
  cout<<"\n Enter Destination \n";
  gets(Destination);
  cout<<"\n Enter Distance \n";
  cin>>Distance;
  Fare=calFare();
}
void TravelPlan :: ShowData()
{
  cout<<"\n Travel Code "<<Tcode;
  cout<<"\n Travel Name "<<Tname;
  cout<<"\n Travel source "<<Source;
  cout<<"\n Destination "<<Destination;
  cout<<"\n Distance"<<Distance;
  cout<<"\n Fare"<<Fare;
}

void main()
{
   clrscr();
   TravelPlan T;
   T.ReadData();
   T.ShowData();
   getch();
}

No comments:

Post a Comment