Draws a line using the inbuilt line function. Takes the end co-ordinates of the line from the user.Draws a line using the inbuilt line function
/******************************************************** * code.cheraus.com * * Draws a line using the inbuilt line function * * ********************************************************/ #include<iostream.h> #include<conio.h> #include<graphics.h> int main() { int gd=DETECT; int gm; clrscr(); //clears the screen in TurboC(available in conio.h header file) int x1,y1,x2,y2; //variables to hold the co-ordinates //taking the line co-ordinates from user cout<<"Enter the x co-ordinate of point 1: "; cin>>x1; cout<<"Enter the y co-ordinate of point 1: "; cin>>y1; cout<<"Enter the x co-ordinate of point 2: "; cin>>x2; cout<<"Enter the y co-ordinate of point 2: "; cin>>y2; /* initialization of graphics mode. The third argument takes the path of the graphics driver in your computer. If you have it in some other directory then specify the appropriate path;otherwise it may not work. */ initgraph(&gd,&gm,"C:\\turboc3\\bgi"); // clears the screen in graphics mode cleardevice(); //line function to draw line from (x1,y1) to (x2,y2) line(x1,y1,x2,y2); //gets a character from the user before exiting the program getch(); //closes the graphics mode closegraph(); //return from main function. Indicates successful run return 0; }