Problem Statement:

advertisement
Problem Statement:
Anyone who is a member of Bowling Green’s Public Library may use the following services:
Check out book(s)
Check out DVD(s)
Check out CD(s)
In order to maintain its inventory and respond to members’ requests for the books, DVDs, and
CDs, the Public Library has the following files:
members.txt
inventory.txt
The members.txt file contains a list of members and the numbers of items each member has
checked out. This file contains 5 columns. The fist column is the ID (String) of the member, the
second column is the name (String) of the member, the third, fourth, and fifth columns indicates
how many books, DVDs, and CDs that member has checked out, respectively. These last three
entries are all integers.
Below is a typical line of the members.txt file is (the header line is not part of the file and only
there to make it easier to understand).
ID
AA800
Name
Mustafa
Book#
15
DVD#
0
CD#
3
This line in the file indicates that Mustafa has checked out 15 books and 3 CDs.
The invetory.txt file contains a list of the items the members may check out from the library. The
file has 4 columns. The first column is the ID number of an item. Every item ID is a 4-digit
integer. The second column is the number of copies of this item which are currently available.
The third column indicates the type of the item, where B indicates the item is a book, D indicates
it is a DVD, and C represents a CD. The last column in the file indicates the title of the item. You
can assume that there are no blanks in the title or an item or the name of a member.
Below is a typical line of the inventory.txt file (the header line is not part of the file and is only
there to make it easier to understand this example).
ID
copies
type
title
1234
2134
9901
2
3
0
D
B
C
Gone_with_the_wind
Southern_cooking
When_you_are_young
These lines in the file indicate that there are two copies of the DVD with the title
“Gone_with_the_wind” and ID number 1234 and three copies of the book “Southern_cooking”
with ID 2134 available in the library.
If a member wants to check out some items from the library, then he/she will list the items in a
file called checkout.txt. The first line of this file contains the ID of the member and the
remaining lines are the IDs of the items that members wants to check out.
Below is a typical line of the checkout.txt.
AA800
1234
9901
This checkout.txt file indicates that the member with ID number AA800 wants to check out one
copy each of the item with ID number 1234 and of the item with ID 9901. The items in the
checkout.txt file are processed in the order in which they appear in the file.
A member of the public library can check out at most 15 books, 10 DVDs, and 5 CDs. If a
member already checked out 14 books and 3 DVDs, then the member can check out at most one
book, 7 DVDs, and 5 CDs before returning the checked out items. Since the items in checkout.txt
are processed in the order in which they appear in the file, if a member may only check out one
more book, but there are two available books in checkout.txt, the first one is checked out to the
user and the second one is not checked out.
Your program is to read the information from the three files and do the following:
1. Create an updated copy of both the members.txt file and the invetory.txt file and store
them in membersnew.txt and inventorynew.txt.
2. Print the items that the member cannot check out due to the member exceeding the quota
or due to the item not being available. The items in this part of the output must contain
the complete title of the item and its ID. You must not include the number of copies
available in the printout.
3. Print the new items that the member checks out in increasing order of their ID number.
The item information for this part of the output must be the same as for 2). The output
must clearly identify where the list of checked out items ends and where the information
about items which could not be checked out begins.
You may assume that member ID and item ID(s) listed in the checkout.txt files will exist in the
members.txt and inventory.txt files. Furthermore, you may assume that each item ID will appear
at most once in each checkout.txt file and there are no more than 500 members and 2000 items in
the library. Items in the members.txt and inventory.txt files are separated by blank spaces. Your
output (to the screen or the files) must separate columns by blank spaces.
Note: The library does allow users to return books, CDs, and DVDs as well as keep track of the
exact items a member has checked out. However due to privacy issues, these aspects of the
requirements are not part of this proficiency exam.
This process can be illustrated by the three input files and the correct sample output and new
files as shown on the next page. Of course your program should work in general, not just for this
example. The bold information in the new files is the changed information. It is merely shown
in bold to emphasize the change. You are not required to line up columns as shown in the
example.
members.txt
AA11
AB01
CC20
DA19
GT88
HH76
GG86
JJ23
checkout.txt
Mustafa
Uta
Xing
Xia
Li
Huang
Gary
David
15
13
10
8
5
14
12
1
2
3
0
10
5
0
1
9
3
8
0
D
B
C
B
B
C
B
C
B
D
D
5
10
9
8
1
8
7
1
4
3
5
1
5
0
2
1
AB01
1234
1010
2244
2324
3321
1200
inventory.txt
1234
2134
9901
1010
1210
2244
3321
1200
2324
2999
1919
Gone_with_the_wind
Southern_cooking
When_you_are_young
Operating_System
Introduction_to_Network
Great_Balls_of_Fire
American_Government
Music_of_Ireland
Atlas_of_Anatomy
House
Laurel_&_Hardy
For the above three input files, your program should print the following information to the screen
Checked out items:
Operating_System (1010)
Music_of_Ireland (1200)
Atlas_of_Anatomy (2324)
Not checked out items:
Gone_with_the_wind
(1234)
Great_Balls_of_Fire
(2244)
American_Government (3321)
and create the following two new files:
membersnew.txt
AA11
AB01
CC20
DA19
GT88
HH76
GG86
JJ23
Mustafa
Uta
Xing
Xia
Li
Huang
Gary
David
15
15
10
8
5
14
12
1
inventorynew.txt
5
10
9
8
1
8
7
1
4
4
5
1
5
0
2
1
1234
2134
9901
1010
1210
2244
3321
1200
2324
2999
1919
2
3
0
9
5
0
1
8
2
8
0
D
B
C
B
B
C
B
C
B
D
D
Gone_with_the_wind
Southern_cooking
When_you_are_young
Operating_System
Introduction_to_Network
Great_Balls_of_Fire
American_Government
Music_of_Ireland
Atlas_of_Anatomy
House
Laurel_&_Hardy
Download