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:
Where:
bar (left, top, right, bottom);
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.The following C++ program draws bar graph for different values in different colors and patterns.
#include
#include
#include
using namespace std;
main()
{
int driver, mode;
driver = DETECT;
initgraph (&driver, &mode, " ");
cleardevice();
bar(200, 100, 240, 600);
getch();
closegraph();
}
#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();
}