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
- 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 a Linux machine. 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 Linux machine 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
You must turn in the following file:
See the turn in instructions for details on how to turn in this assignment.call.h
call.cpp
bill.h
bill.cpp
main.cpp
The turn in instructions contain details on turning in a late assignment.