Study Guides (248,151)
Canada (121,346)
CS 116 (15)


2 Pages
Unlock Document

Computer Science
CS 116
Victoria Sakhnini

;;string-num: (listof num) -> string (define (string-num lon) (foldr string-append "" ;;Append them together (map number->string lon))) ;;Convert all the numbers to strings (define-struct children (total girl boy)) ;;A children is a structure (make-children (t g b)), where ;; t is an integer representing the total number of children in a family, ;; g is an integer representing the total number of girls, and ;; b is an integer representing the total number of boys. (define f (make-children 3 2 1)) ;;update-family: children (union 'girl 'boy) -> string ;; Consumes a children structure, c, and a gender and ;; produces the string telling you what the previous ;; number of children used to be ;;Effects: Increases the total by 1 and increases either the ;; boy or girl field by 1 depending on whether gender is ;; 'girl or 'boy (define (update-family c gender) (local [;;Keep track of previous total (define previous-total (children-total c))] (begin ;; Increase the total by one (set-children-total! c (+ 1 (children-total c))) (cond [(symbol=? gender 'girl) ;;check if gender is girl (set-children-girl! c (+ 1 (children-girl c)))] ;;if it is, update by 1 [else (set-children-boy! c (+ 1 (children-boy c)))]) ;; otherwise, gender is boy (string-append (string-append "This family used to have " ;;Append the sentence together (number->string previous-total)) ;; Since previous-total is a number, " children.")))) ;; change to string # telephone_number: str[len=19] -> string[len=12] def telephone_number(number): lon = number.split() #separate them first = "".join(lon[:3]) #create the first group second = "".join(lon[3:6]) #middle group last = "".join(lon[6:]) #last group return "-".join([first,second,
More Less

Related notes for CS 116

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.