Edit: Closing this, I wasn't able to figure it out so I decided I'd just leave it as is. I completed the bonus questions so I should still get 100% on the assignment. As for the learning aspect of it, oh well. I need to focus on other assignments too.
Thank you for the original help fixing the error! =)
=========================================
Okay, was going to mark as solved but I'm having trouble with 2 more parts that I've been trying to figure out for the last 3 hours.
1. The findArea() function in Triangle.cpp. I think I set it up properly to actually find the area. But I
think I need to call the function and no matter what I try it doesn't work.
2. Sorting triangle ( in main() from main.cpp ). Not sure how to use the sort() for this, all of my attempts have failed. Also, I don't fully understand what I'm supposed to sort. I guessed the sides of the triangles which is what I was trying to sort, but one of the comments says I should use this for it:
friend bool operator<(const Triangle &, const Triangle &);
Which compares the areas of t1 and t2 (triangle objects).
Notes:
- void Triangle::findArea() {} can be found in Triangle.cpp at line 43.
- The parts where I'm trying to use findArea() & getArea() are in main.cpp at the lines: 143-148.
- I'm guessing I'll need to get the area fixed before I can fix sort because in Triangle.h there's a note that says:
1 2
|
// use this friend function to compare and sort triangles
friend bool operator<(const Triangle &, const Triangle &);
|
And that ^ function is found in Triangle.cpp:
1 2 3 4 5 6 7 8 9 10
|
// friend function to Triangle class
bool operator<(const Triangle& t1, const Triangle& t2) {
// FIXME12: - fixed
// return true if t1's area is smaller than t2's area
// false otherwise
if (t1.getArea() < t2.getArea())
return true;
else
return false;
}
|
Latest Code:
main.cpp:
http://cpp.sh/4bsfe
Triangle.h:
http://cpp.sh/9hrsh
Triangle.cpp:
http://cpp.sh/2o4pd
Input File:
1 2 3
|
2.5 2.0 2.0
5.0 5.0 5.0
2.0 3.0 4.0
|
Output File:
(Everything works except the area)
1 2 3 4 5 6 7 8 9
|
*****************************************************************
Triangle Information
*****************************************************************
# side 1 side 2 side 3 area perimeter type
=================================================================
1 2.50 2.00 2.00 0.00 6.50 Isosceles
2 5.00 5.00 5.00 0.00 15.00 Equilateral
3 2.00 3.00 4.00 0.00 9.00 Scalene
=================================================================
|
Edit: Closing this, I wasn't able to figure it out so I decided I'd just leave it as is. I completed the bonus questions so I should still get 100% on the assignment. As for the learning aspect of it, oh well. I need to focus on other assignments too.
Thank you for the original help fixing the error! =)