Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help in doing this: In this assignment, you will write a bash script call

ID: 3886027 • Letter: I

Question

I need help in doing this:

In this assignment, you will write a bash script called tsp which will classify a triangle. It will lake, as command-line arguments, the lengths of the three sides of a triangle, and classify the triangle as exactly one of. Right A 90 degree angle, per the Pythagorean Theorem: a^2 + b^2 = c^2. Equilateral: All three sides are the same length Isosceles: Two sides, but not three, are the same length. Scalene: No sides are the same length. Not a triangle: For example, lengths of 1, 2, and 9. They just don't fit together! Testing Here are some of the ways that we will test your program. You can try your program with these arguments, and fix any problems you may have, or you can wait and let us find your problems. Your grade will reflect your choice. Here are some bad inputs, which must generate only an error message. Requirements Your program should emit a helpful error message if too many or too few arguments are given any argument is not an integer (a whole number) greaterthanorequalto 1 I haven't told you precisely what the output should look like, and I haven't told you precisely what a helpful error message would be. Figuring that out is part of the assignment. If your program emits an error message, it should not emit anything else. For example, given the arguments it would be wrong for the program to complain about the arguments not being greaterthanorequalto 1, and then go on to declare this an equilateral triangle In cases where multiple requirements are violated, say for the two arguments Fish theta, it doesn't matter which requirement you complain about. Pick one, complain, and that should be all This must be a pure bash script, and not use any other languages such as perl awk. You may use programs such as sed or Don't be concerned about leading zeroes in numbers. They are used by bash to indicate octal (base 8). We will not test your program with leading zeroes The first line of your script must be 1 bin/bash Your script must include a comment block after the first line that contains: your name, course, assignment, and date.

Explanation / Answer

Hi,

Here is the script you can use,

if (( $# != 3 )); then # checking for number of parameters

echo "Illegal number of parameters"

exit

fi

x=$1 y=$2 z=$3

for i in $x $y $z; do

if [[ ! $i -gt 0 ]]; then #checking if arguements are positive

echo "sides can only have positive values "

exit

fi

done

if (( ! ( x+y > z && y+z > x && z+x > y ) )); then # checking the triangle equality

echo "not a triangle"

exit

fi

if (( x*x == y*y + z*z) || ( y*y == z*z+ x*x) || ( z*z == y*y + x*x)); then echo RIGHT ANGLED #pythogoreans

elif (( x != z && x != y && y != z )); then echo SCALENE

elif (( x == y && x == z )) ; then echo EQUILATERAL

else echo ISOSCELES

fi
Thumbs up if this was helpful, otherwise let me know in comments.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote