CS代考 Racket programming

Racket programming
Language Level
• Beginning Student
General Expectations

Copyright By PowCoder代写 加微信 powcoder

Remember to use defined constants and helper functions where appropriate.
Follow the full design recipe as outlined below in Question O.
Allowable Racket Functions and Special Forms
define, and, or, not, cond, else, check-expect, check-within
any type predicate such as number?, boolean?
any functions on numbers found in Section 1.5 of the Racket documentation
• any functions on symbols found in Section 1.7 of the Racket documentation
any functions on strings found in Section 1.11 of the Racket documentation
Other Information
Look through the list of allowable built-in functions linked from above. You might find some handy functions that were not explicitly mentioned
in the modules!
All test data for correctness will always meet the stated assumptions for consumed values.

Question 1: Pig Latin
Pig Latin is a specific way of rearranging letters in English words for fun.
Vowels (‘a’, ‘e’, ‘¡’, ‘o’, and ‘u’) are treated separately from the consonants (any letter that isn’t a vowel). For simplicity, we will consider ‘y’ to always be a consonant.
Although various forms of Pig Latin exist, we will use the following rules:
1. Words of two letters or less simply have “way” added on the end. So “go” becomes “goway”
2. In any word of three or more letters that starts with consonants, the consonants are moved to the end, and “ay” is added. But if it begins with more than two
consonants, move only the first two letters to the end. So “hello” becomes “ellohay”, and “string” becomes “ringstay”
3. Any word which begins with a vowel simply has “way” added on the end. So “explain” becomes “explainway”.
Write a function pig-latin. It consumes a string, and produces that string converted to Pig Latin, following the rules described above. The string shall contain only
lowercase letters and have a length of at least 1
For example:
(pig-latin “this”)
> (pig-latin “is”)
> (pig-latin
> (pig-latin
(pig-latin
“exercise”)
“exerciseway

Question 2: Currency Encoding
In order to make it easier to read numbers, we often break a number into powers of one thousand, and add a separator (such as a comma or space) between these
groups. For example, 108 is easier to read when written 100,000,000 than when written 100000000.
In addition, when encoding prices, many currencies (including $, €, £, and at least historically, #) are divisible into 100 smaller pieces. This smaller piece is often
called a “cent” from the Latin word for hundred.
Write a function encode-currency. It consumes a number price and produces a string representing this number. As needed, the string should use a comma
as a thousands separator, and period “.” as a decimal point. You may assume that price is non-negative and less than one million, and does not have more than 2
decimal places.
If a decimal point is used, the number must be represented with 2 decimal places.
If the number can be expressed exactly without cents, the string should not include a decimal point.
For example,
(encode-currency 42)
(encode-currency 42.5)
(encode-currency 420000)

Contact wechat powcoder

Question 3: Currency Decoding
This question is the “reverse” of the previous question, and uses the same conventions.
In addition, some countries use different conventions for thousands separators and decimal places. In much of the world, it is common to use a period “.” as the
thousands separator, and a comma ”
” as the decimal point. We want to be able to work with data written in either format.
Write a function decode-currency. It consumes a string representing a price less than one million, either using comma as the thousands separator and period as
the decimal place, or using period as the thousands separator, and comma as the decimal place. The function produces the corresponding number. For example:
> (decode-currency “42”)
> (decode-currencv
> (decode-currency “2,19”)
> (decode-currency
“21,000.45”)
> (decode-currency
“765.432,10”)