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;
}
}
#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;
}
}
0 comments:
Post a Comment