In this assignment you will write a program for a phone company. Your program will use a list of lists to maintain the database of phone numbers. The main list will refer to the area codes. The lists coming off of the main list will store the telephone numbers in that area code. Each phone number should store the prefix and suffix separately. Here is an example illustration: see image.

Your program should be able to support the following actions:

  • Add a phone number to the list. If necessary, a new area code will be created. For example, using the above list, adding the phone number 817-458-3101 would add a new node to the 817 area code list. Adding the phone number 350-921-6749 would add a new area code node of 350 and then off of that list, the phone number 921-6749 will be added. Be sure not to add duplicate numbers. Each new area code added will be added to the front of the list of area codes and each new phone number will be added to the front of the list of phone numbers.
  • Remove a phone number from the list. If removing the phone number causes the corresponding area code to have an empty list, then you should also remove the area code node.
  • Search for a given phone number
  • Count how many phone numbers there are in the list
  • Count how many phone numbers there are in a given area code
  • Count how many phone numbers there are in a given area code and a given prefix.
  • Split an area code. For example, move all the phone numbers with the 353 prefix in the 909 area code to a new area code of 650. The new area code should not already exist and should be added to the head of the area code list. If splitting causes the old area code to have an empty list of phone numbers, the old area code should also be removed.

There are many List templates available (for example, the Standard Template Library offers a list template class). However, for this assignment, when you use a linked list, it will be your own code so that you can practice your programming and learn the concepts thoroughly. You may however, use any variation of a linked list (double linked list, sentinels, etc) as long as it interfaces with the main functions provided.

Skeleton code provided

DO NOT alter any of the code provided to you. Please only ADD to the code. The files can be found in the Doc Share.

Structure

Your program will consist of 3 basic classes and I have provided you with the skeleton code for those classes in the Doc Share. DO NOT make any additional classes. You only need these 3 classes. You must download these files and complete the code in them.

  • phone_book.h - The first class will be the phonebook list class which will contain a pointer to the head of your area code nodes.
  • phone_book.cpp - You are also being provided the cc file for the phonebook class because it contains the print function that has been written for you. DO NOT change this print function. However, note how the print functions are structured. I have a print function in the phonebook class that only prints the area codes for the lists. Then it calls a print function within the area_node class that prints out the phone numbers in the area code. The phone numbers are hidden from the phonebook class. You should follow this model with EVERY function that you write.
  • area_node.h - The second class will be an area code node that will hold the current area code, a pointer to the next area code in the list, and a pointer to the head of the list of phone numbers in that area code.
  • area_node.cpp - You are also being provided the cc file for the area node class because it contains the print function that has been written for you. DO NOT change this print function.
  • number_node.h - Finally, you will have a phone number class which will hold the current phone number and a pointer to the next phone number in the list.
  • main.cpp - This is the main function for the complete assignment that we will be testing your programs with. It contains function calls that test the code that you write. Since this is THE file we will be using for testing, you know how well you will do on the assignment because you will know how well you perform on the test cases. The output of your program should look like output.txt. DO NOT add anything to the main files that is necessary for your program to compile/function correctly.

Function prototypes

You will write the following functions for your PhoneBook class to interface with the main function. This is in no way an inclusive list of the functions that you will need to write. This is simply the minimum amount of information that I need to give you so that your code will interface with the main testing function. For each function, please follow the specifications listed above.

  • void removePhoneNumber ( int area, int prefix, int suffix ) - This function will remove a phone number from the phone book. The function parameters are:
    • area - the area code of the number to be removed
    • prefix - the prefix of the number to be removed
    • suffix - the suffix of the number to be removed
  • void insertPhoneNumber ( int area, int prefix, int suffix ) - This function will insert a phone number into the phone book. The function parameters are:
    • area - the area code of the number to be inserted
    • prefix - the prefix of the number to be inserted
    • suffix - the suffix of the number to be inserted
  • bool search ( int area, int prefix, int suffix ) - This function will search for a phone number in the phone book. The function will return true if the phone number is found and false if the phone number is not found. The function parameters are:
    • area - the area code of the number to search for
    • prefix - the prefix of the number to search for
    • suffix - the suffix of the number to search for
  • int numNumbers ( ) - This function will return the total number of phone numbers in the phone book.
  • int numAreaCodeNumbers ( int area ) - This function will return the total number of phone numbers in the specified area code. The function parameters are:
    • area - the area code in which to count phone numbers in
  • int numAreaCodeAndPrefixNumbers ( int area, int prefix ) - This function will return the total number of phone numbers in the specified area code that belong to a specified prefix. The function parameters are:
    • area - the area code in which to count phone numbers in
    • prefix - the prefix in which to count phone numbers in
  • void split ( int oldAreaCode, int prefix, int newAreaCode ) - This function will take phone numbers from a given prefix in a given area code and place them into a new area code. The function parameters are:
    • oldAreaCode - the area code which contains the phone numbers that will be moved to a new area code
    • prefix - the prefix of the phone numbers that will be moved to the new area code
    • newAreaCode - the area code that the phone numbers will be moving to

You must also write the following functions for the AreaNode class (not a complete list).

  • int size ( ) - this function will return the number of phone numbers in the list for this area code. This function is important because it is used by the print function to nicely print the phone numbers to the screen.
  • bool isEmpty ( ) - returns true if the areaNode list is empty, false if the list isn't empty.
  • void removeNumber ( int prefix, int suffix ) - This function will remove a phone number from the areaNode list. The function parameters are:
    • prefix - the prefix of the number to be removed
    • suffix - the suffix of the number to be removed
  • void insertNumber ( int prefix, int suffix ) - This function will insert a phone number into the areaNode list. The function parameters are:
    • prefix - the prefix of the number to be inserted
    • suffix - the suffix of the number to be inserted
  • NumberNode* search ( int prefix, int suffix ) - This function will search for a phone number in the areaNode list. The function will return a pointer to the node if the phone number is found and NULL if the phone number is not found. The function parameters are:
    • prefix - the prefix of the number to search for
    • suffix - the suffix of the number to search for
  • int numPrefixNumbers ( int prefix ) - This function will return the total number of phone numbers that belong to a specified prefix. The function parameters are:
    • prefix - the prefix in which to count phone numbers in

Error checking

Please make sure to provide good error checking throughout. If an error occurs, i.e inserting a duplicate number or deleting a number that does not exist, print out an error message and return from the function. Do not exit! Make sure that your error message matches mine the in sample output EXACTLY.

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.