Friday 3 June 2016

Write a program that calls two functions Draw_Horizontal and Draw_Vertical to construct a rectangle.

#include<iostream.h>
#include<conio.h>
void Draw_Horizontal();
void Draw_Vertical();
void main()
{
        clrscr();
        cout<<"Rectangle : "<<endl;
        Draw_Horizontal();
        Draw_Vertical();
        Draw_Horizontal();
        getch();
}
void Draw_Horizontal()
{
        for(int i= 0; i<14; i++)
          cout<<"-";
        cout<<endl;
}
void  Draw_Vertical()
{
        for(int i = 0; i<5 ; i++)
        {
          for(int j = 0; j<14; j++)
                if(j == 0 || j == 13)
                      cout<<"|";
                else
                      cout<<" ";
                cout<<endl;
        }
}

                                                        OR
#include<iostream.h>
#include<conio.h>
void Draw_Horizontal(int l);
void Draw_Vertical(int w, int l);
void main()
{
        clrscr();
        int len, wid;
        cout<<"Enter length of rectangle: ";
        cin>>len;
        cout<<"Enter width of rectangle: ";
        cin>>wid;
        cout<<"Rectangle : "<<endl;
        Draw_Horizontal(len);
        Draw_Vertical(wid, len);
        Draw_Horizontal(len);
        getch();
}
void Draw_Horizontal(int l)
{
        for(int i=0; i<1; i++)
                cout<<"*";
        cout<<endl;
}
void Draw_Vertical(int w, int l)
{
        for(int i=0; i<w-2; i++)
        {
         for(int j= 0; j<1; j++)
                if(j == 0 || j == 1-1)
                        cout<<"*";
                else
                        cout<<" ";
                cout<<endl;
        }
}

Share:

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

About Me

My photo
A group of two, with a little hope of helping beginners to learn how to code :)
Powered by Blogger.

Comments

Facebook

Ad Home

Follow Us

Random Posts

Sponsor

Recent Posts

Header Ads

Popular Posts

Copyright © Functions in C++ | Powered by Blogger

Design by ThemePacific | Blogger Theme by NewBloggerThemes.com | Distributed By Blogger Templates20