Question

In: Computer Science

Write a program that prompts for and reads in the two side lengths of a right...

Write a program that prompts for and reads in the two side lengths of a right triangle (floating point numbers) and then calls a float-valued function, hypot1, that calculates and returns the length of the hypotenuse of the triangle. The program then displays the two side lengths and the hypotenuse length. Note: The hypot1 function returns the hypotenuse length – it does not display it; the function should not contain any cout nor cin statements. Math review: Recall that for any right triangle with side lengths a and b, and hypotenuse length c, a2+b2=c2. Here is an example of what output should look like from running your program (user input is shown in bold).  

Enter the side lengths: 1.2 3.4

First side length = 1.2

Second side length = 3.4

Hypotenuse length = 3.60555

Solutions

Expert Solution

SOLUTION-
I have solve the problem in C++ code with comments and screenshot for easy understanding :)

CODE-

//c++ code
#include <iostream>
#include <cmath>
using namespace std;
//function to calculate length of the hypotenuse of the triangle.
float Hypot(float a, float b)
{
    return sqrt(pow(a, 2) + pow(b, 2));
}
//main function
int main()
{
    float a, b;
    cout << "Enter the side lengths: ";
    cin >> a >> b; //gets input from user
    cout << "First side length = " << a << endl;
    cout << "Second side length = " << b << endl;
    cout << "Hypotenuse length = " << Hypot(a, b) << endl; //call function and print
    return 0;
}


SCREENSHOT-


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

Write a program that prompts for the lengths of the sides of a triangle and reports...
Write a program that prompts for the lengths of the sides of a triangle and reports the three angles. Make sure you have a good introduction stating what the program does when it is run, and a helpful prompt for the user when asking for input: i.e. Here is the generated output from a sample program: This program computes the angles of a triangle given the lengths of the sides. What is the length of side 1? <wait for user...
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
PYTHON WHILE Write a program that prompts for and reads the number ? of spheres to...
PYTHON WHILE Write a program that prompts for and reads the number ? of spheres to be processed. If ?≤0 your program must display an error message and terminate; otherwise it does the following for ? times: Write a program that prompts for and reads the number ?n of spheres to be processed. If ?≤0n≤0 your program must display an error message and terminate; otherwise it does the following for ?n times: Prompts for and reads the volume of a...
Write a program that prompts the user for the length of one side of a triangle...
Write a program that prompts the user for the length of one side of a triangle and the sizes of the two adjacent angles in degrees and then displays the length of the two other sides and the size of the third angle.
(C++) Write a program that prompts the user for the length of one side of a...
(C++) Write a program that prompts the user for the length of one side of a triangle and the sizes of the two adjacent angles in degrees and then displays the length of the two other sides and the size of the third angle.
Write a Java program that prompts for and reads the number N of cities or locations...
Write a Java program that prompts for and reads the number N of cities or locations to be processed. It then loops N times to prompt for and read, for each location, the decimal latitude, decimal longitude, and decimal magnetic declination. It then computes and displays, for each location, the Qibla direction (or bearing) from Magnetic North. The true bearing from a point A to a point B is the angle measured in degrees, in a clockwise direction, from the...
Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user...
Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user to enter the name of a field (other than Date), and then outputs the highest and lowest values recorded in that field for the month of August. The file climate_data_2017_numeric.csv contains the following fields: Date Minimum temperature (C) Maximum temperature (C) Rainfall (mm) Speed of maximum wind gust (km/h) 9am Temperature (C) 9am relative humidity (%) 3pm Temperature (C) 3pm relative humidity (%) Expected...
1. Write an assembly language program that prompts the user for and reads four integers (x1,...
1. Write an assembly language program that prompts the user for and reads four integers (x1, y1, x2, y2) which represent the coordinates of two points. Make sure you keep track of which number is which. 2. Treat the line between the points as the radius of a sphere and compute the surface area of the sphere. Print the output with a label, such as “The surface area of the sphere is: …”. Hint: The distance between the points is...
A triangle has side lengths of 3cm, 4cm, and, 6cm. Is it a right triangle explain?
A triangle has side lengths of 3cm, 4cm, and, 6cm. Is it a right triangle explain?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT