Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C++ Programming Code Examples

Learn C++ Language

line() Function in C++ Programming Language

line() Function in C++
The header file graphics.h contains line() function which is used to draw a line from a point(x1, y1) to point(x2, y2) i.e. (x1, y1) and (x2, y2) are end points of the line. The function line() draws a line on the graphics screen between two specified points. So this function requires four parameters namely x1, y1, x2, and y2 to represent two points. This function draws a line from (x1, y1) coordinates to (x2, y2) coordinates on the graphics screen.
Syntax for line() Function in C++
void line(int x1, int y1, int x2, int y2);
x1
X coordinate of first point
y1
Y coordinate of first point.
x2
X coordinate of second point.
y2
Y coordinate of second point. You can change "linestyle", "pattern", "thickness" of the line by setlinestyle() function.
/* draw a line in C++ graphic code example */ #include<iostream.h> #include<conio.h> #include<graphics.h> void main() { int gd=DETECT,gm,x,y; clrscr(); initgraph(&gd,&gm,"c:\\TC\\bgi"); //INITIALISING GRAPHICS MODE setlinestyle(0,0,3); outtextxy(300,150,"LINE()"); line(350,60,200,200); outtextxy(300,300," CURRENT POSITION"); linerel(320,350); outtextxy(335,315,"LINEREL()"); outtextxy(30,30," CURRENT POSITION"); lineto(30,200); outtextxy(70,45,"LINETO()"); getch(); closegraph(); }