→This assignment is due by Friday, June 16, 2023 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L5A,
L5B
←
→ Do not forget to complete zyBooks Assignment 5 for this set.←
· Instructions · Rubric · Best Practices · Submission Process · Submission Contents ·
For this assignment, we will write a program to read in a list of polygon data and draw an image comprised of those simple polygons. The full UML diagram is shown below (click to enlarge).
![Polygon UML Hierarchy](images/uml_polygons.png)
The Abstract Polygon
Begin by creating an abstract Polygon
class. The class will have the following members and corresponding implementations:
public
- default constructor - sets the color to white, specifies the number of vertices as 0, sets the vertices array to be a nullptr
- a virtual destructor - deallocates the vertices array
void setColor(const sf::Color color)
- sets the private color data membervoid draw(sf::RenderTarget& window)
- creates aConvexShape
, sets the points for each coordinate, sets the fill color, draws it to the provided window- a
void setCoordinate(int idx, Coordinate coord)
function that sets the corresponding coordinate in the vertices array - a pure virtual
bool validate()
function that returnstrue
if the set coordinates form the intended polygon
protected
- the number of vertices making up the polygon as a short integer
- a Coordinate array
private
- the color of the triangle as an SFML Color object
The Abstract Triangle
Next create the abstract Triangle
class that extends Polygon
. The class will have the following members and corresponding implementations:
public
- default constructor - sets the number of vertices to be three and allocates the vertex array to hold three coordinates
The Concrete ScaleneTriangle
Now we'll begin creating concrete instances of a triangle. Create a class called ScaleneTriangle
that implements Triangle
.
It will need to override the validate()
method. Given the three vertex coordinates, compute the length of each side. If
the three sides form a triangle (that is - all three sides are non-zero and the sum of any two is greater than the third) AND all three side
lengths are different, then return true. If the sides do not form a triangle or have equivalent lengths, return false.
The Concrete IsoscelesTriangle
Create a class called IsoscelesTriangle
that implements Triangle
.
It will need to override the validate()
method. Given the three vertex coordinates, compute the length of each side. If
the three sides form a triangle (that is - all three sides are non-zero and the sum of any two is greater than the third) AND at least two of
the three sides are equal in length, then return true. If the sides do not form an isosceles triangle, return false.
The Concrete EquilateralTriangle
Create a class called EquilateralTriangle
that implements Triangle
.
It will need to override the validate()
method. Given the three vertex coordinates, compute the length of each side. If
the three sides form a triangle (that is - all three sides are non-zero and the sum of any two is greater than the third) AND all three of
the three sides are equal in length, then return true. If the sides do not form an equilateral triangle, return false.
The Abstract Quadrilateral
Next create the abstract Quadrilateral
class that extends Polygon
. The class will have the following members and corresponding implementations:
public
- default constructor - sets the number of vertices to be four and allocates the vertex array to hold four coordinates
The Concrete Rhombus
Create a class called Rhombus
that implements Quadrilateral
.
It will need to override the validate()
method. Given the four vertex coordinates, compute the length of each side. If
the four sides form two isosceles triangles (comprised of vertices 0, 1, 2 & 0, 2, 3) AND all four of
the four sides are equal in length, then return true. If the sides do not form a rhombus, return false. (Note: for this assignment, we can assume the points
will form a simple polygon and the edges will not cross themselves.)
Read the File
A sample polygon data file is provided. The file contains some number of lines in the following format:
T x1 y1 x2 y2 x3 y3 x4 y4 r g b
Where each value is:
T
- a character denoting the polygon type. One ofS
,I
,E
, orR
x1
- the double x coordinate for vertex 1y1
- the double t coordinate for vertex 1x2
- the double x coordinate for vertex 2y2
- the double t coordinate for vertex 2x3
- the double x coordinate for vertex 3y3
- the double t coordinate for vertex 3x4
- the double x coordinate for vertex 4 (will only be present if type isR
)y4
- the double t coordinate for vertex 4 (will only be present if type isR
)r
- the integer red component of the colorg
- the integer green component of the colorb
- the integer blue component of the color
We want to be sure to leverage runtime polymorphism as we read in the file. Therefore, create a list of Polygon
pointers.
As you read each line, create a Polygon
pointer of the corresponding type. Call the setCoordinate()
method with
the corresponding coordinate. If the vertices form a polygon of the appropriate type, then set the color and add the pointer to the list.
If the vertices do not form the corresponding polygon, then print out "polygon is invalid
" and the line that corresponds to the polygon.
The sample file results in the following output denoting which polygons are invalid:
polygon is invalid - "E 0 0 5 5 10 10 255 255 255"
polygon is invalid - "I 0 0 5 5 10 10 255 255 255"
polygon is invalid - "E 0 0 5 5 11 11 255 255 255"
polygon is invalid - "I 0 0 5 5 11 11 255 255 255"
polygon is invalid - "S 0 0 0 0 0 0 255 255 255"
polygon is invalid - "I 0 0 0 0 0 0 255 255 255"
polygon is invalid - "E 0 0 0 0 0 0 255 255 255"
polygon is invalid - "S 10 0 10 0 0 0 255 255 255"
polygon is invalid - "I 10 0 10 0 0 0 255 255 255"
polygon is invalid - "E 10 0 10 0 0 0 255 255 255"
polygon is invalid - "S 0 0 10 0 10 0 255 255 255"
polygon is invalid - "I 0 0 10 0 10 0 255 255 255"
polygon is invalid - "E 0 0 10 0 10 0 255 255 255"
polygon is invalid - "S 10 0 0 0 10 0 255 255 255"
polygon is invalid - "I 10 0 0 0 10 0 255 255 255"
polygon is invalid - "E 10 0 0 0 10 0 255 255 255"
polygon is invalid - "R 112.154 200 112.154 440 527.846 440 527.846 200 255 255 255"
polygon is invalid - "R 0 0 10 10 20 20 30 30 255 255 255"
polygon is invalid - "R 0 10 20 20 20 10 0 10 255 255 255"
Draw the Image
Now that we have a list of valid polygons, when inside our SFML draw loop we'll draw all the polygons. Loop through your polygon list, call the draw()
method and pass it the window object. The sample file should generate the following image:
![triangle C++ triangle C++](images/triangle_cpp_image.png)
Best Practices To Follow
· Code Style · Code Correctness · Code Structure · Dynamic Memory Management · Software Engineering Design Principles ·
Code Style
The following set of guidelines ensure all code in this class will be written in a similar and consistent manner, allowing any reader to understand the program's intent and contents.
- One clear and consistent coding style used (such as K&R, 1TBS, or Allman).
- Course naming scheme is followed for variable, function, class, and other identifiers. See the course style guide for more specifics.
- Code is self-documenting. Variables sensibly named, function names descriptive of their purpose.
Code Correctness
The following set of guidelines ensure all programs written in this class behave properly without side effects.
- Code compiles and links without any errors or warnings.
- Program runs without any run time errors. Exceptions are properly caught, user input is validated appropriately, and program exits successfully without error.
- Use
const
wherever possible:- If you declare a variable and that variable is never modified, that variable should be
const
. - If your function takes a parameter and does not modify that parameter, that parameter should be
const
. - If a member function does not modify the callee, that member function should be
const
. - If you are pointing at a value that does not change, the pointer should point at a constant value (e.g.
const T*
). - If the pointer itself is never modified, the pointer should be a constant pointer (e.g.
T* const
). - If the pointer itself is never modified AND the value pointed at does not change, the pointer should be a constant pointer AND the pointer should point at a constant value (e.g.
const T* const
).
- If you declare a variable and that variable is never modified, that variable should be
Code Structure
The following set of guidelines ensure all programs written in this class are done in an abstracted, modular, extendable, and flexible manner.
- Do not use global variables unless absolutely necessary. Instead, encapsulate them and design your interfaces effectively. If there is no way around using a global variable, be prepared to defend and justify its usage.
- Program flow uses structural blocks (conditionals/loops) effectively, appropriately, and efficiently.
- Keep your headers clean. Put the absolute minimum required in your headers for your interface to be used.
Anything that can go in a source file should. Do not
#include
any system headers in your .h files that are not absolutely required in that file specifically. Do not addusing namespace
in headers. - Use header guards correctly and appropriately.
- Place templated class and function definitions in a
*.hpp
file. - Place static class and function definitions in abstracted
*.h
and*.cpp
files. - Place each class and structure in their own files as appropriate based on their makeup.
Dynamic Memory Management
The following set of guidelines ensure all programs written in this class behave properly without side effects.
- Implement the Big-3 as appropriate.
- Do not leak memory. Every allocation using
new
needs to have a correspondingdelete
.
Software Engineering Design Principles
The following set of guidelines ensure all program components written in this class are done in an abstracted, modular, extendable, and flexible manner.
- Follow and apply the following design principles:
- Write Once, Use Many / Write Once, Read Many (WORM) / Don't Repeat Yourself (DRY): Use loops, functions, classes, and
const
as appropriate. - Encapsulate what varies: Use functions and classes as appropriate. Identify the aspects that vary and separate them from what stays the same.
- Favor composition over inheritance.
- Program to an interface, not an implementation & SOLID Principles: When using object-oriented inheritance & polymorphism, do the following:
- No variable should hold a reference to a concrete class.
- No class should derive from a concrete class.
- No method should override an implemented method from any of its base classes.
- Use appropriate inheritance access. Only expose necessary members to derived classes and/or publicly.
- Use
virtual
andoverride
as appropriate. Mark members asfinal
wherever possible and/or appropriate on derived classes.
- Write Once, Use Many / Write Once, Read Many (WORM) / Don't Repeat Yourself (DRY): Use loops, functions, classes, and
Grading Rubric
Your submission will be graded according to the following rubric.
Points | Requirement Description |
10 | All labs completed and submitted L5A, L5B |
3 | Abstract Polygon class created correctly. |
3 | Abstract Triangle class created correctly. |
3 | Concrete ScaleneTriangle class created correctly. |
3 | Concrete IsoscelesTriangle class created correctly. |
3 | Concrete EquilateralTriangle class created correctly. |
3 | Abstract Quadrilateral class created correctly. |
3 | Concrete Rhombus class created correctly. |
2 | File read correctly. |
8 | Runtime Polymorphism used with list of Polygon pointers. |
1 | Public polygon file generates correct results and image. |
1 | Private polygon file generates correct results and image. |
5 | Best practices are followed:
|
0 | Submission structured appropriately. Submissions structured improperly will receive deductions. |
48 | Total Points |
→This assignment is due by Friday, June 16, 2023 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L5A,
L5B
←
→ Do not forget to complete zyBooks Assignment 5 for this set.←
Submission
Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.
It is critical that you follow these steps when submitting homework.
If you do not follow these instructions, your assignment will receive a major deduction. Why all the fuss? Because we have several hundred of these assignments to grade, and we use computer tools to automate as much of the process as possible. If you deviate from these instructions, our grading tools will not work.
Submission Instructions
Here are step-by-step instructions for submitting your homework properly:
-
Make sure you have the appropriate comment header block at the top of every source code file for this set. The header
block should include the following information at a minimum.
Be sure to fill in the appropriate information, including:/* CSCI 200: Assignment 5: A5 - SFML: Polygon Land
* * Author: XXXX (INSERT_NAME) * Resources used (Office Hours, Tutoring, Other Students, etc & in what capacity): * // list here any outside assistance you used/received while following the * // CS@Mines Collaboration Policy and the Mines Academic Code of Honor * * XXXXXXXX (MORE_COMPLETE_DESCRIPTION_HERE) */- Assignment number
- Assignment title
- Your name
- If you received any type of assistance (office hours - whose, tutoring - when), then list where/what/who gave you the assistance and describe the assistance received
- A description of the assignment task and what the code in this file accomplishes.
Additionally, update theMakefile
for A5 to generate a target executable namedA5
.
- File and folder names are extremely important in this process.
Please double-check carefully, to ensure things are named correctly.
- The top-level folder of your project must be named
Set5
- Inside
Set5
, create 3 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g.L5A
,L5B
, andA5
). - Copy your files into the subdirectories of
Set5
(steps 2-3), zip thisSet5
folder (steps 4-5), and then submit the zipped file (steps 6-11) to Canvas. - For example, when you zip/submit
Set5
, there will be 3 sub-folders calledL5A
,L5B
, andA5
inside theSet5
folder, and each of these sub-folders will have the associated files.
- The top-level folder of your project must be named
- Using Windows Explorer (not to be confused with Internet Explorer), find the files
named
main.cpp, Makefile, *.h, *.cpp
.
STOP: Are you really sure you are viewing the correct assignment's folder? - Now, for A5, right click on
main.cpp, Makefile, *.h, *.cpp
to copy the files. Then, return to theSet5/A5
folder and right click to paste the files. In other words, put a copy of your homework'smain.cpp, Makefile, *.h, *.cpp
source code into theSet5/A5
folder.
Follow the same steps for each lab to put a copy of each lab's deliverable into theSet5/L5
folders. Do this process forSet5/L5A
(ExitRoom.h, ExitRoom.cpp, GuessTheNumberRoom.h, GuessTheNumberRoom.cpp, Room.h, Room.cpp, main.cpp, Makefile
),Set5/L5B
(List.hpp, Array.hpp, LinkedList.hpp
).
STOP: Are you sure yourSet5
folder now has all your code to submit?
The structure of the submission is as follows:- Set5/
- A5/
- main.cpp
- Makefile
- *.h
- *.cpp
- L5A/
- ExitRoom.h
- ExitRoom.cpp
- GuessTheNumberRoom.h
- GuessTheNumberRoom.cpp
- Room.h
- Room.cpp
- main.cpp
- Makefile
- L5B/
- List.hpp
- Array.hpp
- LinkedList.hpp
- A5/
*
only if present and appropriate to the implementation.
- Set5/
- Now, right-click on the
"Set5"
folder.- In the pop-up menu that opens, move the mouse
"Send to..."
and expand the sub-menu. - In the sub-menu that opens, select
"Compressed (zipped) folder"
.
STOP: Are you really sure you are zipping aSet5
folder with sub-folders that each contain amain.cpp
file in it?
- In the pop-up menu that opens, move the mouse
- After the previous step, you should now see a
"Set5.zip"
file.
- Now visit the Canvas page for this course
and click the
"Assignments"
button in the sidebar.
- Find Set5, click on it, find the
"Submit Assignment"
area, and then click the"Choose File"
button.
- Find the
"Set5.zip"
file created earlier and click the"Open"
button.
STOP: Are you really sure you are selecting the right homework assignment? Are you double-sure?
- WAIT! There's one more super-important step. Click on the blue
"Submit Assignment"
button to submit your homework.
- No, really, make sure you click the
"Submit Assignment"
button to actually submit your homework. Clicking the"Choose File"
button in the previous step kind of makes it feel like you're done, but you must click the Submit button as well! And you must allow the file time to upload before you turn off your computer!
- Canvas should say "Submitted!". Click "Submission Details" and you can download the zip file you just submitted. In other words, verify you submitted what you think you submitted!
In summary, you must zip the "Set5"
folder
and only the "Set5"
folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this
homework, and you must click the "Submit Assignment"
button. Not doing these steps is like bringing your
homework to class but forgetting to hand it in. No concessions will be made for
incorrectly submitted work. If you incorrectly submit your homework, we will not be able to
give you full credit. And that makes us unhappy.
→This assignment is due by Friday, June 16, 2023 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L5A,
L5B
←
→ Do not forget to complete zyBooks Assignment 5 for this set.←