Pages

Wednesday, March 23, 2011

RECTANGLE DRAWING ALGORITHM

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<graphics.h>
void main()
{
int gdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi ");
errorcode=graphresult();
if(errorcode!=grOk)
{
cout<<"graphics error"<<grapherrormsg(errorcode)<<endl;
cout<<"press any key to start";
getch();
exit(1);
}
int x1,y1,x2,y2;
cout<<"///////////////// RECTANGLE/////////////////";
cout<<"\n enter x - cordinate of upper right side of rectangle";
cin>>x1;
cout<<"\n enter y - cordinate of upper right side of rectangle";
cin>>y1;
cout<<"\n enter x - cordinate of lower left side of rectangle";
cin>>x2;
cout<<"\n enter y - cordinate of lower left side of rectangle";
cin>>y2;
clrscr();
cout<<" DESIRED RECTANGLE";
line(x1,y1,x1,y2);
line(x2,y2,x1,y2);
line(x1,y1,x2,y1);
line(x2,y2,x2,y1);
getch();
closegraph();
}

No comments:

Post a Comment