Search This Blog

Tuesday, December 14, 2010

Function Overloading - ICSE BOARD QUESTION 2009

/**
 * Design a class to overload a function num_calc() as follows:
 *
 * void num_calc(int num, char ch) with one integer argument and one char
 * argument, computes the square of integer argument if choice ch is 's'
 * otherwise find its cube.
 *
 * void num_calc(int a, int b, char ch) with two integer arguments and
 * character argument. It computes the product of integer arguments if ch
 * is 'p' else adds the integers.
 *
 * void num_calc(String s1, String s2) with two string arguments, which
 * prints whether the strings are equal or not
 *
 */
public class questionSEVEN2009
{
   public void num_calc(int num, char ch)
   {
       if(ch=='s')
       {
           int square=num*num;
           System.out.println("The square of the number is = "+ square);
        }
        else
        {
            int cube=num*num*num;
            System.out.println("The cube of the number is =  "+ cube);
        }
    }
    public void num_calc(int a, int b, char ch)
   {
       if(ch=='p')
       {
           int product=a*b;
           System.out.println("The product of the two numbers is = "+ product);
        }
        else
        {
            int sum=a+b;
            System.out.println("The sum of the two number is = "+ sum);
        }
    }
    public void num_calc(String s1, String s2)
   {
       if(s1.equals(s2))
       {
           System.out.println("The two strings are equal");
        }
        else
        {
          System.out.println("The two strings are not equal"); 
        }
    }
}

13 comments:

  1. Why is there no public static void main?

    ReplyDelete
  2. DAMN.......JUST GO AND FUCK OFF>>

    ReplyDelete
    Replies
    1. Do u know how to do programmming .Seriously u r a big fool..

      Delete
    2. Class overload
      {
      Void num_calc(int num,chat ch
      {
      If (ch=='S')
      {
      system.out.println (num*num);
      }
      else
      {
      system.out.println (num*num*num);
      }
      }
      Void num_calc (int a,int b,char ch)
      {
      if (ch=='P')
      {
      System.out.println(a*b);
      }
      else
      {
      System.out.println (a+b);
      }
      }
      Void num_calc (string S1,strong S2)
      {
      If (S1 compare to (S2)==0)
      {
      System.out.println ("THEY ARE EQUAL");
      }
      else
      {
      system.out.println ("THEY ARE NOT EQUAL");
      }
      }
      }

      Delete
    3. This is the correct way to program

      Delete
    4. Yes I know I am teacher of computer applications for icse in doddaballapur in ADITYA PUBLIC school

      Delete
    5. Please you y\teach us to FKOF .As he is a champion in programing,you may be the same in F**king off yourself...

      Delete
    6. all the keywords are wrong.. class, public, void.. they are case sensitive..

      Delete
  3. Thanks really needed a help in this😉

    ReplyDelete
  4. Thanks really needed a help in this😉

    ReplyDelete
  5. all the programs are wrong u failures specially that chutiya teacher from Aditya public schoo,dodbellapur

    ReplyDelete