UMBC CMSC 104 CSEE | 104 | current 104

CMSC104, Spring 2009

Programming Project 2

Book Ordering Software

Out: Wednesday, April 15, 2009
Due: Wednesday, April 22, 2009 before 11:59 p.m.


The Objective

This project is designed to give you practice writing a C program on your own. It will also give you practice using a while loop with a sentinel value and Unix redirection.

The Task

Your job is to write a program that will read in the prices of several books purchased from an online bookstore. You will then display the receipt, listing the subtotal, the tax, the cost of shipping and the total cost of the order. You should also print out some statistical information regarding the book order. You should include the total number of books purchased, the average book price, the minimum book price and the maximum book price.

More Details

Input to the Program

A data file containing the items for you to use as input to your program will be provided. The items are all greater than 0. The last value in the file will be -1. This is the sentinel value that signals the program to stop reading items.

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.dat
    
This 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

Sample Output


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 to  Booksellers!!
	
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]%

Submitting the Program

Your program should be in a file called proj2.c.

Here is a sample submission command. Note that the project name starts with uppercase 'P'.

submit cs104_101 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_101 Proj2