Input three sides to determine whether a triangle can be formed

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.