| 1. |
Define a class Tour C++ with the description given below: Private Members:TCode of type stringNoofAdults of type integerNoofKids of type integerKilometres of type integerTotalFare of type floatPublic Members:• A constructor to assign initial values as follows:TCode with the word "NULL"NoofAdults as 0NoofKids as 0Kilometres as 0TotalFare as 0• A function AssignFare() which calculates and assign the value of the date member TotalFare as follows: For each AdultFare(Rs)For Kilometres500>=1000300<1000 & >=500200<500For each Kid the above Fare will be 50% of the Fare mentioned in the above table.For example:If Distance is 850, NoofAdults=2 and NoofKids =3Then TotalFare should be calculated as NoofAdults*30 + NoofKids *150 i.e., 2*300+3*150=1050• A function EnterTour() to input the values of the data members TCode, Noofadults, NoofKids and Kilometres; and invoke the AssignFare() function• A Function ShowTour() which display the content of all the data members for a Tour. |
|
Answer» class Tour { char TCode[5]; int NoofAdults; int NoofKids; int Kilometres; float TotalFare; public: Tour () { strcpy(TCode,"NULL"); NoofAduts=0; NoofKids =0; Kilometres =0; TotalFare=0; } void AssignFare() { int I,j; TotalFare=0; for(i=0;i<NoofAdults;i++) { if(Kilometeres>=1000) TotalFare+=500; else if(Kilometeres>=500) TotalFare+=300; else TotalFare+=200; } for(j=0;j=1000) TotalFare+=500/2; else if(Kilometeres>=500) TotalFare+=300/2; else TotalFare+=200/2; } void EnterTour() { cout<<"Enter value of travel code:"; cin>>TCode; cout<<"Enter No. of Adults:"; cin>>NoofAdults; cout<<"Enter No. of Children:"; cin>> NoofKids; cout<<"Enter Distance:"; cin>> Kilometeres; AssignFare(); } void ShowTour() { cout<<"Travel code:"<<TCode<<endl; cout<<"No of Adults:"<<NoofAdults<<endl; cout<<"No of Children:"<< NoofKids <<endl; cout<<"Distance:"<< Kilometres <<endl; cout<<"Total Fare:"<<TotalFare<<endl; } }; |
|