{"id":217632,"date":"2018-09-15T22:58:52","date_gmt":"2018-09-15T22:58:52","guid":{"rendered":"http:\/\/localhost\/wordpress\/index.php\/2018\/09\/15\/gsp-125-week-2-ilab-rectangles\/"},"modified":"2018-10-24T08:57:46","modified_gmt":"2018-10-24T08:57:46","slug":"gsp-125-week-2-ilab-rectangles","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/gsp-125-week-2-ilab-rectangles\/","title":{"rendered":"GSP 125 Week 2 ILab Rectangles"},"content":{"rendered":"<p>\/ lab2: rectangles\t\/\/ &lt;insert your name here&gt;\t\/\/ read main.cpp, and follow the instructions at the bottom of main.cpp\t#define NOMINMAX \/\/ prevent Windows API from conflicting with &quot;min&quot; and &quot;max&quot;\t#include &lt;stdio.h&gt; \/\/ C-style output. printf(char*,&#8230;), putchar(int)\t#include &lt;windows.h&gt; \/\/ SetConsoleCursorPosition(HANDLE,COORD)\t#include &lt;conio.h&gt; \/\/ _getch()\t\/**\t* moves the console cursor to the given x\/y coordinate\t* 0, 0 is the upper-left hand coordinate. Standard consoles are 80&#215;24.\t* @param x\t* @param y\t*\/\tvoid moveCursor(int x, int y)\t{\tCOORD c = {x,y};\tSetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);\t}\tstruct Vec2\t{\tshort x, y;\tVec2() : x(0), y(0) { }\tVec2(int x, int y) : x(x), y(y) { }\tvoid add(Vec2 v)\t{\tx += v.x;\ty += v.y;\t}\t};\tclass Rect\t{\tVec2 min, max;\tpublic:\tRect(int minx, int miny, int maxx, int maxy)\t:min(minx,miny),max(maxx,maxy)\t{}\tRect(){}\tvoid draw(const char letter) const\t{\tfor(int row = min.y; row &lt; max.y; row++)\t{\tfor(int col = min.x; col &lt; max.x; col++)\t{\tif(row &gt;= 0 &amp;&amp; col &gt;= 0)\t{\tmoveCursor(col, row);\tputchar(letter);\t}\t}\t}\t}\tbool isOverlapping(Rect const &amp; r) const\t{ return !( min.x &gt;= r.max.x || max.x &lt;= r.min.x\t|| min.y &gt;= r.max.y || max.y &lt;= r.min.y); }; }\tvoid translate(Vec2 const &amp; delta)\t{\tmin.add(delta);\tmax.add(delta);\t} int main()\t{\t\/\/ initialization\tRect userRect(7, 5, 10, 9);\tRect rect0(10, 2, 14, 4);\tRect rect1(1, 6, 5, 15);\tint userInput;\tdo\t{\t\/\/ draw\trect0.draw(&#8216;0&#8217;);\trect1.draw(&#8216;1&#8217;);\tmoveCursor(0, 0);\t\/\/ re-print instructions\tprintf(&quot;move with &#8216;w&#8217;, &#8216;a&#8217;, &#8216;s&#8217;, and &#8216;d&#8217;&quot;);\tuserRect.draw(&#8216;#&#8217;);\t\/\/ user input\tuserInput = _getch();\t\/\/ update\tVec2 move;\tswitch(userInput)\t{\tcase &#8216;w&#8217;:\tmove = Vec2( 0,-1); break;\tcase &#8216;a&#8217;:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/ lab2: rectangles \/\/ &lt;insert your name here&gt; \/\/ read main.cpp, and follow the instructions at the bottom of main.cpp #define NOMINMAX \/\/ prevent Windows API from conflicting with &quot;min&quot; and &quot;max&quot; #include &lt;stdio.h&gt; \/\/ C-style output. printf(char*,&#8230;), putchar(int) #include <a href=\"https:\/\/www.benedictsol.com\/blogs\/gsp-125-week-2-ilab-rectangles\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-217632","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/comments?post=217632"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217632\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=217632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=217632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=217632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}