Remember to follow the Expectations on Homework when preparing your solutions, including the academic honesty policy.
The social networking website MyFace has heard of your prowess in CS 1102 and has hired you to re-implement their system. In order for other developers to understand and use your programs, your code must follow good programming practice, including using helper functions and adhering to templates. Code that "works" but violates template structure will result in your dismissal from the company, and getting a low grade on this assignment.
A profile
consists of a member's name, age, the
school s/he attends, and a list of activities s/he participates in.
A network
is a list of profiles
.
Write data definitions and provide examples of data for activities list, profile, and network. Use component name "attends" for the school name, rather than "school", for reasons that will become apparent later in this assignment.
Write the template for networks.
Write a function members
that consumes a network
and produces a list of all the members' names.
Write a function active-members
that consumes a network
and produces a list of names of members who engage in 3 or more activities.
Write a function schools
that consumes a network
and produces a list of all the schools attended. No school may
appear more than once.
Write a function count-members-at-school
that
consumes a school name and a network
and produces the number of members at that school.
Write a function average-age
that
consumes a network and produces the average age of its members.
Assume that the network is non-empty.
Write a function same-activities
that consumes 2
people's names and a network and produces a list of those activities
that both participate in.
It is important that MyFace protect the information of young
members. Write a function create-profile
that consumes the same
data as make-profile
and produces a profile. If the
member's age is less than 14, the name in the returned profile is left
blank, otherwise the name that is supplied is used.
This is a common technique for adding data checking features to
constructors.
Write a function add-activity-to-member
that
consumes an activity and a profile and returns a profile that includes
the activity. If the activity is already present, it is not repeated.
MyFace realizes that some members have forgotten to include
"MyFace" as an activity. Write a function
add-activity-to-everyone
that consumes an activity and a
network and produces a network where every member participates in that
activity exactly once.
Due to declining student interest in clerking as a career,
Clerk College has agreed to be absorbed by nearby College of the Hardy Class.
Rather than update all Clerk student profiles individually, write a
function rename-school
that consumes two school names and
a network, producing a network in which everyone who formerly attended
the first school now attends the second and everyone else is as before.
MyFace decides to represent schools more accurately as either a
k12
or college
. A k12-school
has a name and a grade from 0
(kindergarten) through 12 (senior).
A college
has a name, year from 1 (freshman) through 5
(super-senior). Write data definitions for school, k12, and college.
Note that the data definition for profile should now use school
instead of string. We won't worry about that here.
Write a function to revise the MyFace network from the old school to
the new.
revise-school-network
consumes a network where schools
are represented as in problem 1, producing a network using the data
definitions from problem 13.
Students age 17 or less are assumed to attend k12, with 17-year-olds
in grade 12 etc. Students age 18 or older are assumed to attend
college, with 18-year-olds in year 1, etc.
You do not have to check that k12 students have a non-negative grade;
college students can have a year greater than 4, also.
Write a function average-schooling
that consumes a
network and returns the average number of years of school. For k12
students, use their grade, for college students use their year + 12.
Assume that the network is non-empty.
Turn in a single file hwk2.ss or hwk2.scm containing all code and documentation for this assignment. Make sure that both students' names are in a comment at the top of the file.
This page maintained by Mike Gennert Department of Computer Science Worcester Polytechnic Institute |