Question: Consider the following UML diagram: remove ( ) should remove a customer from the list. If the customer is not present, the operation should return
Consider the following UML diagram: remove should remove a customer from the list. If the customer is not present, the
operation should return false, otherwise it should remove the customer and return
true.
findByID should return a customer that has the provided ID If the list contains no
customer with that ID the operation should return the null pointer.
findByName should return a list of customers that have the provided name. If no
customers have that name, it should return an empty list.
findByDPC should return a list of customers that have the provided postal code in
their delivery address. If no customers have that code, it should return an empty list.
As specified in the diagram, the CustomerList class must inherit from QList. To
implement its member functions, one could search through the QList using a linear
search, but this would be very inefficient. A better way would be to maintain a number
of indices in the form of an associative container like a QMap, QHash, QMultiMap or
QMultiHash to provide fast lookups. In particular: Use an associative container to store pointers to customers with their IDs as keys,
to allow a customer with a particular ID to be found quickly.
Use an associative container to store pointers to customers with their names as
keys, to allow customers with a particular name to be found quickly.
Use an associative container to store pointers to customers with the postal codes
of their delivery addresses as keys, to allow customers with a particular code to be
found quickly.
Note that the pointers in these associative containers should point to the existing
Customers in the QList, not to copies of the customers. These containers should
be defined as private data members of the customerList class. Then the member
functions of CustomerList should do the following:
findByID findByName and findByDPC should use the relevant
indexing container to find and extract the required information.
add should use findByID to check whether the ID is unique. If so it must
append the customer to the list and also update the three indexing containers.
remove should find and remove a specified customer. It also needs to update
the three indexing containers, and deallocate the memory used for the customer.
Write a console application to test all these functions. The program should add at least
customers to a list and then generate and display the result of searching for
customers with a particular ID a particular name and a particular postal code entered
from the keyboard.
We have provided the definition and implementation of a RandomCustomerFactory
class in the Additional Resources folder for COS which will generate random
Customers that can be stored in the customerList. This will save you and us
from having to type in the details of customers to be stored in the list when testing
your program. You should use this class as part of your project.
The customer class is as defined follows:
Customer
mName : QString
mCellNum : QString
mAddress : QStringList
Customer
Customername: QString, cell : QString, addr : QStringList
toStringlabelled : bool: QString
The operations of the customerList class are intended to do the following:
add should append a customer to the list. However, it must first check whether the
ID of the customer is unique by searching for it in the customers already in the list. If
another customer has the same ID the operation should return false and terminate
without adding the new customer. Otherwise it should append the customer to the end
of the list and return true.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
