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

Finalreviewquestions.pdf

3 Pages
291 Views

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

Description
Abstract List Functions: Using abstract list functions, write a function, string-num, that consumes a list of number, lon, and produces a single string that contains all the numbers in lon, in the order that they appear in the list. ;; (string-num empty) => “” ;; (string-num (list 1)) => “1” ;; (string-num (list 4 0.6 54 -9.9) => “40.654-9.9” Mutation: (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 number of girls in the family, and ;; b is an integer representing the number of boys in the family. Write a function, update-family, that consumes a children structure, c, and a symbol, gender, which is either ‘girl or ‘boy, and mutates the structure to account for a new baby being born into a family. It will increase the total number of children by 1, and increase either the girl or the boy field by one depending on whether gender is ‘girl or ‘boy. It will produce the string “This family used to have x children.” where x is the total number of children before it was mutated. Example: ;; (define f (make-children 3 2 1)) ;; If we call (update-family f ‘boy), the total number of children is now 4, the number of girls is still 2, ;; and the number of boys is now 2. It will produce “This family used to have 3 children.” Strings in Python: Write a function, telephone_number, that consumes a string, number, that contains exactly 10 natural numbers with a space between each number and produces a string in the form “###-###-####”, where the first group is the first three numbers, the second group is the fourth, fifth and sixth number, and the last group is the last four numbers. Example: # telephone_nu
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.