Handout - Software design

//
// Triangle program
// This program finds the length of the hypotenuse of a right
// triangle, given the lengths of the other two sides
// Adapted from Dale, Weems, Headington "Programming and Problem
// Soving with C++"
//
#include < iostream>
#include < cmath>     //for sqrt()

using namespace std;

int main()
{
  float lengthOfA;   //length of one of the known sides
  float lengthOfB;    //length of the other known side
  float sumOfSquares; //sum of the squares of the known sides
  float hypotenuse;   //length of the hypotenuse

  cout << "This program calculates the length of the hypotenuse";
  cout << endl << "of a right triangle given the lengths of the";
  cout << endl << "other two sides." << endl << endl;

  // Get data

  cout << "Enter the lengths of the two sides." << endl;
  cin >> lengthOfA >> lengthOfB;

  // Print data

  cout << endl;
  cout << "The length of side A is " << lengthOfA << endl;
  cout << "The length of side B is " << lengthOfB << endl;

  // Compute sum of squares

  sumOfSquares = lengthOfA * lengthOfA + lengthOfB * lengthOfB;

  // Find length of hypotenuse

  hypotenuse = sqrt(sumOfSquares);

  // Print length of hypotenuse

  cout << "The length of the hypotenuse is " << hypotenuse << endl;
  return 0;
}