CS 1400 Lab #11: Hypotenuse Calculator
One of the neat things about methods is that if they are correctly written, you can use them in lots of different places, and in many different kinds of programs. An important property of a well written method is that it only does one thing, and that it does it well. The Method you wrote in lab #10 does one thing: given the lengths of two sides of a right triangle, it calculates the length of the hypotenuse. The method does not care where the lengths of the two sides came from, nor does it care about where the results that it calculates will go.
In the previous lab you created a method that calculates and returns the length of the hypotenuse of a right triangle. If your method is written correctly, you should be able to copy it out of the code for lab #10, and drop it without change into a similar program that uses a Graphical User Interface.
Start Visual Studio and create a new Windows Forms Application. You may design your own interface, but it should be intuitive and easy to use. My program looks like this:
There are two TextBoxes where the user enters in the lengths of the sides of a right triangle. There is a button that the user presses to make the program do the calculation, and a TextBox for displaying the result.
Writing the Code
Switch to the code view for your Form. Cut the code for the method you wrote to calculate the hypotenuse of a right triangle out of the program you wrote in lab #10, and paste it as a method inside the Form class of your new program. Be sure it exists as a separate method. Don't paste the code into an existing method.
Go back to the Designer view and double click on the button to create a skeleton for the method to handle the button_Click event. In this method you should
When you submit your lab to Canvas, add a comment to your submission that correctly answers the following two questions.
Question #1: When designing a method, how many things should the method be responsible for doing?
Question #2: True or false: When a method is written correctly, it is possible to use the
same method, without change, in a Console program or a GUI program.
When you are satisfied that your program works correctly, submit it to Canvas.
File(s) to Submit:
Place your complete project folder in a zip file and name the zip file lab_11_your-initials_V1.0.zip. For example, I would name my file lab_11_RKD_v1.0.zip. Submit this assignment as Lab #11 on Canvas.