0% found this document useful (0 votes)
18 views3 pages

Lab Scheme

Uploaded by

ustazdanshirfan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Lab Scheme

Uploaded by

ustazdanshirfan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB SCHEME

Scheme is a language that using functional and basic data structure, List.

BUILT-IN FUNCTION

List handling function

Mathematical function
LAB SCHEME

Predicates Function

LAB EXERCISES

1. Find the output of the following built-in functions in Scheme.


a) (length (cdr (reverse '(this is (my final examination)))))
b) (cons (car (cdr ‘(nani nana nanu))) (cdr ‘(dance sing read)))
c) (even? (max (* 3 2) (/ 100 20) (sqrt 225)))
d) (length ‘((1 2) 3 (4 5 6)))

2. Given the simple Scheme conversion function to bring Celsius degree amount into
Fahrenheit:
(define (fahrenheitConversion celcius)
(+ (* 1.8 celcius) 32))
a) What will be the output if current Celcius degree is 45?

b) Convert the given function to convert from Fahrenheit degree into Cel sius.
c) Based on your answer in (b), show how to call the function and its output if
Fahrenheit degree is 55.

3. Write a function in Scheme that can:


a) Calculate and display the total of FIVE (5) given numbers.
b) Calculate and display the average of FIVE (5) given numbers.
c) Display the largest number among the FIVE (5) given numbers.
d) Display the smallest number among the FIVE (5) given numbers.
LAB SCHEME

4. A photo printing service charges less for each print when you order in bulk. For orders of
fewer than 10 prints, they charge RM 0.39 per print. For orders of more than 10 but fewer
than 50 prints, the cost per print is RM 0.29, and for orders of 50 or more prints, the price is
RM 0.24 per print. Write a function in Scheme that takes the number of prints ordered and
returns the total price.
5. By referring to the following table, write a scheme function that displays the respective
names of the speakers according to the type and selection chosen by the user.
Type Speaker
1 Don Bika
2 Eusof Islam
3 Dr Mahather

6. The National Earthquake Center has asked you to write a scheme f unction implementing the
f ollowing decision table to display characterization of an earthquake based on its Richter scale number.

Richter Scale Number (n) Characterization


n<5.0 Little or no damage
5.0≤n<5.5 Some damage
5.5≤n<6.5 Serious damage
6.5≤n<7.5 Disaster
n≥7.5 Catastrophe

7. Based on the description given, write the function definitions in Scheme.


i) calSalaryIncrement() that receives the department and the current salary.
The function will then calculate and returns the new monthly salary based on the
following table:

Department Current Monthly Salary Increment Rate (%)


(RM)
<= 1500 7
A
>1500 5
<=2000 5
B
>2000 3

ii) calBonus() that is able to receive the current salary and returns the amount of
bonus received based on the following table:

Salary (RM) Bonus (RM)


<2000 500
2000 - 5000 400
>5000 300

iii) calTotalIncome() that calls the functions in (i) and (ii) and sums the amount.

You might also like