Page 470 - Computer science 868 Class 12
P. 470

21         { Area ob=new Area(sz);
                22           ob.area();

                23           ob.display();
                24          }

                25       }
              The output of the preceding program is as follows:
















                Program 9      An abstract base class Series is defined as follows:
                               Class name                     :  Series
                               Data Members
                               int x, n                       :   To store the values of variable and number of terms
                                                                 respectively
                               Member Methods
                               Series(int xx, int nn)         :  Parameterised constructor to initialise data members
                               abstract void calculate()      :  Abstract method
                               void show()                    :  Displays the values of x and n respectively
                               A derived class CalSeries is defined to print the sum of the following series:
                                  x 2  x 3  x 4
                               x +   +   +   ............ n  terms
                                   2   3   4
                               Class name                     :  CalSeries
                               Data Members
                               double s                       :  To store sum of the series
                               Member Methods
                               CalSeries(int xx, int nn)      :   Parameterised constructor to initialise data members
                                                                 of base and derived classes
                               void calculate()               :  Calculates thte sum of the series given above
                               void show()                    :  Displays x and n and sum s
                               Also define the main method to create object of the derived class to implement the above.

                 1       abstract class Series

                 2       { int x,n;
                 3         Series(int xx,int nn) // contructor

                 4         { x=xx;
                 5           n=nn;

                 6         }
                 7         abstract void calculate();  //abstract method of base class



                468468  Touchpad Computer Science-XII
   465   466   467   468   469   470   471   472   473   474   475