Assigned: Tuesday February 11, 2003 Deadline: Tuesday February 18, 2003 at MIDNIGHT PROGRAM 5: DrawObjects.cpp --------- Extend/modify you program to include a drawObject() class. The draw object class is an object in the x/y coordinate plane that contains rectangles. To simplify the program you may assume that a drawObject object can have a maximum of 4 non-overlapping rectangles (there is no penalty for allowing overlapping rectangles, nor allowing a larger maximum for the number of rectangles). The size of the drawObject is a 60x60 area in the x/y plane with the constraints that coordinates have values that are <= | 30 |. Your program should have the below functionality: * The drawObject may be read from standard input by overloading the the stream-extraction operator (w/ cin), cin >> the draw object should read in rectangles in by the following format: (x1, y2) (x2, y2) (x3, y3) (x4, y3) if the draw object is instantiated to contain a maximum of 2 rectangles, it should accept the below input consisting of two rectangles: (x1, y2) (x2, y2) (x3, y3) (x4, y4) (x5, y5) (x6, y6) (x7, y7) (x7, y7) * The stream-insertion operator (w/ cout), cout << should display your current drawing of rectangle(s), including the x/y axis. * Your drawObject class should include functions that specifies how the objects in the plane are drawn, specifically you should include: - a setFillCharacter function to specify the character out which the body of the rectangles will be drawn. - Include a setPerimeter function to specify the character that will be used to draw the borders of the rectangles. - Include a setAxis function to specify the character that will be used to draw the borders of the rectangles. - Include a setAxis function to specify the character that will be used to draw the x and y axis. The x-axis and y-axis should "erase" any border of fill characters. * drawObject comparisons can be made with the equality operators == and !=. * drawObject additions can be made with the += operator, i.e. i_drawObject += j_drawObjects Adds j_drawObjects rectangles to i_drawObjects drawing. Your assignment is to write a "driver" program that demonstrate your implementation of the above functionality and that it works correctly. The "driver" program is the main function. OTHER REQUIREMENTS: ------------------- * Proper commented code * Modularized program * Good software engineering techniques, hints in text book. * You must submit at least the following files (i.e., all the files necessary to compile your program): README.txt DrawObjectsDriver.cpp Makefile To submit the files, you will need to use the submit program. Your files need to be under a common subdirectory called "1730_program5". Execute the below command line while in your home directory: submit 1730_program5 cs1730 NOTE: you need to be LOGGED ONTO ajax when you execute the submit command. -------------------------------------------------------------------------- FAQ: -------------------------------------------------------------------------- 1. Is the drawObject class is a sub-class of Rectangle class in project #4? No it is not a subclass of Rectangle, I had envisioned that people would make drawObject a "composite" class containing shapes to be drawn (e.g. Rectangles). drawObject is essentially a "canvas" which contains shapes and the canvas is defined in the x/y coordinate plane. -------------------------------------------------------------------------- 2. What did you mean by saying "The draw object class is an object in the x/y coordinate plane that contains rectangles."? Does it mean that the drawObject class creates 4 instances of Rectangle object inside it when the program is ran? Yes. See question "1" for more details. -------------------------------------------------------------------------- 3. What did you mean by the size of the drawObject area is 60 x 60? what is the significance of the size of the area in this project? That is the "size" of the canvas. The area in which you can draw your rectangles. For instance drawing something at (50, 65) would not show up on the canvas. -------------------------------------------------------------------------- 4. As far as reading coordinates such as: (x1, y2) (x2, y2) (x3, y3) (x4, y3) we can do that just using normal "cin >>", just like we did in assignment #4. why do we must overload "cin >>" for this project? Is there any specific reason for that? Your drawObject needs to understand the format above (four four x and y points within parentheses). This part of the exercise is analogous to reading the "phone number" in the form: (800) 555-1212 as illustrated in Fig 8.3 in the textbook. -------------------------------------------------------------------------- 5. (x1, y2) (x2, y2) (x3, y3) (x4, y3) -- is (x1, y2) and (x4, y3) printing mistake? supposed to be (x1, y1) and (x4, y4)? Yes a typo, thanks for being observant. -------------------------------------------------------------------------- 6. How does the program know to instantiate to contain maximum of 2, 3 or 4 rectangles? Does the user input that? if yes, should our program prompt for that input? You should write a "driver" program demonstrate your implementation of the above functionality and that it works correctly. In the driver program you could "prompt" the user for input, that is perfectly acceptable. Note that you are not constrained to "allow" a maximum of four, however your drawObject class need to handle "at least" four rectangles. -------------------------------------------------------------------------- 7. Do we need user input prompt, possible a menu for setFillCharacter, setPerimeter, and setAxis functions? The answer is the same as the above. It is your job to demonstrate that those functions work correctly. So yes it is nice if your "driver" is menu driven. -------------------------------------------------------------------------- 8. I am assuming that we have to overload == , +=, and != operators, could you give me an example why we would compare or add two drawObjects? Compare: The == operator compares two "canvases" or drawObjects to see if they contain the same information, same reason why you compare two variables -- two drawObjects containing the same shapes in the same locations are equal. The "==" operator returns "true" if the drawObjects are equal. The != is the opposite of the "==" operator, i.e. it returns "true" if the two drawings DIFFER. Addition: += adds a new shape to the drawObject -------------------------------------------------------------------------- 9. Do we need a user menu prompt for this or just overloading it should be enough? Just overloading is fine, but you need to demonstrate in your driver program that your drawObject provides this functionality. --------------------------------------------------------------------------