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

For C++..... In a right triangle, the square of the length of one side is equal

ID: 1798681 • Letter: F

Question

For C++.....

In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Stephanie has the integer lengths of three sides of a triangle and needs to know if it is a right triangle.

Write a program to solve this problem. NOTE: The user must be allowed to input the values of the sides in ANY ORDER!

1. Identify the inputs and outputs of the problem.


2. Identify the processing needed to convert the inputs to the outputs.


3. Design an algorithm in pseudocode to solve the problem. Make sure to include steps to get each input and to report each output.


4. Identify five significant test cases including one for incorrect input (ie. Input a letter rather than a digit for the numeric input). (Think about what impact changing the order of the input values should have on your program!) For each of the five test cases show what inputs you will use and calculate what your expected outputs should be.



5. Write the program to implement your algorithm.

Explanation / Answer

1. In this problem, to find whether or not the triangle is a right triangle, the sides are analysed. Therefore there are three inputs, the three integer side lengths. The only thing wished to be accomplished by this code is to determine whether or not the triangle is right angled. There is only one boolean output used to indicate this (denote right angle result as true, otherwise false).

2. In order to get to the output from the input parameters, first to be done is to find the square of each value. After this the sum of two of the squares are tested against the remaining square for equality, updated the boolean flag appropriately.

3. The general algorithm that must be followed is described in the following question. The pseudo code is included below:
a)take in three integer input values
b)square all of the values
c)add the square of int1 to int2
d)does this sum equal the square of int3?
e)if equal, set boolean flag to true and return
f)otherwise, add the squares of int2 and int3
g)does this sum equal the square of int1?
h)if equal, set boolean flag to true and return
i)otherwise, add the squares of int1 and int3
j)does this equal the square of int2?
k)if equal, set boolean flag to true, otherwise set to false and return.

4. For the described program, the effect that switching the order or the inputs has is that it will alter the running time of the program (but only if the triangle is right, otherwise the running time is constant no matter what). If a floating point value is taken as input, the number will be truncated to its integer form, obviously skewing the actual answer. On the other hand, if a letter character is taken as input, it will in fact be represented by its numerical ASCII value.

5. The program to implement the method described could possible be as follows:

boolean isItRight ( int num1, int num2, int num3){
int s1,s2,s3;
boolean right = false;
s1=num1*num1;
s2=num2*num2;
s3=num3*num3;
if((s1+s2) == s3)
right = true;
else if((s1+s3) == s2)
right = true;
else if ((s2+s3) == s1)
right = true;
else
right = false;

return right;
}



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