using System; using System.Collections.Generic; using System.Text; namespace Triangle { // All the triangle types. public enum TriangleType { NotTriangle, // Bad / Illegal Triangle Scalene, // All sides have different size Isosceles, // Two sides are equivalent, the ther is different Equilateral // All sides are equal } // Triangle Class: // - Has sides widths, ordered. // - Says the triangle dimensions. // - Says the type of the triangle. public class Triangle { // Sides widths public int[] sides; public Triangle(int A, int B, int C) { sides = new int[3]; // No need to delete dynamic allocations in C#. Wow. sides[0] = A; sides[1] = B; sides[2] = C; } public Triangle() { sides = new int[3]; } // Returns the type of the triangle. // Rule: // - All triangles are not legal triangles until proven the contrary; // - Easiest check: Equilateral (sides are equal); // - As long as dimensions proportions are fine: // - If there is any equivalence between sides and it is NOT an equilateral, it must be an Isosceles; // - If all the above failed, it is a Scalene. public TriangleType SayType() { // Sorting the sides' width is the best way I could think for determining the type. Array.Sort(sides); TriangleType Type = TriangleType.NotTriangle; if (sides[0] == sides[1] && sides[0] == sides[2]) { Type = TriangleType.Equilateral; // Test Hint: we don;t check for 0 values } else if (sides[0] + sides[1] > sides[2]) { if (sides[0] == sides[1] || sides[1] == sides[2]) { Type = TriangleType.Isosceles; // Test Hint: We don't check for negative numbers... } else { Type = TriangleType.Scalene; // Testing Hint: What else falls in this category? } } else { Type = TriangleType.NotTriangle; } return Type; } } }