65.9K
CodeProject is changing. Read more.
Home

C++ -> Drawing Rectangles to Console

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.63/5 (4 votes)

Aug 25, 2011

CPOL
viewsIcon

17375

Smaller code:void DrawRect(int x, int y, int width, int height, int curPosX=0, int curPosY=0){ setxy(x, y); cout << char(201); cout.width(width); cout.fill (char(205)); cout << char(187); setxy(x,height+y); cout << char(200); cout.width(width); cout.fill...

Smaller code:
void DrawRect(int x, int y, int width, int height, int curPosX=0, int curPosY=0)
{
    setxy(x,       y); cout << char(201); 
     cout.width(width); cout.fill (char(205)); cout << char(187);
    setxy(x,height+y); cout << char(200); 
     cout.width(width); cout.fill (char(205)); cout << char(188);
    for(int i = y + 1; i < height+y; i++)
    {
        setxy(x,i);cout << char(186);
        setxy(x + width,i);cout << char(186);
    }
    setxy(curPosX,curPosY);
}
Using ostream::width() and ostream::fill() functions.