Page 260 - CA_Blue( J )_Class10
P. 260

System.out.println("Area of         Trapezium :" + area_t);
                                   System.out.println("Area of Rhombus :" + area_r);
                             }
                     }
                 17.  Design a class to overload a function series() as follows:                                  [2013]
                     (i)    double series(double n) with one double argument and returns the sum of the series,
                        sum = 1 / 1 + 1 / 2 + 1 / 3 + … + 1 / n.
                     (ii)   double series(double a, double n) with two double arguments and returns the sum of the series,
                                 2
                                                    11
                                             8
                                       5
                        sum = 1 / a  + 4 / a  + 7 / a  + 10 / a  + … to n terms.
                Ans.  class Overload_series {
                         double series(double n)
                         {   double sum = 0.0,i;
                             for(i = 1; i <= n; i++)
                                 sum = sum + (1.0 / i);
                             return sum;
                         }
                         double series(double a, double n)
                         {   double sum = 0.0,i;
                             int c = 1;
                             for(i = 1; i <= n; i++)
                              {   sum += sum+ (c / Math.pow(a,(c+1)));
                                 c += 3;
                             }
                             return sum;
                         }
                         void main()
                         {    System.out.println("Sum of series 1: "+series(5));
                              System.out.println("Sum of series 2: "+series(2,5));
                         }
                     }
                 18.  Design a class to overload_polygon a function polygon() as follows:                         [2012]
                     (i)    void polygon(int n, char ch): with one integer argument and one character argument that draws a filled square of side n
                         using the character stored in ch.
                     (ii)    void polygon(int x, int y): with two integer arguments that draws a filled rectangle of length x and breadth y, using the
                         symbol '@'.
                     (iii)   void polygon(): with no arguments that draws a filled triangle shown below.
                     Example:
                     (i)  Input value of n = 2, ch = 'O'
                         Output:  OO
                                 OO
                     (ii)  Input value of x = 2, y = 5
                         Output:  @@@@@
                                 @@@@@
                     (iii)  Output:  *
                                 **
                                 ***
                Ans.  class Overload_polygon
                     {   void polygon(int n, char ch){
                             int i,j;
                             for(i = 1; i <= n; i++){
                                 for(j = 1; j <= n; j++){
                                     System.out.print(ch);
                                 }System.out.println();


                258258  Touchpad Computer Applications-X
   255   256   257   258   259   260   261   262   263   264   265