Posted: Mon Sep 15
Due: Tuesday 9/16 10:00am
Submission name: work04.rkt
For the following functions, you should look back at the quotient and remainder functions.
Write the Following Functions given the contracts.
Paste the contracts into your racket program when starting. Use define and lambda to write your functions. Include test cases with descriptive output.
;(getOnesDigit n) --> integer
; n : non negative integer
;
; Returns the ones digit of n
; (getOnesDigit 7) --> 7
; (getOnesDigit 4132) --> 2
;(removeOnesDigit n) --> integer
; n : non negative integer
;
; Returns n with the ones digit removed and all other digits shifted to the right.
; If the argument given is a one digit number, returns `0`.
; (removeOnesDigit 7) --> 0
; (removeOnesDigit 4132) --> 413
Write contracts and the functions for the following:
getTensDigit
- Takes in a non-negative integer.
- Returns the tens place digit of that number.
- If the argument given is a one digit number, returns
0. - You can assume only valid inputs will be used.
- Examples:
(getTensDigit 7)==>0(getTensDigit 4132)==>3
getNthDigit
- Takes in two non-negative integers (
nanddigit). - Returns the number at the
digitplace ofn. - If
digitis1, return the ones digit, ifdigitis2return the tens digit… - If
ndoes not have a digit at thedigitplace, return0 - You can assume
nis a non-negative integer. - You can assume
digitis a positive integer. - Examples:
(getNthDigit 7 1)==>7(getNthDigit 4132 2)==>3(getNthDigit 4132 3)==>1