Programming Languages
Open the comand prompt / terminal, navigate to your desktop, and enter ghci
. Open a code editor (e.g., Atom, Visual Studio Code, Sublime Text) and create a file activity02.hs
; save it to the cs222
folder on your desktop. As you write code, test it in ghci
.
--
do in a .hs file? How does this compare to a .lhs file? Write your answer in comments above the function.
-- what does this function do???
mystery :: Integer -> Integer
mystery n = if n >= 0 then n else (-n)
Write a function called doubleSmall
that takes an integer x
and doubles it if it is less than or equal than 100, otherwise it returns the given number x
.
Add to your file a definition a function hyp
that computes the hypotenuse given two integer sides of a right triangle. Recall that . Hint: It may help to refer to Fig. 1 on page 13 of your book.
Write a function that computes the area of a circle given the radius.
Add a function whatToWear :: Float -> (Float, String)
that takes degrees fahrenheit as input. Use the where
clause to compute degrees in celsius. Recall that degrees celsius is given by C = (F - 32) * (5/9)
, where C
is degrees celsius and F
is degrees fahrenheit. The function should output a tuple consisting of degrees celsius followed by a string saying what to wear.
For example:
> whatToWear 5
(-15.0,"Wear a coat!")
Write a function called lucky
which takes an integer and evalutes to “LUCKY NUMBER SEVEN!” if the integer is 7, and “No dice.” otherwise.
Write a function that computes the circumference of a circle given the radius.
Write a function that computes the average of two numbers.
Submit your file to Moodle which has all function definitions.