Page 461 - Computer science 868 Class 12
P. 461

Program 5     A super class Airlines having different rates for travelling at some popular tourist destination
                                 is defined as follows:
                                 Class name               :   Airlines
                                 Data Members
                                 char place               :   Stores place of visit as character as follows:
                                                              N for New York, P for Paris, L for London and I for Italy
                                 int heads                :   Total number of persons of a family going for vacation
                                 double amount            :   Stores total amount to be paid by each family to buy tickets
                                 Member Methods
                                 Airlines(char p, int h)   :   Parameterised constructor to initialise
                                 Data Members
                                 void calamt()            :     Calculates  total  amount to be paid  by each family  as per
                                                              given conditions
                                                                      Place            Rate per ticket
                                                              New York                    65000
                                                              Paris                       52000
                                                              London                      45000
                                                              Italy                       55000
                                 void print()             :   Prints place of visit, total heads and net amount
                                 A sub class Discount is defined to calculate discount and final amount to be paid. The details
                                 is given below.
                                 Class name               :   Discount
                                 Data Members
                                 double  dis              :   To store discount amount
                                 double  famt             :   To store final amount
                                 Discount(char, int)      :     Parameterised constructor to initialise data members of base
                                                              and derived classes
                                 void calnet()            :     Calculates discount and net amount as per conditions given
                                                              below:
                                                                    Total Amount          Discount percent
                                                              > = 500000                       15%
                                                              Between 499999 to 250000         12%
                                                              Between 249999 to 100000         10%
                                                              Below 100000                     8%
                                 void print()             :   Prints discount and net amount to be paid

                   1       class Airlines
                   2       { char place;

                   3         int heads;
                   4         double amt;

                   5         Airlines(char p,int h)
                   6         { place=p;
                   7           heads=h;

                   8           amt=0;




                                                                                                                       459
                                                                                  Inheritance, Interfaces and Polymorphism  459
   456   457   458   459   460   461   462   463   464   465   466