CS105 Lab 1 (B) : Sum-Of-Squares
CS105 Lab 1 (B) : Sum-Of-Squares
Write Scheme expression to find the result for the following arithmetic expression:
Arithmetic Expression Result Scheme Expression
1+53 3 (- (+ 1 5) 3) (+ 1 5 -3)
1+5*3 16
(1 + 5) * 3 18
(1 + 5) * (3 6) -18
1+5*36 10
Write a scheme function sum-of-squares that consumes two numbers, and produces the sum of
the squares of both numbers. For example, (sum-of-squares 3 4) produces 25, and (sum-of-
squares 1.5 3) produces 11.25.
Write a Scheme function circle-area that consumes the radius of a circle, and produces the area
of the circle. For example, (circle-area 10) produces 314, and (circle-area 1.5) produces 7.065.
NOTE: Use 3.14 for . Define a constant named PI (define PI 3.14)
James would like to earn some extra pocket money during his summer break. He found a job as a
surveyor. His job is to interview people. For a person he interviewed, he is paid RM10. But to
encourage James to interview more people, the company decide to give him RM65 for every 5
person he interview, rather than the normal RM50. Write a Scheme function amount that
consumes an integer representing the number of person interview by James, and produces the
amount he should get. For example, (amount 1) produces 10, (amount 4) produces 40, (amount 5)
produces 65, (amount 6) produces 75, (amount 10) produces 130, (amount 11) produces 140.
Number of people interview Amount Computation
1 10 1 x 10 + 0 x 65
4 40 4 x 10 + 0 x 65
5 65 0 x 10 + 1 x 65
6 75 1 x 10 + 1 x 65
10 130 0 x 10 + 2 x 65
11 140 1 x 10 + 2 x 65