Program Specifications ( please show full working code that builds successfully and with all
implementations )
This program is to build a simplified Address Book application (console version). The Address
Book will allow employees or contractors working for a company to search contact information
of their peers. The program should allow users to:
View all employees/contractors contact information
Search by name
Insert new contact
From CS 2B concepts the assignment should cover:
Linked List implementation
Abstract classes with pure virtual functions
Polymorphism and dynamic_cast
Operator Overloading
Sample run of your program:
TP Communications Address Book Menu
1. View all contacts // polymorphism
2. Search by name // operator overloading
3. Search by department // employees only - dynamic_cast
4. Quit
Select an option (1-4): 1
// showing all contacts
// ..............................................
TP Communications Address Book Menu
1. View all contacts
2. Search by name
3. Search by department
4. Quit
Select an option (1-4): 2
Enter a contact name: Jane Doe
Sorry no match is found.
TP Communications Address Book Menu
1. View all contacts
2. Search by name
3. Search by department
4. Quit
Select an option (1-4): 2
Enter a contact first name: James
Enter a contact last name: West
// display James West contact information
// ..............................................
TP Communications Address Book Menu
1. View all contacts
2. Search by name
3. Search by department
4. Quit
Select an option (1-4): 3
Enter a department: Engineering
// display all employees in Engineering department
4. Quit
Select an option (1-4): 4
Thanks for using our AddressBook. See you again!
Implementation Phases
You've been thru half of the quarter. It's time to learn how to use divide-conquer technique to
efficiently deal with complex programs especially in work place environment with multiple
developers. In such environment typically we would divide the program into different phases.
Each developer is assigned to develop different classes or different components in the same
class. At the conclusion of each phase we will perform unit testing to ensure the individual
assignments are working properly per customer's specs. By the end of the project there will be an
integrating process that puts all code together and starts the integration test performed by QA
(Quality Assurance) engineers. You're strongly encouraged (but not required) to do the below
while working on this assignment. It's up to you however to schedule/devise your own plan of
implementing this program.
Phase 1: develop the skeleton of your program (main function and class declarations and
definitions with no-op or empty function bodies) without any specific implementation to the
classes. See example at the end of the specs.
Phase 2: implement the abstract base class Contact and its derived classes.
Phase 3: implement the Linked List of Contact namely ContactList.
Phase 4: implement AddressBook class and the main function
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 Name objects have the same first name and last name. The comparison must be case
sensitive (james West is NOT the same as James wesT). If the names are not the same return
false. To display a Name object you have two choices: provide getters for first name and last
name or overload the operator <<. You know which one is my preference. It's up to you to
decide if you want to go to the next level or stay with what everyone currently taking CS 2A in
Winter 2023 knows :-)
class Contact (abstract class)
Private member data: apointer 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 (linked 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 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 explicitly initialize it. Set member data to default values specified by
static data (don't forget to initialize the "next" link to nullptr or NULL).
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.
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.
The below diagram is to depict what an AddressBook object should look like. At this level it's
highly recommended that you draw diagram of your program's objects so that you can visualize
what's at hand which should help you to better understand the data structures and their
relationships.
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.
Testing
Run the program to test all functionalities such as
Option 1: Show all contacts
Option 2: Search by name
not found
found the first contact
found a contact in the middle of the list
found the last contact
Option 3: Search by department
non-existing department
a department that has only one employee
a department has more than one employee
How to submit your assignment
Same as assignment 1.
Late assignment submission policy
Same as assignment 1.
IMPORTANT NOTE:
If your assignment is not not working or incomplete you must state that in the email subject. You
will receive partial credit. Otherwise I may compile and try to run your code when grading. It's a
waste of my time to try figuring out why your program is not compiled or why it crashes.
Everyone has a 3-day late pass to be used one time on either assignment 1, 2 or 3. If you plan to
use it on an assignment please send me an email on the assignment's due date stating that you
intend to use it the late pass on that assignment. Then you may submit the assignment 3 days
later without incurring any penalty. If you finally submit the assignment say 5 days later instead
then your assignment's score will be subtracted by 10% (2 days late). The late pass can't be used
on assignment 4. Lastly if you never use the late pass then your assignment 4's score will receive
an automatic 10% extra credit.
CODE HELPER: ContactList's Init function
Contact examples
Title: Application Engineer, Mechanical Engineer, Manager, Product Support Engineer, Test
Technician, Software Engineer, Business Analyst, Admin Assistant, Manufacturing Engineer, IT
Technical Support, Hardware Engineer, Director, Human Resources Representative, Marketing
Analyst.
Department: Engineering, Finance, Manufacturer, Customer Support, Sales, IT, Human
Resources, Marketing.
void ContactList::Init ( ) {
Insert ( new EmployeeContact ("David", "Summer", "1-408-790-1682",
"davids@tpcommuniations", 23, "Software Engineer", "Engineering"));
Insert ( new EmployeeContact ("Jennifer", "Hans", "1-408-790-2381",
"jenniferh@tpcommuniations", 17, "HR Representative", "Human Resources"));
Insert (new ContractorContact ( "Cindy", "Morgan", "1-408-790-3953",
"cindym@tpcommuniations", 43, 12 , "TK Consultings"));
// ... insert at least 16 contacts
}
Phase 1 Skeleton Program
// 1. class declarations
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
Extra Credit (5 points)
1. (2 pts) Use InsertSort (in ascending order) instead of InsertFront. The ContactList should be
sorted by Name (last name then first name). You must overload < operator for the Name class.
2. (1 pt) Modify FindContact to stop searching if the target Name < current Node's Name.
3. (2 pts) Add a new menu option "Remove Contact" to remove a contact from the ContactList
by Name.

Program Specifications ( please show full working code that builds s.pdf

  • 1.
    Program Specifications (please show full working code that builds successfully and with all implementations ) This program is to build a simplified Address Book application (console version). The Address Book will allow employees or contractors working for a company to search contact information of their peers. The program should allow users to: View all employees/contractors contact information Search by name Insert new contact From CS 2B concepts the assignment should cover: Linked List implementation Abstract classes with pure virtual functions Polymorphism and dynamic_cast Operator Overloading Sample run of your program: TP Communications Address Book Menu 1. View all contacts // polymorphism 2. Search by name // operator overloading 3. Search by department // employees only - dynamic_cast 4. Quit Select an option (1-4): 1 // showing all contacts // .............................................. TP Communications Address Book Menu 1. View all contacts 2. Search by name 3. Search by department 4. Quit Select an option (1-4): 2 Enter a contact name: Jane Doe Sorry no match is found. TP Communications Address Book Menu 1. View all contacts 2. Search by name
  • 2.
    3. Search bydepartment 4. Quit Select an option (1-4): 2 Enter a contact first name: James Enter a contact last name: West // display James West contact information // .............................................. TP Communications Address Book Menu 1. View all contacts 2. Search by name 3. Search by department 4. Quit Select an option (1-4): 3 Enter a department: Engineering // display all employees in Engineering department 4. Quit Select an option (1-4): 4 Thanks for using our AddressBook. See you again! Implementation Phases You've been thru half of the quarter. It's time to learn how to use divide-conquer technique to efficiently deal with complex programs especially in work place environment with multiple developers. In such environment typically we would divide the program into different phases. Each developer is assigned to develop different classes or different components in the same class. At the conclusion of each phase we will perform unit testing to ensure the individual assignments are working properly per customer's specs. By the end of the project there will be an integrating process that puts all code together and starts the integration test performed by QA (Quality Assurance) engineers. You're strongly encouraged (but not required) to do the below while working on this assignment. It's up to you however to schedule/devise your own plan of implementing this program. Phase 1: develop the skeleton of your program (main function and class declarations and definitions with no-op or empty function bodies) without any specific implementation to the classes. See example at the end of the specs. Phase 2: implement the abstract base class Contact and its derived classes. Phase 3: implement the Linked List of Contact namely ContactList. Phase 4: implement AddressBook class and the main function Class Design
  • 3.
    At the minimumthe 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 Name objects have the same first name and last name. The comparison must be case sensitive (james West is NOT the same as James wesT). If the names are not the same return false. To display a Name object you have two choices: provide getters for first name and last name or overload the operator <<. You know which one is my preference. It's up to you to decide if you want to go to the next level or stay with what everyone currently taking CS 2A in Winter 2023 knows :-) class Contact (abstract class) Private member data: apointer 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 (linked 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 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 explicitly initialize it. Set member data to default values specified by
  • 4.
    static data (don'tforget to initialize the "next" link to nullptr or NULL). 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
  • 5.
    class ContactList Private memberdata: 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. 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).
  • 6.
    GetUserOption: ask usersfor 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. The below diagram is to depict what an AddressBook object should look like. At this level it's highly recommended that you draw diagram of your program's objects so that you can visualize what's at hand which should help you to better understand the data structures and their relationships. 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. Testing Run the program to test all functionalities such as Option 1: Show all contacts Option 2: Search by name not found found the first contact found a contact in the middle of the list found the last contact Option 3: Search by department non-existing department a department that has only one employee a department has more than one employee How to submit your assignment Same as assignment 1. Late assignment submission policy
  • 7.
    Same as assignment1. IMPORTANT NOTE: If your assignment is not not working or incomplete you must state that in the email subject. You will receive partial credit. Otherwise I may compile and try to run your code when grading. It's a waste of my time to try figuring out why your program is not compiled or why it crashes. Everyone has a 3-day late pass to be used one time on either assignment 1, 2 or 3. If you plan to use it on an assignment please send me an email on the assignment's due date stating that you intend to use it the late pass on that assignment. Then you may submit the assignment 3 days later without incurring any penalty. If you finally submit the assignment say 5 days later instead then your assignment's score will be subtracted by 10% (2 days late). The late pass can't be used on assignment 4. Lastly if you never use the late pass then your assignment 4's score will receive an automatic 10% extra credit. CODE HELPER: ContactList's Init function Contact examples Title: Application Engineer, Mechanical Engineer, Manager, Product Support Engineer, Test Technician, Software Engineer, Business Analyst, Admin Assistant, Manufacturing Engineer, IT Technical Support, Hardware Engineer, Director, Human Resources Representative, Marketing Analyst. Department: Engineering, Finance, Manufacturer, Customer Support, Sales, IT, Human Resources, Marketing. void ContactList::Init ( ) { Insert ( new EmployeeContact ("David", "Summer", "1-408-790-1682", "davids@tpcommuniations", 23, "Software Engineer", "Engineering")); Insert ( new EmployeeContact ("Jennifer", "Hans", "1-408-790-2381", "jenniferh@tpcommuniations", 17, "HR Representative", "Human Resources")); Insert (new ContractorContact ( "Cindy", "Morgan", "1-408-790-3953", "cindym@tpcommuniations", 43, 12 , "TK Consultings")); // ... insert at least 16 contacts } Phase 1 Skeleton Program // 1. class declarations //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////// Extra Credit (5 points) 1. (2 pts) Use InsertSort (in ascending order) instead of InsertFront. The ContactList should be sorted by Name (last name then first name). You must overload < operator for the Name class.
  • 8.
    2. (1 pt)Modify FindContact to stop searching if the target Name < current Node's Name. 3. (2 pts) Add a new menu option "Remove Contact" to remove a contact from the ContactList by Name.