Answer to Question #176826 in C++ for Luna

Question #176826

Write a program that will read an arbitrary number of sets of triangle sides using only integer values. 

  1. Prompt the user for sets of numbers and process them until the user submits the numbers 0 0 0, which will terminate the program.
  2. For each set of three numbers, the program should print the values read.
  3. For each set of three numbers, the program should decide if the numbers represent the sides of a valid triangle.
  4. If the numbers could not represent a valid triangle, display an appropriate error message.
  5. If the numbers are valid, the program should determine, and display, the:
  6. classify sides of the triangle – equilateral, isosceles, or scalene
  7. classify angles of the triangle – right, acute, or obtuse

You need to have functions for the following tasks:

  1. do the 3 side length form a triangle
  2. classify the triangle by side lengths
  3. classify the triangle as right or non-right triangle

Sample run:

Provide three side lengths – 0 0 0 to terminate.

3

5

4

3 5 4   Triangle possible:  Scalene and Right.


1
Expert's answer
2021-03-30T06:56:06-0400
def checkTypeOfTriangle(a,b,c):
sqa = pow(a, 2)
sqb = pow(b, 2)
sqc = pow(c, 2)
  
if (sqa == sqa + sqb or
sqb == sqa + sqc or
sqc == sqa + sqb):
print("Right.",end="\n")
  
elif(sqa > sqc + sqb or
sqb > sqa + sqc or
sqc > sqa + sqb):
print("Obtuse.",end="\n")
  
else:
print("Acute.",end="\n")
def is_valid_triangle(a,b,c):
if a+b>=c and b+c>=a and c+a>=b:
return True
else:
return False
while(1):
a=int(input())
b=int(input())
c=int(input())
if(a==0 and b==0 and c==0):
break
if is_valid_triangle(a, b, c):
print( a,b,c ,'Triangle possible: ',end="")
else:
print(a,b,c, 'Triangle is Invalid.')
continue
if a == b == c:
   print("Equilateral and ",end="")
elif a==b or b==c or c==a:
   print("Isosceles and ",end="")
else:
   print("Scalene and ",end="")
checkTypeOfTriangle(a, b, c)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS