Questions complémentaires

Questions complémentaires

SMS Store

Create a new class SMSStore. The class will instantiate SMS_store objects, which can store SMS messages, similar to an inbox or outbox on a cellphone:

my_inbox = SMS_store()

This store can hold multiple SMS messages (its internal state will just be a list of messages). Each message will be represented as a tuple: (has_been_viewed, from_number, time_arrived, text_of_SMS)

The inbox object should provide these methods:

my_inbox.add_new_arrival(from_number, time_arrived, text_of_SMS)
    # Makes a new SMS tuple, and inserts it after the other messages
    # in the store. When creating this message,
    # its has_been_viewed status is set False.

my_inbox.message_count()
    # Returns the number of sms messages in my_inbox

my_inbox.get_unread_indexes()
    # Returns list of indexes of all not-yet-viewed SMS messages

my_inbox.get_message(i)
    # Return (from_number, time_arrived, text_of_sms) for message[i]
    # Also change its state to "has been viewed".
    # If there is no message at position i, return None

my_inbox.delete(i)
    # Delete the message at index i

my_inbox.clear()
    # Delete all messages from inbox

Write the class ``SMS_store``, create a message store object,
write tests for each of the above methods, and implement the methods.


        
        

Création d'objets depuis un fichier

Dans cet exercice, il vous est demandé de créer une fonction créant des instances de la classe Student basées sur les informations contenus dans un fichier, et les renvoyant dans une liste. Ceci afin de récupérer les notes de l'interros des différents participants.

Voici le constructeur de la classe Student:

class Student:
    def __init__(self, firstname, surname, mark):
        self.firstname = firstname
        self.surname = surname
        self.mark = mark

Le fichier suit le format suivant:

Kim Mens 12
Charles Pecheur 13
Siegfried Nijssen 18

Implémentez la fonction marks_from_file(filename) qui lit, ligne par ligne, le fichier nommé filename, et qui retourne une liste d'instances de Student, correspondant aux différents lignes du fichier.