Question

Convert your algorithm into a C++ program. Your program should output the value of the longest...

Convert your algorithm into a C++ program. Your program should output the value of the longest side of the right-angled triangle.

Note, to answer the question, you will need to be able to do square root. To do square root, follow these 2 steps.

1) include the cmath library that allows square root using the statement

#include <cmath>

2) To perform a square root, use the syntax

sqrt(a double variable or number goes in here);

For example

cout << sqrt(25.0);   

OR

double answer = sqrt(25.0);

The first statement above will display 5 to the output screen and the second statement will store the 5 in a variable. Use whichever you like

Homework Answers

Answer #1

C++ code:

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    //initializing two sides
    double side1,side2;
    //asking for their lengths
    cout<<"Enter the lengths of the other two sides: ";
    //accepting them
    cin>>side1>>side2;
    //printing the length of longest side by finding square root of both sides squared and added
    cout<<"The length of the longest side is "<<sqrt(side1*side1+side2*side2)<<endl;
    return 0;
}

Screenshot:


Input and Output:

Know the answer?
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
Similar Questions
Write a program that asks for five test scores. The program should calculate the average test...
Write a program that asks for five test scores. The program should calculate the average test score and display it. The number displayed should be formatted in fixed-point notation, with one decimal point of precision. Display: (1) your (1) interactive dialog with the console, (2) the five test scores entered, and (3) the computed average. the pseudo code is: you will need to include a library for the output formatting for specifying decimal point display: #include <iomanip> in std namespace...
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments ** Print Name and Assignment on screen ** Date ** Submit .cpp file. Demo // This program uses a type cast to avoid an integer division. #include <iostream> // input - output stream #include <fstream> //working file...
// This program prints a table to convert numbers from one unit to another. // The...
// This program prints a table to convert numbers from one unit to another. // The program illustrates some implementation techniques. //Include the header file ostream for including all stream. ---------------------------------------------------------*/ #include <iostream> //Provides cout <v1.0> //Include iomanip that is used for set precision. #include <iomanip> //Provides setw function for setting output width <v1.1> //Header file for EXIT_SUCCESS. #include <stdlib.h>// Provides EXIT_SUCCESS <v1.2> //Header file for assert. #include <assert.h>// Provides assert function <1.3> using namespace std; // Allows all standard...
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's...
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's length, width, and area Define an overloaded constructor and use it when creating the Rectangle object instead of using the setters. Change this program to calculate and display the rectangle's perimeter. Example: In feet, how wide is your house? 20 In feet, how long is your house? 25 The house is 20.00 feet wide. The house is 25.00 feet long. The house has 500.00...
C++ 1. Modify the code from your HW2 as follows: Your triangle functions will now return...
C++ 1. Modify the code from your HW2 as follows: Your triangle functions will now return a string object. This string will contain the identification of the triangle as one of the following (with a potential prefix of the word “Right ”): Not a triangle Scalene triangle Isosceles triangle Equilateral triangle 2. All output to cout will be moved from the triangle functions to the main function. 3. The triangle functions are still responsible for rearranging the values such that...
complete a C++ program that asks the user to make a choice off a menu that...
complete a C++ program that asks the user to make a choice off a menu that will be displayed to them. The user can make as many selections as they wish. The last choice from the menu will give them an option to stop. The menu choices will be the following four calculations: Find the volume of a cone Find the volume of a sphere Find the area of octagon Find the distance between two points Stop For the different...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT