Study Guides (248,151)
CS 116 (15)
Final

finalreviewsoln.pdf

2 Pages
186 Views

School
Department
Computer Science
Course
CS 116
Professor
Victoria Sakhnini
Semester
Fall

Description
;;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
Me

OR

Join OneClass

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

Join to view

OR

By registering, I agree to the Terms and Privacy Policies
Just a few more details

So we can recommend you notes for your school.