Page 255 - Computer science 868 Class 12
P. 255

The output of the preceding program is as follows:
                 Area of Rectangle : 8
                 Area of Square : 25
                 Area of Circle : 38.4895



                  Program 7      Design a class to overload a function num_calc() as follows:
                                 a.  void num_calc(int num,char ch) with one integer argument and one character argument –
                                   Computes the square of integer argument if choice ch is ‘s’, otherwise find its cube.
                                 b.  void num_calc(int a, int b,char ch) with two integer arguments – Finds the product of the
                                   integers if ch is ‘p’, else adds the integers.
                                 c.  void num_calc(String s1,String s2) with two String arguments, – Prints whether the strings
                                   are equal or not.
                   1      class Overload

                   2      {

                   3          void num_calc(int num,char ch)
                   4      {
                   5          if(ch=='s')

                   6              System.out.println("Square:"+(num*num));
                   7          else

                   8              System.out.println("Cube:"+(num*num*num));
                   9          }

                  10          void num_calc(int a,int b,char ch)
                  11          {

                  12              if(ch=='p')
                  13                    System.out.println("Product:"+(a*b));

                  14              else
                  15                    System.out.println("Sum:"+(a+b));

                  16              }
                  17              void num_calc(String s1,String s2)

                  18              }
                  19              {

                  20              if(s1.equalsIgnoreCase(s2))
                  21                    System.out.println("Equal");

                  22              else
                  23                    System.out.println("Not Equal");

                  24              }
                  25          }



                                                                                                                       253
                                                                                                            Methods    253
   250   251   252   253   254   255   256   257   258   259   260