Question

In: Computer Science

Write in c++ as simple as possible In a right triangle, the square of the length...

Write in c++ as simple as possible

In a right triangle, the square of the length on one side is equal to the sum of the squares of the lengths of the other two sides.  Write a program that prompts the user to enter the length of three sides of the tringle (as doubles) and the outputs a message indication whether the triangle is a right triangle.  You should split this into two functions (but only one .cpp file).  One function is main() where you input the values of the three sides, and then print out the final answer. The other function is where you determine if the triangle is a right triangle. Watch out about using == with doubles. Put comments at the top of your code.

Solutions

Expert Solution

/*Write a program to check whether triangle is right angled triangle or not. */
#include<iostream.h>
#include<conio.h>
int findRightTriangle(double,double,double);
void main()
{
double a,b,c;
int ch=0;
clrscr();
cout<<"Enter first side of triangle: ";
cin>>a; //accepts one side of triangle from user
cout<<"Enter second side of triangle: ";
cin>>b;
cout<<"Enter third side of triangle: ";
cin>>c;
ch=findRightTriangle(a,b,c); //calls findRightTriangle function
if(ch==1)
cout<<"Triangle is right triangle"<<endl;
else
cout<<"Triangle is not right triangle"<<endl;
getch();
}
int findRightTriangle(double a,double b,double c)
{
if((a*a+b*b==c*c)||(a*a+c*c==b*b)||(c*c+b*b==a*a)) //pythagoras theorem
return 1;
else
return 0;
}

Output:

Please give positive rating.


Related Solutions

Write class Hypotenuse that calculates the length of the hypotenuse of a right triangle and return...
Write class Hypotenuse that calculates the length of the hypotenuse of a right triangle and return to HypotenuseTest class. The lengths of the other two sides are given by the user by using HypotenuseTest class and send into Hypotenuse class. Hypotenuse class should take two arguments of type double and return the hypotenuse as a double into HypotenuseTest’s Main method. Finally, the HypotenuseTest class displays the hypotenuse side of a triangle.
Find the lengths of the arms of a right triangle whose hypotenuse has length c if...
Find the lengths of the arms of a right triangle whose hypotenuse has length c if these arms have a ratio of (a) 3;4 and c=15, (b) 5;12 and c=26, (c) 8;15 and c =170 and (d) 1;2 and c=10
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on...
5.11 LAB: Drawing a right triangle c++ This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as...
Given a right triangle with one leg length of a, one leg length of x-3 and...
Given a right triangle with one leg length of a, one leg length of x-3 and the hypo is x, how does a affect x? Shown on a graph. I solved for a, it is equal to the square root of 6x-9.... I am having a difficult time interpreting how a affects x.. I am not sure how to graph
Write a C# console program that fills the right to left diagonal of a square matrix...
Write a C# console program that fills the right to left diagonal of a square matrix with zeros, the lower-right triangle with -1s, and the upper left triangle with +1s. Let the user enter the size of the matrix up to size 21. Use a constant and error check. Output the formatted square matrix with appropriate values. Refer to the sample output below. Sample Run: *** Start of Matrix *** Enter the size of square (<= 21): 5 1 1...
Find a b c of a right triangle. with a perimeter of 18.
Find a b c of a right triangle. with a perimeter of 18.
a) The triangle △ ABC is right-angled with right angle at corner C and angle α...
a) The triangle △ ABC is right-angled with right angle at corner C and angle α at corner A. Calculate a = | BC |, given that c = | AB | = 8, and that tan α = 12. Calculate a= ? b) In the triangle △ ABC before the designations a = | BC |, b = | CA |, c = | AB |, and ∠A = α, ∠B = β and ∠C = γ. Find c,...
write a java program for area and perimeter of right triangle
write a java program for area and perimeter of right triangle
Week 10 - Please write in C++ as simple as possible RRCC has a schedule of...
Week 10 - Please write in C++ as simple as possible RRCC has a schedule of courses that includes: Subject (like: CSC) Course Number (like: 119) Section (like: 802) Credits (like: 3) Title Days (like: MW) Time (like 8:00am-9:15am) Instructor From this schedule information above create a class called RRCC_schedule (with a .cpp file and a .h file). Look at each item above and determine the type of data that will go into the variable. Then create a UML with...
As simple as possible. Please In C++ Computers are playing an increasing role in education. Write...
As simple as possible. Please In C++ Computers are playing an increasing role in education. Write a program that will help an elementary school student learn multiplication. Use rand() to produce two positive single digit integers. It should then display a question in the following format (assume 6 and 7 are randomly generated): How much is 6 * 7? The student then types the answer. Your program checks the student’s answer. If it is correct, print “Very good!” If the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT