Purchase Solution

Visual Basic (Triangle Application)

Not what you're looking for?

Ask Custom Question

(Triangle Creator Application) Create an application that allows the user to enter the lengths for the three sides of a triangle as Integers. The application should then determine whether the triangle is a right triangle (two sides of the triangle form a 90-degree angle), an equilateral triangle (all sides of equal length) or neither. The application's GUI is completed for you (Fig. 19.45). You must create a class to represent a triangle object and define the event handler for the Create Button.

a) Copying the template to your working directory. Copy the directory C: Exampl esTutori al 19ExercisesTri angl e to your C: Si mpl yVB2008 directory.
b) Opening the application's template file. Double click Tri angl e. sl n in the Tri angl e directory to open the application.
c) Creating the Triangle class. Add a class to the project, and name it Tri angl e. This is where you define the properties of the Tri angl e class.
d) Defining the necessary constructor and properties. Define a constructor that takes the lengths of the three sides of the triangle as arguments. Create three properties that enable clients to access and modify the lengths of the three sides. If the user enters a negative value, that side should be assigned the value zero and the display updated.
e) Adding additional features. Create two more properties in the Tri angl e class— one determines whether the sides form a right triangle, the other an equilateral triangle. Use the Pythagorean theorem (a 2 + b 2 = c 2) to test for a right triangle. These properties are considered read-only, because you would naturally define only the Get accessor. There is no simple Set accessor that can make a triangle a right triangle or an equilateral triangle without first modifying the lengths of the triangle's sides. To create a read-only property (where the Set accessor is omitted), precede keyword Property with the keyword ReadOnl y.
f) Adding code to event handler. Now that you have created your Tri angl e class, you can use it to create objects in your application. Double click the Create Button in Design view to generate the event handler. Create new variables to store the three lengths from the TextBoxes; then use those values to create a new Tri angl e object.
g) Displaying the result. Use an If... ElseIf statement to determine whether the triangle is a right triangle, an equilateral triangle or neither. Display the result in a Label .
h) Running the application. Select Debug > Start Debugging to run your application. Add various inputs until you have created an equilateral triangle, a right triangle and a triangle that is neither right nor equilateral. Verify that the proper output is displayed for each.
i) Closing the application. Close your running application by clicking its close box.
j) Closing the IDE. Close the Visual Basic IDE by clicking its close box.

Purchase this Solution

Solution Summary

The expert examines visual basic for triangle applications.

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Networking Questions

This quiz consists of some basic networking questions.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.