#include<windows.h>
#include<iostream>
using namespace std;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
void SetCursor(int x, int y)//function to set cursor
{
COORD myCoords = { x,y };
SetConsoleCursorPosition(hStdOut, myCoords);
}
void WriteCenter(int x, int y, int width, int height, const char* word)//function to write in center of rectangle
{
SetCursor(x + (width - strlen(word)) / 2, y + height / 2);
cout<<word<<endl;
}
void DrawSquare (int x, int y, int wid, int hei, int col)//function to draw rectangle
{
SetConsoleTextAttribute(hStdOut, col);//setting background color
for(int i = 0; i < hei; i++)
{
SetCursor(x, y + i);//setting cursor position onto next line
for(int j = 0; j < wid; j++)
{
cout<<" ";//writing wid number of spaces (" ") with current background color
}
cout<<endl;
}
}
int main()
{
DrawSquare(1, 3, 4, 5, 112);
WriteCenter(1, 3, 4, 5, "r1");
SetConsoleTextAttribute(hStdOut, 0);
cout<<std::endl;
return 0;
}
Comments
Leave a comment