LAB 06A - TRIANGLE SRUCTS
Concepts
To gain practice with structs
, we will use a struct
to represent a Triangle. The user will be able to enter the length of sides for two triangles. Our program will then calculate if the two triangles are equivalent via SSS (side, side, side) similarity.
Instructions
A starting template has been provided for you in Lab06Amain.cpp
. BE WARNED! This template will not compile out of the box; you must complete the TO DO items before it will fully work. Below are short instructions for each TO DO item.
- TO DO #1:
Define astruct
that describes a Triangle, appropriately namedTriangle
. The struct should contain the necessary information to store the lengths of the three sides of a triangle.
- TO DO #2:
Declare a function namedHaveUserEnterTriangle
. This function should take aTriangle
variable as a paramenter passed by reference. The function has no return value. The function should prompt the user to enter the length for each side of the triangle and store the entered values onto theTriangle
parameter passed into the function.
- TO DO #3:
Declare a function namedOrderTriangleSides
. This function should take aTriangle
variable as a parameter passed by reference. The function has no return value. The function should sort the lengths of the triangle from smallest to largest. After the function completes,side1
of the triangle should have the shortest side length,side2
should have the middle side length, andside3
should have the longest side length.
- TO DO #4:
Declare a function namedAreTrianglesEquivalent
. This function should take twoTriangle
variables as parameters, both passed by value. The function will return a boolean. The function must compare the ratios of like sides of the triangles to determine if the two are equivalent (remember geometry? Side-Side-Side similarity). The function will return true if the two triangles are similar. Otherwise, it returns false.
You may assume that the user will enter valid sides that form a triangle, so you do not have to test if the sides are all positive and/or form a triangle.
Hints
We recommend that you create the Triangle struct first and then create a function stub for each function so your program can compile.
Once your program successfully compiles and can execute, then start filling in each function one at a time in the order the TO DOs are listed.
Use an incremental build strategy. Once TO DO #1 is completed and tested, get TO DO #2 working properly. Once TO DO #2 is completed and tested, move on. And so forth.