Question: A c++ question: Class Design At the minimum the required classes are specified below. They should be sufficient for this assignment. However you're free to

A c++ question:

Class Design

At the minimum the required classes are specified below. They should be sufficient for this assignment. However you're free to come up with more classes as needed. It's important to recognize the needed classes before starting coding. Making a list of those classes ahead of time will definitely help you visualize the tasks at hand.

  • AddressBook: this class is responsible for keeping the all contact information as well as how to access/manipulate it. It contains a ContactList object which is a Linked List of Contact objects and the needed interface to access/manipulate the contact_list.
  • ContactList: a linked list whose nodes are Contact objects which can be EmployeeContact or ContractorContact.
  • Contact: an abstract base class.
  • EmployeeContact: derived class from Contact.
  • ContractorContact: derived class from Contact.
  • Name: first name and last name.

Class Implementation

If you use single file compilation the order of classes declarations must be: Name, Contact, EmployeeContact, ComtractorContact, ContactList and finally AddressBook. This will avoid unnecessary compilation errors.

class Name: simple class containing last name and first name as member data. This class must overload the equality operator == to compare two Name objects: name_1 == name_2 return true if both Names have the same first name and last name ignoring case sensitive (james West is the same as James wesT) or return false otherwise.

class Contact (abstract class)

  • Private member data: a pointer to a Contact object (which can be an EmployeeContact or ContractorContact) called next - this is the link to the next node in a Contact List.
  • Protected member data: name (a Name object), business phone (string in the form "1-408-222-8888"), email (jamesw@tpcommunications.com), location (a number for cubical location say 4, 10, 20, ...).
  • Public static data (constant): default values for name, business phone, email and location to be used by default constructor.
  • Constructors:
    • Default constructor: note that name is an object inside another object (composition). Make sure you use the right syntax to initialize it. Set member data to default values specified by static data (don't forget to initialize the "next" link).
    • Non-default constructor: take 5 parameters first name, last name, phone, email, location. Don't forget to initialize the next field.
  • Destructor: must be declared as virtual destructor. Output (" has gone home ...").
  • Public member functions:
    • accessors/mutators for all member data including the next pointer.
    • ShowContact: a pure virtual function (no implementation is required) which will be defined later by its derived classes. It should return void, take no parameter and be declared as constant function.

class EmployeeContact (derived from Contact)

  • Private member data: title and department.
  • Public static data (constant): default values for title and department to be used by default constructor.
  • Constructors
    • Default constructor: Must explicitly invoke base class default constructor.
    • Non-default constructor: takes 7 parameters: 5 required by the base class constructor and 2 required by itself. Perform initialization similar to default constructor.
  • Destructor: explicitly declared as virtual (no-op).
  • Public member functions:
    • accessor/mutator for both member data.
    • ShowContact: must be explicitly declared it as virtual and nicely format the data as seen below:

James West Software Engineer Engineering Room 23 1-408-790-8251 jamesw@tpcommunications.com

class ContractorContact (derived from Contact)

  • Private member data: company and assignment duration (months).
  • Public static data (constant): default values for company and assignment duration to be used by default constructor.
  • Constructor
    • Default constructor: Must explicitly invoke base class default constructor.
    • Non-default constructor: takes 7 parameters. You must know what to do here.
  • Destructor: explicitly declared as virtual (no-op).
  • Public member functions:
    • accessor/mutator to both member data.
    • ShowContact: must be explicitly declared it as virtual and nicely format the data as seen below:

Cindy Lincoln 6 months (contractor) TK Consultings Room 9 1-408-790-7372 cindyl@tpcommunications.com

class ContactList

  • Private member data: head (a pointer to a Contact object). Note: you can have a pointer to an abstract object but you can't instantiate an abstract object. We will be instantiating "concrete" objects: EmployeeContact objects and ContractorContact objects when building this ContactList.
  • Constructor
    • Default constructor: initialize head to nullptr.
  • Destructor: free memory for all nodes in the linked list to avoid memory leak.
  • Private member function (used internally only):
    • FindContact: take a constant reference to a Name object. Search the ContactList for a match using the overloaded operator == defined in the Name class. If found return the pointer to the found Contact. Otherwise return nullptr.
    • Insert: take a pointer to a Contact object): add a Contact object to the front of the linked list. Note: the pointer parameter must be pointing to a dynamically allocated EmployeeContact or ContractorContact object prior to the Insert function's invocation.
  • Public member functions:
    • Init: manually (hard-coded) build the list. See Code Helper section at the end of the specs. We should read a text file here but I will give you some break.
    • ShowAllContacts: take no parameter. Traverse through the entire linked list to invoke ShowContact function for each node. The function should also show a header:

Name Title Department Location Business Phone Email

  • SearchByName: take a constant reference to a Name object as its only parameter. Invoke the FindContact function. If the returned pointer it not nullptr show the contact info. Otherwise display an error message.
  • SearchByDepartment: take a department as its only parameter. Search the whole linked list looking for EmployeeContact objects only. Display employee contact info if and only if the employee is working for the requested department.

class AddressBook

  • Private member data: company name and a ContactList object.
  • Public static data (constant): default value for company name to be used by default constructor.
  • Constructors: provide both default and non-default constructors.
  • Destructor: no-op.
  • Public member functions:
    • Init: invoke the Init function from ContactList object to build the Linked List of Contacts.
    • Run: a menu-driven function with do-while loop and a switch statement. Each case in the switch must be handled by a function. No cin/cout should be seen in this function.
  • Private member functions (used internally by the Run function):
    • Menu: display the menu to the console (showing company name).
    • GetUserOption: ask users for an option (1-4) and return it.
    • ShowAllcontacts: invoke ShowAllContacts from the ContactList object.
    • SearchByName: ask users for first name and last name, construct a Name object then invoke SearchByName from the ContactList object passing the newly constructed Name object as its parameter.
    • SearchByDepartment:ask users for department. Invoke SearchByDepartment from the ContactList object.
    • Quit: display a goodbye message and exit the loop.

Main Program

  • Dynamically allocate an AddressBook object.
  • Invoke its Init function.
  • Invoke its Run function.
  • Free memory for the AddressBook object. FYI: This will cause ContacList object being de-allocated which in turn causes Contact nodes being de-allocated. As a result it will show a bunch of "... has gone home" messages (destructor call by Contact nodes) to be displayed on the console.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!