You are on page 1of 2

information about registered users is recorded in a (global) master dictionary: Users = { user_id_1: (name, place, date_of_birth), ...

user_id_n: (name, place, date_of_birth), } registered user!s ac"uaintances (a#a friends) is stored in another global dictionary: c"uaintances = { user_id_1: $ ac"uaintance_id_1, ..., ac"uaintance_id_% &) 'here % (= ) ... user_id_n: $ ac"uaintance_id_1, ..., ac"uaintance_id_# &) 'here # (= ) } 'here each ac"uaintance_id refers to a *alid (registered) user. +he messages recei*ed by a user are grouped as follo's: ,essages = { user_id_1: $msg_1, ..., msg_%&) 'here % (= ) ... user_id_n: $msg_1, ..., msg_#) 'here # (= ) } -ach message has four components: (sender_id, message_id, te.t, date_recei*ed, time_recei*ed) /mplement the follo'ing procedures: add_friend(user_id, friend_id) add_friends(user_id, (friend_id_1, ..., friend_id_n)) 'here n (= 1. 00 update c"uaintances dictionary 'ith !friend_id! for a specific user. 00 both procedures return +rue on success, and 1alse on failure. remo*e_user(user_id) 00 updates the !Users! dictionary. +he ! c"uaintances! is not immediately updated to reflect the potential side0effects. 00 returns +rue on success. 00 returns 1alse if user_id is in*alid (there!s no user 'ith that id). get_friends(user_id) 00 on success, returns a tuple of friends of a particular user. 00 returns 2one other'ise. get_friends_of_friends(user_id) 00 on success, returns a tuple containing user ids 'ho are friends of friends. 00 returns 2one other'ise 3pecial note: friends0of0friends may not include immediate friends4 that is, e.clude friends from the friends0of0friends send_message(sender_id, recei*er_id, msg) send_group_message(sender_id, (recei*er_id_1, ..., recei*er_id_n), msg) 00 return 1alse if either !sender_id! or !recei*er_id! is in*alid. 00 return +rue if the message is properly added to the recei*er!s message list in !,essages! dictionary. get_messages_from_friend(recei*er_id, friend_id) 00 returns a tuple of messages on success. +hsi tuple may be empty

if there are no messages from the specified friend. 00 returns 2one if !recei*er_id! or !friend_id! is in*alid. get_messages_from_all_friends(recei*er_id) 00 returns a tuple of messages, 'hich may be empty (if there are no messages for a person 'ith id !recei*er_id!). get_birth_day_messages(recei*er_id) delete_message(user_id, msg_id) 00 return +rue on success. 00 returns 1alse if !user_id! or !msg_id! is in*alid. delete_messages(user_id, (msg_id_1, ..., msg_id_n)) 'here n (= ) 00 return the number of messages that 'ere actually deleted. 00 ,ay return any number bet'een 5ero and !n!. delete_all_messages(user_id) delete_messaged_from_friend(recei*er_id, friend_id)

-.ercise 6 00000000000000 78 9artesian coordinate is represented as a tuple: (., y, 5) *ector is represented by a tuple of t'o points: (p1, p6) 'here p1 is a tuple (.1, y1, 51) and p6 is also a tuple (.6, y6, 56) /mplement the follo'ing procedures: length(*ector) normali5e(*ector) 00 returns a *ector (p1, p6) 'here p1 is (), ), )) dot_product(*ector, *ector) cross_product(*ector, *ector) : 00 returns a *ector (p1, p6) 'here p1 is (), ), ))

-.ercise 7 00000000000000 9omplete the :honenum and 9ontacts data types that 'ere discussed in the lecture sessions on ;an0<, 3aturday. +he follo'ing enhancements are mandatory: ( ) the ten digit phone number should consist of only digits. (=) phone number should allo' an optional country code. (9) a ne' procedure: update_contact_number(contact_name, old_number, ne'_number) 00 updates the old number 'ith the ne' one. old number 'ill be no longer accessible after a successful update. 00 returns +rue on success and 1alse on failure.

You might also like