Hey again. You did a great job last week so I figured I
Hey again. You did a great job last week so I figured I would use you directly this time around. I need help with
this weeks lab. I have attached the source code and instructions for the program. Could you please add comments in the cpp.file so I can try and get a better understanding of what you did? It would be greatly appreciated. ATTACHMENT PREVIEW Download attachment// lab2: rectangles// <insert your name here>// read main.cpp, and follow the instructions at the bottom of main.cpp#deFneNOMINMAX// prevent Windows API from con±icting with “min” and “max”#include<stdio.h>// C-style output. printf(char*,…), putchar(int)#include<windows.h>// SetConsoleCursorPosition(HANDLE,COORD)#include<conio.h>// _getch()/*** moves the console cursor to the given x/y coordinate* 0, 0 is the upper-left hand coordinate. Standard consoles are 80×24.* @param x* @param y*/voidmoveCursor(intx,inty){COORDc = {x,y};SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);}structVec2{shortx, y;Vec2() : x(0), y(0) { }Vec2(intx,inty) : x(x), y(y) { }voidadd(Vec2v){x +=v.x;y +=v.y;}};classRect{Vec2min, max;public:Rect(intminx,intminy,intmaxx,intmaxy):min(minx,miny),max(maxx,maxy){}Rect(){}voiddraw(constcharletter)const{for(introw = min.y; row < max.y; row++){for(intcol = min.x; col < max.x; col++){if(row >= 0 && col >= 0){moveCursor(col, row);putchar(letter);}}}}boolisOverlapping(Rectconst&r)const{

View the Answerreturn!( min.x >=r.max.x || max.x <=r.min.x|| min.y >=r.max.y || max.y <=r.min.y);}voidtranslate(Vec2const&delta){min.add(delta);max.add(delta);}};intmain(){// initializationRectuserRect(7, 5, 10, 9);Rectrect0(10, 2, 14, 4);Rectrect1(1, 6, 5, 15);intuserInput;do{// drawrect0.draw(‘0’);rect1.draw(‘1’);moveCursor(0, 0);// re-print instructionsprintf(“move with ‘w’, ‘a’, ‘s’, and ‘d'”);userRect.draw(‘#’);// user inputuserInput = _getch();// updateVec2move;switch(userInput){case’w’:move=Vec2( 0,-1);break;case’a’:move=Vec2(-1, 0);break;case’s’:move=Vec2( 0,+1);break;case’d’:move=Vec2(+1, 0);break;}userRect.draw(‘ ‘);// un-draw before movinguserRect.translate(move);}while(userInput != 27);// escape keyreturn0;}
