CMSC 201
Programming Project Three
The CSEE Book Store
Out: Wednesday 10/27/04
Due: Before Midnight, Sunday 11/14/04
The design document for this project, design3.txt
is due: Before Midnight, Friday 11/5/04
|
The Objective
The objective of this assignment is to give you experience working with
pointers. You'll be doing file handling, dynamic memory allocation, and
passing by reference. You will also continue to practice using good program
design and implementation techniques.
The Background
The CSEE Book Store offers students a selection of Computer Science textbooks
that are required for many of the CS core courses as well as a few reference
books. The store keeps track of the books in inventory with an inventory file.
A student can use the order system to purchase single or multiple copies of
the books available. The system creates an invoice for the student and also
removes the books ordered from the inventory.
The Task
Design and code a project that after printing a greeting to the user, presents
the user with a list of the book titles available. The user can then choose
to see more information about one of the books on the list or quit. If the
user chooses to see the information about a book, s/he is presented with the
book's ISBN number, title, author, publisher, the price per copy and the number
of copies in stock. The user will then enter the number of copies s/he wants
to order (0 is a possibility).
Once the user has entered the number of copies to order, a line item is
generated and written on the invoice and the inventory is decreased by that
number of copies. The user is then presented with the list of titles again.
When the user has finished ordering books, the invoice is completed by adding
the sales tax (5% of the subtotal) and writing the tax and total. A new
inventory file is then produced which is exactly like the original inventory
file but with the new numbers of copies adjusted to reflect the order.
Sample Run
linux1[71] % a.out
Your greeting and instructions go here
01 - C_How_To_Program
02 - Unix_In_A_Nutshell
03 - The_C_Programming_Language
04 - Learning_the_UNIX_Operating_System
05 - Programming_Languages:Concepts_&_Constructs
06 - Computer_Architecture_A_Quantitative_Approach
07 - Computer_Networks
08 - A_First_Course_in_Database_Systems
09 - Introduction_To_Algorithms
10 - Introduction_to_Automata_Theory
11 - Software_Engineering
12 - Introduction_to_Computer_Graphics
13 - Computer_Engineering:Hardware_Design
14 - UNIX_Internals
15 - Compilers:Principles,_Techniques,_and_Tools
16 - Modern_Operating_Systems
17 - Data_Structures_with_C++
18 - Operating_System_Concepts
19 - Modern_Information_Retrieval
To view a book's information enter its number or -1 to quit : 15
Inventory number: 15
ISBN: 0-201-10088-6
Title: Compilers:Principles,_Techniques,_and_Tools
Author: Aho_Sethi_&_Ullman
Publisher: Addison_Wesley
Price: $ 75.00
Number of copies available: 83
How many would you like to order (0 - 83) : 10
01 - C_How_To_Program
02 - Unix_In_A_Nutshell
03 - The_C_Programming_Language
04 - Learning_the_UNIX_Operating_System
05 - Programming_Languages:Concepts_&_Constructs
06 - Computer_Architecture_A_Quantitative_Approach
07 - Computer_Networks
08 - A_First_Course_in_Database_Systems
09 - Introduction_To_Algorithms
10 - Introduction_to_Automata_Theory
11 - Software_Engineering
12 - Introduction_to_Computer_Graphics
13 - Computer_Engineering:Hardware_Design
14 - UNIX_Internals
15 - Compilers:Principles,_Techniques,_and_Tools
16 - Modern_Operating_Systems
17 - Data_Structures_with_C++
18 - Operating_System_Concepts
19 - Modern_Information_Retrieval
To view a book's information enter its number or -1 to quit : 9
Inventory number: 9
ISBN: 0-262-03141-8
Title: Introduction_To_Algorithms
Author: Cormen_Leiserson_&_Rivest
Publisher: McGraw_Hill
Price: $ 69.95
Number of copies available: 51
How many would you like to order (0 - 51) : 5
01 - C_How_To_Program
02 - Unix_In_A_Nutshell
03 - The_C_Programming_Language
04 - Learning_the_UNIX_Operating_System
05 - Programming_Languages:Concepts_&_Constructs
06 - Computer_Architecture_A_Quantitative_Approach
07 - Computer_Networks
08 - A_First_Course_in_Database_Systems
09 - Introduction_To_Algorithms
10 - Introduction_to_Automata_Theory
11 - Software_Engineering
12 - Introduction_to_Computer_Graphics
13 - Computer_Engineering:Hardware_Design
14 - UNIX_Internals
15 - Compilers:Principles,_Techniques,_and_Tools
16 - Modern_Operating_Systems
17 - Data_Structures_with_C++
18 - Operating_System_Concepts
19 - Modern_Information_Retrieval
To view a book's information enter its number or -1 to quit : 13
Inventory number: 13
ISBN: 0-13-162926-3
Title: Computer_Engineering:Hardware_Design
Author: Mano
Publisher: Prentice_Hall
Price: $ 101.67
Number of copies available: 79
How many would you like to order (0 - 79) : 0
01 - C_How_To_Program
02 - Unix_In_A_Nutshell
03 - The_C_Programming_Language
04 - Learning_the_UNIX_Operating_System
05 - Programming_Languages:Concepts_&_Constructs
06 - Computer_Architecture_A_Quantitative_Approach
07 - Computer_Networks
08 - A_First_Course_in_Database_Systems
09 - Introduction_To_Algorithms
10 - Introduction_to_Automata_Theory
11 - Software_Engineering
12 - Introduction_to_Computer_Graphics
13 - Computer_Engineering:Hardware_Design
14 - UNIX_Internals
15 - Compilers:Principles,_Techniques,_and_Tools
16 - Modern_Operating_Systems
17 - Data_Structures_with_C++
18 - Operating_System_Concepts
19 - Modern_Information_Retrieval
To view a book's information enter its number or -1 to quit : 4
Inventory number: 4
ISBN: 1-56392-390-1
Title: Learning_the_UNIX_Operating_System
Author: Peek_Todino_&_Strong
Publisher: O'Reilly
Price: $ 11.96
Number of copies available: 24
How many would you like to order (0 - 24) : 4
01 - C_How_To_Program
02 - Unix_In_A_Nutshell
03 - The_C_Programming_Language
04 - Learning_the_UNIX_Operating_System
05 - Programming_Languages:Concepts_&_Constructs
06 - Computer_Architecture_A_Quantitative_Approach
07 - Computer_Networks
08 - A_First_Course_in_Database_Systems
09 - Introduction_To_Algorithms
10 - Introduction_to_Automata_Theory
11 - Software_Engineering
12 - Introduction_to_Computer_Graphics
13 - Computer_Engineering:Hardware_Design
14 - UNIX_Internals
15 - Compilers:Principles,_Techniques,_and_Tools
16 - Modern_Operating_Systems
17 - Data_Structures_with_C++
18 - Operating_System_Concepts
19 - Modern_Information_Retrieval
To view a book's information enter its number or -1 to quit : 14
Inventory number: 14
ISBN: 0-13-101908-2
Title: UNIX_Internals
Author: Vahalia
Publisher: Prentice_Hall
Price: $ 61.00
Number of copies available: 67
How many would you like to order (0 - 67) : 1
01 - C_How_To_Program
02 - Unix_In_A_Nutshell
03 - The_C_Programming_Language
04 - Learning_the_UNIX_Operating_System
05 - Programming_Languages:Concepts_&_Constructs
06 - Computer_Architecture_A_Quantitative_Approach
07 - Computer_Networks
08 - A_First_Course_in_Database_Systems
09 - Introduction_To_Algorithms
10 - Introduction_to_Automata_Theory
11 - Software_Engineering
12 - Introduction_to_Computer_Graphics
13 - Computer_Engineering:Hardware_Design
14 - UNIX_Internals
15 - Compilers:Principles,_Techniques,_and_Tools
16 - Modern_Operating_Systems
17 - Data_Structures_with_C++
18 - Operating_System_Concepts
19 - Modern_Information_Retrieval
To view a book's information enter its number or -1 to quit : -1
linux1[72] more inventory.dat
19
1 0-12-089572-5 C_How_To_Program Deitel_&_Deitel Prentice_Hall 72.00 50
2 1-56392-001-5 Unix_In_A_Nutshell Gilly O'Reilly 20.95 15
3 0-17-110362-6 The_C_Programming_Language Kernighan_&_Ritchie Prentice_Hall 40.00 73
4 1-56392-390-1 Learning_the_UNIX_Operating_System Peek_Todino_&_Strong O'Reilly 11.96 24
5 0-201-59065-4 Programming_Languages:Concepts_&_Constructs Sethi Addison_Wesley 86.00 52
6 1-55860-329-8 Computer_Architecture_A_Quantitative_Approach Hennesy_&_Patterson Morgan_Kaufmann 83.95 37
7 0-13-162959-X Computer_Networks Tanenbaum Prentice_Hall 89.00 39
8 0-13-861337-0 A_First_Course_in_Database_Systems Ullman_&_Widom Prentice_Hall 65.00 84
9 0-262-03141-8 Introduction_To_Algorithms Cormen_Leiserson_&_Rivest McGraw_Hill 69.95 51
10 0-201-02988-X Introduction_to_Automata_Theory Hopcroft_&_Ullman Addison_Wesley 49.00 48
11 0-201-42765-6 Software_Engineering Sommerville Addison_Wesley 84.00 78
12 0-201-60921-5 Introduction_to_Computer_Graphics Foley_et_al Addison_Wesley 47.95 59
13 0-13-162926-3 Computer_Engineering:Hardware_Design Mano Prentice_Hall 101.67 79
14 0-13-101908-2 UNIX_Internals Vahalia Prentice_Hall 61.00 67
15 0-201-10088-6 Compilers:Principles,_Techniques,_and_Tools Aho_Sethi_&_Ullman Addison_Wesley 75.00 83
16 0-13-145721-4 Modern_Operating_Systems Tanenbaum Prentice_Hall 78.00 59
17 0-02-420971-6 Data_Structures_with_C++ Ford_&_Topp Prentice_Hall 75.00 53
18 0-201-56835-3 Operating_System_Concepts Silberschatz_et_al Addison_Wesley 96.60 83
19 0-201-48792-5 Modern_Information_Retrieval Baeza-Yates_et_al Addison_Wesley 50.00 42
linux1[73] % more invoice.txt
Title qty unit price
Compilers:Principles,_Techniques,_and_Tools 10 @ 75.00 750.00
Introduction_To_Algorithms 5 @ 69.95 349.75
Learning_the_UNIX_Operating_System 4 @ 11.96 47.84
UNIX_Internals 1 @ 61.00 61.00
--------------------------------------------------------------------------------
Subtotal 1208.59
Sales tax 60.43
--------------------
Total $ 1269.02
linux1[74] % more newInventory.dat
19
1 0-12-089572-5 C_How_To_Program Deitel_&_Deitel Prentice_Hall 72.00 50
2 1-56392-001-5 Unix_In_A_Nutshell Gilly O'Reilly 20.95 15
3 0-17-110362-6 The_C_Programming_Language Kernighan_&_Ritchie Prentice_Hall 40.00 73
4 1-56392-390-1 Learning_the_UNIX_Operating_System Peek_Todino_&_Strong O'Reilly 11.96 20
5 0-201-59065-4 Programming_Languages:Concepts_&_Constructs Sethi Addison_Wesley 86.00 52
6 1-55860-329-8 Computer_Architecture_A_Quantitative_Approach Hennesy_&_Patterson Morgan_Kaufmann 83.95 37
7 0-13-162959-X Computer_Networks Tanenbaum Prentice_Hall 89.00 39
8 0-13-861337-0 A_First_Course_in_Database_Systems Ullman_&_Widom Prentice_Hall 65.00 84
9 0-262-03141-8 Introduction_To_Algorithms Cormen_Leiserson_&_Rivest McGraw_Hill 69.95 46
10 0-201-02988-X Introduction_to_Automata_Theory Hopcroft_&_Ullman Addison_Wesley 49.00 48
11 0-201-42765-6 Software_Engineering Sommerville Addison_Wesley 84.00 78
12 0-201-60921-5 Introduction_to_Computer_Graphics Foley_et_al Addison_Wesley 47.95 59
13 0-13-162926-3 Computer_Engineering:Hardware_Design Mano Prentice_Hall 101.67 79
14 0-13-101908-2 UNIX_Internals Vahalia Prentice_Hall 61.00 66
15 0-201-10088-6 Compilers:Principles,_Techniques,_and_Tools Aho_Sethi_&_Ullman Addison_Wesley 75.00 73
16 0-13-145721-4 Modern_Operating_Systems Tanenbaum Prentice_Hall 78.00 59
17 0-02-420971-6 Data_Structures_with_C++ Ford_&_Topp Prentice_Hall 75.00 53
18 0-201-56835-3 Operating_System_Concepts Silberschatz_et_al Addison_Wesley 96.60 83
19 0-201-48792-5 Modern_Information_Retrieval Baeza-Yates_et_al Addison_Wesley 50.00 42
Although your output need not be identical to the above,
all information (including the greeting) must be present.
Please be aware that this is definitely NOT a complete
test of the program. Your testing should be much more extensive.
Input Guarantees
- The first item in the inventory file is the number of records in the
file. It is an integer.
- Any inventory file we use will have the same format as the one provided,
inventory.dat
- Graders will enter only integers as book choices
Further Specifications
- You must use separate compilation for this project. You may have as
many .c and .h files as you want to fit your project design. Your file
that contains main() should be called proj3.c You must have at least 3
files.
- You MUST have a function called OpenInventoryFile which has the
following function prototype:
FILE* OpenInventoryFile (int *numPtr);
where num is the number of records in the file.
You may not change this prototype in any way.
- The inventory.dat file has the following information:
- The first item in the file is the integer number of records in the
file.
- After that, each record is on one line and is made up of the
following data in this order:
- inventory number (positive integer)
- ISBN number (a string of not more than 14 characters)
- title (a string of not more than 49 characters)
- author (a string of not more than 34 characters)
- publisher (a string of not more than 19 characters)
- the unit price of the book (float expressed to 2 decimal places)
- the number of copies in stock (non-negative integer)
- You may get a copy of the inventory.dat file from my account. The file is in the
/afs/umbc.edu/users/s/b/sbogar1/pub directory.
- You MUST use dynamic memory allocation (malloc or calloc) to
allocate the memory to hold the array of structures after you have read
the number of records from the file (num). HINT: num is modified by the
function OpenInventoryFile() since it is passed by reference into that
function.
- The filename "inventory.dat" should be hard-coded in the function
OpenInventoryFile().
- If any file fails to open, you should print an appropriate message to
the screen and exit the program.
- The invoice is to be written to a file called invoice.txt (not to the
screen).
- After the user has completed ordering and the invoice.txt file has
been produced, you must generate a new inventory file called
newInventory.dat
- You must close all files as soon as you are finished either reading
from them or writing to them.
- On normal (non-error) execution of the program, you must free all
memory that you allocated dynamically.
Submitting the Program
Here is a sample submission command. Since you may have different file names
you'll have to adjust it to fit your needs. As always, be sure to submit all
of the files necessary for your project to compile.
Note that the project name starts with uppercase 'P'.
submit cs201 Proj3 proj3.c bookstore.c bookstore.h
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show the file that
you submitted in a format similar to the Unix 'ls' command.
submitls cs201 Proj3