Skip to content

Instantly share code, notes, and snippets.

@isc-rsingh
Created February 27, 2020 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isc-rsingh/c88db9f36b7df04425960c4d1dbea642 to your computer and use it in GitHub Desktop.
Save isc-rsingh/c88db9f36b7df04425960c4d1dbea642 to your computer and use it in GitHub Desktop.
ROUTINE RightTriangle
/* compute area and hypotenuse of a right triangle
this routine contains examples of
new ObjectScript features */
Write !, "Compute the area and hypotenuse of a right triangle",
!, "given the lengths of its two sides."
Set units = "feet"
Set side1 = 3
Set side2 = 6
Do Compute( units, side1, side2)
Write !!, "Current date: "
Do ^%D
Write !, "Current time:"
Do ^%T
Quit
IsNegative(num) PUBLIC // is num negative?
{
If (num '> 0) {
Write " Enter a positive number."
Quit 1 // return "true"
}
Else {
Write " Accepted."
Quit 0 // return "false"
}
}
Compute(units,A,B) // compute and display area and hypotenuse
{
Set area = ( A * B ) / 2,
area = $justify( area, 0, 2),
squaredSides = ( A ** 2 ) + ( B ** 2 )
// $zsqr function computes square root
Set hypot = $zsqr(squaredSides)
// round hypot to 2 places
Set hypot = $justify( hypot, 0, 2)
Write !!, "The area of this triangle is ", area, " square ", units, ".",
!!, "The hypotenuse is ", hypot, " ", units, "."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment