Programming Project 2
Book Ordering Software
#define SHIP_COST 7.00 #define FREE_SHIP_LIMIT 25.00
To use the data file as input to your program, you will use Unix redirection.
By using redirection, you can get input from a file rather
than from the keyboard. The scanf
statement that you use in
your program will look exactly the same as it would if you were getting
your input from the keyboard. Since you will be getting the values
from a file instead of from a user typing at the keyboard, you will not
need to prompt the user.
For instance, if the data file was called books1.dat
, you
would run your program, using the following command:
a.out < books1.datThis is how Unix redirection is done. It is saying to run your executable file using the file
books1.dat
as input.
I have provided two data files for this project. The first, books1.dat
, is an order that qualifies for free shipping. The second,
books2.dat
, is an order that does not qualify for free shipping. You
will need to copy the files into your directory. To do this, go to the
directory where you would like to store the data files. Then, use the
following command to copy them into the directory:
cp /afs/umbc.edu/users/d/b/dblock/pub/CS104/Proj2/books*.dat .Notice that the space and period at the end of the command are part of the command.
Here is a example of what the input data file could look like:
12.95 16.00 24.95 9.95 13.95 59.93 -1
linux2[130]% cat books1.dat 12.95 16.00 24.95 9.95 13.95 59.93 -1 linux2[131]% gcc proj2.c linux2[132]% a.out < books1.dat Welcome toBooksellers!! Your receipt: Subtotal: $ 137.73 Tax: $ 6.89 Shipping: FREE! Final total: $ 144.62 Some statistics regarding your order: The total number of books ordered: 6 The average book price: $ 22.96 The minium book price: $ 9.95 The maximum book price: $ 59.93 Thank you for placing your book order! linux2[133]% cat books2.dat 12.95 9.95 -1 linux2[134]% a.out < books2.dat Welcome to Booksellers!! Your receipt: Subtotal: $ 22.90 Tax: $ 1.14 Shipping: $ 7.00 Final total: $ 31.05 Some statistics regarding your order: The total number of books ordered: 2 The average book price: $ 11.45 The minium book price: $ 9.95 The maximum book price: $ 12.95 Thank you for placing your book order! linux2[135]%
Here is a sample submission command. Note that the project name starts with uppercase 'P'.
submit cs104_0101/0501 Proj2 proj2.c
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 cs104_0101/0501 Proj2