Professional Documents
Culture Documents
Scheme Lab2 Studs
Scheme Lab2 Studs
SCHEME: LAB 2
(a) Write a function in Scheme that is able to calculate the area of a rectangle.
[area = width x length]
(b) Write a function in Scheme that is able to calculate the perimeter of a rectangle.
[perimeter = 2 x (length + width)]
(c) Write a function in Scheme that is able to call both functions written in (a) and (b) and
then display their results.
The behavior of the conditional expressions is determined by whether objects are true or false.
The conditional expressions count only #f as false. They count everything else, including #t, pairs,
symbols, numbers, strings, vectors, and procedures as true.
:: Examples ::
Question 1
Write a function in Scheme that is able to display the following message when an age is input by
the user.
Table 1
Age Message
18 and above You are an adult.
Less than 18 You are still a kid.
Question 2
Write a function in Scheme that will receive a word as an input from the user. If the word entered
is “hello”, the function will display ‘o l l e h’ to the user; otherwise it will display the length of
“hello” to the user.
where predicate is any expression. The last clause may be an else clause, which has the form:
(else expression expression ...)
:: Examples ::
Question 1
Table 2
Average marks Message
>= 80 Excellent
70 - 79 Good
50 - 69 Pass
< 50 Fail
Question 2
Write functions in Scheme that is able to calculate the price after discount based on the given
tables below:
Table 3
Item Name Price Per Unit
Item 1 4.50
Item 2 5.99
Item 3 8.75
Table 4
Price (RM) Discount (%)
More than or equal to 500 10
Between 250 to 500 8
Between 100 to 250 5
Less than 100 2
Question 1
Convert the given factorial formula given in mathematical expression into a function in Scheme.
Question 2
Write function in Scheme to calculate the length of a list using simple recursion.