The problem
Create an application used to store and manage a bank account database, each client having an unique ID. For every client, the application will store the dates in which the client made a transaction. The application must be able to add, remove and print all transactions for all the clients. Also, it must be able to check if a user had any transaction on a given date.
Problem solved using a Multimap implemented using Singly Linked Lists alocated dinamically
See Specification π₯
See Interface π₯
See Representation π₯
o Multimap = {m| m is a map with elements e = (k,v), where k β TKey and v β set on SLL}
o Set = S = {s|s is a set with elements of the type TElement}
o TKey -> each key has one single associated value and keys have to be unique.
The interface of TKey contains the following operations:
β’ assignment (k1 β k2)
β£ pre: k1, k2 β TKey
β£ post: kβ²1 = k2
β’ equality test (k1 = k2)
β£ pre: k1, k2 β TKey
β£ post:
True, if k1 = k2
False, otherwise
TElement -> the general element in containers
The interface of TElem contains the following operations:
β’ assignment (e1 β e2)
β£ pre: e1, e2 β TElement
β£ post: eβ²1 = e2
β’ equality test (e1 = e2)
β£ pre: e1, e2 β TElement
β£ post:
True, if e1 = e2
False, otherwise
o Iterator = { it | it β iterator over Multimap }
Multimap
β’ init(m):
β£ descr: creates a new empty map
β£ pre: True
β£ post: mβM, m is an empty map
β’ destroy(m):
β£ descr: destroys a map
β£ pre: mβM
β£ post: m was destroyed
β’ add(m,k,v):
β£ descr: add a new key-value pair to the map (the operation can be called put as well)
β£ pre: m β M, k β TKey, v β set on SLL
β£ post: mβ² β M,mβ² = m βͺ < k,v >
β’ remove(m,k,v):
β£ descr: removes a pair with a given key from the map
β£ pre: m β M, k β TKey
β£ post: v β TValue
v = vβ, if β<k,vβ² >βm and mβ² βM, mβ = m<k,vβ>
|0, otherwise
β’ search(m,k,v):
β£ descr: searches for the value associated with a given key in the map
β£ pre: m β M, k β TKey
β£ post: v β Set on SLL
v = vβ, ifβ<k,vβ² >βm
0, otherwise
β’ iterator(m, it ):
β£ descr: returns an iterator for a map
β£ pre: m β M
β£ post: it Iterator, it β iterator over m
β’ size(m):
β£ descr: returns the number of pairs from the map
β£ pre: m β M
β£ post: size <- the number of pairs from m
β’ keys(m,s):
β£ descr: returns the set of keys from the map
β£ pre: m β M
β£ post: s β S, s is the set of all keys from m
β’ values(m,b):
β£ descr: returns a bag with all the values from the map
β£ pre: m β M
β£ post: b β B, b is the bag of all values from m
β’ add(m,s):
β£ descr: returns the set of pairs from the map
β£ pre: m β M
β£ post: s β S, s is the set of all pairs from m s
Iterator
β’ init(m):
β£ pre: m M
β£ post: it Iterator , it β iterator over m pointing to βfirst elementβ
β’ next(it):
β£ pre: it Iterator, it is a valid iterator
β£ post: itβ² - pointing to the next element
β’ valid( it ):
β£ pre: it Iterator
β£ post:
valid(it) = True, if it valid
False, otherwise
β’ getCurrent(it, v):
β£ pre: it Iterator
β£ post: e(k,v) Multimap, e β the current pair pointed by it
Multimap (Implemented on a singly linked list with dynamic allocation)
β’ cap : Integer
β’ k: TKey
β’ v: Set on SLL
β’ next: Integer[]
β’ head: Integer
Iterator
β’ m : βMultimap
β’ currentPos : βTKey