Question
C++ Figure 4.4. Contacts a. Figure 4.4 describes a model [39] for a Contact system. ContactList can derive from or reuse any Qt container that
C++
Figure 4.4. Contacts
a. Figure 4.4 describes a model[39] for a Contact system. ContactList can derive from or reuse any Qt container that you like, as long as it supports the operations listed.
getPhoneList(int category) accepts a value to be compared with a Contact's category member for selection purposes. It returns a QStringList containing, for each selected Contact, the name and phone number, separated by the tab symbol: "\t".
getMailingList() has a similar selection mechanism and returns a QStringList containing address label data.
b. Write a ContactFactory class that generates random Contact objects. Example 4.4 contains a substantial hint.
Example 4.4. src/containers/contact/testdriver.cpp
[ . . . . ] void createRandomContacts(ContactList& cl, int n=10) { static ContactFactory cf; for (int i=0; i> cl; } } <>
Adds a Contact into the ContactList. |
There are many ways to generate random names/addresses. One way is to have the ContactFactory create lists of typical first names, last names, street names, city names, and so forth.[40] When it is time to generate a Contact, it can pick a random element from each list, add randomly generated address numbers, zip codes, etc. We demonstrate the use of the random() function in Section 1.13.3
c. Write client code to test your classes. In particular, the client code should generate some random contacts. After that, it should test the two query methods (getPhoneList() and getMailingList()) to ensure that they return the proper sublists. Print the original list and the query results to standard output. Summarize the results by listing the number of elements in the original ContactList compared to the query results.
C++
Contact ContactList category :int firstName QString lastName QString streetAddress : QString zipCode QString city: QString -phoneNumber QString +toString:QString + add(c : Contact) remove(c Contact) +getPhoneList(category : int) : QStringList + getMailingList(category : int): QStringList QtContainerClassStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started