Created
February 27, 2020 15:03
-
-
Save isc-rsingh/c88db9f36b7df04425960c4d1dbea642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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