CS 157 Spring 2001                       Assignment 6 – Validation, For, and Switch, Oh My!                                         100 points

 

Assigned: 02/28/2001

Due: 03/07/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:

We are writing a program to keep track of gasoline sales for a service station. Your program will operate as shown below. It will request the number of customers, then loop through that many customers, getting as input: an indication of whether the gas required is regular, plus, or premium (with integers, see below), and how many gallons of gas were pumped.  Your program will display for the customer the customer number, price, gallons, and total cost. Current costs are $1.399 / gal for regular, $1.499 / gal for plus, and $1.599 / gal for super. After all customers have been processed, your program will print a report showing subtotals (number customers, gallons, and revenues) for each type of gas for the customer (see below), and total revenues. All inputs should be validated to ensure that even the most dimwitted typist cannot get invalid inputs past the program. Gallons purchased can range from 0.5 gallons to 30.0 gallons.

 

Sample interaction with the user:

Welcome to the GasCo Calculator Program

 

How many customers to process right now? 3

 

Please enter gas type (1 - regular; 2 - plus; 3 - super): 1

 

Please enter number of gallons purchased (between 1/2 and 30): 20.1

 

customer:   1   price:  1.399   gallons:  20.1   total:  28.12

 

Please enter gas type (1 - regular; 2 - plus; 3 - super): 2

 

Please enter number of gallons purchased (between 1/2 and 30): 10.5

 

customer:   2   price:  1.499   gallons:  10.5   total:  15.74

 

Please enter gas type (1 - regular; 2 - plus; 3 - super): 4

 

Please enter gas type (1 - regular; 2 - plus; 3 - super): 1

 

Please enter number of gallons purchased (between 1/2 and 30): 31.0

 

Please enter number of gallons purchased (between 1/2 and 30): 29.5

 

customer:   3   price:  1.399   gallons:  29.5   total:  41.27

 

=======================================================================

 

Totals:

 

                Type of Gas              # Customers               Num Gallons       Revenues

                ===========        ==========          ==========             =======             

                Regular                                 2                         49.6                   69.39

                Plus                                        1                         10.5                   15.74

                Super                                     0                           0.0                       0.00

                                                                                                                      =======

                                                                                                                           85.13

 

=======================================================================

 

Hand-in:

     1) Listing of the program

     2) Disk with  .c source file plus .exe executable file.

 

NAME YOUR PROGRAM FILE yourlastname6.c

 

Miscellaneous:

                                1. It is intended that you use at least one switch and at least one for statement.  Do it.

2. Make the output of your program like mine. It should be in neat columns – use printf formatting to line up the numbers.

3. Don’t try to get inputs as characters; there are complexities that we haven’t talked about yet.

4. 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 (except letters). Ask the questions in the exact order shown, otherwise I will get confused grading your program.

5. Remember: Indentation, meaningful variable names, 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 and e-mail address in comments at the beginning of the program.