Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Function Overloading Polygon Function For ICSE

 Design a class to overload a function polygon() as follows:


(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.


Input value of n = 2, ch = ‘O’

Output:

OO

OO


(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 ‘@’.

Input value of x = 2, y = 5

Output:

@@@@@

@@@@@



(iii) void polygon(): with no arguments that draws a filled triangle shown below.

Example:


Output:

*

**

***


Program

                

class Poly
{
  
public static void polygon(int n, char ch)
{
        for(int i = 1; i        {
            for(int j = 1; j            {
                System.out.print(ch);
           }
            System.out.println();
       }
  }
    public static void polygon(int x, int y)
{
        for(int i = 1; i        {
            for(int j = 1; j           {
                System.out.print("@");
            }
            System.out.println();
       }
    }
    public static void polygon()
{
       for(int i=0;i{
 for(int j= 0;j{
System.out.print("*");
}
        System.out.println();
}

    public static void main(String args[])
    {
        polygon(5,'o');
        polygon(4,7);
        polygon();
    }
}



This post first appeared on Tutorial Site On Computer Programming Languages F, please read the originial post: here

Share the post

Function Overloading Polygon Function For ICSE

×

Subscribe to Tutorial Site On Computer Programming Languages F

Get updates delivered right to your inbox!

Thank you for your subscription

×