Answer to Question #93008 in C++ for gvvg

Question #93008
Give the statement which would enable you to create a rectangle having corners (10,30),(50,30), (10,80), (50,80). The rectangle should be given the name "r1".
1
Expert's answer
2019-08-21T05:21:18-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS