A family tree can be represented by a list. For example:
(define myfamily
“Dog” (“Mug”
“Hug” (“Boo”)) (“Shoe”‘)) )e
Copyright By PowCoder代写 加微信 powcoder
Each level of the list represents a different generation. The first two elements
of a list are the parents and any sub-lists that follow are children and future
generations. The example above represents the tree:
a. [10 marks] Write a predicate to test immediate parental relationships:+
(parent myfamily, “Boo”
(parent mifamilx
b. [10 marks] Write a function to determine how many offspring someone has:
(offspring myfamily “Dog”) – (“Mug”
[10 marksl write a function to flatten a familv tree and return a sorted list of
family members. You will be given half marks if you flatten the list, but don’t
(flatten myfamily)
> (“Boo” “Cat”
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com