# CS155 HW4: Triangles!

• King Arthur, Guinevere, and Sir Lancelot?
• Curly McLain, Laurey Williams and Jud Fry?
• Archie, Betty, and Veronica?

Nope, not those triangles. We’re talking about geometric triangles—three-sided polygons.

## Summary

In this assignment, you will write a bash script called tsp which will classify a triangle. It will take, as command-line arguments, the lengths of the three sides of a triangle, and classify the triangle as exactly one of:

 Right: A 90° angle, per the Pythagorean Theorem: a²+b²=c². 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.

CommandOutput
./tsp 3 3 3equilateral
./tsp 3 4 5right
./tsp 5 4 3right
./tsp 4 3 5right
./tsp 6 7 8scalene
./tsp 102 100 102isosceles
./tsp 42 42 36isosceles
./tsp 1 2 9not a triangle

Here are some bad inputs, which must generate only an error message.

 ./tsp -3 12 99 ./tsp 10 20 9-Jack-9 ./tsp My Dog Kokopelli ./tsp ./tsp 42 ./tsp 1 2 3 4 5 6 7

## Requirements

• too many or too few arguments are given
• any argument is not an integer (a whole number) ≥ 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 0 0 0, it would be wrong for the program to complain about the arguments not being ≥ 1, and then go on to declare this an equilateral triangle.
• In cases where multiple requirements are violated, say for the two arguments Fish 0, 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 or awk. You may use programs such as sed or grep.
• 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:
#! /bin/bash
• Your script must include a comment block after the first line that contains: your name, course, assignment, and date.

## How to submit your homework:

Follow the directions on the homework page.

## How to receive fewer points:

Produce a poor error message. For example, “bad number” doesn’t tell me what argument it didn’t like, or what was so bad about it.

## How to receive negative points:

Turn in someone else’s work.

 Modified: 2017-12-06T12:45                  User: Guest                  Check: HTML CSS Edit History Source Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University