05 Jun GSP 125 Week 5 iLab Shapes NEW
/ INSTRUCTIONS
// ————
// Compile this code. After pressing any key to clear the instructions, You
// should see three rectangles labeled ‘#’, ‘b’, and ‘c’. You should also see
// two triangles, labeled ‘d’ and ‘e’. Pressing ‘>’ and ‘<‘ will change which
// shape is labeled ‘#’. Pressing ‘w’, ‘a’, ‘s’, and ‘d’ will move the shape
// labeled ‘#’. Pressing ‘space’ will randomize the selected shape.
//
// Read through this code! Try to understand it before starting the assignment.
// Comment confusing lines with what you think code is doing, and experiment
// with existing code to test your understanding.
// Once you feel comfortable with this code, accomplish each of the following,
// and make sure your code compiles and runs after each step is completed.
//
// 1. Getting comfortable with the code
// a) Create a “makeRandom” method in both the Rect and Tri classes, based
// on the “makeRandomRect” and “makeRandomTri” functions in
// “application.cpp”. The makeRandom function should take no parameters,
// and instead make itself random. Removing the old “makeRandomRect”
// and “makeRandomTri” functions as well. Be sure to consider what to do
// about “screenMin” and “screenMax”.
// b) Create a print method for the Tri class, similar to the print method
// for the Rect class. This method may come in very handy when debugging.
// 2. Create Shape base class
// a) Create a header file (without a .cpp file) for a Shape class.
// b) Create the Shape class, which should have no member variables.
// c) Make the Shape class an interface for the Rect and Tri classes. Shape
// should have pure-virtual methods for each method that Rect and Tri have
// in common.
// d) Make sure Shape has a virtual destructor with an empty body.
// 3. Make Rect and Triangle extend Shape
// 4. Change selected
// a) Change the type of “Application::selected” from “void *” to “Shape *”.
// b) Every piece of code that typecasts “selected” (and the logic around it)
// can be removed now. Simply call functions using the “Shape” interface.
// c) Remove the “selectedType” variable from Application. Logic that needs
// some form of RunTime Type Information should use dynamic_cast instead.
// 5. Merge all Shape objects into a single array
// a) Create an array of Shape pointers in the Application called “shapes”.
// b) Making a complementary NUM_SHAPES variable would make sense.
// b) Remove “rectangles” and “triangles” arrays.
// c) Put each Tri and Rect object managed by the Application class into
// the “shapes” array. This will require re-factoring in multiple files.
// While removing references to “rectangles” and “triangles” arrays, it
// may make sense to replace pairs of for-loops using each of the old
// arrays with a single for-loop using just “shapes”.
// 6. Make “shapes” dynamic
// a) Give Application::init() 2 parameters: int numRect, int numTri
// b) Make “shapes” a pointer of type “Shape **”, and allocate it to be
// “numShapes” big, where “numShapes” is an int member of Application
// equal to (numRect + numTri), defined in Application::init().
// c) When calling “app.init()” in main, pass valid arguments for numRect
// and numTri.
// d) De-allocate the “shapes” array in Application::Release().
// 7. Clean up old variables
// a) Remove the TYPE_RECT and TYPE_TRI variables from Application.
// b) Remove NUM_TRI and NUM_RECT, and any NUM_SHAPES variable as well. Use
// numShapes where needed.
// 8. Add Circle class
// a) Create a header file AND a source file for a Circle class.
// b) Use Rect and Tri as examples to create the Circle class with.
// c) A Circle class should have at least a 2 dimensional position, and a
// radius.
// d) A simple algorithm for drawing a Circle will be similar to drawing a
// Rect or Tri, thought it might include the following code:
// float dx = center.x – col, dy = center.y – row;
// if( dx*dx + dy*dy <= radius * radius ) {
// moveCursor(col, row);
// putchar(letter);
// }
// e) Add an additional parameter to Application::init(), “int numCircles”.
// Implement init to generate Circle objects along with Rect and Tri
// objects.
// 9. Implement add/remove for the shapes array
// a) Add code that increases the size of the shapes array, adding a random
// shape, whenever the ‘=’ or ‘+’ key is pressed. Take a look at the week
// 5 lecture showing explicit constructors for help with this algorithm.
// a) Add code that decreases the size of the shapes array, removing the last
// shape, whenever the ‘-‘ or ‘_’ key is pressed. End the program when the
// last shape is removed. Removing a shape, like adding a shape, can be
// done by allocating an array of a different size (smaller this time).
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
