{"id":217638,"date":"2018-09-15T22:59:33","date_gmt":"2018-09-15T22:59:33","guid":{"rendered":"http:\/\/localhost\/wordpress\/index.php\/2018\/09\/15\/gsp-125-week-5-ilab-shapes\/"},"modified":"2018-10-24T09:03:54","modified_gmt":"2018-10-24T09:03:54","slug":"gsp-125-week-5-ilab-shapes","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/gsp-125-week-5-ilab-shapes\/","title":{"rendered":"GSP 125 Week 5 iLab Shapes"},"content":{"rendered":"<p>GSP 125 GSP\/125 GSP 125 \u00a0Week 5 iLab\t\u00a0\t\/\/ INSTRUCTIONS\t\/\/ &#8212;&#8212;&#8212;&#8212;\t\/\/ Compile this code. After pressing any key to clear the instructions, You\t\/\/ should see three rectangles labeled &#8216;#&#8217;, &#8216;b&#8217;, and &#8216;c&#8217;. You should also see\t\/\/ two triangles, labeled &#8216;d&#8217; and &#8216;e&#8217;. Pressing &#8216;>&#8217; and &#8216;<' will change which\t\/\/ shape is labeled '#'. Pressing 'w', 'a', 's', and 'd' will move the shape\t\/\/ labeled '#'. Pressing 'space' will randomize the selected shape.\t\/\/\t\/\/ Read through this code! Try to understand it before starting the assignment.\t\/\/ Comment confusing lines with what you think code is doing, and experiment\t\/\/ with existing code to test your understanding.\t\/\/ Once you feel comfortable with this code, accomplish each of the following,\t\/\/ and make sure your code compiles and runs after each step is completed.\t\/\/\t\/\/ 1. Getting comfortable with the code\t\/\/ a) Create a \"makeRandom\" method in both the Rect and Tri classes, based\t\/\/ on the \"makeRandomRect\" and \"makeRandomTri\" functions in\t\/\/ \"application.cpp\". The makeRandom function should take no parameters,\t\/\/ and instead make itself random. Removing the old \"makeRandomRect\"\t\/\/ and \"makeRandomTri\" functions as well. Be sure to consider what to do\t\/\/ about \"screenMin\" and \"screenMax\".\t\/\/ b) Create a print method for the Tri class, similar to the print method\t\/\/ for the Rect class. This method may come in very handy when debugging.\t\/\/ 2. Create Shape base class\t\/\/ a) Create a header file (without a .cpp file) for a Shape class.\t\/\/ b) Create the Shape class, which should have no member variables.\t\/\/ c) Make the Shape class an interface for the Rect and Tri classes. Shape\t\/\/ should have pure-virtual methods for each method that Rect and Tri have\t\/\/ in common.\t\/\/ d) Make sure Shape has a virtual destructor with an empty body.\t\/\/ 3. Make Rect and Triangle extend Shape\t\/\/ 4. Change selected\t\/\/ a) Change the type of \"Application::selected\" from \"void *\" to \"Shape *\".\t\/\/ b) Every piece of code that typecasts \"selected\" (and the logic around it)\t\/\/ can be removed now. Simply call functions using the \"Shape\" interface.\t\/\/ c) Remove the \"selectedType\" variable from Application. Logic that needs\t\/\/ some form of RunTime Type Information should use dynamic_cast instead.\t\/\/ 5. Merge all Shape objects into a single array\t\/\/ a) Create an array of Shape pointers in the Application called \"shapes\".\t\/\/ b) Making a complementary NUM_SHAPES variable would make sense.\t\/\/ b) Remove \"rectangles\" and \"triangles\" arrays.\t\/\/ c) Put each Tri and Rect object managed by the Application class into\t\/\/ the \"shapes\" array. This will require re-factoring in multiple files.\t\/\/ While removing references to \"rectangles\" and \"triangles\" arrays, it\t\/\/ may make sense to replace pairs of for-loops using each of the old\t\/\/ arrays with a single for-loop using just \"shapes\".\t\/\/ 6. Make \"shapes\" dynamic\t\/\/ a) Give Application::init() 2 parameters: int numRect, int numTri\t\/\/ b) Make \"shapes\" a pointer of type \"Shape **\", and allocate it to be\t\/\/ \"numShapes\" big, where \"numShapes\" is an int member of Application\t\/\/ equal to (numRect + numTri), defined in Application::init().\t\/\/ c) When calling \"app.init()\" in main, pass valid arguments for numRect\t\/\/ and numTri.\t\/\/ d) De-allocate the \"shapes\" array in Application::Release().\t\/\/ 7. Clean up old variables\t\/\/ a) Remove the TYPE_RECT and TYPE_TRI variables from Application.\t\/\/ b) Remove NUM_TRI and NUM_RECT, and any NUM_SHAPES variable as well. Use\t\/\/ numShapes where needed.\t\/\/ 8. Add Circle class\t\/\/ a) Create a header file AND a source file for a Circle class.\t\/\/ b) Use Rect and Tri as examples to create the Circle class with.\t\/\/ c) A Circle class should have at least a 2 dimensional position, and a\t\/\/ radius.\t\/\/ d) A simple algorithm for drawing a Circle will be similar to drawing a\t\/\/ Rect or Tri, thought it might include the following code:\t\/\/ float dx = center.x - col, dy = center.y - row;\t\/\/ if( dx*dx + dy*dy <= radius * radius ) {\t\/\/ moveCursor(col, row);\t\/\/ putchar(letter);\t\/\/ }\t\/\/ e) Add an additional parameter to Application::init(), \"int numCircles\".\t\/\/ Implement init to generate Circle objects along with Rect and Tri\t\/\/ objects.\t\/\/ 9. Implement add\/remove for the shapes array\t\/\/ a) Add code that increases the size of the shapes array, adding a random\t\/\/ shape, whenever the '=' or '+' key is pressed. Take a look at the week\t\/\/ 5 lecture showing explicit constructors for help with this algorithm.\t\/\/ a) Add code that decreases the size of the shapes array, removing the last\t\/\/ shape, whenever the '-' or '_' key is pressed. End the program when the\t\/\/ last shape is removed. Removing a shape, like adding a shape, can be\t\/\/ done by allocating an array of a different size (smaller this time).\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GSP 125 GSP\/125 GSP 125 \u00a0Week 5 iLab \u00a0 \/\/ INSTRUCTIONS \/\/ &#8212;&#8212;&#8212;&#8212; \/\/ Compile this code. After pressing any key to clear the instructions, You \/\/ should see three rectangles labeled &#8216;#&#8217;, &#8216;b&#8217;, and &#8216;c&#8217;. You should also see <a href=\"https:\/\/www.benedictsol.com\/blogs\/gsp-125-week-5-ilab-shapes\/\" 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-217638","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217638","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=217638"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217638\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=217638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=217638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=217638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}