Input three integers a, B, and c from the keyboard (1 <= a, B, and c <= 100)
Determines whether a triangle is formed. If a triangle can be formed, it indicates that
Equi triangle? Isosceles triangle? Equi triangle?
The condition for determining whether a triangle can be formed is: whether the sum of the three sides is greater than the third side.
# Include <iostream> using namespace std; class triangle {private: float edge_a; float edge_ B; float edge_c; bool compare (); public: triangle () {edge_a = 0.0; edge_ B = 0.0; edge_c = 0.0;} triangle (float a, float B, float c) {edge_a = a; edge_ B = B; edge_c = c;} int isTriangle (); int whatTriangle () ;}; bool triangle: compare () {if (edge_a + edge_ B> edge_c & edge_ B + edge_c> edge_a & edge_c + edge_a> edge_ B) Return true; else return false;} int triangle: isTriangle () {if (this-> compare () {return this-> whatTriangle ();} else return 0 ;} int triangle: whatTriangle () {if (edge_a = edge_ B & edge_ B = edge_c & edge_c = edge_a) return 1; else if (edge_a = edge_ B | edge_ B = edge_c | edge_c = edge_a) return 2; else return 3;} int main () {int a, B, c; int choice = 1; while (choice) {system ("cls"); cout <"Enter The length of the three sides of the triangle. "<Endl; cout <" a = "; cin> a; cout <" B = "; cin> B; cout <" c = "; cin> c; triangle tri (a, B, c); int result = tri. isTriangle (); switch (result) {case 1: cout <"can be an equi-edge triangle. "; Break; case 2: cout <" can be an isosceles triangle. "; Break; case 3: cout <" can form an unequal triangle. "; Break; default: cout <" cannot be a triangle. ";}Cout <endl; cout <" to continue, enter 1. to exit, output 0. "<endl; cin> choice;} cout <" exit the program. "<endl; return 0 ;}
If you want source code, click.
This article is from the "Calm dreamer" blog, please be sure to keep this source http://idiotxl1020.blog.51cto.com/6419277/1290434