CS 157 Spring 2001 Assignment 8 – Writing Functions (and previous material) 100 points
Assigned: 03/21/2001
Due: 03/28/2001 at the start of class.
Pre-Lab (Do Before Lab): Bring an empty (or nearly empty) disk (keep any .c files you create, but other files can be deleted). Plan out sequence of statements needed for program.
Main Assignment:
NapsterII is working on
a new program in conjunction with the coming “pay for music” system. Your
program is a simplification dealing with customer billing. It should ask the
user how many people will be processed in a batch. Then, for each person, the
program should ask the user for the number of songs downloaded and the number
of minutes connected to the - see below. The program should then call a
function to calculate the cost for the current month (see details below). After
processing all of the people in the batch, the program should display a report
including how many people were processed, the total number of songs downloaded,
the total minutes connected, the total costs charged, and averages (details
below).
Sample interaction with the user:
How many people
will be logged in this batch? 3
Person 1
Number of Downloads This Month Please Enter
Between 0 and 1000: 16
Number of Minutes Connected Please Enter
Between 0 and 40000: 81
Cost: 47.81
Ave Cost Per
Song: 2.99
Person 2
Number of Downloads This Month Please Enter
Between 0 and 1000: 3
Number of Minutes Connected Please Enter
Between 0 and 40000: 40
Cost: 19.40
Ave Cost Per
Song: 6.47
Person 3
Number of Downloads This Month Please Enter
Between 0 and 1000: -1
Please Enter Between 0 and 1000: 10
Number of Minutes Connected Please Enter
Between 0 and 40000: 200
Cost: 37.00
Ave Cost Per
Song: 3.70
Final Report
------------
Customers Songs
Minutes Cost
========= =====
======== ======
Total 3 29 321 104.21
Average 9.67 107.00 34.74
Average Cost
Per Song: 3.59
Goodbye
Details:
1) Use doubles for anything that COULD be a
non-whole number (money ...). Minutes can be a whole number.
2) This is an exercise in writing and using
C functions. You must write and use a function to calculate the monthly cost.
You may use functions for other parts of the task.
3) You must pass parameters to functions.
Using global variables inside a function is a poor practice making functions
less reusable, and more likely to produce bugs.
4) The schedule for monthly cost is as
follows:
Base cost - $10
Plus
$0.01 per minute connected
downloading songs
$3 per song for first 5 songs
downloaded in a month
$2 for each additional song
above 5
5) Write your cost function so that number
of songs and minutes connected are parameters and the cost is returned. Don’t
do input and output in that function.
6) Details of what you should present in
the bill and the final report are shown in the example below. Do not free-lance
on this. Your output should be pretty darn close to mine.
7) Your program should ensure that the user
types in valid data (i.e. non-negative number of songs, and minutes, and lets
say minutes less than 40000 J and songs less than 1000). Loop
to ensure they cannot in any circumstances get invalid data into your
calculations. Use function(s) if you want.
Hand-in:
1) Listing of the program
2) Disk with whole project on it
(including .c source file plus other project files). Note that you may need to
follow instructions under “Saving Space” when creating the project.
NAME YOUR PROGRAM FILE
yourlastname8.c; Name your project yourlastname8.
Miscellaneous:
Make
your program work like shown above. If you have any questions about what should
be done, please ask!!
MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just
removing compile errors). You can test your program on the above example, but
make sure you test it on other data as well - I will! Your program needs to be
able to handle any inputs
including catching invalid inputs.
Remember:
Indentation, meaningful variable names, symbolic constants, and meaningful
comments. Weaknesses in any of these could result in points off. You MUST include
comments that explain your program in order to get full credit. Also make sure
you put YOUR NAME, section, and e-mail address in comments at the beginning of
the program.