Background

To become familiar with program designs dealing with dynamic data structures as well as programming with Classes. In this assignment, you should explore the following features:

  • Functional decompositions
  • Classes and objects
  • Operator overloading
  • Exception handling
  • File input/output

Specification

In this assignment, you are required to implement a simple electronic contact list using classes. The contact list consists of a list of entries, each one consisting of a name, a telephone number, and an email address. As is often the case in computerized application, your application must consist of the following functionalities:

1. Create a new, empty directory if no contact list file exists. If a contact list file exist, create a directory containing the entries of the contact list from the file;

2. Insert a new entry into the directory;

3. Lookup the content in an entry, given a contact persons name;

4. Remove the entry corresponding to a given name, and

5. Update the entry corresponding to a given name.

There are two special requirements that you must implement in your application. First, your application must overload the input/output extractor (>>) and inserter (<<) operators to display the content of contact list instances. Second, when a directory is full, your application must be able to extend the directory by doubling its current size.

Task 1

Your are to implement an appropriate class for the entries of contact list and then make a directory class containing an array of entries. An instance of a directory is shown below, for your reference: see image.

Each instance of a contact list consists of a name, telephone number, and an email address.

Hint:

(i) You may need to define the member data that each entry object will contain, along with the member functions you will use to manipulate the data. You may consider overloading the >> operator and << operator in this class.

class Entry {
// declaration of friend classes here

public:
// declaration of public functions here
// default constructor

// public function to read from file

// public function to display entry

private:
// declaration of members data here

};

(ii) Define a Directory class that maintains a list of entries.

class Directory {
public:
// constructor
// destructor
// other useful functions

private:
// private function to extend

// declaration of members data here
};

Task 2

What operations would be appropriate for an electronics contact list directory?

As specified in the specification, we would like to be able to

1. Create a new, empty directory if no contact list file exists. If a contact list file exist, create a directory containing the entries of the contact list from the file;

2. Insert a new entry into the directory;

3. Lookup the content in an entry, given a contact persons name;

4. Display the content of the directory;

5. Remove the entry corresponding to a given name, and

6. Update the entry corresponding to a given name.

Let us describe in detail each functionality here.

Create (instantiate) a directory

How large is a directory?

We would like to make the directory dynamic so that it can grow and shrink during your programs execution. Rather than storing the array in the directory, the Directory class will instead just keep a pointer to the array and use new() function to build the array in the Heap. Your program should begin with a pointer to a small array, and keep track of the maximum possible number of entries the array can hold. When a user attempts to insert a new entry into a full array, your program will create a new array twice the size of the old one, copy the entries into the new array, adjust the maximum size, and use the delete() function to destroy the old array.

We would also like to have contact list from a file be read into the directory when we instantiate one. Of course if there is no contact list file exist, the directory will be instantiated emptied. When a user ends the program, the program needs to copy the entries in the directory into a contact list file. Hence for the very first time a user run your program, there will be no contact list file, but subsequently, there should be one.

You might consider implement this requirement using constructor and destructor.

Insert a new entry into the directory

To implement this function, we would like you to overload the operator >>. As discussed in Topic 3.1, to overload the operator >>, you will need to take a reference to an istream as its first argument and a reference to an entry as its second and returns to the program a reference to the istream it saw as its left argument.

Your function will first prompt the user to enter the contact list, and use the istream function getline to get the name, telephone number, and email address. Of course, your function must also check if the name of the contact person has already existed. If an entry exists, rejects the entry, otherwise adds the entry to the contact list.

When an entry is added to the directory, your function must check that if the directory is already full (reach its maximum number of entries allowed). If the directory is already full, the insert entry function must call a function to extend the capacity of the directory by doubling its current capacity.

You might want to consider implementing an exception in the extend function. If the heap is running out of space, the extend function will raise an exception, and your insert function will then handle this exception by simply close (terminate) the program with an appropriate message. see image.

Lookup the content in an entry, given a contact persons name

Similarly, to implement this function, we would like you to overload the operator <<. The overloading of the << operator is similar to the overloading of >> operator. The only difference is that the reference is to an ostream.

Your function will first prompt the user to enter the name of the contact person to lookup. If the contact details are found in the directory, the function will use the overloaded << operator to display the entry, otherwise, display an appropriate message.

The following is a sample screen on the Lookup process: see image.

Display the content of the directory

This function is simply display the content of the entire directory.

The following is a sample screen of the display directory function: see image.

Remove the entry corresponding to a give name

This function should be simple. The only trick here is to close the gap in the array after the entry is removed from the directory. Your function will first prompt the user to enter the name of the contact person to be removed from the directory. If the contact details are found in the directory, the function will remove the entry from the directory, otherwise display an appropriate message.

The following is a sample screen of the remove entry operation: see image.

Update the entry corresponding to a give name

To simplify the updating process, this function updates an existing directory entry by re-entering each of its values. The function will first prompt the user to enter the name of the contact person to be updated. If the contact details are found in the directory, the function will use the overloaded << operator to display the current entry, and use the >> to get new values for the entry.

The following is a sample screen of the update process: see image.

Task 3

Finally, you need to write a main function together with some other necessary functions that are not mentioned in Task 1 and Task 2 to drive the whole application. The action of the main function should be quite familiar by now. It creates a new Directory object, displays a menu of available operations, and keeps getting command characters from the user and executing the function corresponding to those commands until the user decides to quite the program.

The following is a sample screen showing the menu of available operations: see image.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.