Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Your Right Triangle class will consist of the following: Variables: - a_leg (type double) for the a_leg of the right triangle - b_leg (type

C++

Your Right Triangle class will consist of the following:

Variables:

- a_leg (type double) for the a_leg of the right triangle

- b_leg (type double) for the b_leg of the right triangle

Constructors/Functions

- A constructor that takes no arguments. This constructor will initialize both a_leg and b_leg to 0.0000001. You can initialize a_leg and b_leg either in the member initializer list or in the body of the constructor.

- A constructor that takes two arguments, one for the a leg value and one for the b leg value, and initializes the a_leg and b_leg member variables from these values. Input validation: if the a leg and/or b leg values passed to the constructor are not greater than zero, then set the a_leg and/or b_leg member variables to 0.0000001. Otherwise, set the a_leg and/or b_leg member variables to the values passed to the constructor. You can validate the input either by checking it directly in the body of the constructor, or by having this constructor call the set_a_leg and set_b_leg functions, as these functions will validate the input for a leg and b leg respectively (see below).

- A function named set_a_leg, which sets a_leg member variable with the value passed to the function. : Input validation: if the a leg value passed to the function is not greater than zero, then set the a_leg member variable to 0.0000001. Otherwise, set the a_leg member variable to the value passed to the function.

- A function named set_b_leg, which sets b_leg member variable with the value passed to the function. : Input validation: if the a leg value passed to the function is not greater than zero, then set the b_leg member variable to 0.0000001. Otherwise, set the b_leg member variable to the value passed to the function.

- A function named get_a_leg, which returns the value of the a_leg member variable.

- A function named get_b_leg, which returns the value of the b_leg member variable.

- A function named get_c_leg, which calculates the value of the c leg (hypotenuse) using the formula shown above and returns this value.

- A function named get_area, which calculates the value of the area using the formula shown above and returns this value.

- A function named get_perimeter, which calculates the value of the perimeter using the formula shown above and returns this value.

Application Program:

- In your application program you will be creating two Right Triangle objects. The first RT object that you create will call the no-argument constructor, which will initialize the a_leg and b_leg member variables to 0.0000001, and then print out the results by calling the appropriate get member functions from the class (see below). To create the second RT object, you need to first prompt the user to enter the inputs for a_leg and b_leg, and then create the object using the two-argument constructor, and then print out the results by calling the appropriate get member functions from the class (see below).

NOTES:

- There is no c_leg member variable, because the value of the c leg (hypotenuse) is calculated from the values of a_leg and b_leg. For this same reason, there is no set_c_leg member

function.

image text in transcribed

RT object 1 a_leg value: 0.0000001000 RT object 1 b_leg value: 0.0000001000 RT object 1 c_leg value: 0.0000001414 RT object 1 area: 0.0000000000 RT object 1 perimeter: 0.0000003414 Enter the a_leg value for RT object 2: 2 Enter the b_leg value for RT object 2: 3 RT object 2 a_leg value: 2.0000000000 RT object 2 b_leg value: 3.0000000000 RT object 2 c_leg value: 3.6055512755 RT object 2 area: 3.0000000000 RT object 2 perimeter: 8.6055512755 Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions