Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C++ bar() - Draw a Bar Between Two Points


In C++, the bar() function is used to draw a bar between two points on the screen. The general syntax of this function is as follows:

bar (left, top, right, bottom);
Where:
left and top represents the x & y co-ordinates of the first point. The "left" indicates x-coordinate of the first point and the "top" indicates the y-coordinate of the first point.
right and bottom represents the x & y co-ordinates of the second point. The "right" indicates x-coordinate of the second point and the "bottom" indicates the y-coordinate of the second point.


These four parameters may be variables of "int" type or values.

Example of C++ bar() Function

The following C++ program draws a bar between two points (200, 100) & (240, 600) on the screen.

#include
#include
#include
using namespace std;
main()
{
int driver, mode;
driver = DETECT;
initgraph (&driver, &mode, " ");
cleardevice();
bar(200, 100, 240, 600);
getch();
closegraph();
}
The following C++ program draws bar graph for different values in different colors and patterns.


#include
#include
#include
using namespace std;
main()
{
int d, m, x1, x2, i;
driver = DETECT;
initgraph (&driver, &m, " ");
cleardevice();
for (i = 1, x1 = 100, x2 = 120; i {
setfillstyle (i, i);
bar (x1, 50, x2, 300);
}
getch();
closegraph();
}


This post first appeared on Programming Explain, please read the originial post: here

Share the post

C++ bar() - Draw a Bar Between Two Points

×

Subscribe to Programming Explain

Get updates delivered right to your inbox!

Thank you for your subscription

×