CSCI 261 - Programming Concepts - Maynooth 2022

A6 - Triangle Land

→This assignment is due by Thursday, July 28, 2022, 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: ←

· Instructions · Rubric ·Submission ·

For this assignment, we will write a program to read in a list of triangle data and sort them by area.


The Abstract Triangle


Begin by creating an abstract Triangle class. The class will have the following members and corresponding implementations:

How you represent the (x, y) coordinate and the list is up to your choosing.

As you implement the concrete classes below, you may find it useful to add additional helper functions to your Triangle class.


The Concrete ScaleneTriangle


Now we'll begin creating concrete instances of a triangle. Create a class called ScaleneTriangle that extends Triangle.

It will need to override the setCoordinates() 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 in length and the sum of two is greater than the third), then set the vertex coordinates in the list and return true. If the sides do not form a triangle, return false.

It also needs to override the getTriangleType() method and return "Scalene".


The Concrete IsoscelesTriangle


Create a class called IsoscelesTriangle that extends Triangle.

It will need to override the setCoordinates() 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 in length and the sum of two is greater than the third) AND at least two of the three sides are equal in length, then set the vertex coordinates in the list and return true. If the sides do not form an isosceles triangle, return false.

It also needs to override the getTriangleType() method and return "Isosceles".


The Concrete EquilateralTriangle


Create a class called EquilateralTriangle that extends Triangle.

It will need to override the setCoordinates() 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 in length and the sum of two is greater than the third) AND all three of the three sides are equal in length, then set the vertex coordinates in the list and return true. If the sides do not form an equilateral triangle, return false.

It also needs to override the getTriangleType() method and return "Equilateral".


Read the File


A sample triangle data file is provided. The file contains some number of lines in the following format:

T x1 y1 x2 y2 x3 y3

Where each value is:

We want to be sure to leverage runtime polymorphism as we read in the file. Therefore, create a list of Triangle pointers. As you read each line, create a Triangle pointer of the corresponding type. Call the setCoordinates() method with the three vertex coordinates. If the vertices form a triangle of the appropriate type, then add the pointer to the list. If the vertices do not form a triangle, then print out "invalid triangle" and the line that corresponds to the triangle.

The sample file results in the following output of which triangles are invalid:

triangle is invalid - "E 0 0 5 5 10 10"
triangle is invalid - "I 0 0 5 5 10 10"
triangle is invalid - "E 0 0 5 5 11 11"
triangle is invalid - "I 0 0 5 5 11 11"
triangle is invalid - "S 0 0 0 0 0 0"
triangle is invalid - "I 0 0 0 0 0 0"
triangle is invalid - "E 0 0 0 0 0 0"
triangle is invalid - "S 10 0 10 0 0 0"
triangle is invalid - "I 10 0 10 0 0 0"
triangle is invalid - "E 10 0 10 0 0 0"
triangle is invalid - "S 0 0 10 0 10 0"
triangle is invalid - "I 0 0 10 0 10 0"
triangle is invalid - "E 0 0 10 0 10 0"
triangle is invalid - "S 10 0 0 0 10 0"
triangle is invalid - "I 10 0 0 0 10 0"
triangle is invalid - "E 10 0 0 0 10 0"

Sort the Triangles


Now that we have a list of valid triangles, sort the list of triangles by area from smallest to largest. Print out the sorted triangles in the following format:

TYPE AREA

where TYPE is the type of the triangle and AREA is it's corresponding area. Have the two values aligned in columns with the area printed to three decimals.

The sample file results in the following output of sorted triangles:

Scalene            300.000
Scalene            300.000
Scalene            300.000
Scalene            300.000
Isosceles          400.000
Isosceles          400.000
Isosceles          400.000
Isosceles          400.000
Isosceles          400.000
Isosceles          400.000
Isosceles          400.000
Isosceles          400.000
Scalene            800.000
Scalene            800.000
Scalene           3200.000
Scalene           3200.000
Scalene           3600.000
Scalene           3600.000
Scalene           3600.000
Scalene           3600.000
Equilateral      24941.532
Equilateral      24941.532
Equilateral      24941.532
Isosceles        24941.532
Equilateral      24941.532
Equilateral      24941.532

Best Practices To Follow


Hints


Testing


The graders will build your program with the Makefile you provide to match your code structure.


Grading Rubric


Your submission will be graded according to the following rubric.

PointsRequirement Description
6 Abstract Triangle class created correctly.
3 Concrete ScaleneTriangle class created correctly.
3 Concrete IsoscelesTriangle class created correctly.
3 Concrete EquilateralTriangle class created correctly.
3 File read correctly.
10 Runtime Polymorphism used with list of Triangle pointers.
2 Triangles sorted by area.
2 Public triangle file generates correct results.
1 Private triangle file generates correct results.
5 The above items make up 33/38 points towards the assignment. The rest of the assignment grade is based on how well the best practices are followed:
  • +5 Code is easily readable, follows best practices, well structured
  • +4 Code is easy to follow, only a few small violations of best practices
  • +3 No egregiously bad practices
  • +2 Lots of violations of best practices
  • +1 Little effort to follow best practices
  • +0 No effort to follow best practices
38 Total Points

→This assignment is due by Thursday, July 28, 2022, 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: ←


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:

  1. 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.
    /* CSCI 261: Assignment 6: A6 - Triangle 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)  */
    Be sure to fill in the appropriate information, including:
    • 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 the Makefile for A6 to generate a target executable named A6.

  2. File and folder names are extremely important in this process. Please double-check carefully, to ensure things are named correctly.
    1. The top-level folder of your project must be named Set6
    2. Inside Set6, create 1 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g. and A6).
    3. Copy your files into the subdirectories ofSet6 (steps 2-3), zip this Set6 folder (steps 4-5), and then submit the zipped file (steps 6-11) to Canvas.
    4. For example, when you zip/submit Set6, there will be 1 sub-folders called and A6 inside the Set6 folder, and each of these sub-folders will have the associated files.

  3. Using Windows Explorer (not to be confused with Internet Explorer), find the files named main.cpp, Makefile, *.hpp, *.h, *.cpp.

    STOP: Are you really sure you are viewing the correct assignment's folder?

  4. Now, for A6, right click on main.cpp, Makefile, *.hpp, *.h, *.cpp to copy the files. Then, return to the Set6/A6 folder and right click to paste the files. In other words, put a copy of your homework's main.cpp, Makefile, *.hpp, *.h, *.cpp source code into the Set6/A6 folder.

    Follow the same steps for each lab to put a copy of each lab's deliverable into the Set6/L6 folders.

    STOP: Are you sure your Set6 folder now has all your code to submit?

  5. Now, right-click on the "Set6" folder.
    1. In the pop-up menu that opens, move the mouse "Send to..." and expand the sub-menu.
    2. In the sub-menu that opens, select "Compressed (zipped) folder".

    STOP: Are you really sure you are zipping a Set6 folder with sub-folders that each contain a main.cpp file in it?

  6. After the previous step, you should now see a "Set6.zip" file.

  7. Now visit the Canvas page for this course and click the "Assignments" button in the sidebar.

  8. Find Set6, click on it, find the "Submit Assignment" area, and then click the "Choose File" button.

  9. Find the "Set6.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?

  10. WAIT! There's one more super-important step. Click on the blue "Submit Assignment" button to submit your homework.

  11. 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!

  12. 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 "Set6" folder and only the "Set6" 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 Thursday, July 28, 2022, 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: ←