Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create the following prototypes it a project for my programming class, i really need your help :] double get_double(string prompt); double sroot(double number); double calc_hypotenuse(double
- Create the following prototypes it a project for my programming class, i really need your help :]
-
double get_double(string prompt); double sroot(double number); double calc_hypotenuse(double side1, double side2); double calc_area(double side1, double side2); double calc_perimeter(double side1, double side2);
- Create definition stubs for each of the above function prototypes. Each of the functions can be set to return 0. Stubs simply allow the functions to be called and compiled without it having to be completely written out. Specifically, for this exercise, you can type out main() as given below in its entirety. The code will compile as long as the stubs are written out.
- For each of the functions below, read each description and replace the stub definition with each specific description as given.
- get_double(string prompt) will pass in a string parameter. In get_double(), ask the user to enter a number, but only allow numbers greater than zero (use a do-while loop). prompt will be displayed to the user as the message to receive user input. The return value will be always be a positive number.
- sroot(double) takes one double parameter. This function will calculate the square root of the parameter by calling the pow() function. DO NOT USE the sqrt() function to calculate the square root. Use this sroot() function that you created. You will need to include
to use the pow() function. Remember that raising a number to 0.5 is equivalent to the square root of the number. The sroot() function in this case is simply wrapping the pow() function. Wrapping takes an existing function and emulates similar behavior, but usually changes the parameters needed. - calc_hypotenuse(double, double) takes in 2 parameters which represent two sides of the triangle. This function will return a double value. The return value will be the result of the Pythagorean Theorem: hypotenuse = sroot(pow(side1, 2.0) + pow(side2, 2.0))
a2 = b2 + c2
- calc_perimeter(double, double) takes two parameters representing two sides. In the body of calc_perimeter(), you will have to call calc_hypotenuse() to determine the length of the third side and calculate the perimeter. The result of the calc_perimeter() function is the perimeter value.
- calc_area(double, double) takes two parameters representing two sides. The result of the calc_area() function is the area. Remember that the formula for area of a triangle is Area = 0.5 * side1 * side2
- Copy main() below as it is. You dont need to change it.
Sample Main
// your function prototypes go here int main() { double side1, side2; double perimeter, area; side1 = get_double("Enter the length of one side"); side2 = get_double("Enter the length of the adjacent side"); perimeter = calc_perimeter(side1, side2); area = calc_area(side1, side2); cout << A right triangle with sides << side1 << and << side2 << has a perimiter of << perimeter << and an area of << area << . The length of the third side is << calc_hypotenuse(side1, side2) << endl; return 0; } // your function definitions go here
Sample Interaction / Output
Enter the length of one side: 3 Enter the length of the adjacent side: 4 A right triangle with sides 3 and 4 has a perimeter of 12 and an area of 6. The length of the third side is 5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started