I really need help with my c++
I need to write 4 functions:
1. findRightTriangles
2. area
3. congruent
4. similar
I think I might have done the findRightTriangle, not sure if its correct though. I am clueless how to do this, any insights or help is appreciated (like how to start on any of these functions; how to go about them).
1) First of all, I need to check with you, 'findRightTriangles' meaning checking if the triangle is a right-angle triangle? If is to check, you can use this formula to check: a^2+b^2 = c^2, where c is the longest side of the triangle.
3) For checking of congruent, just check if the sides of the triangles are equal. This can be done by arranging the length of the triangle by increasing/decreasing order. After arranging, you can compare the lengths of the 2 triangles respectively.
4) For checking of similarity, you can use 'SSS' (side, side, side) test. This can be done, again, by first arranging the length of the triangle by increasing/decreasing order. After arranging, check the ratio respectively.
Thanks for the reply!
findRightTriangles searches for right triangles satisfying certain conditions:
1. All the side lengths must be integers
2. The triangles must be right triangles
3. The perimeter must be bounded above and below any input paraameters that is, l <= perimeter <= h
I somewhat have the idea in my head of how to do each one, its just.. I don't know how to write a code for each of them
If it's possible, can someone show me an example of how to start making a code for one of the functions
Hi aquaturtle, I think understand what you want. Below is an example, hope it helps.
I have stored the sides of the triangle into a vector. So vector<int>trianglesides contains the 3 sides of the triangle. Not too sure if you are familiar with vector.
In addition, to use vector, you will need to include #include <vector> .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
bool ifRightAngle(vector<int> trianglesides)
{
sort(trianglesides.begin(), trianglesides.end()); //have to include "#include <algorithm>"
if ((pow(double(trianglesides.at(0)),2)+pow(double(trianglesides.at(1)),2)) == pow(double(trianglesides.at(2)),2))
returntrue; //Is a right angle triangle
elsereturnfalse; //Is not a right angle triangle
}
bool perimeterCheck(vector<int> trianglesides)
{
int nSum = trianglesides.at(0)+trianglesides.at(1)+trianglesides.at(2);
int nSum_lower = 10;
int nSum_upper = 100;
if (nSum_lower < nSum && nSum < nSum_upper)
returntrue; //Meet the requirement
elsereturnfalse;//Did not meet the requirement
}