Implement a linked-list to store a collection of phone calls as they would appear on a telephone bill. Each item in the call list includes:
Your program must provide the following functionality:
- month of call (integer)
- day of the month of the call (integer)
- number called (string)
- length of the call in minutes (integer)
- insert a new call
- remove a call by specifying the date and the number called
- lookup the length of a call by specifying the date and number called. If found, print the call to standard output using the same format as the print command. If not found, do nothing.
- total of all calls in a given month
- print all calls
Implement your program using the following two classes:
class CallStores the information about the call (date, number, minutes) and the next pointer used to link calls together.
Unlike the Movie class in the previous assignment, class Call will NOT have an initialize() function and MUST have a constructor that takes arguments to initialize all of its member variables.
This program will be easier to implement if class Bill can access the private member variables (date, number, minutes). You can provide access to private member variables by using the friend mechanism. The friend mechanism allows another class access to all private variables.
class Call
{
friend class Bill;
public:
...
private:
// private members are now public for class Bill member functions
};class BillImplements the linked-list (a linked-list of class Call)
Will need a constructor to initialized the linked list to empty
Must have a public member function for each of the functionality listed above (insert, remove, lookup, total minutes, print).
Your program must read commands (insert, remove, lookup, total, print) and data (month, day, number, minutes) from standard input (cin). The input will be a collection of commands (each on its own line) followed by the data used by the command. The commands can be in any order, in other words, all the inserts don't have to be first.
The insert command takes four arguments (month, day, number, minutes), and looks like:
insert 1/4 530-555-1234 42
The remove command takes three arguments (month, day, number):
The lookup command takes a three arguments (month, day, number) and if there is a matching record, prints the call to the screen just like the print command.remove 2/23 530-898-6442The total command takes a month as the argument and prints the sum of all the minutes of all the calls for that month (see below for format):lookup 4/12 800-588-1990
The print command does not take any arguments and prints all calls (see below for format):total 1
Note that the commands don't all take the same number of arguments. In main() you will have to decide how many arguments to read based on the command just read:
- insert takes 4 arguments
- remove takes 3 arguments
- lookup takes 3 arguments
- total takes 1 argument
- print takes 0 arguments
The linked list of calls must be ordered by date. If there are multiple calls for a single day, then the calls for that day should be in the same order that they were inserted into the list.Files:
call.h
call.cpp
bill.h
bill.cpp
main.cpp
1/4: 530-555-1234 42
total for month 1 is 218 minutes
main() must print out all the error messages. The Bill and Call classes cannot print error messages.
All error messages must be written to standard error (cerr << "Call on ...." << endl).
Only one call per day is allowed to each number (this makes lookup and remove easier). If the user inserts a call with the same date and number as a call already in the list, ignore the requests and print the following error (replace the <month> with the actual month, the <day> with actual day, and the <number> with the actual number):
Call on <month>/<day> to <number> is already in list, could not be inserted.
If a call associated with a remove command is not in the list (i.e. no call in the list has this date and number), ignore the request and print the following error:
Call on <month>/<day> to <number> not in list, could not be removed.
If the description associated with a lookup command is not in the list, ignore the request and print the following error:
If a command is given other than the legal commands (insert, remove, lookup, total, print), print the following error, and terminated the program by calling exit(1) (since each command has a different number of arguments, it is hard to recover from a bad command):Call on <month>/<day> to <number> not in list, could not be looked up.
Unrecognized command: <command>
Can't recover. Giving up.
I will deduct 10 percent if your program does not compile using my Makefile on the department's Sun workstations. Thus you must make sure to use the filenames listed below (do not capitalize your filenames), and if you are working on windows, you should compile your program on a Sun before turning it in.
I will grade your program using another program, so if your program does not work exactly as specified below you will lose points.
The first lines of all your files (.h and .cpp) must contain:
/****
last name, first name
ecst_username@ecst.csuchico.edu
112 Program 3: Telephone bill
****/
If you download my Makefile, and have your program on a Department machine, you can submit your program by typing:
$ make submitLook carefully at the output to make sure all the following files were copied:
You may submit as many times as you want before the deadline. Once the deadline passes, you will not be able to submit.call.h
call.cpp
bill.h
bill.cpp
main.cpp
You can also just copy or ftp the above files into the directory:
where USERNAME is your ecst username./user/projects/csci112/p3/USERNAME
See how to turn in assignments for detailed instructions on how to turn in the assignment.
Note: You will not be able to access this directory once the deadline has passed.
If you do not finish by the deadline (see top for the deadline), you may turn your assignment in up to 24 hours late. You will lose 15% for turning your assignment in 1-24 hours late.
If you turn your assignment in late, use the following command:
$ make submit_lateOr you can copy or ftp your assignment into the following directory
Assignments will not be accepted if more than 24 hours late./user/projects/csci112/p3_late/USERNAME