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

CS105 Lab 4: Subset-2?, and In-Subset-3?)

This lab assignment involves writing several functions in Scheme: 1) A function that determines if a number is a multiple of two other numbers 2) Functions that check if a number is in a given range or union of ranges 3) A function that switches the case of a character 4) A function that checks if two strings connect 5) A function that generates an account number by adding a check digit 6) A function that calculates the floor area of a kitchen layout

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)
21 views

CS105 Lab 4: Subset-2?, and In-Subset-3?)

This lab assignment involves writing several functions in Scheme: 1) A function that determines if a number is a multiple of two other numbers 2) Functions that check if a number is in a given range or union of ranges 3) A function that switches the case of a character 4) A function that checks if two strings connect 5) A function that generates an account number by adding a check digit 6) A function that calculates the floor area of a kitchen layout

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 4

The purpose of this lab is for you to get practice in using the design recipe, including testing. Make
sure to use check-expect or check-within, as appropriate. Follow the instructions given in the
Assignment Style Guide.
1. Create a function two-multiples that consumes three numbers, target, candidate1, and candidate2,
and determines whether target is a multiple of both candidates. Your function should produce
both if it is multiples of both, neither if it is a multiple of neither, and the value of the
candidate if it is the multiple of one of the two. If any of the three numbers is a non-integer, your
function should produce false.
2. Translate each of the following subsets of the real line into Scheme functions that consume a
number and produce true if the number is in the subset and false if it is outside the subset: (3,7]; the
union of (1,3) and (9,11); the range of numbers outside of [1,3] (use the names in-subset-1?, in-
subset-2?, and in-subset-3?).
3. Create a function switch-case-char that consumes a character and produces the same character, if it
is not a letter, the character in upper case if it is a lower-case letter, and the character in lower case
if it is an upper-case letter.
4. Create the predicate connect? that consumes two strings and determines if the last letter in the first
string is the same as the first letter in the second string.
5. Account numbers, such as credit card numbers, often include a check-digit as part of the account
number. This "check-digit", used to quickly check for an error in the transmission of the account
number, is often the remainder when the rest of the digits are added together and divided by some
other number. For example, in the account number 1234567893, the ones digit 3 is the remainder
when the sum of the rest of the digits (45) is divided by 7.
Complete the Scheme function create-account-num which consumes a 4-digit number, starter, and
produces the actual account number, which is obtained by adding a fifth digit to starter namely,
the remainder when the sum of the 4 digits of starter is divided by 7. Assume that starter is
between 1000 and 9999. For example, (create-account-num 1234) produces 12343, and (create-
account-num 8001) produces 80012.
6. Complete the Scheme function floor-area for a kitchen (of width kitchenwidth and length kitchen-
length) with the following floor plan:

fridge stove
island

The function consumes kitchen-width, kitchen-length (the width and length, in metres, of the
kitchen), stove-width, stove-length (the width and depth of the stove in metres), fridge-width,
fridge-depth (the width and depth of the fridge in metres), and island-radius (the radius of the
circular island), and produces the floor area of the kitchen (in square metres), excluding the space
covered by the stove, fridge and island.
Assume that the stove, fridge and island all fit entirely in the kitchen. A zero measurement for a
width, depth or radius is used when the appliance or island is not present in the kitchen.
For example, (floor-area 10 12 1 1.5 1.5 1 3) => 117 - 9*pi.
When testing your function, be sure to use check-within rather than checkexpect if island-radius >
0. A range of 0.0001 is sufficient for testing purposes.

You might also like