The Server A Triangle will have 3 sides. It will be able to keep track of the nu
ID: 3683410 • Letter: T
Question
The Server A Triangle will have 3 sides. It will be able to keep track of the number of Triangle objects created. It will also hold the total of the perimeters of all the Triangle objects created. It will allow a client to create a Triangle, passing in integer values for the three sides. If the values for the sides that are passed in do not represent a valid Triangle, then all sides will be set to a value of1. The constructor should add 1 to the count of the number of Triangles created and also call a method to calculate the perimeter and then add the perimeter for that object to an accumulator. It will contain a separate private method called isValid0. The sum of any two sides of a triangle must be greater than the third in order to represent a valid triangle. Also, no side may be 0 or negative. The Triangle class must have the following methods that return a Boolean value is _right 0 - a right triangle is_scalene0 - no two sides are the same length is_isosceles0 - exactly two sides are the same lengtlh is_equilateral0 all three sides are the same length .In addition, the Triangle class will need the following methods: toString0- returns a String that specifies the values for the 3 sides of the triangle eals (Triangle) -compares two Triangle objects to determine if they are equal. We will compare their perimeters to determine equality - calcPerim0 - calculate and return the perimeter of the object -addTotalPerim). This method will call calc _perim() and add the perimeter for that object to an accumulator. -Accessor and mutator methods for all properties isValid0 - returns a Boolean based on the criteria described above. reduceTotalPerim0. This method should subtract the perimeter for that object from the accumulator. Be sure to specify proper visibility for all methods and properties The Client The Describe class will contain mainO . It will instantiate 5 Triangles .tril with sides 3,4,5 tri2 with sides 3, 3, 3 tri3 with sides 4, 4,5 tri4 with sides 1, 1, 2 triS with sides -3, 4, 5 Allow the user to type 3 positive integers on separate lines for each triangle. Instantiate five separate objects of the Triangle class (tri 1...tri 5). Use if statements to test each triangle for its properties and print appropriate output. .Print the values of the sides of each triangle .Print the properties that apply for each triangle. See the sample output. . Print the Perimeter for each triangle At the end print the total of the perimeters for all triangles. Output must be labeled, aligned, and reasonably well-spaced .Since we haven't discussed arrays in class, do not try to use a loop to instantiate these objects. There will be a lot of duplicate code in Describe. One approach is to create your first triangle, test for the various properties, and display its output. Then simply copy and paste that code replacing tril with tri2. Do the same for all 5 triangles.Explanation / Answer
The constructor of Triangle should look like this
Triangle(float a, float b, float c)
{
// in here check if the triangle is valid by calling isValid() method if its valid then intialize the three sides by a, b, c
side1=a; side2=b; side3=c;
// if the triagle is invalid then set three sides to 1 like
side1=1; side2=1; side3=1;
}
// similarly implement other methods
In describe class make different triangles by simply making objects of triangle class like
Triangle t1 = new Triangle(3,4,5);
Triangle t2 = new Triangle(3,3,3);
Triangle t3 = new Triangle(4,4,5);
// then call methods of triangle to check if triangle is equilateral etc like
if(t1.is_scalene())
System.out.println("t1 is scalene");
else if(t1.is_isoceles())
System.out.println("t1 is isosceles triangle");
else if(t1.is_equilateral)
System.out.println("t1 is equilateral");
// Similarly for other triangles
The code I used is in java but the working and procedure is same for cpp also. you can do same in cpp with little or no change. Please comment if you need more assistance.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.