Sie sind auf Seite 1von 5

due: 14 April CS515 Assignment 7 last accept: 19 April

The purpose of this assignment is to give you practice with binary search trees, command
line argument, and using files, as well as more practice with input order lists and with
using head sentinels on a list. In addition, it will give you practice combining two storage
structures, sharing the elements between the structures.
For this assignment you are to write a program which will accept input from two different
files (the file names are on the command line). The first file contains account information for
telephone accounts, while the second file contains information about calls made. If there are
problems with the command line or the files, the program is to abort (call exit with non-zero
argument) after printing an appropriate error message. Otherwise, bills for all the accounts
in the account file are to be printed, in the order the accounts appear in the file.
The account information in the account file is in the form:

phoneNumber |accountAddress| prevBalance

where the phone number is in the form

(aaa) eee-nnnn

The account address is delimited by or bars and will contain spaces. The previous balance
is an integer number of cents. You may assume that this data is in the correct format and
there is no duplication. The phone number is used to uniquely identify the account. The
following is the contents of a simple sample account file.
(555) 555-5555 |Anonymous, 0 Lost Ln, Nowhere| 100000
(123) 456-7890 |Fred Flintstone, 1 Rock Way, Bedrock| 3500
(555) 555-6666 |HAL, 2001 Space Drive, Holywood| 1000
(123) 456-1111 |Barney Rubble, 3 Rock Way, Bedrock| 0

The call information in the call file is in the form

callingNumber calledNumber date time duration

where the calling number and called number are phone numbers in the form described above.
The date and time are space delimited strings in the forms yyyy/mm/dd and hh:mm:ss
respectively. The duration is the length of the call (integer) in minutes. You may assume
that all this data is in the correct form. The following is the contents of a simple sample
calls file.
(123) 456-1111 (123) 456-7890 2010/03/30 20:45:00 6
(123) 456-7890 (123) 456-1111 2010/03/30 20:59:12 3
(555) 555-5555 (555) 444-4444 2010/03/30 20:59:12 1
(555) 555-5555 (555) 444-4444 2010/03/30 21:59:12 1
(555) 555-5555 (555) 444-4444 2010/03/30 22:59:12 1
(123) 456-7890 (555) 456-1111 2010/03/30 23:00:00 10
(123) 456-1111 (123) 555-5555 2010/03/30 23:45:00 5
(123) 456-1111 (123) 555-5555 2010/03/30 23:51:00 5

1
due: 14 April CS515 Assignment 7 last accept: 19 April

The new charges to the accounts are based on the phone calls made by the accounts.
There are three kinds of calls: local calls, where the area code and the exchange are the
same; in area calls, where the exchange codes are different, but the area code is the same;
and out of area calls, where the area codes are different. Local calls cost 1 cent per minute.
In are calls cost 5 cents per minute. Out of area calls cost 25 cents per minute. The total for
the period would be the total of these three kinds of calls and the previous balance, if any.
The bill is to include separate charges for each kind of call, along with the total dutations
for each kind. All money values are to be printed as a decimal (dollars) with exactly 2 digits
(cents) after the decimal point. In addition, all the calls made are to be listed, by category
(in the order input). A sample run of the program with the data files provided above is
shown below.
blj(mithrandir): a.out accounts.dat calls.dat

=================================
(555) 555-5555 Anonymous, 0 Lost Ln, Nowhere
previous balance: 1000.00
local minutes: 0
charge: 0.00
area minutes: 3
charge: 0.15
non area minutes: 0
charge: 0.00
total charge: 1000.15
local calls
area calls
(555) 555-5555 (555) 444-4444 2010/03/30 20:59:12 1
(555) 555-5555 (555) 444-4444 2010/03/30 21:59:12 1
(555) 555-5555 (555) 444-4444 2010/03/30 22:59:12 1
non area calls

=================================
(123) 456-7890 Fred Flintstone, 1 Rock Way, Bedrock
previous balance: 35.00
local minutes: 3
charge: 0.03
area minutes: 0
charge: 0.00
non area minutes: 10
charge: 2.50
total charge: 37.53
local calls
(123) 456-7890 (123) 456-1111 2010/03/30 20:59:12 3
area calls
non area calls

2
due: 14 April CS515 Assignment 7 last accept: 19 April

(123) 456-7890 (555) 456-1111 2010/03/30 23:00:00 10

=================================
(555) 555-6666 HAL, 2001 Space Drive, Holywood
previous balance: 10.00
local minutes: 0
charge: 0.00
area minutes: 0
charge: 0.00
non area minutes: 0
charge: 0.00
total charge: 10.00
local calls
area calls
non area calls

=================================
(123) 456-1111 Barney Rubble, 3 Rock Way, Bedrock
previous balance: 0.00
local minutes: 6
charge: 0.06
area minutes: 10
charge: 0.50
non area minutes: 0
charge: 0.00
total charge: 0.56
local calls
(123) 456-1111 (123) 456-7890 2010/03/30 20:45:00 6
area calls
(123) 456-1111 (123) 555-5555 2010/03/30 23:45:00 5
(123) 456-1111 (123) 555-5555 2010/03/30 23:51:00 5
non area calls

=================================
blj(mithrandir):

The account database class (“AccountDB ”) stores all the account information, including
the calls. It must be able to output the account bills in the same order that the accounts
are originally input. Thus, in part, the storage needs to be an input order list.
In a real situation, there would be many thousands of calls, and there is no guarantee that
the input order is designed to be able to quickly find accounts (in fact, it isn’t). Thus the
database also needs a way to be able to look up the accounts quickly based on their phone
number. To do this, the information is also to be stored on a binary search tree (ordered by
phone number). Note: in the ordering of the phone numbers, the area code should be the
most important, the exchange next, and then finally the last four digits of the number. The

3
due: 14 April CS515 Assignment 7 last accept: 19 April

structure you are to build is a hybrid of the two storage structures, and input order list and
a binary search tree. Each Node/Element is to have three pointers, the next pointer used
for the list, and the right and left pointers used by the tree.

struct Node {
Account info;
Node * next; // list
Node * left; // tree
Node * right; // tree
};

Each account is to be in only one node, which is inserted into both the chain for the list
and the tree. The diagram below shows the sample account data (only initials and phone
number are shown) in the resulting data base (tree and list) after the account data has been
read in.
root

head
A
555
tail
555
5555
next
left
right

FF HAL
123 555
456 555
7890 5556

0
0 0

BR
123
456
1111
0
0
0

4
due: 14 April CS515 Assignment 7 last accept: 19 April

The result of this hybrid structure is to maintain the original input order of the data and
at the same time providing a fast lookup for accounts by phone number when handling the
call data.
The calls from the individual accounts are to be stored on input order lists (three of them,
one for each type of call) associated with each account. These lists are to be constructed
with a head sentinel so the list is never truely empty. This eliminates the special empty
chain test that would otherwise be needed on each insertion.
When testing your program you should test for various bad command line arguments
(wrong number of arguments and files that cannot be opened) in addition to testing the
correct handling of the data. Be sure to test printing money amounts with no cents and less
than 10 cents.

Das könnte Ihnen auch gefallen