Page 459 - CA_Blue( J )_Class10
P. 459

Variable Description
                   NAME       DATATYPE                                     DESCRIPTION
                  n          int          Instance Variable to store number
                  i          int          Loop variable

                  c          int          Variable to count how many times "n" gets divisible

                 (e)  Programs based on overloaded methods.


                  Program 5    Create a class overload which will contain the following functions:
                                   a.  double perimeter(double)    -      Calculating the circumference of a circle
                                   b.  int perimeter(int)          -      Calculating the perimeter of square
                                   c.  int perimeter(int, int)     -      Calculating the perimeter of a rectangle

                   1      class overloadmethod
                   2      {

                   3          double perimeter(double r)
                   4          {

                   5              double peri = 2*3.142*r;
                   6              return peri;

                   7          }
                   8          int perimeter(int s)

                   9          {
                  10              int peri = 4 *s;

                  11              return peri;
                  12          }

                  13          int perimeter(int l, int b)
                  14          {

                  15              int peri = 2*(l+b);
                  16              return peri;

                  17          }
                  18          void main()

                  19          {
                  20              double c;

                  21              int p1, p2;
                  22              c=perimeter(4.5);

                  23              p1=perimeter(4);
                  24              p2=perimeter(8,2);





                                                                                                                       457
                                                                                                   Internal Assessment  457
   454   455   456   457   458   459   460   461   462   463   464