0% found this document useful (0 votes)
25 views

CS105 Lab 1 (B) : Sum-Of-Squares

This document contains examples of arithmetic expressions and their results in Scheme expressions. It also contains examples of using quotient and remainder functions. It provides examples to write functions for sum-of-squares, circle-area, and an amount function based on number of people interviewed.

Uploaded by

AndrewChan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

CS105 Lab 1 (B) : Sum-Of-Squares

This document contains examples of arithmetic expressions and their results in Scheme expressions. It also contains examples of using quotient and remainder functions. It provides examples to write functions for sum-of-squares, circle-area, and an amount function based on number of people interviewed.

Uploaded by

AndrewChan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

CS105 Lab 1 (b)

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

Use quotient and remainder to find the following information:


Number Divisor Quotient Remainder Quotient Remainder
15 2 7 1 (quotient 15 2) (remainder 15 2)
32 4 8 0
65 3 21 2

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

Remainder when p divided by 5 Quotient when p divided by 5

You might also like