CS14 - At-Home Programming Assignment 1
Small demo in lab during week 2
Part 1 due Sunday, January 18 at 8:00 pm
Complete project due Sunday, January 25 at 8:00 pm
Updated Monday Jan, 12 at 3:20pm - Added clarification to the grading
section
Updated Sunday Jan, 11 at 6:20pm - Added section about error checking
In this project 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
seperately. Here is an example illustration:

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.
-
Add phone numbers to the list from a user specified file. This operation
adds to the current list being used. Duplicate numbers should not
be added. The format of the file will be a phone number on each line
in the following format: 909-787-1234
-
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, sentinals, etc) as long as it interfaces
with the main functions provided.
Skeleton code provided
So that your program will interface with our testing environment for
grading, you must adhere to the following specifications and use the
skeleton code provided. If you deviate from the specifications and your
program does not interface with our testing environment, you program
will not be graded. To ensure that your code will interface correctly,
DO NOT alter any of the code provided to you. Please only ADD to the code.
Structure
Your program will consist of 3 basic classes and I have provided you
with the skeleton code for those classes. 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.cc - 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.
-
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.cc - 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.cc - 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 this.
-
main1.cc - This is the main function for part 1 of
the 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 this.
-
main_lab.cc - This is the main function for
the lab demo part of the 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 this.
-
phone_numbers.txt - This is the file
that your program will read phone numbers from. We will use this file
to test your program while grading.
-
Download all of the files here
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 readFromFile ( string fileName ) - This function will read phone
numbers in from a file and add them to the phone book. The function
parameters are:
-
fileName - the name of the file to read in from (NOTE: the file name
is of type string. You may not change that)
-
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 removed
-
prefix - the prefix of the number to be removed
-
suffix - the suffix of the number to be removed
-
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 be removed
-
prefix - the prefix of the number to be removed
-
suffix - the suffix of the number to be removed
-
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 function for the AreaNode class.
-
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.
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! I did not provide the error messages in the sample test output
that I gave you for each main function because that is something that you
will need to determine.
Small demo in lab during the second week
This project is most likely by far the largest programming assignment that
you have ever been given and I am sure that it seems overwhelming. This
project (along with every subsequent project you will be given this
quarter) absolutely cannot be left until the last minute to complete.
To help you complete this project, you will have an in lab demo during
the second week of class. For in in lab demo, you will only need to operate
on one area code. You will need to complete the size functions, the search
function, and be able to insert 1 phone number. Please use the
main_lab.cc file to test your code. You must
demo your program with main_lab.cc during lab
and it will account for a portion of your total score for the complete
assignment.
Part 1 due Sunday, January 18 at 8:00 pm
Part of it will be due 1 week before
the final due date of the completed project and must be turned in using
the electronic turnin. For part 1,
your code only
needs to work with one area code, you do not need to handle removing
phone numbers, and you do not have to process
phone numbers from a file. For part 1, please use the
main1.cc file to test your code. You must turn
in part 1 electronically because it will be graded and will account for
a portion of your total score for the complete assignment.
Complete project due Sunday, January 25 at 8:00 pm
You will be given one additional week to complete your code so that it
will work with multiple area codes and processes phone numbers from a file.
For the completed project, please use the main.cc
file to test your code. Your program must be turned in using
the electronic turnin.
Notes on grading
Grading programming assignments can be a very time consuming
operation if programs cannot be automatically tested with a test function.
I would like to stress again how important it is for your programs to work
with the main functions provided. Your programs will be graded with
main1.cc for part 1 and and main.cc
for the final complete project. You will
receive points for the test cases that your code passes. If your code
does not interface with main functions provided, you will not receive any
functionality points (which is 70% of your grade for the assignment).
Much of the grading of your program will be based on not just getting code to
do the necessary functions correctly, but on your actual coding (these
points are part of the 70% listed above). Be sure to use
good programming where possible (use of classes, functions, good parameter
passing techniques, error checking, encapsulation, object oriented
programming). Make sure your program is user friendly.
You must use a makefile to compile your program and you must at least
use the compilation flags -W -Wall -Werror -pedantic. Programs will be graded
under linux on hill.cs.ucr.edu. Significant points will be taken off if your
program does not compile with a makefile or if you code under Windows.
Suggestions to follow while coding
-
Follow a modular programming style. Write one function for your program
and completely test it before moving to the next function. This will
isolate your debugging because most of the time the bug will be in the
newly created module. However, if you forget a test case in an old
module and do not completely test it, a new module can reveal old bugs.
Watch out for this.
-
The main function provided assumes a certain order that you will code
your program in. You in no way need to follow this same order while coding.
I suggest that while code, you do not use my main function and write your
own to test the code that you are writing. (Please make sure you conform
to the provided function prototypes). After you have tested your code,
try the main functions provided. Or, you may use my main functions and
simply comment out everything except the current tests you are interested
in.
What to turn in
You should have turned in what you have thus far on our program at least
6 hours before the due date (by 2pm). Then continue to work on your program
and turn in more current versions as you get them working. Ideally, you should
have your project done well before the due date.
You must turn in all .cc and .h files and your makefile. Furthermore, you
must turn in a file called readme.txt that states which test cases
your program passes and which test cases your program fails. In addition, you
must follow any guidelines and include any information that is stated
on the
main page about at-home programming assignments.
A reminder about collaboration on home programming assignments
Please remember, at-home programming assignments are not lab assignments and
you may not team-code with your lab partner or any other individual. Limited
collaboration may be acceptable, but programs must represent
YOUR OWN original work. Sharing code or team-coding are strictly
not allowed. Copying code from ANY source (any book, current or
past students, past solutions, web, etc) is
strictly not allowed even with citation. Collaboration may
consist of discussing the general approach to solving the
problem, but should not involve communicating in code or even
pseudo-code. Students may help others find bugs. Your code MUST
be unique -- the odds of randomly producing similar code is
very low. Computing, like surgery or driving a car or playing
golf, can only be learned by doing it yourself!