Question

In this exercise, you will modify the hypotenuse program shown earlier in Figure 9-6. Follow the...

In this exercise, you will modify the hypotenuse program shown earlier in Figure 9-6. Follow the instructions for starting C++ and viewing the ModifyThis13.cpp file, which is contained in either the Cpp8/Chap09/ModifyThis13 Project folder or the Cpp8/Chap09 folder. Remove both calculation tasks from the main function, and assign both to a program-defined value-returning function named getHypotenuse. Test the program appropriately.

//Hypotenuse.cpp - displays the length of a right
//triangle's hypotenuse

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
double sideA = 0.0;
double sideB = 0.0;
double sumSqrs = 0.0;
double hypotenuse = 0.0;

//get length of two sides
cout << "Side a length: ";
cin >> sideA;
cout << "Side b length: ";
cin >> sideB;

//calculate the hypotenuse length
sumSqrs = pow(sideA, 2) + pow(sideB, 2);
hypotenuse = sqrt(sumSqrs);

//display the hypotenuse length
cout << fixed << setprecision(1);
cout << "Hypotenuse length: " << hypotenuse << endl;
return 0;
}   //end of main function

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//Hypotenuse.cpp - displays the length of a right
//triangle's hypotenuse

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

double getHypotenuse(double sideA, double sideB){
   return pow(sideA, 2) + pow(sideB, 2);
}

int main()
{
double sideA = 0.0;
double sideB = 0.0;
double sumSqrs = 0.0;
double hypotenuse = 0.0;

//get length of two sides
cout << "Side a length: ";
cin >> sideA;
cout << "Side b length: ";
cin >> sideB;

//calculate the hypotenuse length
sumSqrs = getHypotenuse(sideA, sideB);
hypotenuse = sqrt(sumSqrs);

//display the hypotenuse length
cout << fixed << setprecision(1);
cout << "Hypotenuse length: " << hypotenuse << endl;
return 0;
}   //end of main function

Add a comment
Know the answer?
Add Answer to:
In this exercise, you will modify the hypotenuse program shown earlier in Figure 9-6. Follow the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What am I doing wrong here...…. Question is this : In this exercise, you will create...

    What am I doing wrong here...…. Question is this : In this exercise, you will create a program that displays a table consisting of four rows and three columns. The first column should contain the numbers 10 through 13. The second and third columns should contain the results of squaring and cubing, respec- tively, the numbers 10 through 13. The table will look similar to the one shown in Figure 9-38. If necessary, create a new project named Introductoryl6 Project,...

  • Follow the instructions for starting C++ and viewing the Intermediate23.cpp file, which is contained in either...

    Follow the instructions for starting C++ and viewing the Intermediate23.cpp file, which is contained in either the Cpp8IChap11\Intermediate23 Project folder or the Cpp8\Chap11 folder. (Depending on your C++ development tool, you may need to open the project/solution file first.) The program uses an array to store the amount of money a game show contestant won in each of five days. The program should display the total amount won and the average daily amount won. It should also display the day...

  • Consider the following program in which the statements are in the incorrect order. Rearrange the statements...

    Consider the following program in which the statements are in the incorrect order. Rearrange the statements so that the program prompts the user to input the height and the radius of the base of a cylinder and outputs the volume and surface area of the cylinder. Formant the output to two decimal places. #include <iomanip> #include <cmath> int main () {} double height; cout << ”Volume of the cylinder = “ <<PI * pow(radius, 2.0) * height << endl; cout...

  • PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program...

    PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program in which the statements are in the incorrect order. Rearrange the statements in the following order so that the program prompts the user to input: The height of the base of a cylinder The radius of the base of a cylinder The program then outputs (in order): The volume of the cylinder. The surface area of the cylinder Format the output to two decimal...

  • C++ code for CIS054 Create a program that uses a function to determine the length of...

    C++ code for CIS054 Create a program that uses a function to determine the length of a line by inputting the X,Y coordinates of the line endpoints. Show the result with a precision of four decimal places. The function prototype is to be specified as follows:     double LengthOfLine (double X1, double Y1, double X2, double Y2); // returns length of line by using this code: #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(int argc, char* argv[])...

  • Im having trouble with this C++ program. Lab 10/object/test files provided LAB 10 1 //Savings.cpp - displays the account balance at 2 //the end of 1 through 3 years 3 //Created/revised by <your nam...

    Im having trouble with this C++ program. Lab 10/object/test files provided LAB 10 1 //Savings.cpp - displays the account balance at 2 //the end of 1 through 3 years 3 //Created/revised by <your name> on <current date> 4 5 #include <iostream> 6 #include <iomanip> 7 #include <cmath> 8 using namespace std; 9 10 //function prototype 11 double getBalance(int amount, double rate, int y); 12 13 int main() 14 { 15 int deposit = 0; 16 double interestRate = 0.0; 17...

  • I have this code, but I need a flowchart that shows how my program works, and...

    I have this code, but I need a flowchart that shows how my program works, and the inputs and outputs??? #include <iostream> #include <cmath> using namespace std; int fact(int n) { int i; int c = 1; for(i=1; i<=n; i++) { if(n==0) c = 1; else c = c*i; } return c; } double ex(int n,double x) { int i; double c = 0.0; for(i=0; i<=n; i++) { c = c + (double)(pow(x,i)/ (double)fact(i)); } return c; } double sinx(int...

  • Please help me to write a program in C++ with comments and to keep it simple...

    Please help me to write a program in C++ with comments and to keep it simple as possible. Thank you! Here is my program I have done before and that need to be change: #include <iostream> #include <iomanip> using namespace std; // function prototype – returning one value double cylvol(double, double); // Note: two data types inside brackets double surfarea(double, double); // Note: two data types inside brackets int main() { double r, l, V, S; cout << setprecision(2) <<...

  • Open with Drive N // Test1B-Debug.cpp .This is a program with 6 errors in it Find and fix each er...

    NEED HELP WITH THIS!! Open with Drive N // Test1B-Debug.cpp .This is a program with 6 errors in it Find and fix each error. // Simple Container made from circular paper // Test-1B Debug Program #include #include

  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT